brainevent.coomm#
- brainevent.coomm = <NameScope(brainevent.coomm)>#
Perform COO sparse matrix-matrix multiplication.
Computes the product of a sparse matrix stored in COO format and a dense matrix
B.With
transpose=False:Y[i, n] = sum_{k} A[i, k] * B[k, n]With
transpose=True:Y[k, n] = sum_{i} A[i, k] * B[i, n]- Parameters:
data (
Array|ndarray|Quantity|Number) – Non-zero values of the sparse matrix. Either a scalar (shape(1,)for homogeneous weights) or a 1-D array of lengthnnz.row (
Array|ndarray) – 1-D int array of row indices, lengthnnz.col (
Array|ndarray) – 1-D int array of column indices, lengthnnz.B (
Array|ndarray|Quantity|Number) – Dense right-hand matrix. Shape(shape[1], n)whentranspose=False, or(shape[0], n)whentranspose=True.shape (
Tuple[int,int]) – Logical(m, k)shape of the sparse matrix.transpose (
bool) – IfTrue, multiply byA.T. Default isFalse.backend (
str|None) – Compute backend.Noneselects the default.
- Returns:
Result matrix. Shape
(shape[0], n)whentranspose=False, or(shape[1], n)whentranspose=True.- Return type:
jax.Array or Quantity
See also
coomvCOO sparse matrix-vector multiplication.
binary_coommEvent-driven (binary) COO matrix-matrix multiplication.
Notes
The kernel iterates over all
nnzstored elements and, for each triplet(data[s], row[s], col[s]), addsdata[s] * B[col[s], :]intoY[row[s], :](forward) ordata[s] * B[row[s], :]intoY[col[s], :](transpose).Physical units from
brainunitare handled transparently.Examples
>>> import jax.numpy as jnp >>> from brainevent import coomm >>> data = jnp.array([1.0, 2.0]) >>> row = jnp.array([0, 1]) >>> col = jnp.array([1, 0]) >>> B = jnp.ones((2, 3)) >>> coomm(data, row, col, B, shape=(2, 2))