brainevent.coo_to_csc_index

brainevent.coo_to_csc_index#

brainevent.coo_to_csc_index(pre_ids, indices, *, shape)[source]#

Convert COO format index arrays to CSC format.

Transforms a sparse matrix representation from Coordinate (COO) format (explicit row and column index arrays) to Compressed Sparse Column (CSC) format. The implementation automatically selects NumPy or JAX operations based on the type of the input arrays.

Parameters:
  • pre_ids (Array | ndarray) – Row index array in COO format. Contains the row index for each non-zero element.

  • indices (Array | ndarray) – Column index array in COO format. Contains the column index for each non-zero element.

  • shape (Tuple[int, int]) – A (n_rows, n_cols) tuple specifying the dimensions of the sparse matrix. Keyword-only argument.

Returns:

  • csc_indptr (jax.Array or numpy.ndarray) – Column pointer array in CSC format. For a matrix with n columns, this has length n + 1. Element csc_indptr[j] gives the position in csc_indices where column j starts.

  • csc_indices (jax.Array or numpy.ndarray) – Row index array in CSC format. Contains the row index for each non-zero element, ordered by column.

  • post_positions (jax.Array or numpy.ndarray) – Permutation array that reorders data values from COO order to CSC order. If data is the COO data array, then data[post_positions] gives the values in CSC order.

See also

csr_to_coo_index

Convert CSR indices to COO format.

csr_to_csc_index

Convert CSR indices directly to CSC format.

Notes

When JAX arrays are provided, the computation is wrapped in jax.ensure_compile_time_eval() so that it executes at trace time rather than at runtime.

Examples

>>> import numpy as np
>>> from brainevent._misc import coo_to_csc_index
>>> row_ids = np.array([0, 0, 1, 2, 2])
>>> col_ids = np.array([0, 2, 1, 0, 3])
>>> indptr, row_indices, perm = coo_to_csc_index(
...     row_ids, col_ids, shape=(3, 4)
... )