[][src]Struct ndsparse::csl::Csl

pub struct Csl<DA, DS, IS, OS> where
    DA: Dims
{ /* fields omitted */ }

Base structure for all CSL* variants.

It is possible to define your own fancy CSL, e.g., Csl<[BigNum; 32], ArrayVec<[usize; 32]>, StaticVec<usize, 123>, 321>.

Types

  • DS: Data Storage
  • IS: Indices Storage
  • OS: Offsets Storage
  • const DIMS: usize: Dimensions length

Methods

impl<DA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: WithCapacity<Input = usize>,
    IS: WithCapacity<Input = usize>,
    OS: WithCapacity<Input = usize>, 
[src]

pub fn with_capacity(nnz: usize, nolp1: usize) -> Self[src]

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 ndsparse::csl::CslVec;
let dims = [11, 10, 1];
let nolp1 = dims.iter().rev().skip(1).product::<usize>() + 1;
let nnz = 2;
let _ = CslVec::<[usize; 3], i32>::with_capacity(nnz, nolp1);

impl<DA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

pub fn dims(&self) -> &DA[src]

The definitions of all dimensions.

Example

use ndsparse::doc_tests::csl_array_4;
assert_eq!(csl_array_4().dims(), &[2, 3, 4, 5]);

impl<DA, DATA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: AsRef<[DATA]> + Storage<Item = DATA>,
    IS: AsRef<[usize]>,
    OS: AsRef<[usize]>, 
[src]

pub fn new<ID, IDS, IIS, IOS>(
    into_dims: ID,
    into_data: IDS,
    into_indcs: IIS,
    into_offs: IOS
) -> Self where
    ID: Into<ArrayWrapper<DA>>,
    IDS: Into<DS>,
    IIS: Into<IS>,
    IOS: Into<OS>, 
[src]

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

  • into_dims: Array of dimensions
  • into_data: Data collection
  • into_indcs: Indices of each data item
  • into_offs: Offset of each innermost line

Example

use ndsparse::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: CslVec<[usize; 9001], ()>;
_over_nine = CslVec::new([0; 9001], vec![], vec![], vec![]);

Assertions

  • Innermost dimensions length must be greater than zero
use ndsparse::csl::CslVec;
let _: CslVec<[usize; 7], i32> = CslVec::new([1, 2, 3, 4, 5, 0, 7], vec![], vec![], vec![]);
  • The data length must equal the indices length
use ndsparse::csl::CslVec;
let _ = CslVec::new([10], vec![8, 9], vec![0], vec![0, 2]);
  • Offsets must be in ascending order
use ndsparse::csl::CslArray;
let _ = CslArray::new([10], [8, 9], [0, 5], [2, 0]);
  • Offsets length must equal the dimensions product (without the innermost dimension) plus one
use ndsparse::csl::CslVec;
let _ = CslVec::new([10], vec![8, 9], vec![0, 5], vec![0, 2, 4]);
  • Indices of a line must be unique
use ndsparse::csl::CslArray;
let _ = CslArray::new([10], [8, 9], [0, 0], [0, 2]);
  • The data and indices length must be equal or less than the product of all dimensions length
use ndsparse::csl::CslVec;
let _ = CslVec::new([10], vec![8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9], vec![0, 5], vec![0, 2]);
  • Last offset must equal the nnz
use ndsparse::csl::CslArray;
let _ = CslArray::new([10], [8, 9], [0, 5], [0, 4]);
  • The indices must be less than the innermost dimension length
use ndsparse::csl::CslArray;
let _ = CslArray::new([10], [8, 9], [0, 10], [0, 2]);

pub fn data(&self) -> &[DATA][src]

The data that is being stored.

Example

use ndsparse::doc_tests::csl_array_4;
assert_eq!(csl_array_4().data(), &[1, 2, 3, 4, 5, 6, 7, 8, 9]);

pub fn indcs(&self) -> &[usize][src]

Indices (indcs) of a line, i.e., indices of the innermost dimension.

Example

use ndsparse::doc_tests::csl_array_4;
assert_eq!(csl_array_4().indcs(), &[0, 3, 1, 3, 4, 2, 2, 4, 2]);

pub fn line(&self, indcs: DA) -> Option<CslRef<[usize; 1], DATA>>[src]

Any immutable line reference determined by indcs. The innermost dimension is ignored.

Examples

use ndsparse::{csl::CslRef, doc_tests::csl_array_4};
let csl = csl_array_4();
assert_eq!(csl.line([0, 0, 2, 0]), Some(CslRef::new([5], &[][..], &[][..], &[3, 3][..])));
assert_eq!(csl.line([0, 1, 0, 0]), Some(CslRef::new([5], &[6][..], &[2][..], &[5, 6][..])));

