Struct sprs::sparse::vec::CsVec
[−]
[src]
pub struct CsVec<N, IStorage, DStorage> where N: Clone, IStorage: Deref<Target=[usize]>, DStorage: Deref<Target=[N]> {
// some fields omitted
}
A sparse vector, storing the indices of its non-zero data. The indices should be sorted.
Methods
impl<'a, N: 'a + Copy> CsVec<N, &'a [usize], &'a [N]>
[src]
fn new_borrowed(n: usize, indices: &'a [usize], data: &'a [N]) -> Result<CsVec<N, &'a [usize], &'a [N]>, SprsError>
Create a borrowed CsVec over slice data.
unsafe fn new_raw(n: usize, nnz: usize, indices: *const usize, data: *const N) -> CsVec<N, &'a [usize], &'a [N]>
Create a borrowed CsVec over slice data without checking the structure This is unsafe because algorithms are free to assume that properties guaranteed by check_structure are enforced. For instance, non out-of-bounds indices can be relied upon to perform unchecked slice access.
impl<N: Copy> CsVec<N, Vec<usize>, Vec<N>>
[src]
fn new_owned(n: usize, indices: Vec<usize>, data: Vec<N>) -> Result<CsVec<N, Vec<usize>, Vec<N>>, SprsError>
Create an owning CsVec from vector data.
fn empty(dim: usize) -> CsVec<N, Vec<usize>, Vec<N>>
Create an empty CsVec, which can be used for incremental construction
fn append(&mut self, ind: usize, val: N)
Append an element to the sparse vector. Used for incremental building of the CsVec. The append should preserve the structure of the vector, ie the newly added index should be strictly greater than the last element of indices.
Panics
Panics if ind
is lower or equal to the last
element of self.indices()
Panics if ind
is greater than self.dim()
fn reserve(&mut self, size: usize)
Reserve size
additional non-zero values.
fn reserve_exact(&mut self, exact_size: usize)
Reserve exactly exact_size
non-zero values.
fn clear(&mut self)
Clear the underlying storage
impl<N, IStorage, DStorage> CsVec<N, IStorage, DStorage> where N: Copy, IStorage: Deref<Target=[usize]>, DStorage: Deref<Target=[N]>
[src]
impl<'a, N, IStorage, DStorage> CsVec<N, IStorage, DStorage> where N: 'a + Copy, IStorage: 'a + Deref<Target=[usize]>, DStorage: Deref<Target=[N]>
[src]
fn iter(&self) -> VectorIterator<N>
Iterate over the non zero values.
Example
use sprs::CsVec; let v = CsVec::new_owned(5, vec![0, 2, 4], vec![1., 2., 3.]).unwrap(); let mut iter = v.iter(); assert_eq!(iter.next(), Some((0, 1.))); assert_eq!(iter.next(), Some((2, 2.))); assert_eq!(iter.next(), Some((4, 3.))); assert_eq!(iter.next(), None);
fn indices(&self) -> &[usize]
The underlying indices.
fn data(&self) -> &[N]
The underlying non zero values.
fn dim(&self) -> usize
The dimension of this vector.
fn nnz(&self) -> usize
The non zero count of this vector.
fn check_structure(&self) -> Result<(), SprsError>
Check the sparse structure, namely that: - indices is sorted - indices are lower than dims()
fn to_owned(&self) -> CsVecOwned<N>
Allocate a new vector equal to this one.
fn row_view(&self) -> CsMatVecView<N>
View this vector as a matrix with only one row.
fn col_view(&self) -> CsMatVecView<N>
View this vector as a matrix with only one column.
fn dot<IS2, DS2>(&self, rhs: &CsVec<N, IS2, DS2>) -> N where N: Num, IS2: Deref<Target=[usize]>, DS2: Deref<Target=[N]>
Vector dot product
Example
use sprs::CsVec; let v1 = CsVec::new_owned(8, vec![1, 2, 4, 6], vec![1.; 4]).unwrap(); let v2 = CsVec::new_owned(8, vec![1, 3, 5, 7], vec![2.; 4]).unwrap(); assert_eq!(2., v1.dot(&v2)); assert_eq!(4., v1.dot(&v1)); assert_eq!(16., v2.dot(&v2));
Trait Implementations
impl<N: Debug, IStorage: Debug, DStorage: Debug> Debug for CsVec<N, IStorage, DStorage> where N: Clone, IStorage: Deref<Target=[usize]>, DStorage: Deref<Target=[N]>
[src]
impl<N: PartialEq, IStorage: PartialEq, DStorage: PartialEq> PartialEq for CsVec<N, IStorage, DStorage> where N: Clone, IStorage: Deref<Target=[usize]>, DStorage: Deref<Target=[N]>
[src]
fn eq(&self, __arg_0: &CsVec<N, IStorage, DStorage>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &CsVec<N, IStorage, DStorage>) -> bool
This method tests for !=
.
impl<'a, 'b, N, IS1, DS1, IpS2, IS2, DS2> Mul<&'b CsMat<N, IpS2, IS2, DS2>> for &'a CsVec<N, IS1, DS1> where N: 'a + Copy + Num + Default, IS1: 'a + Deref<Target=[usize]>, DS1: 'a + Deref<Target=[N]>, IpS2: 'b + Deref<Target=[usize]>, IS2: 'b + Deref<Target=[usize]>, DS2: 'b + Deref<Target=[N]>
[src]
type Output = CsVecOwned<N>
The resulting type after applying the *
operator
fn mul(self, rhs: &CsMat<N, IpS2, IS2, DS2>) -> CsVecOwned<N>
The method for the *
operator
impl<'a, 'b, N, IS1, DS1, IS2, DS2> Add<&'b CsVec<N, IS2, DS2>> for &'a CsVec<N, IS1, DS1> where N: Copy + Num, IS1: Deref<Target=[usize]>, DS1: Deref<Target=[N]>, IS2: Deref<Target=[usize]>, DS2: Deref<Target=[N]>
[src]
type Output = CsVecOwned<N>
The resulting type after applying the +
operator
fn add(self, rhs: &CsVec<N, IS2, DS2>) -> CsVecOwned<N>
The method for the +
operator
impl<'a, 'b, N, IS1, DS1, IS2, DS2> Sub<&'b CsVec<N, IS2, DS2>> for &'a CsVec<N, IS1, DS1> where N: Copy + Num, IS1: Deref<Target=[usize]>, DS1: Deref<Target=[N]>, IS2: Deref<Target=[usize]>, DS2: Deref<Target=[N]>
[src]
type Output = CsVecOwned<N>
The resulting type after applying the -
operator
fn sub(self, rhs: &CsVec<N, IS2, DS2>) -> CsVecOwned<N>
The method for the -
operator