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 withpre_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 dtypeint32.
- Raises:
ValueError – If any
pre_idsfalls outside[0, num_row). Such an entry would otherwise be silently dropped fromindptr(its scatter index is out-of-bounds), producing a structurally invalid CSR in whichindptr[-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 underjit/vmap.