brainevent.csrmm_dt2t#
- brainevent.csrmm_dt2t = <NameScope(brainevent.csrmm_dt2t)>#
Batched element-wise product of dense vectors and CSR weights, indexed by CSR structure.
Batched generalization of
csrmv_dt2t(): for each batch elementband non-zero entryjin the CSR matrix at position(row, col), computesout[b, j] = w[b, j] * y[b, row](non-transposed) orout[b, j] = w[b, j] * y[b, col](transposed). Bothwandycarry a shared leading batch axis, and the result has the same shape asw(one value per batch element and per structural non-zero).This operation implements the \(D^t \epsilon^{t-1}\) term of the D-RTRL eligibility-trace update \(\epsilon^t \approx D^t \epsilon^{t-1} + \mathrm{diag}(D_f^t) \otimes x^t\) for a batch of samples:
yholds the batched per-neuron factor \(D^t\) andwholds the batched per-synapse trace \(\epsilon^{t-1}\) stored in CSR data order.The function supports physical units via
brainunit.- Parameters:
y (
Array|ndarray|Quantity|Number) – Batch of dense vectors indexed by the CSR structure. Shape(n_batch, shape[0])whentranspose=Falseor(n_batch, shape[1])whentranspose=True.w (
Array|ndarray|Quantity|Number) – Batch of per-synapse values. Shape(n_batch, nse); the trailing axis must match the shape ofindices.indices (
Array|ndarray) – Column indices of the CSR matrix. Shape(nse,)with integer dtype.indptr (
Array|ndarray) – Row index pointer array. Shape(shape[0] + 1,)with integer dtype.shape (tuple of int) – Two-element tuple
(m, k)giving the logical shape of the CSR matrix.transpose (
bool) – IfTrue, indexyby column indices instead of row indices. Default isFalse.backend (
str|None) – Compute backend. Default isNone(auto-select).
- Returns:
out – Batched per-synapse result. Shape
(n_batch, nse), same asw.- Return type:
Array|ndarray|Quantity|Number
See also
csrmv_dt2tUnbatched (single-vector) variant of this operator.
csrmmStandard CSR matrix–matrix multiplication.
Notes
This operation is differentiable with respect to both
yandwvia custom JVP rules. The transpose rule is not yet implemented.Mathematically, for each batch element
band structural non-zero entryjof the CSR matrix at position(row, col), the output is computed as:out[b, j] = w[b, j] * y[b, row](non-transposed,transpose=False)out[b, j] = w[b, j] * y[b, col](transposed,transpose=True)where
rowis determined by theindptrarray (the row to which thej-th non-zero belongs) andcol = indices[j].Like
csrmv_dt2t(), the output keeps the unit ofwand drops the unit ofy.Examples
>>> import jax.numpy as jnp >>> from brainevent import csrmm_dt2t >>> y = jnp.array([[1.0, 2.0], [10.0, 20.0]]) # (n_batch=2, m=2) >>> 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) >>> csrmm_dt2t(y, w, indices, indptr, shape=(2, 3))