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 Array
s. 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
, View
s are immutable; getting values using View::at()
does
not mutate the View
. You are encouraged to use View
s compositionally,
like Iterator
s, 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 View
s with different
Index
types, elements are replicated as necessary using a Broadcast
rule, similarly to NumPy
.
Index
es 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
Index
es to apply operations to. The main thing you can’t do with
tuple isomorphism is to reorder the Index
es; 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
Index
es andView
s based onusize
. - ops
- Generic programming over binary arithmetic operators.
- view
Macros§
- impl_
memoryview - A helper macro for implementing
ViewRef
andViewMut
. - impl_
op_ for_ view - Implement one of the
std::ops
traits for a type that implementsView
. - impl_
ops_ for_ memoryview - A helper macro for implementing
std::ops::Index
andstd::ops::IndexMut
in terms of [View
] and [ViewMut
]. - impl_
ops_ for_ view - Implement all of the
std::ops
traits for a type that implementsView
. The implementations callView::binary()
.
Structs§
- All
- The return type of
Index::all()
. - Array
- A dense array of
T
s indexed byI
. - Coated
Coated<I>
behaves likeI
in most respects, but implementsNonTuple
.
Traits§
- Broadcast
Self
implementsBroadcast<Other>
to say what happens when you zip aView
indexed bySelf
with one indexed byOther
.- Coat
- Implemented by types that differ from
T
by 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
Array
and where the size of theArray
is a compile-time constant.