Array

Struct Array 

Source
pub struct Array<I: Index, T> { /* private fields */ }
Expand description

A dense array of Ts indexed by I.

Implementations§

Source§

impl<I: Index, T> Array<I, T>

Source

pub fn new(size: impl Isomorphic<I::Size>, items: impl Into<Box<[T]>>) -> Self

Constructs an Array of size size given its elements.

use multidimension::{Index, Array};
let a: Array<(usize, bool), f32> = Array::new(3, [0.0, 1.0, -1.0, 2.0, 3.0, -2.0]);
assert_eq!(a[(0, false)], 0.0);
assert_eq!(a[(0, true)], 1.0);
assert_eq!(a[(1, false)], -1.0);
assert_eq!(a[(1, true)], 2.0);
assert_eq!(a[(2, false)], 3.0);
assert_eq!(a[(2, true)], -2.0);
Source

pub fn from_fn(size: impl Isomorphic<I::Size>, f: impl FnMut(I) -> T) -> Self

Construct an Array of size size from a function.

Consider also fn_view().

use multidimension::{Index, Array};
let a: Array<usize, _> = Array::from_fn(10, |x| x % 3 == 0);
assert_eq!(a.as_ref(), [true, false, false, true, false, false, true, false, false, true]);
Source

pub fn to_raw(self) -> Box<[T]>

Returns the raw array elements.

Source

pub fn iso<J>(self) -> Array<J, T>
where J: Isomorphic<I> + Index, J::Size: Isomorphic<<I as Index>::Size>,

Change the index type of this array without moving any of the items.

Trait Implementations§

Source§

impl<RHS: View, I: Index, T> Add<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Add<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Add>

The resulting type after applying the + operator.
Source§

fn add(self, other: RHS) -> Self::Output

Performs the + operation. Read more
Source§

impl<I: Index, T> AsMut<[T]> for Array<I, T>

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<I: Index, T> AsRef<[T]> for Array<I, T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<RHS: View, I: Index, T> BitAnd<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: BitAnd<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, BitAnd>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: RHS) -> Self::Output

Performs the & operation. Read more
Source§

impl<RHS: View, I: Index, T> BitOr<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: BitOr<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, BitOr>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: RHS) -> Self::Output

Performs the | operation. Read more
Source§

impl<RHS: View, I: Index, T> BitXor<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: BitXor<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, BitXor>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: RHS) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<I: Clone + Index, T: Clone> Clone for Array<I, T>
where I::Size: Clone,

Source§

fn clone(&self) -> Array<I, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug + Index, T: Debug> Debug for Array<I, T>
where I::Size: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<RHS: View, I: Index, T> Div<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Div<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Div>

The resulting type after applying the / operator.
Source§

fn div(self, other: RHS) -> Self::Output

Performs the / operation. Read more
Source§

impl<I: Index, T> Index<<Array<I, T> as View>::I> for Array<I, T>
where Self: ViewRef,

Source§

type Output = <Array<I, T> as View>::T

The returned type after indexing.
Source§

