orx_v

Struct SparseVec

Source
pub struct SparseVec<D, T, C, L = DefaultLookup<D, T>>
where D: Dim, T: Copy, L: Lookup<D::Idx, T>, C: Card<D>,
{ /* private fields */ }
Expand description

A sparse vector of dimension D.

Sparse vectors maintain a (idx, value) lookup under the hood and has a default_value, and works as follows:

  • at(idx) returns the corresponding value if the idx exists in the lookup, or the default value otherwise.
  • at_mut(idx) first adds (idx, default_value) to the lookup only if it is absent, and returns a mutable reference to the value in the lookup.

The objective of sparse vectors are to significantly reduce the memory requirement of vectors which has the same value for most of its positions. Consider for instance a 100x100 matrix which is all zeros except for the element at the (42,42)-th position which is 42. This matrix can be represented by a sparse vector with lookup containing only one element.

Since sparse vector assumes all indices absent in the lookup have the default_value, the vector on construction has UnboundedCard; i.e., it has a value for any possible index.

In order to convert the sparse vector into one with a provided bound, you may use the bounded, with_rectangular_bounds or with_variable_bounds transformations.

Implementations§

Source§

impl<T, L> SparseVec<D1, T, UnboundedCard<D1>, L>
where T: Copy, L: Lookup<<D1 as Dim>::Idx, T>,

Source

pub fn bounded(self, num_elements: usize) -> SparseVec<D1, T, CardD1, L>

Converts an unbounded sparse vector into one with a provided bound.

Note that in practice, unbounded cardinality corresponds to a length of usize::MAX. One needs to be careful in using the all method which would iterate over the entire 0..usize::MAX range unless it is stopped on a condition such as in find method or limited by methods such as take.

With bounded method, domain of the vector is defined.

§Examples
use orx_v::*;

let v1 = V.d1().sparse(42);
assert!(v1.is_unbounded());

let mut v1 = V.d1().sparse(42).bounded(4);
assert!(v1.is_bounded());
assert_eq!(v1.card([]), 4);

*v1.at_mut(0) = 10;
v1.set(2, 4);

assert_eq!(
    v1.equality(&[10, 42, 4, 42]),
    Equality::Equal
);

assert_eq!(v1.in_bounds([100]), false);
assert_eq!(v1.try_at([100]), None);
assert_eq!(v1.at([100]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source§

impl<T, L> SparseVec<D2, T, UnboundedCard<D2>, L>
where T: Copy, L: Lookup<<D2 as Dim>::Idx, T>,

Source

pub fn with_rectangular_bounds( self, dimensions: [usize; 2], ) -> SparseVec<D2, T, RectangularCardD2, L>

Converts an unbounded sparse vector into one with rectangular bounds as in matrices:

  • the vector has dimensions[0] children, and
  • each children has dimensions[1] elements.
§Examples
use orx_v::*;

let v2 = V.d2().sparse(42);
assert!(v2.is_unbounded());

let mut v2 = V.d2().sparse(42).with_rectangular_bounds([2, 3]);
assert!(v2.is_bounded());
assert_eq!(v2.card([]), 2);
assert_eq!(v2.card([0]), 3);
assert_eq!(v2.card([1]), 3);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 4);

assert_eq!(
    v2.equality(&[[10, 42, 42], [42, 42, 4]]),
    Equality::Equal
);

assert_eq!(v2.in_bounds([100, 27]), false);
assert_eq!(v2.try_at([100, 27]), None);
assert_eq!(v2.at([100, 27]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source

pub fn with_variable_bounds<C>( self, cardinality: C, ) -> SparseVec<D2, T, VariableCardD2<C>, L>
where C: V1<usize>,

Converts an unbounded sparse vector into one with variable bounds as in jagged arrays:

  • the vector has cardinality.card([]) children, and
  • i-th child has cardinality.at([i]) elements.
§Examples
use orx_v::*;

// jagged => [ [42, 42], [42, 42, 42], [42] ]
let num_cols = vec![2, 3, 1];
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 3);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 1);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42]]),
    Equality::Equal,
);

