brainevent.binary_coomm

Contents

brainevent.binary_coomm#

brainevent.binary_coomm = <NameScope(brainevent.binary_coomm)>#

Perform event-driven COO sparse matrix-matrix multiplication.

Computes the product of a sparse matrix stored in COO (Coordinate) format and a dense matrix B, where B is treated as containing binary events (spikes). Only entries of B that are active (nonzero / True) contribute to the output.

Mathematically, with transpose=False the operation is

result[i, n] = sum_j A[i, j] * (B[j, n] > 0)

and with transpose=True:

result[j, n] = sum_i A[i, j] * (B[i, n] > 0)

where A is the sparse matrix defined by (data, row, col).

Parameters:
  • data (Array | ndarray | Quantity | Number) – The non-zero weight values of the sparse matrix. Can be either a scalar (shape (1,), homogeneous weights) or a 1-D array of length nnz (heterogeneous weights).

  • row (Array | ndarray) – 1-D array of row indices for each non-zero element, with length nnz.

  • col (Array | ndarray) – 1-D array of column indices for each non-zero element, with length nnz.

  • B (Array | ndarray | Quantity | Number) – Dense input matrix treated as binary events. Shape must be (shape[0], n) when transpose=True or (shape[1], n) when transpose=False.

  • shape (Tuple[int, int]) – The (m, k) shape of the sparse matrix.

  • transpose (bool) – If True, multiply by the transpose of the sparse matrix, i.e. A^T @ B. Default is False.

  • backend (str | None) – Compute backend to use (e.g. 'numba', 'pallas'). When None the backend is chosen automatically.

Returns:

Result matrix of the multiplication. Shape is (shape[0], n) when transpose=False or (shape[1], n) when transpose=True.

Return type:

Array | ndarray | Quantity | Number

Raises:

ValueError – If row or col are not 1-D, have mismatched lengths, B is not 2-D, data is not scalar or 1-D, or array dimensions are incompatible with shape and transpose.

See also

binary_coomv

Event-driven COO sparse matrix-vector multiplication.

coomm

Standard (non-event-driven) COO sparse matrix-matrix multiplication.

Notes

Physical units attached via brainunit are automatically split off before the computation and re-applied to the result.

This function supports automatic differentiation (JVP and transpose rules), vmap batching, and multiple hardware backends (CPU via Numba, GPU via Pallas/Triton, TPU via Pallas/Mosaic).

Examples

>>> import jax.numpy as jnp
>>> from brainevent._coo.binary import binary_coomm
>>> data = jnp.array([0.5])          # homogeneous weight
>>> row = jnp.array([0, 1, 2])
>>> col = jnp.array([1, 0, 2])
>>> B = jnp.array([[True, False],
...                [False, True],
...                [True, True]])    # binary event matrix
>>> binary_coomm(data, row, col, B, shape=(3, 3), transpose=False)