Skip to main content

SparseMatrixGpu

Struct SparseMatrixGpu 

Source
pub struct SparseMatrixGpu {
    pub n: usize,
    pub nnz: usize,
    pub row_ptr: Vec<usize>,
    pub col_idx: Vec<usize>,
    pub values: Vec<f64>,
}
Expand description

Compressed Sparse Row (CSR) matrix stored in GPU-friendly layout.

Rows have entries in col_idx[row_ptr[i]..row_ptr[i+1]] with corresponding values in values[row_ptr[i]..row_ptr[i+1]].

Fields§

§n: usize

Number of rows (and columns — assumed square).

§nnz: usize

Number of non-zero entries.

§row_ptr: Vec<usize>

Row pointer array (length n+1).

§col_idx: Vec<usize>

Column index array (length nnz).

§values: Vec<f64>

Value array (length nnz).

Implementations§

Source§

impl SparseMatrixGpu

Source

pub fn new(n: usize) -> Self

Create a new empty n×n sparse matrix.

Source

pub fn from_csr( n: usize, row_ptr: Vec<usize>, col_idx: Vec<usize>, values: Vec<f64>, ) -> Self

Construct from pre-built CSR arrays.

§Panics

Panics in debug mode if row_ptr.len() != n + 1.

Source

pub fn add_entry(&mut self, row: usize, col: usize, val: f64)

Append a single entry (row, col, val) in COO style.

This invalidates the CSR structure until finalize is called.

Source

pub fn finalize(&mut self)

Convert count-per-row in row_ptr to proper CSR offsets.

Must be called after a series of add_entry calls and before any SpMV or solver operations.

Source

pub fn nnz(&self) -> usize

Return the number of non-zero entries.

Source

pub fn rows(&self) -> usize

Return the number of rows.

Source

pub fn diagonal(&self) -> Vec<f64>

Extract the main diagonal as a dense vector.

Missing diagonal entries are filled with zero.

Source

pub fn is_symmetric(&self) -> bool

Check whether the matrix is structurally symmetric (A[i,j] ↔ A[j,i]).

Source

pub fn frobenius_norm(&self) -> f64

Frobenius norm: √(∑ aᵢⱼ²).

Trait Implementations§

Source§

impl Clone for SparseMatrixGpu

Source§

fn clone(&self) -> SparseMatrixGpu

Returns a duplicate 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 Debug for SparseMatrixGpu

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

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