// jagged => [ [42, 42], [42, 42, 42], [42, 42], [42, 42, 42] ]
let num_cols = V.d1().fun(|[i]| match i % 2 == 0 {
    true => 2,
    false => 3,
}).bounded(4);
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 4);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 2);
assert_eq!(v2.card([3]), 3);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42, 42], vec![42, 42, 42]]),
    Equality::Equal,
);

assert_eq!(v2.in_bounds([100, 27]), false);
assert_eq!(v2.try_at([100, 27]), None);
assert_eq!(v2.at([100, 27]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source§

impl<T, L> SparseVec<D3, T, UnboundedCard<D3>, L>
where T: Copy, L: Lookup<<D3 as Dim>::Idx, T>,

Source

pub fn with_rectangular_bounds( self, dimensions: [usize; 3], ) -> SparseVec<D3, T, RectangularCardD3, L>

Converts an unbounded sparse vector into one with rectangular bounds as in a dimensions[0] x dimensions[1] x dimensions[2] matrix.

§Examples
use orx_v::*;

let v3 = V.d3().sparse(42);
assert!(v3.is_unbounded());

let mut v3 = V.d3().sparse(42).with_rectangular_bounds([2, 1, 3]);
assert!(v3.is_bounded());
assert_eq!(v3.card([]), 2);
assert_eq!(v3.card([0]), 1);
assert_eq!(v3.card([1]), 1);
assert_eq!(v3.card([0, 0]), 3);
assert_eq!(v3.card([1, 0]), 3);

*v3.at_mut([0, 0, 0]) = 10;
v3.set([1, 0, 2], 4);

assert_eq!(
    v3.equality(&[[[10, 42, 42]], [[42, 42, 4]]]),
    Equality::Equal
);

assert_eq!(v3.in_bounds([100, 27, 75]), false);
assert_eq!(v3.try_at([100, 27, 75]), None);
assert_eq!(v3.at([100, 27, 75]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source

pub fn with_variable_bounds<C>( self, cardinality: C, ) -> SparseVec<D3, T, VariableCardD3<C>, L>
where C: V2<usize>,

Converts an unbounded sparse vector into one with variable bounds as in jagged arrays:

  • the vector has cardinality.card([]) children, and
  • i-th child has cardinality.card([i]) children, and
  • j-th child of the i-th child has cardinality.at([i, j]) elements.
§Examples
use orx_v::*;

// jagged => [ [42, 42], [42, 42, 42], [42] ]
let num_cols = vec![2, 3, 1];
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 3);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 1);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42]]),
    Equality::Equal,
);

// jagged => [ [42, 42], [42, 42, 42], [42, 42], [42, 42, 42] ]
let num_cols = V.d1().fun(|[i]| match i % 2 == 0 {
    true => 2,
    false => 3,
}).bounded(4);
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 4);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 2);
assert_eq!(v2.card([3]), 3);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42, 42], vec![42, 42, 42]]),
    Equality::Equal,
);

