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]>,

source

pub fn new_checked(storage: Storage) -> Result<Self, (Storage, StructureError)>

source

pub fn view(&self) -> IndPtrView<'_, Iptr>

source

pub fn len(&self) -> usize

The length of the underlying storage

source

pub fn is_empty(&self) -> bool

Tests whether this indptr is empty

source

pub fn outer_dims(&self) -> usize

The number of outer dimensions this indptr represents

source

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.

source

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.

source

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

source

pub fn into_raw_storage(self) -> Storage

Consume self and return the underlying storage

source

pub fn to_owned(&self) -> IndPtr<Iptr>

source

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);
source

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

source

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.

source

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

source

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

source

pub fn outer_inds(&self, i: usize) -> Range<Iptr>

Get the start and end indices for the requested outer dimension

Panics

If i >= self.outer_dims()

source

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()

source

pub fn nnz_in_outer(&self, i: usize) -> Iptr

Get the number of nonzeros in the requested outer dimension

Panics

If i >= self.outer_dims()

source

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()

source

pub fn outer_inds_slice(&self, start: usize, end: usize) -> Range<usize>

Get the start and end indices for the requested outer dimension slice

Panics

If start >= self.outer_dims() || end > self.outer_dims()

source

pub fn nnz(&self) -> usize

The number of nonzero elements described by this indptr

source

pub fn nnz_i(&self) -> Iptr

The number of nonzero elements described by this indptr, using the actual storage type

Trait Implementations§

source§

impl<Iptr, Storage> Clone for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Clone, Storage: Deref<Target = [Iptr]> + Clone,

source§

fn clone(&self) -> IndPtrBase<Iptr, Storage>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Iptr, Storage> Debug for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Debug, Storage: Deref<Target = [Iptr]> + Debug,

source§

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

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

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Iptr, Storage> Hash for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Hash, Storage: Deref<Target = [Iptr]> + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Iptr, Storage> Serialize for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]> + Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Iptr, Storage> Copy for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Copy, Storage: Deref<Target = [Iptr]> + Copy,

source§

impl<Iptr, Storage> Eq for IndPtrBase<Iptr, Storage>where Iptr: SpIndex + Eq, Storage: Deref<Target = [Iptr]> + Eq,

source§

impl<Iptr, Storage> StructuralEq for IndPtrBase<Iptr, Storage>where Iptr: SpIndex, Storage: Deref<Target = [Iptr]>,

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,