brainevent.cscmv_dt2t

Contents

brainevent.cscmv_dt2t#

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

Element-wise product of a vector and CSC weights, indexed by CSC structure.

For each non-zero entry j in the CSC matrix at position (row, col), computes out[j] = w[j] * y[row] (non-transposed) or out[j] = w[j] * y[col] (transposed). The result has the same shape as w and indices (i.e., one value per structural non-zero).

This is the CSC counterpart of csrmv_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 csrmv_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) – Dense vector indexed by the CSC structure. Shape (shape[0],) when transpose=False or (shape[1],) when transpose=True.

  • w (Array | ndarray | Quantity | Number) – Per-synapse weight values in CSC data order. Shape (nse,), 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 – Per-synapse result vector. Shape (nse,), same as w.

Return type:

Array | ndarray | Quantity | Number

See also

csrmv_dt2t

The CSR primitive this wraps.

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:

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

Examples

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