assert_eq!(v2.in_bounds([100, 27]), false);
assert_eq!(v2.try_at([100, 27]), None);
assert_eq!(v2.at([100, 27]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source§

impl<T, L> SparseVec<D4, T, UnboundedCard<D4>, L>
where T: Copy, L: Lookup<<D4 as Dim>::Idx, T>,

Source

pub fn with_rectangular_bounds( self, dimensions: [usize; 4], ) -> SparseVec<D4, T, RectangularCardD4, L>

Converts an unbounded sparse vector into one with rectangular bounds as in a dimensions[0] x dimensions[1] x dimensions[2] x dimensions[3] matrix.

§Examples
use orx_v::*;

let v3 = V.d3().sparse(42);
assert!(v3.is_unbounded());

let mut v3 = V.d3().sparse(42).with_rectangular_bounds([2, 1, 3]);
assert!(v3.is_bounded());
assert_eq!(v3.card([]), 2);
assert_eq!(v3.card([0]), 1);
assert_eq!(v3.card([1]), 1);
assert_eq!(v3.card([0, 0]), 3);
assert_eq!(v3.card([1, 0]), 3);

*v3.at_mut([0, 0, 0]) = 10;
v3.set([1, 0, 2], 4);

assert_eq!(
    v3.equality(&[[[10, 42, 42]], [[42, 42, 4]]]),
    Equality::Equal
);

assert_eq!(v3.in_bounds([100, 27, 75]), false);
assert_eq!(v3.try_at([100, 27, 75]), None);
assert_eq!(v3.at([100, 27, 75]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source

pub fn with_variable_bounds<C>( self, cardinality: C, ) -> SparseVec<D4, T, VariableCardD4<C>, L>
where C: V3<usize>,

Converts an unbounded sparse vector into one with variable bounds as in jagged arrays:

  • the vector has cardinality.card([]) children, and
  • i-th child has cardinality.card([i]) children, and
  • j-th child of the i-th child has cardinality.card([i, j]) children, and
  • k-th child of the [i,j]-th child has cardinality.at([i, j, k]) elements.
§Examples
use orx_v::*;

// jagged => [ [42, 42], [42, 42, 42], [42] ]
let num_cols = vec![2, 3, 1];
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 3);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 1);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42]]),
    Equality::Equal,
);

// jagged => [ [42, 42], [42, 42, 42], [42, 42], [42, 42, 42] ]
let num_cols = V.d1().fun(|[i]| match i % 2 == 0 {
    true => 2,
    false => 3,
}).bounded(4);
let mut v2 = V.d2().sparse(42).with_variable_bounds(num_cols);

assert_eq!(v2.card([]), 4);
assert_eq!(v2.card([0]), 2);
assert_eq!(v2.card([1]), 3);
assert_eq!(v2.card([2]), 2);
assert_eq!(v2.card([3]), 3);

*v2.at_mut([0, 0]) = 10;
v2.set([1, 2], 20);

assert_eq!(
    v2.equality(&[vec![10, 42], vec![42, 42, 20], vec![42, 42], vec![42, 42, 42]]),
    Equality::Equal,
);

assert_eq!(v2.in_bounds([100, 27]), false);
assert_eq!(v2.try_at([100, 27]), None);
assert_eq!(v2.at([100, 27]), 42); // (!) un-compromised performance

(!) un-compromised performance

Main reason to add bounds to a sparse vector is to set its domain. However, calling at with an out-of-bounds index can still produce a valid element in order not to compromise performance. If we want to check whether or not an index is in bounds or not, we can use the in_bounds or card methods, or use try_at instead which would return None if the index is out of bounds.

Source§

impl<D, T, L, C> SparseVec<D, T, C, L>
where D: Dim, T: Copy, L: Lookup<D::Idx, T>, C: Card<D>,

Source

pub fn new(lookup: L, default_value: T, card: C) -> Self

Creates a new sparse vector with the given card where all elements that are absent in the lookup are equal to value.

The lookup can later be extended by using at_mut or set methods.

Alternatively, unbounded sparse vectors of different dimensions can be created by V.d1().sparse(42), V.d2().sparse(42), etc., which can later be transformed into bounded vectors by applying bounded, with_rectangular_bounds or with_variable_bounds transformations.

Similarly, an unbounded sparse vector can be created by a non-empty lookup by V.d1().sparse_from(lookup, 42), V.d2().sparse_from(lookup, 42), etc.

Source

pub fn into_inner(self) -> (L, C)

Destructs the sparse vector into its inner lookup and cardinality.

Source

pub fn lookup_len(&self) -> usize

Returns the number of non-default elements which are actually stored in the lookup.

Trait Implementations§

Source§

impl<T, C, L> Debug for SparseVec<D1, T, C, L>
where T: Copy + Debug, L: Lookup<<D1 as Dim>::Idx, T>, C: Card<D1>, Self: NVec<D1, T>,

Source§

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

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

