pub struct NDArray<T, const N: usize> { /* private fields */ }Expand description
A simple N-dimensional array type with shape, strides, and contiguous data storage.
§Example
use timsrust_utils::ndarray::NDArray;
let arr = NDArray::new([2, 3], vec![1, 2, 3, 4, 5, 6]).unwrap();
assert_eq!(arr[[1, 2]], 6);Implementations§
Source§impl<T, const N: usize> NDArray<T, N>
impl<T, const N: usize> NDArray<T, N>
Sourcepub fn new(shape: [usize; N], data: Vec<T>) -> Result<Self, NDArrayError>
pub fn new(shape: [usize; N], data: Vec<T>) -> Result<Self, NDArrayError>
Creates a new NDArray with the given shape and data.
§Arguments
shape- The shape of the array as an array of dimension sizes.data- The data to fill the array, must match the product of shape dimensions.
§Errors
Returns TimsUtilsError if the shape and data length are incompatible.
§Example
use timsrust_utils::ndarray::NDArray;
let arr = NDArray::new([2, 2], vec![1, 2, 3, 4]).unwrap();
assert_eq!(arr.shape(), [2, 2]);
assert_eq!(arr[[1, 1]], 4);Sourcepub fn shape(&self) -> [usize; N]
pub fn shape(&self) -> [usize; N]
Returns the shape of the array.
§Example
use timsrust_utils::ndarray::NDArray;
let arr = NDArray::new([2, 3], vec![1, 2, 3, 4, 5, 6]).unwrap();
assert_eq!(arr.shape(), [2, 3]);Sourcepub fn inverted_index(&self, idx: usize) -> [usize; N]
pub fn inverted_index(&self, idx: usize) -> [usize; N]
Source§impl<T: Default + Copy + AddAssign, const N: usize> NDArray<T, N>
impl<T: Default + Copy + AddAssign, const N: usize> NDArray<T, N>
Sourcepub fn project_axis(&self, axis: usize) -> Vec<T>
pub fn project_axis(&self, axis: usize) -> Vec<T>
Projects the array along the specified axis, summing over all other axes.
§Arguments
axis- The axis to project onto.
§Returns
A vector of values, one for each index along the specified axis.
§Panics
Panics if the axis is out of bounds.
§Example
use timsrust_utils::ndarray::NDArray;
let arr = NDArray::new([2, 2], vec![1, 2, 3, 4]).unwrap();
let proj = arr.project_axis(0);
assert_eq!(proj, vec![1+2, 3+4]);Trait Implementations§
Source§impl<T: AddAssign + Copy, const N: usize> AddAssign for NDArray<T, N>
impl<T: AddAssign + Copy, const N: usize> AddAssign for NDArray<T, N>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Adds another NDArray to this one, elementwise.
§Panics
Panics if the shapes do not match.
§Example
use timsrust_utils::ndarray::NDArray;
let mut a = NDArray::new([2, 2], vec![1, 2, 3, 4]).unwrap();
let b = NDArray::new([2, 2], vec![10, 20, 30, 40]).unwrap();
a += b;
assert_eq!(a[[0, 0]], 11);
assert_eq!(a[[1, 1]], 44);impl<T: Eq, const N: usize> Eq for NDArray<T, N>
Source§impl<T: PartialEq, const N: usize> PartialEq for NDArray<T, N>
impl<T: PartialEq, const N: usize> PartialEq for NDArray<T, N>
impl<T, const N: usize> StructuralPartialEq for NDArray<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for NDArray<T, N>
impl<T, const N: usize> RefUnwindSafe for NDArray<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for NDArray<T, N>where
T: Send,
impl<T, const N: usize> Sync for NDArray<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for NDArray<T, N>where
T: Unpin,
impl<T, const N: usize> UnsafeUnpin for NDArray<T, N>
impl<T, const N: usize> UnwindSafe for NDArray<T, N>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more