coo_to_csr

Contents

coo_to_csr#

class brainpy.math.sparse.coo_to_csr(pre_ids, post_ids, *, num_row)[source]#

Convert COO (pre_ids, post_ids) connectivity to CSR (indices, indptr).

Parameters:
  • pre_ids (Array) – Row (pre-synaptic) index of each non-zero entry. Every value must be in [0, num_row).

  • post_ids (Array) – Column (post-synaptic) index of each non-zero entry, aligned with pre_ids.

  • num_row (int) – Number of rows of the sparse matrix (shape[0]).

Return type:

Tuple[Array, Array]

Returns:

  • indices (ndarray) – CSR column indices of shape (nse,).

  • indptr (ndarray) – CSR row pointers of shape (num_row + 1,) and dtype int32.

Raises:

ValueError – If any pre_ids falls outside [0, num_row). Such an entry would otherwise be silently dropped from indptr (its scatter index is out-of-bounds), producing a structurally invalid CSR in which indptr[-1] != len(indices).

Notes

This is an eager preprocessing helper: it relies on jnp.unique (whose output size is data-dependent) and therefore cannot be traced under jit/vmap.