impl<T, C, L> Debug for SparseVec<D2, T, C, L>
where T: Copy + Debug, L: Lookup<<D2 as Dim>::Idx, T>, C: Card<D2>, Self: NVec<D2, T>,

Source§

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

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

impl<T, C, L> Debug for SparseVec<D3, T, C, L>
where T: Copy + Debug, L: Lookup<<D3 as Dim>::Idx, T>, C: Card<D3>, Self: NVec<D3, T>,

Source§

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

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

impl<T, C, L> Debug for SparseVec<D4, T, C, L>
where T: Copy + Debug, L: Lookup<<D4 as Dim>::Idx, T>, C: Card<D4>, Self: NVec<D4, T>,

Source§

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

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

impl<T, L, C> NVec<D1, T> for SparseVec<D1, T, C, L>
where T: Copy + Default, L: Lookup<<D1 as Dim>::Idx, T>, C: Card<D1>,

Source§

fn at(&self, idx: impl IntoIdx<D1>) -> T

Returns the element at the idx-th position of the vector. Read more
Source§

fn in_bounds(&self, idx: impl Into<<D1 as Dim>::LeqIdx>) -> bool

Returns whether or not the given idx is in bounds. Read more
Source§

fn child(&self, _: <D1 as Dim>::ChildIdx) -> impl NVec<<D1 as Dim>::PrevDim, T>

Returns the i-th child of the vector. Read more
Source§

fn all(&self) -> impl Iterator<Item = T>

Returns a flattened iterator over all scalar (D0) elements of the vector. Read more
Source§

fn num_children(&self) -> usize

Returns the number of children of the vector; i.e., number of elements of the one lower dimension. Read more
Source§

fn card(&self, idx: impl Into<D::CardIdx>) -> usize

Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§

fn is_bounded(&self) -> bool

Returns whether or not the vector is bounded. Read more
Source§

fn is_rectangular(&self) -> bool

Returns whether or not the cardinalities of the vector are rectangular. A rectangular vector of dimension D has the same number of children at a given lower dimension for all indices. Read more
Source§

fn is_unbounded(&self) -> bool

Returns whether or not the vector is unbounded. Read more
Source§

fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>

Returns the cardinality equality of this vec with the other: Read more
Source§

fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>

Returns the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>
where T: PartialEq,

Returns the equality of this vec with the other: Read more
Source§

fn children(&self) -> impl Iterator<Item = impl NVec<D::PrevDim, T>>

Returns an iterator of all children of the vector. Read more
Source§

fn all_in( &self, indices: impl Iterator<Item = impl IntoIdx<D>>, ) -> impl Iterator<Item = T>

Returns an iterator of elements for the given indices. Read more
Source§

impl<T, L, C> NVec<D2, T> for SparseVec<D2, T, C, L>
where T: Copy, L: Lookup<<D2 as Dim>::Idx, T>, C: Card<D2>,

Source§

fn at(&self, idx: impl IntoIdx<D2>) -> T

Returns the element at the idx-th position of the vector. Read more
Source§

fn in_bounds(&self, idx: impl Into<<D2 as Dim>::LeqIdx>) -> bool

Returns whether or not the given idx is in bounds. Read more
Source§

fn child(&self, i: <D2 as Dim>::ChildIdx) -> impl NVec<<D2 as Dim>::PrevDim, T>

Returns the i-th child of the vector. Read more
Source§

fn all(&self) -> impl Iterator<Item = T>

Returns a flattened iterator over all scalar (D0) elements of the vector. Read more
Source§

fn num_children(&self) -> usize

Returns the number of children of the vector; i.e., number of elements of the one lower dimension. Read more
Source§

fn card(&self, idx: impl Into<D::CardIdx>) -> usize

Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§

fn is_bounded(&self) -> bool

Returns whether or not the vector is bounded. Read more
Source§

fn is_rectangular(&self) -> bool

Returns whether or not the cardinalities of the vector are rectangular. A rectangular vector of dimension D has the same number of children at a given lower dimension for all indices. Read more
Source§

fn is_unbounded(&self) -> bool