pub fn nnz(&self) -> usize[src]

Number of NonZero elements.

Example

use ndsparse::doc_tests::csl_array_4;
assert_eq!(csl_array_4().nnz(), 9);

pub fn offs(&self) -> &[usize][src]

The joining of two consecutives offsets (offs) represent the starting and ending points of a line in the data and indcs slices.

Example

use ndsparse::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]
);

pub fn outermost_iter(&self) -> CsIterRef<DA, DATA>[src]

Iterator that returns immutable references of the outermost dimension

Examples

use ndsparse::{csl::CslRef, doc_tests::csl_array_4};
let csl = csl_array_4();
let sub_csl = csl.sub_dim(0..3);
let mut iter = sub_csl.outermost_iter();
assert_eq!(
  iter.next().unwrap(),
  CslRef::new([1, 4, 5], &[1, 2, 3, 4, 5][..], &[0, 3, 1, 3, 4][..], &[0, 2, 3, 3, 5][..])
);
assert_eq!(
  iter.next().unwrap(),
  CslRef::new([1, 4, 5], &[6][..], &[2][..], &[5, 6, 6, 6, 6][..])
);
assert_eq!(
  iter.next().unwrap(),
  CslRef::new([1, 4, 5], &[7, 8][..], &[2, 4][..], &[6, 7, 8, 8, 8][..])
);
assert_eq!(iter.next(), None);

Assertions

  • DIMS must be greater than 1
use ndsparse::csl::CslVec;
let _ = CslVec::<[usize; 1], i32>::default().outermost_iter();

pub fn outermost_rayon_iter(
    &self
) -> ParallelIteratorWrapper<CsIterRef<DA, DATA>>
[src]

Parallel iterator that returns all immutable references of the current dimension using rayon.

Examples

use ndsparse::doc_tests::csl_array_4;
use rayon::prelude::*;
let csl = csl_array_4();
let outermost_rayon_iter = csl.outermost_rayon_iter();
outermost_rayon_iter.enumerate().for_each(|(idx, csl_ref)| {
  assert_eq!(csl_ref, csl.outermost_iter().nth(idx).unwrap());
});

Assertions

  • DIMS must be greater than 1
use ndsparse::csl::CslVec;
let _ = CslVec::<[usize; 1], i32>::default().outermost_rayon_iter();

pub fn sub_dim<TODA>(&self, range: Range<usize>) -> CslRef<TODA, DATA> where
    TODA: Dims
[src]

Retrieves an immutable reference of any sub dimension.

Arguments

  • const N: Desired dimension
  • range: Starting and ending of the desired dimension

Example

use ndsparse::{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][..])
);
// 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][..])
);

pub fn value(&self, indcs: DA) -> Option<&DATA>[src]

Retrieves an immutable reference of a single data value.

Arguments

  • indcs: Indices of all dimensions

Example

use ndsparse::doc_tests::csl_array_4;
assert_eq!(csl_array_4().value([1, 0, 2, 2]), Some(&9));

Assertions

  • indcs must be within dimensions bounds
use ndsparse::doc_tests::csl_array_4;
let _ = csl_array_4().value([9, 9, 9, 9]);

impl<DA, DATA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
    IS: AsRef<[usize]>,
    OS: AsRef<[usize]>, 
[src]

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

Mutable version of data.

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

Mutable version of line.

pub fn outermost_iter_mut(&mut self) -> CslIterMut<DA, DATA>[src]

Mutable version of outermost_iter.

pub fn outermost_rayon_iter_mut(
    &mut self
) -> ParallelIteratorWrapper<CslIterMut<DA, DATA>>
[src]

Mutable version of outermost_rayon_iter.

pub fn sub_dim_mut<TODA>(&mut self, range: Range<usize>) -> CslMut<TODA, DATA> where
    TODA: Dims
[src]

Mutable version of sub_dim.

pub fn value_mut(&mut self, indcs: DA) -> Option<&mut DATA>[src]

Mutable version of value.

impl<DA, DATA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: AsRef<[DATA]> + Push<Input = DATA> + Storage<Item = DATA>,
    IS: AsRef<[usize]> + Push<Input = usize>,
    OS: AsRef<[usize]> + Push<Input = usize>, 
[src]

pub fn constructor(&mut self) -> CslLineConstructor<DA, DS, IS, OS>[src]

See CslLineConstructor for more information.

impl<DA, DATA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Default + Dims,
    DS: AsMut<[DATA]> + AsRef<[DATA]> + Default + Push<Input = DATA> + Storage<Item = DATA>,
    IS: AsMut<[usize]> + AsRef<[usize]> + Default + Push<Input = usize>,
    OS: AsMut<[usize]> + AsRef<[usize]> + Default + Push<Input = usize>, 
