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, whereBis treated as containing binary events (spikes). Only entries ofBthat are active (nonzero /True) contribute to the output.Mathematically, with
transpose=Falsethe operation isresult[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
Ais 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 lengthnnz(heterogeneous weights).row (
Array|ndarray) – 1-D array of row indices for each non-zero element, with lengthnnz.col (
Array|ndarray) – 1-D array of column indices for each non-zero element, with lengthnnz.B (
Array|ndarray|Quantity|Number) – Dense input matrix treated as binary events. Shape must be(shape[0], n)whentranspose=Trueor(shape[1], n)whentranspose=False.shape (
Tuple[int,int]) – The(m, k)shape of the sparse matrix.transpose (
bool) – IfTrue, multiply by the transpose of the sparse matrix, i.e.A^T @ B. Default isFalse.backend (
str|None) – Compute backend to use (e.g.'numba','pallas'). WhenNonethe backend is chosen automatically.
- Returns:
Result matrix of the multiplication. Shape is
(shape[0], n)whentranspose=Falseor(shape[1], n)whentranspose=True.- Return type:
Array|ndarray|Quantity|Number- Raises:
ValueError – If
roworcolare not 1-D, have mismatched lengths,Bis not 2-D,datais not scalar or 1-D, or array dimensions are incompatible withshapeandtranspose.
See also
binary_coomvEvent-driven COO sparse matrix-vector multiplication.
coommStandard (non-event-driven) COO sparse matrix-matrix multiplication.
Notes
Physical units attached via
brainunitare automatically split off before the computation and re-applied to the result.This function supports automatic differentiation (JVP and transpose rules),
vmapbatching, 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)