Returns whether or not the vector is unbounded. Read more
Source§

fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>

Returns the cardinality equality of this vec with the other: Read more
Source§

fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>

Returns the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>
where T: PartialEq,

Returns the equality of this vec with the other: Read more
Source§

fn children(&self) -> impl Iterator<Item = impl NVec<D::PrevDim, T>>

Returns an iterator of all children of the vector. Read more
Source§

fn all_in( &self, indices: impl Iterator<Item = impl IntoIdx<D>>, ) -> impl Iterator<Item = T>

Returns an iterator of elements for the given indices. Read more
Source§

impl<T, L, C> NVec<D3, T> for SparseVec<D3, T, C, L>
where T: Copy, L: Lookup<<D3 as Dim>::Idx, T>, C: Card<D3>,

Source§

fn at(&self, idx: impl IntoIdx<D3>) -> T

Returns the element at the idx-th position of the vector. Read more
Source§

fn in_bounds(&self, idx: impl Into<<D3 as Dim>::LeqIdx>) -> bool

Returns whether or not the given idx is in bounds. Read more
Source§

fn child(&self, i: <D3 as Dim>::ChildIdx) -> impl NVec<<D3 as Dim>::PrevDim, T>

Returns the i-th child of the vector. Read more
Source§

fn all(&self) -> impl Iterator<Item = T>

Returns a flattened iterator over all scalar (D0) elements of the vector. Read more
Source§

fn num_children(&self) -> usize

Returns the number of children of the vector; i.e., number of elements of the one lower dimension. Read more
Source§

fn card(&self, idx: impl Into<D::CardIdx>) -> usize

Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§

fn is_bounded(&self) -> bool

Returns whether or not the vector is bounded. Read more
Source§

fn is_rectangular(&self) -> bool

Returns whether or not the cardinalities of the vector are rectangular. A rectangular vector of dimension D has the same number of children at a given lower dimension for all indices. Read more
Source§

fn is_unbounded(&self) -> bool

Returns whether or not the vector is unbounded. Read more
Source§

fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>

Returns the cardinality equality of this vec with the other: Read more
Source§

fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>

Returns the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>
where T: PartialEq,

Returns the equality of this vec with the other: Read more
Source§

fn children(&self) -> impl Iterator<Item = impl NVec<D::PrevDim, T>>

Returns an iterator of all children of the vector. Read more
Source§

fn all_in( &self, indices: impl Iterator<Item = impl IntoIdx<D>>, ) -> impl Iterator<Item = T>

Returns an iterator of elements for the given indices. Read more
Source§

impl<T, L, C> NVec<D4, T> for SparseVec<D4, T, C, L>
where T: Copy, L: Lookup<<D4 as Dim>::Idx, T>, C: Card<D4>,

Source§

fn at(&self, idx: impl IntoIdx<D4>) -> T

Returns the element at the idx-th position of the vector. Read more
Source§

fn in_bounds(&self, idx: impl Into<<D4 as Dim>::LeqIdx>) -> bool

Returns whether or not the given idx is in bounds. Read more
Source§

fn child(&self, i: <D4 as Dim>::ChildIdx) -> impl NVec<<D4 as Dim>::PrevDim, T>

Returns the i-th child of the vector. Read more
Source§

fn all(&self) -> impl Iterator<Item = T>

Returns a flattened iterator over all scalar (D0) elements of the vector. Read more
Source§

fn num_children(&self) -> usize

Returns the number of children of the vector; i.e., number of elements of the one lower dimension. Read more
Source§

fn card(&self, idx: impl Into<D::CardIdx>) -> usize

Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§

fn is_bounded(&self) -> bool

Returns whether or not the vector is bounded. Read more
Source§

fn is_rectangular(&self) -> bool

Returns whether or not the cardinalities of the vector are rectangular. A rectangular vector of dimension D has the same number of children at a given lower dimension for all indices. Read more
Source§

fn is_unbounded(&self) -> bool

Returns whether or not the vector is unbounded. Read more
Source§

fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>

