Struct sprs::IndPtrBase
source · pub struct IndPtrBase<Iptr, Storage>where
Iptr: SpIndex,
Storage: Deref<Target = [Iptr]>,{ /* private fields */ }
Implementations§
source§impl<Iptr, Storage> IndPtrBase<Iptr, Storage>where
Iptr: SpIndex,
Storage: Deref<Target = [Iptr]>,
impl<Iptr, Storage> IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]>,
pub fn new_checked(storage: Storage) -> Result<Self, (Storage, StructureError)>
pub fn view(&self) -> IndPtrView<'_, Iptr>
sourcepub fn outer_dims(&self) -> usize
pub fn outer_dims(&self) -> usize
The number of outer dimensions this indptr represents
sourcepub fn is_proper(&self) -> bool
pub fn is_proper(&self) -> bool
Indicates whether the underlying storage is proper, which means the indptr corresponds to a non-sliced matrix.
An empty matrix is considered non-proper.
sourcepub fn as_slice(&self) -> Option<&[Iptr]>
pub fn as_slice(&self) -> Option<&[Iptr]>
Return a view on the underlying slice if it is a proper indptr
slice,
which is the case if its first element is 0. None
will be returned
otherwise.
sourcepub fn raw_storage(&self) -> &[Iptr]
pub fn raw_storage(&self) -> &[Iptr]
Return a view of the underlying storage. Should be used with care in sparse algorithms, as this won’t check if the storage corresponds to a proper matrix
sourcepub fn into_raw_storage(self) -> Storage
pub fn into_raw_storage(self) -> Storage
Consume self
and return the underlying storage
pub fn to_owned(&self) -> IndPtr<Iptr>
sourcepub fn to_proper(&self) -> Cow<'_, [Iptr]>
pub fn to_proper(&self) -> Cow<'_, [Iptr]>
Returns a proper indptr representation, cloning if we do not have a proper indptr.
Warning
For ffi usage, one needs to call Cow::as_ptr
, but it’s important
to keep the Cow
alive during the lifetime of the pointer. Example
of a correct and incorrect ffi usage:
let mat: sprs::CsMat<f64> = sprs::CsMat::eye(5);
let mid = mat.view().middle_outer_views(1, 2);
let ptr = {
let indptr = mid.indptr(); // needed for lifetime
let indptr_proper = indptr.to_proper();
println!(
"ptr {:?} is valid as long as _indptr_proper_owned is in scope",
indptr_proper.as_ptr()
);
indptr_proper.as_ptr()
};
// This line is UB.
// println!("ptr deref: {}", *ptr);
It is much easier to directly use the proper_indptr
method of
CsMatBase
directly:
let mat: sprs::CsMat<f64> = sprs::CsMat::eye(5);
let mid = mat.view().middle_outer_views(1, 2);
let ptr = {
let indptr_proper = mid.proper_indptr();
println!(
"ptr {:?} is valid as long as _indptr_proper_owned is in scope",
indptr_proper.as_ptr()
);
indptr_proper.as_ptr()
};
// This line is UB.
// println!("ptr deref: {}", *ptr);
sourcepub fn iter_outer_nnz_inds(
&self
) -> impl DoubleEndedIterator<Item = usize> + ExactSizeIterator<Item = usize> + '_
pub fn iter_outer_nnz_inds( &self ) -> impl DoubleEndedIterator<Item = usize> + ExactSizeIterator<Item = usize> + '_
Iterate over the nonzeros represented by this indptr, yielding the outer dimension for each nonzero
sourcepub fn iter_outer(
&self
) -> impl DoubleEndedIterator<Item = Range<Iptr>> + ExactSizeIterator<Item = Range<Iptr>> + '_
pub fn iter_outer( &self ) -> impl DoubleEndedIterator<Item = Range<Iptr>> + ExactSizeIterator<Item = Range<Iptr>> + '_
Iterate over outer dimensions, yielding start and end indices for each outer dimension.
sourcepub fn iter_outer_sz(
&self
) -> impl DoubleEndedIterator<Item = Range<usize>> + ExactSizeIterator<Item = Range<usize>> + '_
pub fn iter_outer_sz( &self ) -> impl DoubleEndedIterator<Item = Range<usize>> + ExactSizeIterator<Item = Range<usize>> + '_
Iterate over outer dimensions, yielding start and end indices for each outer dimension.
Returns a range of usize to ensure iteration of indices and data is easy
sourcepub fn index(&self, i: usize) -> Iptr
pub fn index(&self, i: usize) -> Iptr
Return the value of the indptr at index i. This method is intended for
low-level usage only, outer_inds
should be preferred most of the time
sourcepub fn outer_inds(&self, i: usize) -> Range<Iptr>
pub fn outer_inds(&self, i: usize) -> Range<Iptr>
sourcepub fn outer_inds_sz(&self, i: usize) -> Range<usize>
pub fn outer_inds_sz(&self, i: usize) -> Range<usize>
Get the start and end indices for the requested outer dimension
Returns a range of usize to ensure iteration of indices and data is easy
Panics
If i >= self.outer_dims()
sourcepub fn nnz_in_outer(&self, i: usize) -> Iptr
pub fn nnz_in_outer(&self, i: usize) -> Iptr
sourcepub fn nnz_in_outer_sz(&self, i: usize) -> usize
pub fn nnz_in_outer_sz(&self, i: usize) -> usize
Get the number of nonzeros in the requested outer dimension
Returns a usize
Panics
If i >= self.outer_dims()
Trait Implementations§
source§impl<Iptr, Storage> Clone for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex + Clone,
Storage: Deref<Target = [Iptr]> + Clone,
impl<Iptr, Storage> Clone for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Clone, Storage: Deref<Target = [Iptr]> + Clone,
source§fn clone(&self) -> IndPtrBase<Iptr, Storage>
fn clone(&self) -> IndPtrBase<Iptr, Storage>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Iptr, Storage> Debug for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex + Debug,
Storage: Deref<Target = [Iptr]> + Debug,
impl<Iptr, Storage> Debug for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Debug, Storage: Deref<Target = [Iptr]> + Debug,
source§impl<'de, Iptr, Storage> Deserialize<'de> for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex,
Storage: Deref<Target = [Iptr]> + Deserialize<'de>,
impl<'de, Iptr, Storage> Deserialize<'de> for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]> + Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<Iptr, Storage> Hash for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex + Hash,
Storage: Deref<Target = [Iptr]> + Hash,
impl<Iptr, Storage> Hash for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Hash, Storage: Deref<Target = [Iptr]> + Hash,
source§impl<Iptr, Storage> PartialEq<IndPtrBase<Iptr, Storage>> for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex + PartialEq,
Storage: Deref<Target = [Iptr]> + PartialEq,
impl<Iptr, Storage> PartialEq<IndPtrBase<Iptr, Storage>> for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + PartialEq, Storage: Deref<Target = [Iptr]> + PartialEq,
source§fn eq(&self, other: &IndPtrBase<Iptr, Storage>) -> bool
fn eq(&self, other: &IndPtrBase<Iptr, Storage>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<Iptr: SpIndex, IptrStorage, IptrStorage2> PartialEq<IptrStorage2> for IndPtrBase<Iptr, IptrStorage>where
IptrStorage: Deref<Target = [Iptr]>,
IptrStorage2: Deref<Target = [Iptr]>,
impl<Iptr: SpIndex, IptrStorage, IptrStorage2> PartialEq<IptrStorage2> for IndPtrBase<Iptr, IptrStorage>where IptrStorage: Deref<Target = [Iptr]>, IptrStorage2: Deref<Target = [Iptr]>,
Allows comparison to vectors and slices
source§fn eq(&self, other: &IptrStorage2) -> bool
fn eq(&self, other: &IptrStorage2) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<Iptr, Storage> Serialize for IndPtrBase<Iptr, Storage>where
Iptr: SpIndex,
Storage: Deref<Target = [Iptr]> + Serialize,
impl<Iptr, Storage> Serialize for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]> + Serialize,
impl<Iptr, Storage> Copy for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Copy, Storage: Deref<Target = [Iptr]> + Copy,
impl<Iptr, Storage> Eq for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Eq, Storage: Deref<Target = [Iptr]> + Eq,
impl<Iptr, Storage> StructuralEq for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]>,
impl<Iptr, Storage> StructuralPartialEq for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]>,
Auto Trait Implementations§
impl<Iptr, Storage> RefUnwindSafe for IndPtrBase<Iptr, Storage>where Storage: RefUnwindSafe,
impl<Iptr, Storage> Send for IndPtrBase<Iptr, Storage>where Storage: Send,
impl<Iptr, Storage> Sync for IndPtrBase<Iptr, Storage>where Storage: Sync,
impl<Iptr, Storage> Unpin for IndPtrBase<Iptr, Storage>where Storage: Unpin,
impl<Iptr, Storage> UnwindSafe for IndPtrBase<Iptr, Storage>where Storage: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.