brainevent.csr_to_csc_index#
- brainevent.csr_to_csc_index(csr_indptr, csr_indices, *, shape, include_perm=True, method='coo', column_block_size=4096)[source]#
Convert CSR format index arrays to CSC format.
Transforms the sparse matrix representation from Compressed Sparse Row (CSR) format to Compressed Sparse Column (CSC) format. The default
method="coo"preserves the legacy CSR -> COO -> CSC behavior.- Parameters:
csr_indptr (
Array|ndarray) – Row pointer array in CSR format. For a matrix withmrows, this has lengthm + 1.csr_indices (
Array|ndarray) – Column index array in CSR 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.include_perm (
bool) – IfTrue(default), return the permutation that maps CSC slots back to CSR data positions. IfFalse, returnNonefor the third result while still constructing the CSC structure.method (
str) – Conversion algorithm."coo"expands CSR to COO first and then converts COO to CSC;"numpy"computes the structure on CPU with NumPy;"gpu_column_block"builds consecutive CSC column blocks with CUDA kernels and falls back to"numpy"when CUDA is not available.column_block_size (
int) – Number of CSC columns per CUDA block formethod="gpu_column_block".
- Returns:
csc_indptr (jax.Array or numpy.ndarray) – Column pointer array in CSC format.
csc_indices (jax.Array or numpy.ndarray) – Row index array in CSC format.
post_positions (jax.Array or numpy.ndarray) – Permutation array that reorders data values from CSR order to CSC order. If
datais the CSR data array, thendata[post_positions]gives the values in CSC order.
- Raises:
AssertionError – If
shapeis not a tuple or list, does not have exactly two elements, or contains non-positive dimensions.
See also
csr_to_coo_indexConvert CSR indices to COO indices.
coo_to_csc_indexConvert COO indices to CSC indices.
Notes
The returned
post_positionspermutation array can be used to reorder a CSR data array into CSC order. Across all methodscsc_indicesare always int32 (secondary-axis coordinates), whilecsc_indptr/post_positionsauto-promote to int64 when the nnz exceeds the int32 range (gated onjax_enable_x64).Examples
>>> import numpy as np >>> from brainevent._misc import csr_to_csc_index >>> indptr = np.array([0, 2, 3, 5]) >>> indices = np.array([0, 2, 1, 0, 3]) >>> csc_indptr, csc_indices, perm = csr_to_csc_index( ... indptr, indices, shape=(3, 4) ... )