Crate multidimension

Source
Expand description

A pure-Rust library providing high-level manipulation of multi-dimensional arrays.

Array<I, T> represents an array of T indexed by I. The T values are internally stored in a [Box<[T]>], which is a dense 1-dimensional representation. The purpose of the Array wrapper is to look like a multi-dimensional collection. To achieve this, the index type I can be any type that implements Index. This includes scalar types such as usize and bool, but also tuples of other types that implement Index. You are encouraged to write your own index types.

Trait View is the main way to access and manipulate Arrays. Unlike Array, a View doesn’t store anything, but instead computes values on demand. In this respect it is a bit like std::iter::Iterator, and indeed View offers some of the same methods as Iterator, including View::map(), View::zip() and View::collect(). However, unlike Iterator, Views are immutable; getting values using View::at() does not mutate the View. You are encouraged to use Views compositionally, like Iterators, and to collect() the results into an Array only at the end of a chain of operations.

All types in this crate which implement View (including Array) define all of Rust’s arithmetic operators (+, * etc.) to mean pointwise arithmetic on the elements. When applied to Views with different Index types, elements are replicated as necessary using a Broadcast rule, similarly to NumPy.

Indexes are often tuples or nested tuples. Trait Isomorphic defines conversions between different tuple structures. For example, ((A,), B, C) implements Isomorphic<(A, (B, C))>. Methods of View exploit tuple isomorphism to ergonomically express which groups of Indexes to apply operations to. The main thing you can’t do with tuple isomorphism is to reorder the Indexes; for this you need to use View::transpose(). Either way, the code to manipulate the array indices is all automatically generated at compile-time, and should mostly be optimized away by the compiler.

Re-exports§

pub use view::Push;
pub use view::NewView;
pub use view::View;
pub use view::ViewRef;
pub use view::ViewMut;
pub use view::Scalar;
pub use view::fn_view;

Modules§

int
A variety of Indexes and Views based on usize.
ops
Generic programming over binary arithmetic operators.
view

Macros§

impl_memoryview
A helper macro for implementing ViewRef and ViewMut.
impl_op_for_view
Implement one of the std::ops traits for a type that implements View.
impl_ops_for_memoryview
A helper macro for implementing std::ops::Index and std::ops::IndexMut in terms of [View] and [ViewMut].
impl_ops_for_view
Implement all of the std::ops traits for a type that implements View. The implementations call View::binary().

Structs§

All
The return type of Index::all().
Array
A dense array of Ts indexed by I.
Coated
Coated<I> behaves like I in most respects, but implements NonTuple.

Traits§

Broadcast
Self implements Broadcast<Other> to say what happens when you zip a View indexed by Self with one indexed by Other.
Coat
Implemented by types that differ from T by adding or removing at most one level of Coated.
Index
Implemented by types that can be used as an index for an Array.
Isomorphic
Relates two types if they have the same canonical form.
NonTuple
Implemented by types that have no tuple-like structure.
Size
The run-time size of an array axis. An array axis with a compile-time constant size can simply use (), which implements this trait.
StaticIndex
Implemented by types that can be used as an index for an Array and where the size of the Array is a compile-time constant.