Struct mudi::ArrayBase [] [src]

pub struct ArrayBase<S, D> where D: Dimensions, S: Storage {
    // some fields omitted
}

ArrayBase implements all the operations on arrays, using a Storage and some Dimensions.

Methods

impl<S, D> ArrayBase<S, D> where D: Dimensions, S: Storage

fn from_vector(vec: Vec<S::Item>, dims: D) -> ArrayBase<S, D>

Create a new array using content from the vector.

use mudi::Array;
// One-dimensional array, with shape (4).
let array = Array::from_vector(vec![1, 2, 3, 4], 4);
assert_eq!(array[2], 3);

// Two-dimensional array, with shape (2, 2)
let array = Array::from_vector(vec![1, 2, 3, 4], (2, 2));
assert_eq!(array[(1, 0)], 3);

Panics

If the size of the vector does not match the size of the dimensions.

use mudi::Array;
// The dimension size is 14 here, and the array only contains 4 elements
let array = Array::from_vector(vec![1, 2, 3, 4], (2, 7));

fn shape(&self) -> D

Get the shape of the array.

use mudi::Array;
let array = Array::from_vector(vec![1, 2, 3, 4], 4);
assert_eq!(array.shape(), 4);

let array = Array::from_element(vec![1, 2, 3, 4], (2, 7));
assert_eq!(array.shape(), (2, 7));

fn flat_iter(&self) -> Iter<S::Item>

Flat (linear) iteration over array elements.

use mudi::Array;
let mut array = Array::from_element(0, (3, 2));
for i in 0..3 {
    for j in 0..2 {
        array[(i, j)] = i;
    }
}

for value in array.flat_iter() {
    print!("{} ", value);
}
// This will print "0 0 1 1 2 2"

fn flat_iter_mut(&mut self) -> IterMut<S::Item>

Flat (linear) iteration over mutable array elements. See the documentation for Array::flat_iter.

impl<S, D> ArrayBase<S, D> where D: Dimensions, S: Storage, S::Item: Clone

fn from_element(element: S::Item, dims: D) -> ArrayBase<S, D>

Create a new array by cloning a specific element as needed.

use mudi::Array;
// Two-dimensional array, with shape (2, 6)
let array = Array::from_element(42, (2, 6));
assert_eq!(array[(1, 4)], 42);

Trait Implementations

impl<S, D, I: Copy> Index<I> for ArrayBase<S, D> where D: Dimensions<Index=I>, S: Storage

type Output = S::Item

fn index(&self, index: I) -> &S::Item

impl<S, D, I: Copy> IndexMut<I> for ArrayBase<S, D> where D: Dimensions<Index=I>, S: Storage

fn index_mut(&mut self, index: I) -> &mut S::Item

impl<S, D> PartialEq for ArrayBase<S, D> where D: Dimensions, S: Storage, S::Item: PartialEq

fn eq(&self, other: &ArrayBase<S, D>) -> bool

fn ne(&self, other: &Rhs) -> bool

Derived Implementations

impl<S: Debug, D: Debug> Debug for ArrayBase<S, D> where D: Dimensions, S: Storage

fn fmt(&self, __arg_0: &mut Formatter) -> Result