Returns the cardinality equality of this vec with the other: Read more
Source§

fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>

Returns the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>
where T: PartialEq,

Returns the equality of this vec with the other: Read more
Source§

fn children(&self) -> impl Iterator<Item = impl NVec<D::PrevDim, T>>

Returns an iterator of all children of the vector. Read more
Source§

fn all_in( &self, indices: impl Iterator<Item = impl IntoIdx<D>>, ) -> impl Iterator<Item = T>

Returns an iterator of elements for the given indices. Read more
Source§

impl<T, L, C> NVecMut<D1, T> for SparseVec<D1, T, C, L>
where T: Copy + Default, L: Lookup<<D1 as Dim>::Idx, T>, C: Card<D1>,

Source§

fn at_mut<Idx: IntoIdx<D1>>(&mut self, idx: Idx) -> &mut T

Returns a mutable reference to the element at the idx-th position of the vector. Read more
Source§

fn set<Idx: IntoIdx<D1>>(&mut self, idx: Idx, value: T)

Sets valueof the element at the idx-th position of the vector. Read more
Source§

fn child_mut( &mut self, _: <D1 as Dim>::ChildIdx, ) -> impl NVecMut<<D1 as Dim>::PrevDim, T>

Returns a mutable reference to the i-th child of the vector. Read more
Source§

fn mut_all<F>(&mut self, f: F)
where F: FnMut(&mut T),

Applies the mutating function f over all scalar elements of the vector. Read more
Source§

fn reset_all(&mut self, value: T)
where T: PartialEq + Copy,

Sets all elements of the vector to the given value. This method is often used at initialization stage of algorithms. Read more
Source§

fn try_at_mut(&mut self, idx: impl IntoIdx<D>) -> Option<&mut T>

Returns a mutable reference to the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

impl<T, L, C> NVecMut<D2, T> for SparseVec<D2, T, C, L>
where T: Copy, L: Lookup<<D2 as Dim>::Idx, T>, C: Card<D2>,

Source§

fn at_mut<Idx: IntoIdx<D2>>(&mut self, idx: Idx) -> &mut T

Returns a mutable reference to the element at the idx-th position of the vector. Read more
Source§

fn set<Idx: IntoIdx<D2>>(&mut self, idx: Idx, value: T)

Sets valueof the element at the idx-th position of the vector. Read more
Source§

fn child_mut( &mut self, i: <D2 as Dim>::ChildIdx, ) -> impl NVecMut<<D2 as Dim>::PrevDim, T>

Returns a mutable reference to the i-th child of the vector. Read more
Source§

fn mut_all<F>(&mut self, f: F)
where F: FnMut(&mut T),

Applies the mutating function f over all scalar elements of the vector. Read more
Source§

fn reset_all(&mut self, value: T)
where T: PartialEq + Copy,

Sets all elements of the vector to the given value. This method is often used at initialization stage of algorithms. Read more
Source§

fn try_at_mut(&mut self, idx: impl IntoIdx<D>) -> Option<&mut T>

Returns a mutable reference to the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

impl<T, L, C> NVecMut<D3, T> for SparseVec<D3, T, C, L>
where T: Copy, L: Lookup<<D3 as Dim>::Idx, T>, C: Card<D3>,

Source§

fn at_mut<Idx: IntoIdx<D3>>(&mut self, idx: Idx) -> &mut T

Returns a mutable reference to the element at the idx-th position of the vector. Read more
Source§

fn set<Idx: IntoIdx<D3>>(&mut self, idx: Idx, value: T)

Sets valueof the element at the idx-th position of the vector. Read more
Source§

fn child_mut( &mut self, i: <D3 as Dim>::ChildIdx, ) -> impl NVecMut<<D3 as Dim>::PrevDim, T>

Returns a mutable reference to the i-th child of the vector. Read more
Source§

fn mut_all<F>(&mut self, f: F)
where F: FnMut(&mut T),

Applies the mutating function f over all scalar elements of the vector. Read more
Source§

fn reset_all(&mut self, value: T)
where T: PartialEq + Copy,

