Struct sprs::IndPtrBase
source · pub struct IndPtrBase<Iptr, Storage>{ /* private fields */ }
Implementations§
source§impl<Iptr, Storage> IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> IndPtrBase<Iptr, Storage>
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>
impl<Iptr, Storage> Clone for IndPtrBase<Iptr, Storage>
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>
impl<Iptr, Storage> Debug for IndPtrBase<Iptr, Storage>
source§impl<'de, Iptr, Storage> Deserialize<'de> for IndPtrBase<Iptr, Storage>
impl<'de, Iptr, Storage> Deserialize<'de> for IndPtrBase<Iptr, Storage>
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>
impl<Iptr, Storage> Hash for IndPtrBase<Iptr, Storage>
source§impl<Iptr: SpIndex, IptrStorage, IptrStorage2> PartialEq<IptrStorage2> for IndPtrBase<Iptr, IptrStorage>
impl<Iptr: SpIndex, IptrStorage, IptrStorage2> PartialEq<IptrStorage2> for IndPtrBase<Iptr, IptrStorage>
Allows comparison to vectors and slices
source§impl<Iptr, Storage> PartialEq for IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> PartialEq for IndPtrBase<Iptr, Storage>
source§impl<Iptr, Storage> Serialize for IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> Serialize for IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> Copy for IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> Eq for IndPtrBase<Iptr, Storage>
impl<Iptr, Storage> StructuralPartialEq for IndPtrBase<Iptr, Storage>
Auto Trait Implementations§
impl<Iptr, Storage> Freeze for IndPtrBase<Iptr, Storage>where
Storage: Freeze,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§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.