pub struct Csl<DS, IS, OS, const D: usize> { /* private fields */ }Expand description
Implementations§
Source§impl<DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>where
DS: WithCapacity<Error = Error, Input = usize>,
IS: WithCapacity<Error = Error, Input = usize>,
OS: WithCapacity<Error = Error, Input = usize>,
impl<DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>where
DS: WithCapacity<Error = Error, Input = usize>,
IS: WithCapacity<Error = Error, Input = usize>,
OS: WithCapacity<Error = Error, Input = usize>,
Sourcepub fn with_capacity(nnz: usize, nolp1: usize) -> Result<Self>
pub fn with_capacity(nnz: usize, nolp1: usize) -> Result<Self>
Creates an empty instance with initial capacity.
For storages involving solely arrays, all arguments will be discarted.
§Arguments
nnz: Number of Non-Zero elementsnolp1: Number Of Lines Plus 1, i.e., the dimensions product (without the innermost dimension) plus 1
§Example
use ndstruct::csl::CslVec;
let dims = [11, 10, 1];
let nolp1 = dims.iter().rev().skip(1).product::<usize>() + 1;
let nnz = 2;
let _ = CslVec::<i32, 3>::with_capacity(nnz, nolp1);Source§impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
Sourcepub fn new(dims: [usize; D], data: DS, indcs: IS, offs: OS) -> Result<Self>
pub fn new(dims: [usize; D], data: DS, indcs: IS, offs: OS) -> Result<Self>
Creates a valid CSL instance.
The compressed fields are a bit complex and unless you really know what you are doing, this
method shouldn’t probably be used directly. Please, try to consider using [#constructor]
instead.
§Arguments
dims: Array of dimensionsdata: Data collectionindcs: Indices of each data itemoffs: Offset of each innermost line
§Example
use ndstruct::csl::{CslArray, CslVec};
// Sparse array ([8, _, _, _, _, 9, _, _, _, _])
let mut _sparse_array = CslArray::new([10], [8.0, 9.0], [0, 5], [0, 2]);
// A bunch of nothing for your overflow needs
let mut _over_nine: ndstruct::Result<CslVec<(), 9001>>;
_over_nine = CslVec::new([0; 9001], vec![], vec![], vec![]);Sourcepub fn data(&self) -> &[DATA]
pub fn data(&self) -> &[DATA]
The data that is being stored.
§Example
use ndstruct::doc_tests::csl_array_4;
assert_eq!(csl_array_4().data(), &[1, 2, 3, 4, 5, 6, 7, 8, 9]);Sourcepub fn indcs(&self) -> &[usize]
pub fn indcs(&self) -> &[usize]
Indices (indcs) of a line, i.e., indices of the innermost dimension.
§Example
use ndstruct::doc_tests::csl_array_4;
assert_eq!(csl_array_4().indcs(), &[0, 3, 1, 3, 4, 2, 2, 4, 2]);Sourcepub fn line(&self, indcs: [usize; D]) -> Option<CslRef<'_, DATA, 1>>
pub fn line(&self, indcs: [usize; D]) -> Option<CslRef<'_, DATA, 1>>
Any immutable line reference determined by indcs. The innermost dimension is ignored.
§Examples
use ndstruct::{csl::CslRef, doc_tests::csl_array_4};
let csl = csl_array_4();
assert_eq!(csl.line([0, 0, 2, 0]), CslRef::new([5], &[][..], &[][..], &[3, 3][..]).ok());
assert_eq!(csl.line([0, 1, 0, 0]), CslRef::new([5], &[6][..], &[2][..], &[5, 6][..]).ok());Sourcepub fn nnz(&self) -> usize
pub fn nnz(&self) -> usize
Number of non zero elements.
§Example
use ndstruct::doc_tests::csl_array_4;
assert_eq!(csl_array_4().nnz(), 9);Sourcepub fn offs(&self) -> &[usize]
pub fn offs(&self) -> &[usize]
The joining of two consecutives offsets (offs) represent the starting and ending points of a
line in the data and indcs slices.
§Example
use ndstruct::doc_tests::csl_array_4;
assert_eq!(
csl_array_4().offs(),
&[0, 2, 3, 3, 5, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
);Sourcepub fn outermost_line_iter(&self) -> Result<CslLineIterRef<'_, DATA, D>>
pub fn outermost_line_iter(&self) -> Result<CslLineIterRef<'_, DATA, D>>
Iterator that returns immutable line references of the outermost dimension
§Examples
use ndstruct::{csl::CslRef, doc_tests::csl_array_4};
let csl = csl_array_4();
let sub_csl = csl.sub_dim(0..3).unwrap();
let mut iter = sub_csl.outermost_line_iter()?;
assert_eq!(
iter.next(),
CslRef::new([1, 4, 5], &[1, 2, 3, 4, 5][..], &[0, 3, 1, 3, 4][..], &[0, 2, 3, 3, 5][..]).ok()
);
assert_eq!(iter.next(), CslRef::new([1, 4, 5], &[6][..], &[2][..], &[5, 6, 6, 6, 6][..]).ok());
assert_eq!(
iter.next(),
CslRef::new([1, 4, 5], &[7, 8][..], &[2, 4][..], &[6, 7, 8, 8, 8][..]).ok()
);
assert_eq!(iter.next(), None);Sourcepub fn outermost_line_rayon_iter(
&self,
) -> Result<ParallelIteratorWrapper<CslLineIterRef<'_, DATA, D>>>
pub fn outermost_line_rayon_iter( &self, ) -> Result<ParallelIteratorWrapper<CslLineIterRef<'_, DATA, D>>>
Parallel iterator that returns all immutable line references of the current dimension
using rayon.
§Examples
use ndstruct::doc_tests::csl_array_4;
use rayon::prelude::*;
let csl = csl_array_4();
let outermost_rayon_iter = csl.outermost_line_rayon_iter()?;
outermost_rayon_iter.enumerate().for_each(|(idx, csl_ref)| {
assert_eq!(csl_ref, csl.outermost_line_iter().unwrap().nth(idx).unwrap());
});Sourcepub fn sub_dim<const TD: usize>(
&self,
range: Range<usize>,
) -> Option<CslRef<'_, DATA, TD>>
pub fn sub_dim<const TD: usize>( &self, range: Range<usize>, ) -> Option<CslRef<'_, DATA, TD>>
Retrieves an immutable reference of any sub dimension.
§Arguments
range: Starting and ending of the desired dimension
§Example
use ndstruct::{csl::CslRef, doc_tests::csl_array_4};
let csl = csl_array_4();
// The last cuboid
assert_eq!(
csl.sub_dim(1..2),
CslRef::new([1, 3, 4, 5], &[9][..], &[2][..], &[8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9][..])
.ok()
);
// The last 2 matrices of the first cuboid;
assert_eq!(
csl.sub_dim(1..3),
CslRef::new([2, 4, 5], &[6, 7, 8][..], &[2, 2, 4][..], &[5, 6, 6, 6, 6, 7, 8, 8, 8][..]).ok()
);Sourcepub fn value(&self, indcs: [usize; D]) -> Option<&DATA>
pub fn value(&self, indcs: [usize; D]) -> Option<&DATA>
Retrieves an immutable reference of a single data value.
§Arguments
indcs: Indices of all dimensions
§Example
use ndstruct::doc_tests::csl_array_4;
let csl = csl_array_4();
assert_eq!(csl.value([1, 0, 2, 2]), Some(&9));
let line = csl.line([0, 0, 3, 0]).unwrap();
assert_eq!(line.value([3]), Some(&4));Source§impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all values and dimensions.
§Example
use ndstruct::{csl::CslVec, doc_tests::csl_vec_4};
let mut csl = csl_vec_4();
csl.clear();
assert_eq!(csl, CslVec::default());Sourcepub fn constructor(&mut self) -> Result<CslLineConstructor<'_, DS, IS, OS, D>>
pub fn constructor(&mut self) -> Result<CslLineConstructor<'_, DS, IS, OS, D>>
See CslLineConstructor for more information.
Sourcepub fn line_mut(&mut self, indcs: [usize; D]) -> Option<CslMut<'_, DATA, 1>>
pub fn line_mut(&mut self, indcs: [usize; D]) -> Option<CslMut<'_, DATA, 1>>
Mutable version of line.
Sourcepub fn outermost_line_iter_mut(&mut self) -> Result<CslLineIterMut<'_, DATA, D>>
pub fn outermost_line_iter_mut(&mut self) -> Result<CslLineIterMut<'_, DATA, D>>
Mutable version of outermost_line_iter.
Sourcepub fn outermost_line_rayon_iter_mut(
&mut self,
) -> Result<ParallelIteratorWrapper<CslLineIterMut<'_, DATA, D>>>
pub fn outermost_line_rayon_iter_mut( &mut self, ) -> Result<ParallelIteratorWrapper<CslLineIterMut<'_, DATA, D>>>
Mutable version of outermost_line_rayon_iter.
Sourcepub fn sub_dim_mut<const TD: usize>(
&mut self,
range: Range<usize>,
) -> Option<CslMut<'_, DATA, TD>>
pub fn sub_dim_mut<const TD: usize>( &mut self, range: Range<usize>, ) -> Option<CslMut<'_, DATA, TD>>
Mutable version of sub_dim.
Sourcepub fn truncate(&mut self, indcs: [usize; D])
pub fn truncate(&mut self, indcs: [usize; D])
Truncates all values in the exactly exclusive line defined by indcs. The last index is ignored.
§Example
use ndstruct::{csl::CslVec, doc_tests::csl_vec_4};
let mut csl = csl_vec_4();
csl.truncate([0, 0, 3, 0]);
assert_eq!(
Ok(csl),
CslVec::new([0, 0, 4, 5], vec![1, 2, 3], vec![0, 3, 1], vec![0, 2, 3, 3, 3])
);Source§impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
Sourcepub fn new_controlled_random_rand<R>(
dims: [usize; D],
nnz: usize,
rng: &mut R,
cb: impl FnMut(&mut R, [usize; D]) -> DATA,
) -> Result<Self>where
R: Rng,
pub fn new_controlled_random_rand<R>(
dims: [usize; D],
nnz: usize,
rng: &mut R,
cb: impl FnMut(&mut R, [usize; D]) -> DATA,
) -> Result<Self>where
R: Rng,
Creates a new random and valid instance delimited by the passed arguments.
§Arguments
dims: Array of dimensionsnnz: Number of Non-Zero elementsrng:rand::Rngtraitcb: Callback to control data creation
§Example
use ndstruct::csl::CslVec;
use rand::{Rng, rngs::mock::StepRng};
let mut rng = StepRng::new(0, 1);
let dims = [1, 2, 3];
let mut _random: ndstruct::Result<CslVec<u8, 3>>;
_random = CslVec::new_controlled_random_rand(dims, 9, &mut rng, |r, _| r.gen());Trait Implementations§
Source§impl<'de, DS, IS, OS, const D: usize> Deserialize<'de> for Csl<DS, IS, OS, D>
impl<'de, DS, IS, OS, const D: usize> Deserialize<'de> for Csl<DS, IS, OS, D>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<DS: Ord, IS: Ord, OS: Ord, const D: usize> Ord for Csl<DS, IS, OS, D>
impl<DS: Ord, IS: Ord, OS: Ord, const D: usize> Ord for Csl<DS, IS, OS, D>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<DS: PartialEq, IS: PartialEq, OS: PartialEq, const D: usize> PartialEq for Csl<DS, IS, OS, D>
impl<DS: PartialEq, IS: PartialEq, OS: PartialEq, const D: usize> PartialEq for Csl<DS, IS, OS, D>
Source§impl<DS: PartialOrd, IS: PartialOrd, OS: PartialOrd, const D: usize> PartialOrd for Csl<DS, IS, OS, D>
impl<DS: PartialOrd, IS: PartialOrd, OS: PartialOrd, const D: usize> PartialOrd for Csl<DS, IS, OS, D>
impl<DS: Eq, IS: Eq, OS: Eq, const D: usize> Eq for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> StructuralPartialEq for Csl<DS, IS, OS, D>
Auto Trait Implementations§
impl<DS, IS, OS, const D: usize> Freeze for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> RefUnwindSafe for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> Send for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> Sync for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> Unpin for Csl<DS, IS, OS, D>
impl<DS, IS, OS, const D: usize> UnwindSafe for Csl<DS, IS, OS, D>
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
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>
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>
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