fn index(&self, index: <Self as View>::I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: Index, T> IndexMut<<Array<I, T> as View>::I> for Array<I, T>
where Self: ViewMut,

Source§

fn index_mut(&mut self, index: <Self as View>::I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<RHS: View, I: Index, T> Mul<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Mul<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Mul>

The resulting type after applying the * operator.
Source§

fn mul(self, other: RHS) -> Self::Output

Performs the * operation. Read more
Source§

impl<I: Index, T: Clone> NewView for Array<I, T>

Source§

type Buffer = Vec<T>

The type of a partially constructed Self.
Source§

fn new_view(size: I::Size, callback: impl FnOnce(&mut Self::Buffer)) -> Self

Construct a Self of size size. Read more
Source§

impl<RHS: View, I: Index, T> Rem<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Rem<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Rem>

The resulting type after applying the % operator.
Source§

fn rem(self, other: RHS) -> Self::Output

Performs the % operation. Read more
Source§

impl<RHS: View, I: Index, T> Shl<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Shl<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Shl>

The resulting type after applying the << operator.
Source§

fn shl(self, other: RHS) -> Self::Output

Performs the << operation. Read more
Source§

impl<RHS: View, I: Index, T> Shr<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Shr<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Shr>

The resulting type after applying the >> operator.
Source§

fn shr(self, other: RHS) -> Self::Output

Performs the >> operation. Read more
Source§

impl<RHS: View, I: Index, T> Sub<RHS> for Array<I, T>
where Self: View, <Self as View>::I: Broadcast<RHS::I>, <Self as View>::T: Sub<RHS::T>,

Source§

type Output = Zip<Array<I, T>, RHS, Sub>

The resulting type after applying the - operator.
Source§

fn sub(self, other: RHS) -> Self::Output

Performs the - operation. Read more
Source§

impl<I: Index, T: Clone> View for Array<I, T>

Source§

type I = I

The index type.
Source§

type T = T

The element type.
Source§

fn size(&self) -> I::Size

The size of the array.
Source§

fn len(&self) -> usize

The number of elements in Self.
Source§

fn at(&self, index: I) -> T

Compute the element at index.
Source§

fn collect<A>(&self) -> A
where A: NewView<I = Self::I, T = Self::T>,

Materialises this View into a collection of type A, e.g. an Array. Read more
Source§

fn nested(self) -> Nested<Self>
where Self: ViewRef, Self::T: View, <<Self::T as View>::I as Index>::Size: Isomorphic<()>,

Creates a View that represents this nested View. Read more
Source§

fn nested_collect<A>(self, size: <<Self::T as View>::I as Index>::Size) -> A
where Self::T: View, A: NewView<I = (Self::I, <Self::T as View>::I), T = <Self::T as View>::T>,

Materialises this nested View into a collection of type A, e.g. an Array. Read more
Source§

fn each(self, f: impl FnMut(Self::T))

Apply f to every element of this View in turn. Read more
Source§

fn enumerate(self) -> Enumerate<Self>

Creates a View with the same Index type as self such that at(i) returns (i, self.at(i)). Read more
Source§

fn diagonal(self, zero: Self::T) -> Diagonal<Self>

Returns a View that maps (i, i) to t when Self maps i to t. It maps (i, j) to zero if i != j. Read more
Source§

fn map<U: Clone, F>(self, f: F) -> Map<Self, F>
where F: Fn(Self::T) -> U,

Creates a View that applies f to the elements of Self. Read more
Source§

fn compose<V: View<I = Self::T>>(self, other: V) -> Compose<Self, V>

Creates a View that uses self to select elements of other. Read more
Source§

fn concat<V: View<T = Self::T>, I: Index, J: Index>( self, other: V, ) -> Concat<Self, V, I, J>
where Self::I: Isomorphic<(I, usize, J)>, <Self::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>, V::I: Isomorphic<(I, usize, J)>, <V::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>,

Concatenates self with other along an axis of type usize. Read more
Source§

fn from_usize<I: Index, X: Index, J: Index>( self, from_length: impl FnOnce(usize) -> X::Size, ) -> FromUsize<Self, I, X, J>
where Self::I: Isomorphic<(I, usize, J)>, <Self::I as Index>::Size: Isomorphic<<(I, usize, J) as Index>::Size>,

Replace an axis Indexed by usize with one indexed by X. Read more
Source§

fn to_usize<I: Index, X: Index, J: Index>(self) -> ToUsize<Self, I, X, J>
where Self::I: Isomorphic<(I, X, J)>, <Self::I as Index>::Size: Isomorphic<<(I, X, J) as Index>::Size>,

Replace an axis Indexed by X with one indexed by usize. Read more
Source§

fn insert_one<I: Index, J: Index, K: Index>( self, size: J::Size, ) -> InsertOne<Self, I, J, K>
where Self::I: Isomorphic<(I, K)>, <Self::I as Index>::Size: Isomorphic<(I::Size, K::Size)>,

Insert an axis of type J and length 1. Read more
Source§

fn remove_one<I: Index, J: Index, K: Index>(self) -> RemoveOne<Self, I, J, K>
where Self::I: Isomorphic<(I, J, K)>, <Self::I as Index>::Size: Isomorphic<(I::Size, J::Size, K::Size)>,

Remove an axis of type J and length 1. Read more
Source§

fn map_axis<I: Index, V: View, J: Index>( self, other: V, ) -> MapAxis<Self, I, V, J>
where V::T: Index, Self::I: Isomorphic<(I, V::T, J)>, <Self::I as Index>::Size: Isomorphic<(I::Size, <V::T as Index>::Size, J::Size)>,

Creates a view such that at((i, x, j)) gives self.at((i, other.at(x), j)). Read more
Source§

fn zip<V: View>(self, other: V) -> Zip<Self, V, Pair>
where Self::I: Broadcast<V::I>,

Creates a View that pairs of an element of self and an element of other. Read more
Source§

fn binary<V: View, B>(self, other: V) -> Zip<Self, V, B>
where Self::I: Broadcast<V::I>, B: Binary<Self::T, V::T>,

Creates a View that pairs of an element of self and an element of other, then applies binary operator B. Read more
Source§

fn coat<I>(self) -> Coat<Self, I>
where I: Coat<Self::I> + Index, Self::I: Coat<I>, I::Size: Coat<<Self::I as Index>::Size>, <Self::I as Index>::Size: Coat<I::Size>,

Wrap some of the Indexes of this View in Coated. Read more
Source§

fn iso<J>(self) -> Iso<Self, J>
where J: Isomorphic<Self::I> + Index, J::Size: Isomorphic<<Self::I as Index>::Size>,

Change the index type of this View to an Isomorphic type.
Source§

fn transpose<I: Index, X: Index, Y: Index, J: Index>( self, ) -> Transpose<Self, I, X, Y, J>
where (I, (Y, X), J): Isomorphic<Self::I>, (I::Size, (Y::Size, X::Size), J::Size): Isomorphic<<Self::I as Index>::Size>,

Reorder the indices of this View up to Isomorphic. Read more
Source§

fn row<I: Index, J: Index>(self, i: I) -> Row<Self, I, J>
where (I, J): Isomorphic<Self::I>, (I::Size, J::Size): Isomorphic<<Self::I as Index>::Size>,

Returns a View whose at(j) returns self.at(i, j). Read more
Source§

fn rows<I: Index, J: Index>(&self) -> Rows<&Self, I, J>
where (I, J): Isomorphic<Self::I>, (I::Size, J::Size): Isomorphic<<Self::I as Index>::Size>,

Returns a View whose at(i) returns self.row(i).
Source§

fn column<I: Index, J: Index>(self, j: J) -> Column<Self, I, J>
where (I, J): Isomorphic<Self::I>, (I::Size, J::Size): Isomorphic<<Self::I as Index>::Size>,

Returns a View whose at(i) returns self.at(i, j). Read more
Source§

fn columns<I: Index, J: Index>(&self) -> Columns<&Self, I, J>
where (I, J): Isomorphic<Self::I>, (I::Size, J::Size): Isomorphic<<Self::I as Index>::Size>,

Returns a View whose at(j) returns self.column(j).
Source§

impl<I: Index, T: Clone> ViewMut for Array<I, T>

Source§

fn at_mut(&mut self, index: Self::I) -> &mut Self::T

Mutably borrow the element at index.
Source§

impl<I: Index, T: Clone> ViewRef for Array<I, T>

Source§

fn at_ref(&self, index: Self::I) -> &Self::T

Borrow the element at index.

Auto Trait Implementations§

§

impl<I, T> Freeze for Array<I, T>
where <I as Index>::Size: Freeze,

§

impl<I, T> RefUnwindSafe for Array<I, T>

§

impl<I, T> Send for Array<I, T>
where <I as Index>::Size: Send, T: Send,

§

impl<I, T> Sync for Array<I, T>
where <I as Index>::Size: Sync, T: Sync,

§

impl<I, T> Unpin for Array<I, T>
where <I as Index>::Size: Unpin,

§

impl<I, T> UnwindSafe for Array<I, T>
where <I as Index>::Size: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<I> Coat<Coated<I>> for I

Source§

fn coat(self) -> Coated<I>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.