Csl

Struct Csl 

Source
pub struct Csl<DS, IS, OS, const D: usize> { /* private fields */ }
Expand description

Base structure for all CSL* variants.

It is possible to define your own fancy CSL.

type CustomCsl = ndstruct::Csl<
  Vec<num_bigint::BigNum, 32>,
  arrayvec::ArrayVec<[usize; 32]>,
  smallvec::SmallVec<[usize; 321]>,
  123
>

§Types

  • DA: Dimensions Array
  • DS: Data Store
  • IS: Indices Store
  • OS: Offsets Store

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>,

Source

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 elements
  • nolp1: 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<DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>

Source

pub fn dims(&self) -> &[usize; D]

The definitions of all dimensions.

§Example
use ndstruct::doc_tests::csl_array_4;
assert_eq!(csl_array_4().dims(), &[2, 3, 4, 5]);
Source§

impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
where DS: AsRef<[DATA]> + SingleTypeStorage<Item = DATA>, IS: AsRef<[usize]>, OS: AsRef<[usize]>,

Source

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 dimensions
  • data: Data collection
  • indcs: Indices of each data item
  • offs: 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![]);
Source

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]);
Source

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]);
Source

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());
Source

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);
Source

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]
);
Source

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);
Source

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());
});
Source

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()
);
Source

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>
where DS: AsMut<[DATA]> + AsRef<[DATA]> + SingleTypeStorage<Item = DATA>, IS: AsRef<[usize]>, OS: AsRef<[usize]>,

Source

pub fn clear(&mut self)
where DS: Clear, IS: Clear, OS: Clear,

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());
Source

pub fn constructor(&mut self) -> Result<CslLineConstructor<'_, DS, IS, OS, D>>
where DS: Push<DATA>, IS: Push<usize>, OS: Push<usize>,

See CslLineConstructor for more information.

Source

pub fn data_mut(&mut self) -> &mut [DATA]

Mutable version of data.

Source

pub fn line_mut(&mut self, indcs: [usize; D]) -> Option<CslMut<'_, DATA, 1>>

Mutable version of line.

Source

pub fn outermost_line_iter_mut(&mut self) -> Result<CslLineIterMut<'_, DATA, D>>

Mutable version of outermost_line_iter.

Source

pub fn outermost_line_rayon_iter_mut( &mut self, ) -> Result<ParallelIteratorWrapper<CslLineIterMut<'_, DATA, D>>>

Mutable version of outermost_line_rayon_iter.

Source

pub fn sub_dim_mut<const TD: usize>( &mut self, range: Range<usize>, ) -> Option<CslMut<'_, DATA, TD>>

Mutable version of sub_dim.

Source

pub fn swap_value(&mut self, a: [usize; D], b: [usize; D]) -> bool

Intra-swap a single data value.

§Arguments
  • a: First set of indices
  • b: Second set of indices
§Example
use ndstruct::doc_tests::csl_vec_4;
let mut csl = csl_vec_4();
csl.swap_value([0, 0, 0, 0], [1, 0, 2, 2]);
assert_eq!(csl.data(), &[9, 2, 3, 4, 5, 6, 7, 8, 1]);
Source

pub fn truncate(&mut self, indcs: [usize; D])
where DS: Truncate<Input = usize>, IS: Truncate<Input = usize>, OS: AsMut<[usize]> + Truncate<Input = usize>,

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

pub fn value_mut(&mut self, indcs: [usize; D]) -> Option<&mut DATA>

Mutable version of value.

Source§

impl<DATA, DS, IS, OS, const D: usize> Csl<DS, IS, OS, D>
where DS: AsMut<[DATA]> + AsRef<[DATA]> + Default + Push<DATA> + SingleTypeStorage<Item = DATA>, IS: AsMut<[usize]> + AsRef<[usize]> + Default + Push<usize>, OS: AsMut<[usize]> + AsRef<[usize]> + Default + Push<usize>,

Source

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 dimensions
  • nnz: Number of Non-Zero elements
  • rng: rand::Rng trait
  • cb: 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());
Source

pub fn new_random_rand<R>(rng: &mut R, upper_bound: usize) -> Result<Self>
where R: Rng, StandardUniform: Distribution<DATA>,

Creates a new random and valid instance.

§Arguments
  • rng: rand::Rng trait
  • upper_bound: The maximum allowed exclusive dimension

Trait Implementations§

Source§

impl<DS: Clone, IS: Clone, OS: Clone, const D: usize> Clone for Csl<DS, IS, OS, D>

Source§

fn clone(&self) -> Csl<DS, IS, OS, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<DS: Debug, IS: Debug, OS: Debug, const D: usize> Debug for Csl<DS, IS, OS, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DS: Default, IS: Default, OS: Default, const D: usize> Default for Csl<DS, IS, OS, D>

Source§

fn default() -> Csl<DS, IS, OS, D>

Returns the “default value” for a type. Read more
Source§

impl<'de, DS, IS, OS, const D: usize> Deserialize<'de> for Csl<DS, IS, OS, D>
where DS: Deserialize<'de>, IS: Deserialize<'de>, OS: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<DS: Ord, IS: Ord, OS: Ord, const D: usize> Ord for Csl<DS, IS, OS, D>

Source§

fn cmp(&self, other: &Csl<DS, IS, OS, D>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<DS: PartialEq, IS: PartialEq, OS: PartialEq, const D: usize> PartialEq for Csl<DS, IS, OS, D>

Source§

fn eq(&self, other: &Csl<DS, IS, OS, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<DS: PartialOrd, IS: PartialOrd, OS: PartialOrd, const D: usize> PartialOrd for Csl<DS, IS, OS, D>

Source§

fn partial_cmp(&self, other: &Csl<DS, IS, OS, D>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<DS, IS, OS, const D: usize> Serialize for Csl<DS, IS, OS, D>
where DS: Serialize, IS: Serialize, OS: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<DS: Eq, IS: Eq, OS: Eq, const D: usize> Eq for Csl<DS, IS, OS, D>

Source§

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>
where DS: Freeze, IS: Freeze, OS: Freeze,

§

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>
where DS: Send, IS: Send, OS: Send,

§

impl<DS, IS, OS, const D: usize> Sync for Csl<DS, IS, OS, D>
where DS: Sync, IS: Sync, OS: Sync,

§

impl<DS, IS, OS, const D: usize> Unpin for Csl<DS, IS, OS, D>
where DS: Unpin, IS: Unpin, OS: Unpin,

§

impl<DS, IS, OS, const D: usize> UnwindSafe for Csl<DS, IS, OS, D>
where DS: UnwindSafe, IS: UnwindSafe, OS: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,