[−][src]Struct ndsparse::csl::Csl
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 StorageIS: Indices StorageOS: Offsets Storageconst DIMS: usize: Dimensions length
Methods
impl<DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: WithCapacity<Input = usize>,
IS: WithCapacity<Input = usize>,
OS: WithCapacity<Input = usize>, [src]
DS: WithCapacity<Input = usize>,
IS: WithCapacity<Input = usize>,
OS: WithCapacity<Input = usize>,
pub fn with_capacity(nnz: usize, nol: 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 elementsnolp1: 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, 01]; let nolp1 = dims.iter().rev().skip(1).product::<usize>() + 1; let nnz = 2; let _ = CslVec::<i32, 3>::with_capacity(nnz, nolp1);
impl<DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS>[src]
pub fn dims(&self) -> &[usize; DIMS][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<DATA, DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>, [src]
DS: AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>,
pub fn new<ID, IDS, IIS, IOS>(
into_dims: ID,
into_data: IDS,
into_indcs: IIS,
into_offs: IOS
) -> Self where
ID: Into<ArrayWrapper<usize, DIMS>>,
IDS: Into<DS>,
IIS: Into<IS>,
IOS: Into<OS>, [src]
into_dims: ID,
into_data: IDS,
into_indcs: IIS,
into_offs: IOS
) -> Self where
ID: Into<ArrayWrapper<usize, DIMS>>,
IDS: Into<DS>,
IIS: Into<IS>,
IOS: Into<OS>,
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 dimensionsinto_data: Data collectioninto_indcs: Indices of each data iteminto_offs: Offset of each innermost line
Example
use ndsparse::csl::{Csl, CslVec}; // A sparse array ([8, _, _, _, _, 9, _, _, _, _]) let mut _sparse_array: Csl<[f64; 2], [usize; 2], [usize; 2], 1>; _sparse_array = Csl::new([10], [8.0, 9.0], [0, 5], [0, 2]); // A bunch of nothing for your overflow needs let mut _over_nine: CslVec<(), 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<i32, 7> = 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: [usize; DIMS]) -> Option<CslRef<DATA, 1>>[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<DATA, DIMS>[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
DIMSmust be greater than 1
use ndsparse::csl::CslVec; let _ = CslVec::<i32, 1>::default().outermost_iter();
pub fn outermost_rayon_iter(
&self
) -> ParallelIteratorWrapper<CsIterRef<DATA, DIMS>>[src]
&self
) -> ParallelIteratorWrapper<CsIterRef<DATA, DIMS>>
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
DIMSmust be greater than 1
use ndsparse::csl::CslVec; let _ = CslVec::<i32, 1>::default().outermost_rayon_iter();
pub fn sub_dim<const N: usize>(&self, range: Range<usize>) -> CslRef<DATA, N>[src]
Retrieves an immutable reference of any sub dimension.
Arguments
const N: Desired dimensionrange: 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: [usize; DIMS]) -> 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
indcsmust be within dimensions bounds
use ndsparse::doc_tests::csl_array_4; let _ = csl_array_4().value([9, 9, 9, 9]);
impl<DATA, DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>, [src]
DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>,
pub fn data_mut(&mut self) -> &mut [DATA][src]
Mutable version of data.
pub fn line_mut(&mut self, indcs: [usize; DIMS]) -> Option<CslMut<DATA, 1>>[src]
Mutable version of line.
pub fn outermost_iter_mut(&mut self) -> CslIterMut<DATA, DIMS>[src]
Mutable version of outermost_iter.
pub fn outermost_rayon_iter_mut(
&mut self
) -> ParallelIteratorWrapper<CslIterMut<DATA, DIMS>>[src]
&mut self
) -> ParallelIteratorWrapper<CslIterMut<DATA, DIMS>>
Mutable version of outermost_rayon_iter.
pub fn sub_dim_mut<const N: usize>(
&mut self,
range: Range<usize>
) -> CslMut<DATA, N>[src]
&mut self,
range: Range<usize>
) -> CslMut<DATA, N>
Mutable version of sub_dim.
pub fn value_mut(&mut self, indcs: [usize; DIMS]) -> Option<&mut DATA>[src]
Mutable version of value.
impl<DATA, DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: AsRef<[DATA]> + Push<Input = DATA> + Storage<Item = DATA>,
IS: AsRef<[usize]> + Push<Input = usize>,
OS: AsRef<[usize]> + Push<Input = usize>, [src]
DS: AsRef<[DATA]> + Push<Input = DATA> + Storage<Item = DATA>,
IS: AsRef<[usize]> + Push<Input = usize>,
OS: AsRef<[usize]> + Push<Input = usize>,
pub fn constructor(&mut self) -> CslLineConstructor<DS, IS, OS, DIMS>[src]
See CslLineConstructor for more information.
impl<DATA, DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
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]
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>,
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, [usize; DIMS]) -> DATA,
ID: Into<ArrayWrapper<usize, DIMS>>,
R: Rng, [src]
into_dims: ID,
nnz: usize,
rng: &mut R,
cb: F
) -> Self where
F: FnMut(&mut R, [usize; DIMS]) -> DATA,
ID: Into<ArrayWrapper<usize, DIMS>>,
R: Rng,
Creates a new random and valid instance delimited by the passed arguments.
Arguments
into_dims: Array of dimensionsnnz: Number of Non-Zero elementsrng:rand::Rngtraitcb: Callback to control data creation
Example
use ndsparse::csl::CslVec; use rand::{thread_rng, Rng}; let mut _random: CslVec<u8, 8>; 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<DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: Clear,
IS: Clear,
OS: Clear, [src]
DS: Clear,
IS: Clear,
OS: Clear,
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, DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>, [src]
DS: AsMut<[DATA]> + AsRef<[DATA]> + Storage<Item = DATA>,
IS: AsRef<[usize]>,
OS: AsRef<[usize]>,
pub fn swap_value(&mut self, a: [usize; DIMS], b: [usize; DIMS]) -> bool[src]
Intra-swap a single data value.
Arguments
a: First set of indicesb: 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<DS, IS, OS, const DIMS: usize> Csl<DS, IS, OS, DIMS> where
DS: Truncate<Input = usize>,
IS: Truncate<Input = usize>,
OS: AsRef<[usize]> + Push<Input = usize> + Truncate<Input = usize>, [src]
DS: Truncate<Input = usize>,
IS: Truncate<Input = usize>,
OS: AsRef<[usize]> + Push<Input = usize> + Truncate<Input = usize>,
pub fn truncate(&mut self, indcs: [usize; DIMS])[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<DS: Clone, IS: Clone, OS: Clone, const DIMS: usize> Clone for Csl<DS, IS, OS, DIMS>[src]
impl<DS: Debug, IS: Debug, OS: Debug, const DIMS: usize> Debug for Csl<DS, IS, OS, DIMS>[src]
impl<DS: Default, IS: Default, OS: Default, const DIMS: usize> Default for Csl<DS, IS, OS, DIMS>[src]
impl<'de, DS, IS, OS, const DIMS: usize> Deserialize<'de> for Csl<DS, IS, OS, DIMS> where
DS: Deserialize<'de>,
IS: Deserialize<'de>,
OS: Deserialize<'de>, [src]
DS: Deserialize<'de>,
IS: Deserialize<'de>,
OS: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
impl<DS: PartialEq, IS: PartialEq, OS: PartialEq, const DIMS: usize> PartialEq<Csl<DS, IS, OS, DIMS>> for Csl<DS, IS, OS, DIMS>[src]
fn eq(&self, other: &Csl<DS, IS, OS, DIMS>) -> bool[src]
fn ne(&self, other: &Csl<DS, IS, OS, DIMS>) -> bool[src]
impl<DS, IS, OS, const DIMS: usize> Serialize for Csl<DS, IS, OS, DIMS> where
DS: Serialize,
IS: Serialize,
OS: Serialize, [src]
DS: Serialize,
IS: Serialize,
OS: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl<DS, IS, OS, const DIMS: usize> StructuralPartialEq for Csl<DS, IS, OS, DIMS>[src]
Auto Trait Implementations
impl<const DIMS: usize, DS, IS, OS> RefUnwindSafe for Csl<DS, IS, OS, DIMS> where
DS: RefUnwindSafe,
IS: RefUnwindSafe,
OS: RefUnwindSafe,
DS: RefUnwindSafe,
IS: RefUnwindSafe,
OS: RefUnwindSafe,
impl<const DIMS: usize, DS, IS, OS> Send for Csl<DS, IS, OS, DIMS> where
DS: Send,
IS: Send,
OS: Send,
DS: Send,
IS: Send,
OS: Send,
impl<const DIMS: usize, DS, IS, OS> Sync for Csl<DS, IS, OS, DIMS> where
DS: Sync,
IS: Sync,
OS: Sync,
DS: Sync,
IS: Sync,
OS: Sync,
impl<const DIMS: usize, DS, IS, OS> Unpin for Csl<DS, IS, OS, DIMS> where
DS: Unpin,
IS: Unpin,
OS: Unpin,
DS: Unpin,
IS: Unpin,
OS: Unpin,
impl<const DIMS: usize, DS, IS, OS> UnwindSafe for Csl<DS, IS, OS, DIMS> where
DS: UnwindSafe,
IS: UnwindSafe,
OS: UnwindSafe,
DS: UnwindSafe,
IS: UnwindSafe,
OS: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>, [src]
T: Deserialize<'de>,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,