[][src]Struct ndsparse::coo::Coo

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

Base structure for all COO* variants.

Types

  • DS: Data Storage
  • const DIMS: usize: Dimensions length

Methods

impl<DA, DS> Coo<DA, DS> where
    DA: Dims
[src]

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

The definitions of all dimensions.

Example

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

impl<DA, DATA, DS> Coo<DA, DS> where
    DA: Dims,
    DS: AsRef<[<DS as Storage>::Item]> + Storage<Item = (ArrayWrapper<DA>, DATA)>, 
[src]

pub fn new<ID, IDS>(into_dims: ID, into_data: IDS) -> Self where
    ID: Into<ArrayWrapper<DA>>,
    IDS: Into<DS>, 
[src]

Creates a valid COO instance.

Arguments

  • into_dims: Array of dimensions
  • into_data: Data collection

Example

use ndsparse::coo::{CooArray, CooVec};
// Sparse array ([8, _, _, _, _, 9, _, _, _, _])
let mut _sparse_array = CooArray::new([10], [([0].into(), 8.0), ([5].into(), 9.0)]);
// A bunch of nothing for your overflow needs
let mut _over_nine: CooVec<[usize; 9001], ()>;
_over_nine = CooVec::new([0; 9001], vec![]);

Assertions

  • Data indices must be in asceding order
use ndsparse::coo::CooArray;
let _ = CooArray::new([2, 2], [([1, 1].into(), 8), ([0, 0].into(), 9)]);
  • All indices must be lesser than the defined dimensions
use ndsparse::coo::CooArray;
let _ = CooArray::new([2, 2], [([0, 1].into(), 8), ([9, 9].into(), 9)]);
  • Must not have duplicated indices
use ndsparse::coo::CooArray;
let _ = CooArray::new([2, 2], [([0, 0].into(), 8), ([0, 0].into(), 9)]);

pub fn data(&self) -> &[(ArrayWrapper<DA>, DATA)][src]

The data that is being stored.

Example

use ndsparse::doc_tests::coo_array_5;
assert_eq!(coo_array_5().data().get(0), Some(&([0, 0, 1, 1, 2].into(), 1)));

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

If any, retrieves an immutable data reference of a given set of indices.

Arguments

  • indcs: Indices of the desired data location

Example

use ndsparse::doc_tests::coo_array_5;
let coo = coo_array_5();
assert_eq!(coo.value([0, 0, 0, 0, 0]), None);
assert_eq!(coo.value([0, 2, 2, 0, 1]), Some(&4));

impl<DA, DATA, DS> Coo<DA, DS> where
    DA: Dims,
    DS: AsMut<[<DS as Storage>::Item]> + Storage<Item = (ArrayWrapper<DA>, DATA)>, 
[src]

pub unsafe fn data_mut(&mut self) -> &[(ArrayWrapper<DA>, DATA)][src]

Mutable version of data.

Safety

Indices can be modified to overflow its dimensions.

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

Mutable version of value.

impl<DA, DATA, DS> Coo<DA, DS> where
    DA: Dims,
    DS: AsMut<[<DS as Storage>::Item]> + AsRef<[<DS as Storage>::Item]> + Default + Storage<Item = (ArrayWrapper<DA>, DATA)> + Push<Input = <DS as Storage>::Item>, 
[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::coo::CooVec;
use rand::{thread_rng, Rng};
let mut _random: CooVec<[usize; 8], u8>;
let mut rng = thread_rng();
_random = CooVec::new_random_with_rand([1, 2, 3, 4, 5, 6, 7, 8], 9, &mut rng, |r, _| r.gen());

Trait Implementations

impl<DA: Clone, DS: Clone> Clone for Coo<DA, DS> where
    DA: Dims
[src]

impl<DA: Debug, DS: Debug> Debug for Coo<DA, DS> where
    DA: Dims
[src]

impl<DA: Default, DS: Default> Default for Coo<DA, DS> where
    DA: Dims
[src]

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

impl<DA: PartialEq, DS: PartialEq> PartialEq<Coo<DA, DS>> for Coo<DA, DS> where
    DA: Dims
[src]

impl<DA, DS> Serialize for Coo<DA, DS> where
    DA: Dims,
    DA: Serialize,
    DS: Serialize
[src]

impl<DA, DS> StructuralPartialEq for Coo<DA, DS> where
    DA: Dims
[src]

Auto Trait Implementations

impl<DA, DS> RefUnwindSafe for Coo<DA, DS> where
    DA: RefUnwindSafe,
    DS: RefUnwindSafe

impl<DA, DS> Send for Coo<DA, DS> where
    DA: Send,
    DS: Send

impl<DA, DS> Sync for Coo<DA, DS> where
    DA: Sync,
    DS: Sync

impl<DA, DS> Unpin for Coo<DA, DS> where
    DA: Unpin,
    DS: Unpin

impl<DA, DS> UnwindSafe for Coo<DA, DS> where
    DA: UnwindSafe,
    DS: 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>,