Struct LilArray

Source
pub struct LilArray<T>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,
{ /* private fields */ }
Expand description

LIL Array format

The LIL (List of Lists) format stores data as a list of lists:

  • data: a vector of vectors, where each inner vector contains the non-zero values for a row
  • indices: a vector of vectors, where each inner vector contains the column indices for the non-zero values

§Notes

  • Efficient for incremental construction (adding values row by row)
  • Good for row-based operations
  • Fast conversion to CSR format
  • Not memory-efficient for large sparse arrays
  • Not efficient for arithmetic operations

Implementations§

Source§

impl<T> LilArray<T>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,

Source

pub fn new(shape: (usize, usize)) -> Self

Creates a new LIL array

§Arguments
  • shape - Shape of the sparse array (rows, cols)
§Returns

A new empty LilArray

Source

pub fn from_lists( data: Vec<Vec<T>>, indices: Vec<Vec<usize>>, shape: (usize, usize), ) -> SparseResult<Self>

Creates a LIL array from existing data and indices

§Arguments
  • data - List of lists containing the non-zero values for each row
  • indices - List of lists containing the column indices for the non-zero values
  • shape - Shape of the sparse array
§Returns

A new LilArray

§Errors

Returns an error if the data and indices are not consistent or if any index is out of bounds

Source

pub fn from_triplets( rows: &[usize], cols: &[usize], data: &[T], shape: (usize, usize), ) -> SparseResult<Self>

Create a LIL array from (row, col, data) triplets

§Arguments
  • row - Row indices
  • col - Column indices
  • data - Values
  • shape - Shape of the sparse array
§Returns

A new LilArray

§Errors

Returns an error if the data is not consistent

Source

pub fn get_data(&self) -> &Vec<Vec<T>>

Get a reference to the data

Source

pub fn get_indices(&self) -> &Vec<Vec<usize>>

Get a reference to the indices

Source

pub fn sort_indices(&mut self)

Sort the indices and data in each row

Trait Implementations§

Source§

impl<T> Clone for LilArray<T>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static + Clone,

Source§

fn clone(&self) -> LilArray<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for LilArray<T>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,

Source§

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

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

impl<T> SparseArray<T> for LilArray<T>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,

Source§

fn shape(&self) -> (usize, usize)

Returns the shape of the sparse array.
Source§

fn nnz(&self) -> usize

Returns the number of stored (non-zero) elements.
Source§

fn dtype(&self) -> &str

Returns the data type of the sparse array.
Source§

fn to_array(&self) -> Array2<T>

Returns a view of the sparse array as a dense ndarray.
Source§

fn toarray(&self) -> Array2<T>

Returns a dense copy of the sparse array.
Source§

fn to_coo(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in COO format.
Source§

fn to_csr(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in CSR format.
Source§

fn to_csc(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in CSC format.
Source§

fn to_dok(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in DOK format.
Source§

fn to_lil(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in LIL format.
Source§

fn to_dia(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in DIA format.
Source§

fn to_bsr(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Returns a sparse array in BSR format.
Source§

fn add( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>

Element-wise addition.
Source§

fn sub( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>

Element-wise subtraction.
Source§

fn mul( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>

Element-wise multiplication.
Source§

fn div( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>

Element-wise division.
Source§

fn dot( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>

Matrix multiplication.
Source§

fn dot_vector(&self, other: &ArrayView1<'_, T>) -> SparseResult<Array1<T>>

Matrix-vector multiplication.
Source§

fn transpose(&self) -> SparseResult<Box<dyn SparseArray<T>>>

Transpose the sparse array.
Source§

fn copy(&self) -> Box<dyn SparseArray<T>>

Return a copy of the sparse array with the specified elements.
Source§

fn get(&self, i: usize, j: usize) -> T

Get a value at the specified position.
Source§

fn set(&mut self, i: usize, j: usize, value: T) -> SparseResult<()>

Set a value at the specified position.
Source§

fn eliminate_zeros(&mut self)

Eliminate zeros from the sparse array.
Source§

fn sort_indices(&mut self)

Sort indices of the sparse array.
Source§

fn sorted_indices(&self) -> Box<dyn SparseArray<T>>

Return a sorted copy of this sparse array.
Source§

fn has_sorted_indices(&self) -> bool

Check if indices are sorted.
Source§

fn sum(&self, axis: Option<usize>) -> SparseResult<SparseSum<T>>

Sum the sparse array elements. Read more
Source§

fn max(&self) -> T

Compute the maximum value of the sparse array elements.
Source§

fn min(&self) -> T

Compute the minimum value of the sparse array elements.
Source§

fn find(&self) -> (Array1<usize>, Array1<usize>, Array1<T>)

Return the indices and values of the nonzero elements.
Source§

fn slice( &self, row_range: (usize, usize), col_range: (usize, usize), ) -> SparseResult<Box<dyn SparseArray<T>>>

Return a slice of the sparse array.
Source§

fn as_any(&self) -> &dyn Any

Returns the concrete type of the array for downcasting.

Auto Trait Implementations§

§

impl<T> Freeze for LilArray<T>

§

impl<T> RefUnwindSafe for LilArray<T>
where T: RefUnwindSafe,

§

impl<T> Send for LilArray<T>
where T: Send,

§

impl<T> Sync for LilArray<T>
where T: Sync,

§

impl<T> Unpin for LilArray<T>
where T: Unpin,

§

impl<T> UnwindSafe for LilArray<T>
where T: UnwindSafe,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V