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§
Sourcefn shape(&self) -> &[usize]
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(), &[]);Provided Methods§
Sourcefn ndims(&self) -> usize
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);Sourcefn len(&self) -> usize
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);Sourcefn size(&self) -> usize
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);Sourcefn is_contiguous(&self) -> bool
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());Sourcefn is_view(&self) -> bool
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());Sourcefn is_uniformly_strided(&self) -> bool
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());Sourcefn has_uniform_stride(&self) -> Option<usize>
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.