StridedMemory

Trait StridedMemory 

Source
pub trait StridedMemory: Sized {
    // Required methods
    fn shape(&self) -> &[usize];
    fn stride(&self) -> &[usize];
    fn flags(&self) -> NdArrayFlags;

    // Provided methods
    fn ndims(&self) -> usize { ... }
    fn len(&self) -> usize { ... }
    fn size(&self) -> usize { ... }
    fn is_contiguous(&self) -> bool { ... }
    fn is_view(&self) -> bool { ... }
    fn is_uniformly_strided(&self) -> bool { ... }
    fn has_uniform_stride(&self) -> Option<usize> { ... }
}

Required Methods§

Source

fn shape(&self) -> &[usize]

Returns the dimensions of the ndarray along each axis.


let a = NdArray::new([3, 4, 5]);
assert_eq!(a.shape(), &[3]);

let b = NdArray::new([[3], [5]]);
assert_eq!(b.shape(), &[2, 1]);

let c = NdArray::scalar(0);
assert_eq!(c.shape(), &[]);
Source

fn stride(&self) -> &[usize]

Returns the stride of the ndarray.

The stride represents the distance in memory between elements in an ndarray along each axis.


let a = NdArray::new([[3, 4], [5, 6]]);
assert_eq!(a.stride(), &[2, 1]);
Source

fn flags(&self) -> NdArrayFlags

Returns flags containing information about various ndarray metadata.

Provided Methods§

Source

fn ndims(&self) -> usize

Returns the number of dimensions in the ndarray.

let a = NdArray::new([3, 4, 5]);
assert_eq!(a.ndims(), 1);

let b = NdArray::new([[3], [5]]);
assert_eq!(b.ndims(), 2);

let c = NdArray::scalar(0);
assert_eq!(c.ndims(), 0);
Source

fn len(&self) -> usize

Returns the length along the first dimension of the ndarray. If the ndarray is a scalar, this returns 0.

§Examples
let a = NdArray::new([3, 4, 5]);
assert_eq!(a.len(), 3);

let b = NdArray::new([[3], [5]]);
assert_eq!(b.len(), 2);

let c = NdArray::scalar(0);
assert_eq!(c.len(), 0);
Source

fn size(&self) -> usize

Returns the total number of elements in the ndarray.

let a = NdArray::new([3, 4, 5]);
assert_eq!(a.size(), 3);

let b = NdArray::new([[3], [5]]);
assert_eq!(b.size(), 2);

let c = NdArray::scalar(0);
assert_eq!(c.size(), 1);
Source

fn is_contiguous(&self) -> bool

Returns whether this ndarray is stored contiguously in memory.

let a = NdArray::new([[3, 4], [5, 6]]);
assert!(a.is_contiguous());

let b = a.slice_along(Axis(1), 0);
assert!(!b.is_contiguous());
Source

fn is_view(&self) -> bool

Returns whether this ndarray is slice of another ndarray.

let a = NdArray::new([[3, 4], [5, 6]]);
assert!(!a.is_view());

let b = a.slice_along(Axis(1), 0);
assert!(b.is_view());
Source

fn is_uniformly_strided(&self) -> bool

Whether the elements of this ndarray are stored in memory with a uniform distance between them.

Contiguous arrays are always uniformly strided. Views may sometimes be uniformly strided.

let a = NdArray::new([[3, 4, 5], [6, 7, 8]]);
assert!(a.is_uniformly_strided());

let b = a.slice_along(Axis(1), 0);
assert!(b.is_uniformly_strided());

let c = a.slice_along(Axis(1), ..2);
assert!(!c.is_uniformly_strided());
Source

fn has_uniform_stride(&self) -> Option<usize>

If the elements of this ndarray are stored in memory with a uniform distance between them, returns this distance.

Contiguous arrays always have a uniform stride of 1. NdArray views may sometimes be uniformly strided.

let a = NdArray::new([[3, 4, 5], [6, 7, 8]]);
assert_eq!(a.has_uniform_stride(), Some(1));

let b = a.slice_along(Axis(1), 0);
assert_eq!(b.has_uniform_stride(), Some(3));

let c = a.slice_along(Axis(1), ..2);
assert_eq!(c.has_uniform_stride(), None);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§