Sets all elements of the vector to the given value. This method is often used at initialization stage of algorithms. Read more
Source§

fn try_at_mut(&mut self, idx: impl IntoIdx<D>) -> Option<&mut T>

Returns a mutable reference to the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more
Source§

impl<T, L, C> NVecMut<D4, T> for SparseVec<D4, T, C, L>
where T: Copy, L: Lookup<<D4 as Dim>::Idx, T>, C: Card<D4>,

Source§

fn at_mut<Idx: IntoIdx<D4>>(&mut self, idx: Idx) -> &mut T

Returns a mutable reference to the element at the idx-th position of the vector. Read more
Source§

fn set<Idx: IntoIdx<D4>>(&mut self, idx: Idx, value: T)

Sets valueof the element at the idx-th position of the vector. Read more
Source§

fn child_mut( &mut self, i: <D4 as Dim>::ChildIdx, ) -> impl NVecMut<<D4 as Dim>::PrevDim, T>

Returns a mutable reference to the i-th child of the vector. Read more
Source§

fn mut_all<F>(&mut self, f: F)
where F: FnMut(&mut T),

Applies the mutating function f over all scalar elements of the vector. Read more
Source§

fn reset_all(&mut self, value: T)
where T: PartialEq + Copy,

Sets all elements of the vector to the given value. This method is often used at initialization stage of algorithms. Read more
Source§

fn try_at_mut(&mut self, idx: impl IntoIdx<D>) -> Option<&mut T>

Returns a mutable reference to the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more

Auto Trait Implementations§

§

impl<D, T, C, L> Freeze for SparseVec<D, T, C, L>
where L: Freeze, T: Freeze, C: Freeze,

§

impl<D, T, C, L> RefUnwindSafe for SparseVec<D, T, C, L>

§

impl<D, T, C, L> Send for SparseVec<D, T, C, L>
where L: Send, T: Send, C: Send, D: Send,

§

impl<D, T, C, L> Sync for SparseVec<D, T, C, L>
where L: Sync, T: Sync, C: Sync, D: Sync,

§

impl<D, T, C, L> Unpin for SparseVec<D, T, C, L>
where L: Unpin, T: Unpin, C: Unpin, D: Unpin,

§

impl<D, T, C, L> UnwindSafe for SparseVec<D, T, C, L>

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> 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, V> IntoJagged<T> for V
where V: NVec<D1, T>,

Source§

fn into_jagged<I>(self, row_end_indices: I) -> FlatJagged<Self, I, T>
where I: NVec<D1, usize>,

Converts a D1 vector into a jagged D2 vector where each row is identified by row_end_indices. Read more
Source§

fn as_jagged<I>(&self, row_end_indices: I) -> FlatJagged<&Self, I, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a jagged D2 vector view where each row is identified by row_end_indices. Read more
Source§

fn as_jagged_mut<I>( &mut self, row_end_indices: I, ) -> FlatJagged<&mut Self, I, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a mutable jagged D2 vector view where each row is identified by row_end_indices. Read more
Source§

fn into_jagged_from_row_lengths<I>( self, row_lengths: &I, ) -> FlatJagged<Self, Vec<usize>, T>
where I: NVec<D1, usize>,

Converts a D1 vector into a jagged D2 vector where each row is identified by row_lengths. Read more
Source§

fn as_jagged_from_row_lengths<I>( &self, row_lengths: &I, ) -> FlatJagged<&Self, Vec<usize>, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a jagged D2 vector view where each row is identified by row_lengths. Read more
Source§

fn as_jagged_mut_from_row_lengths<I>( &mut self, row_lengths: &I, ) -> FlatJagged<&mut Self, Vec<usize>, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a mutable jagged D2 vector view where each row is identified by row_lengths. Read more
Source§

fn into_jagged_with_uniform_lengths( self, uniform_length: usize, ) -> FlatJagged<Self, UniformEndIndices, T>

Converts a D1 vector into a jagged D2 vector where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length. Read more
Source§

