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 andViews based onusize. - ops
- Generic programming over binary arithmetic operators.
- view
Macros§
- impl_
memoryview - A helper macro for implementing
ViewRefandViewMut. - impl_
op_ for_ view - Implement one of the
std::opstraits for a type that implementsView. - impl_
ops_ for_ memoryview - A helper macro for implementing
std::ops::Indexandstd::ops::IndexMutin terms of [View] and [ViewMut]. - impl_
ops_ for_ view - Implement all of the
std::opstraits for a type that implementsView. The implementations callView::binary().
Structs§
- All
- The return type of
Index::all(). - Array
- A dense array of
Ts indexed byI. - Coated
Coated<I>behaves likeIin most respects, but implementsNonTuple.
Traits§
- Broadcast
SelfimplementsBroadcast<Other>to say what happens when you zip aViewindexed bySelfwith one indexed byOther.- Coat
- Implemented by types that differ from
Tby adding or removing at most one level ofCoated. - 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. - Static
Index - Implemented by types that can be used as an index for an
Arrayand where the size of theArrayis a compile-time constant.