[src]

pub fn new_random_with_rand<F, ID, R>(
    into_dims: ID,
    nnz: usize,
    rng: &mut R,
    cb: F
) -> Self where
    F: FnMut(&mut R, DA) -> DATA,
    ID: Into<ArrayWrapper<DA>>,
    R: Rng
[src]

Creates a new random and valid instance delimited by the passed arguments.

Arguments

  • into_dims: Array of dimensions
  • nnz: Number of Non-Zero elements
  • rng: rand::Rng trait
  • cb: Callback to control data creation

Example

use ndsparse::csl::CslVec;
use rand::{thread_rng, Rng};
let mut _random: CslVec<[usize; 8], u8>;
let mut rng = thread_rng();
_random = CslVec::new_random_with_rand([1, 2, 3, 4, 5, 6, 7, 8], 9, &mut rng, |r, _| r.gen());

impl<DA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: Clear,
    IS: Clear,
    OS: Clear
[src]

pub fn clear(&mut self)[src]

Clears all values and dimensions.

Example

use ndsparse::{csl::CslVec, doc_tests::csl_vec_4};
let mut csl = csl_vec_4();
csl.clear();
assert_eq!(csl, CslVec::default());

impl<DATA, DA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
    IS: AsRef<[usize]>,
    OS: AsRef<[usize]>, 
[src]

pub fn swap_value(&mut self, a: DA, b: DA) -> bool[src]

Intra-swap a single data value.

Arguments

  • a: First set of indices
  • b: Second set of indices

Example

use ndsparse::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]);

Assertions

Uses the same assertions of value.

impl<DA, DS, IS, OS> Csl<DA, DS, IS, OS> where
    DA: Dims,
    DS: Truncate<Input = usize>,
    IS: Truncate<Input = usize>,
    OS: AsRef<[usize]> + Push<Input = usize> + Truncate<Input = usize>, 
[src]

pub fn truncate(&mut self, indcs: DA)[src]

Truncates all values in the exactly exclusive point defined by indcs.

Example

use ndsparse::{csl::CslVec, doc_tests::csl_vec_4};
let mut csl = csl_vec_4();
csl.truncate([0, 0, 3, 4]);
assert_eq!(
  csl,
  CslVec::new([0, 0, 4, 5], vec![1, 2, 3, 4], vec![0, 3, 1, 3], vec![0, 2, 3, 3, 4])
);

Trait Implementations

impl<DA: Clone, DS: Clone, IS: Clone, OS: Clone> Clone for Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

impl<DA: Debug, DS: Debug, IS: Debug, OS: Debug> Debug for Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

impl<DA: Default, DS: Default, IS: Default, OS: Default> Default for Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

impl<'de, DA, DS, IS, OS> Deserialize<'de> for Csl<DA, DS, IS, OS> where
    DA: Dims,
    DA: Deserialize<'de>,
    DS: Deserialize<'de>,
    IS: Deserialize<'de>,
    OS: Deserialize<'de>, 
[src]

impl<DA: PartialEq, DS: PartialEq, IS: PartialEq, OS: PartialEq> PartialEq<Csl<DA, DS, IS, OS>> for Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

impl<DA, DS, IS, OS> Serialize for Csl<DA, DS, IS, OS> where
    DA: Dims,
    DA: Serialize,
    DS: Serialize,
    IS: Serialize,
    OS: Serialize
[src]

impl<DA, DS, IS, OS> StructuralPartialEq for Csl<DA, DS, IS, OS> where
    DA: Dims
[src]

Auto Trait Implementations

impl<DA, DS, IS, OS> RefUnwindSafe for Csl<DA, DS, IS, OS> where
    DA: RefUnwindSafe,
    DS: RefUnwindSafe,
    IS: RefUnwindSafe,
    OS: RefUnwindSafe

impl<DA, DS, IS, OS> Send for Csl<DA, DS, IS, OS> where
    DA: Send,
    DS: Send,
    IS: Send,
    OS: Send

impl<DA, DS, IS, OS> Sync for Csl<DA, DS, IS, OS> where
    DA: Sync,
    DS: Sync,
    IS: Sync,
    OS: Sync

impl<DA, DS, IS, OS> Unpin for Csl<DA, DS, IS, OS> where
    DA: Unpin,
    DS: Unpin,
    IS: Unpin,
    OS: Unpin

impl<DA, DS, IS, OS> UnwindSafe for Csl<DA, DS, IS, OS> where
    DA: UnwindSafe,
    DS: UnwindSafe,
    IS: UnwindSafe,
    OS: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,