CSC#
- class saiunit.sparse.CSC(args, *, shape)[source]#
Unit-aware Compressed Sparse Column (CSC) matrix.
Stores a 2-D sparse matrix in CSC format with optional physical-unit support via
Quantity.- Parameters:
- indices#
Row indices of shape
(nse,).- Type:
jax.Array
- indptr#
Column pointer array of shape
(ncols + 1,).- Type:
jax.Array
See also
CSRUnit-aware Compressed Sparse Row matrix.
csc_fromdenseCreate a CSC matrix from a dense array.
csc_todenseConvert a CSC matrix to a dense array.
Examples
>>> import jax.numpy as jnp >>> import saiunit as u >>> import saiunit.sparse as susparse >>> dense = jnp.array([[1., 0., 2.], [0., 0., 3.]]) >>> csc = susparse.CSC.fromdense(dense) >>> csc.shape (2, 3) >>> csc.todense() Array([[1., 0., 2.], [0., 0., 3.]], dtype=float32)
- todense()[source]#
Convert this CSC matrix to a dense array.
- Returns:
Dense 2-D array equivalent to this sparse matrix.
- Return type:
jax.Array or Quantity
Examples
>>> import jax.numpy as jnp >>> import saiunit as u >>> import saiunit.sparse as susparse >>> dense = jnp.array([[0., 3.], [4., 0.]]) >>> csc = susparse.CSC.fromdense(dense) >>> csc.todense() Array([[0., 3.], [4., 0.]], dtype=float32)
- transpose(axes=None)[source]#
Return the transpose of this CSC matrix as a CSR matrix.
- Parameters:
axes (None, optional) – Not supported. Must be
None.- Returns:
The transposed matrix in CSR format.
- Return type:
- Raises:
NotImplementedError – If
axesis notNone.
- with_data(data)[source]#
Create a new CSC matrix with the same sparsity structure but different data.
- Parameters:
data (
Array| saiunit.Quantity) – New non-zero values. Must have the same shape, dtype, and unit as the currentself.data.- Returns:
A new CSC matrix sharing the same
indicesandindptrbut holding the provideddata.- Return type:
Examples
>>> import jax.numpy as jnp >>> import saiunit as u >>> import saiunit.sparse as susparse >>> dense = jnp.array([[1., 0.], [0., 2.]]) >>> csc = susparse.CSC.fromdense(dense) >>> new_csc = csc.with_data(csc.data * 5) >>> new_csc.todense() Array([[ 5., 0.], [ 0., 10.]], dtype=float32)