fn as_jagged_with_uniform_lengths( &self, uniform_length: usize, ) -> FlatJagged<&Self, UniformEndIndices, T>

From a flat D1 vector, creates a jagged D2 vector view where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length. Read more
Source§

fn as_jagged_mut_with_uniform_lengths( &mut self, uniform_length: usize, ) -> FlatJagged<&mut Self, UniformEndIndices, T>

From a flat D1 vector, creates a mutable jagged D2 vector view where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length. 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, V> V1AsMatrix<T> for V
where V: NVec<D1, T>,

Source§

fn v1_into_matrix( self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, Self, V1LayoutRowMajor>
where Self: NVec<D1, T>,

Converts the flat D1 vector into a row-major matrix. Read more
Source§

fn v1_as_matrix( &self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, &Self, V1LayoutRowMajor>
where Self: NVec<D1, T>,

Creates a row-major matrix view over the flat D1 vector. Read more
Source§

fn v1_as_matrix_mut( &mut self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, &mut Self, V1LayoutRowMajor>
where Self: NVecMut<D1, T>,

Creates a mutable row-major matrix view over the flat D1 vector. Read more
Source§

fn v1_into_matrix_col_major( self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, Self, V1LayoutColMajor>
where Self: NVec<D1, T>,

Converts the flat D1 vector into a column-major matrix. Read more
Source§

fn v1_as_matrix_col_major( &self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, &Self, V1LayoutColMajor>
where Self: NVec<D1, T>,

Creates a column-major matrix view over the flat D1 vector. Read more
Source§

fn v1_as_matrix_col_major_mut( &mut self, num_rows: usize, num_cols: usize, ) -> V1Matrix<T, &mut Self, V1LayoutColMajor>
where Self: NVecMut<D1, T>,

Creates a mutable column-major matrix view over the flat D1 vector. Read more
Source§

impl<T, V> V2AsMatrix<T> for V
where V: NVec<D2, T>,

Source§

fn into_matrix(self) -> V2MatrixRowMajor<T, Self>
where Self: NVec<D2, T>,

Converts the rectangular D2 vector into a row-major matrix. Read more
Source§

fn as_matrix(&self) -> V2MatrixRowMajor<T, &Self>
where Self: NVec<D2, T>,

Creates a row-major matrix view over the rectangular D2 vector. Read more
Source§

fn as_matrix_mut(&mut self) -> V2MatrixRowMajor<T, &mut Self>
where Self: NVecMut<D2, T>,

Creates a mutable row-major matrix view over the rectangular D2 vector. Read more
Source§

fn into_matrix_col_major(self) -> V2MatrixColMajor<T, Self>
where Self: NVec<D2, T>,

Converts the rectangular D2 vector into a column-major matrix. Read more
Source§

fn as_matrix_col_major(&self) -> V2MatrixColMajor<T, &Self>
where Self: NVec<D2, T>,

Creates a column-major matrix view over the rectangular D2 vector. Read more
Source§

fn as_matrix_col_major_mut(&mut self) -> V2MatrixColMajor<T, &mut Self>
where Self: NVecMut<D2, T>,

Creates a mutable column-major matrix view over the rectangular D2 vector. Read more
Source§

impl<D, V, T> NVecCore<D, T> for V
where D: Dim, V: NVecCoreSealed<D, T>,

Source§

impl<T, N> V1<T> for N
where N: NVec<D1, T>,

Source§

impl<T, N> V1Mut<T> for N
where N: NVecMut<D1, T>,

Source§

impl<T, N> V2<T> for N
where N: NVec<D2, T>,

Source§

impl<T, N> V2Mut<T> for N
where N: NVecMut<D2, T>,

Source§

impl<T, N> V3<T> for N
where N: NVec<D3, T>,

Source§

impl<T, N> V3Mut<T> for N
where N: NVecMut<D3, T>,

Source§

impl<T, N> V4<T> for N
where N: NVec<D4, T>,

Source§

impl<T, N> V4Mut<T> for N
where N: NVecMut<D4, T>,