saiunit.sparse.csc_fromdense

Contents

saiunit.sparse.csc_fromdense#

saiunit.sparse.csc_fromdense(mat, *, nse=None, index_dtype=<class 'numpy.int32'>)[source]#

Create a CSC-format sparse matrix from a dense matrix.

Parameters:
  • mat (Array | saiunit.Quantity) – Dense 2-D array to be converted to CSC format.

  • nse (int | None) – Number of specified (non-zero) entries in mat. If None (default), it is computed automatically from the input matrix.

  • index_dtype (str | type[Any] | dtype | SupportsDType) – Data type for the sparse index arrays. Default is numpy.int32.

Returns:

The CSC representation of the input matrix.

Return type:

CSC

Examples

>>> import jax.numpy as jnp
>>> import saiunit as u
>>> import saiunit.sparse as susparse
>>> dense = jnp.array([[1., 0., 0.], [0., 2., 3.]])
>>> csc = susparse.csc_fromdense(dense)
>>> csc.shape
(2, 3)
>>> csc.todense()
Array([[1., 0., 0.],
       [0., 2., 3.]], dtype=float32)