brainevent.cscmm_dt2t

Contents

brainevent.cscmm_dt2t#

brainevent.cscmm_dt2t(y, w, indices, indptr, *, shape, transpose=False, backend=None)[source]#

Batched element-wise product of dense vectors and CSC weights, indexed by CSC structure.

Batched generalization of cscmv_dt2t(): for each batch element b and non-zero entry j in the CSC matrix at position (row, col), computes out[b, j] = w[b, j] * y[b, row] (non-transposed) or out[b, j] = w[b, j] * y[b, col] (transposed). Both w and y carry a shared leading batch axis, and the result has the same shape as w (one value per batch element and per structural non-zero).

This is the CSC counterpart of csrmm_dt2t(). Because the CSC arrays of a matrix W of shape (m, k) are, array-for-array, the CSR arrays of W.T of shape (k, m), this function simply forwards to csrmm_dt2t() with the shape reversed and the transpose flag flipped. No data permutation is required, so it inherits the differentiability, unit handling, and backend dispatch of the underlying CSR primitive.

The function supports physical units via brainunit.

Parameters:
  • y (Array | ndarray | Quantity | Number) – Batch of dense vectors indexed by the CSC structure. Shape (n_batch, shape[0]) when transpose=False or (n_batch, shape[1]) when transpose=True.

  • w (Array | ndarray | Quantity | Number) – Batch of per-synapse values in CSC data order. Shape (n_batch, nse); the trailing axis must match the shape of indices.

  • indices (Array | ndarray) – Row indices of the CSC matrix. Shape (nse,) with integer dtype.

  • indptr (Array | ndarray) – Column index pointer array. Shape (shape[1] + 1,) with integer dtype.

  • shape (tuple of int) – Two-element tuple (m, k) giving the logical shape of the CSC matrix.

  • transpose (bool) – If True, index y by column indices instead of row indices. Default is False.

  • backend (str | None) – Compute backend. Default is None (auto-select).

Returns:

out – Batched per-synapse result. Shape (n_batch, nse), same as w.

Return type:

Array | ndarray | Quantity | Number

See also

csrmm_dt2t

The CSR primitive this wraps.

cscmv_dt2t

Unbatched (single-vector) variant of this operator.

Notes

A matrix W of shape (m, k) stored in CSC order has the same data / indices / indptr arrays as W.T stored in CSR order with shape (k, m). Under that view, indexing y by the CSC row (transpose=False) corresponds to indexing the CSR column axis, and indexing by the CSC column (transpose=True) corresponds to the CSR row axis. Hence the call delegates to:

csrmm_dt2t(y, w, indices, indptr,
           shape=shape[::-1], transpose=not transpose)

Examples

>>> import jax.numpy as jnp
>>> from brainevent import cscmm_dt2t
>>> # CSC of a (3, 2) matrix: indptr over the 2 columns.
>>> y = jnp.array([[1.0, 2.0, 3.0], [10.0, 20.0, 30.0]])  # (n_batch=2, m=3)
>>> w = jnp.array([[0.5, 0.3, 0.7, 0.1],
...                [1.0, 2.0, 3.0, 4.0]])                 # (n_batch=2, nse=4)
>>> indices = jnp.array([0, 2, 1, 2], dtype=jnp.int32)
>>> indptr = jnp.array([0, 2, 4], dtype=jnp.int32)
>>> cscmm_dt2t(y, w, indices, indptr, shape=(3, 2))