brainevent.binary_fcnmv

Contents

brainevent.binary_fcnmv#

brainevent.binary_fcnmv = <NameScope(brainevent.binary_fcnmv)>#

Event-driven sparse matrix–vector product with fixed connection number.

Computes y = W @ s (or y = W^T @ s when transpose=True) where W is a sparse weight matrix stored in fixed-connection-number format and s is a binary spike vector. Only the connections to spiking neurons contribute to the result, making this operation event-driven.

Parameters:
  • weights (Array | Quantity) – Non-zero weight values. Shape is (1,) for homogeneous weights or (num_pre, num_conn) for heterogeneous weights. Must have a floating-point dtype.

  • indices (Array) – Integer index array of shape (num_pre, num_conn) specifying the post-synaptic (column) indices of each connection.

  • spikes (Array | Quantity) – Binary spike vector. Entries are treated as active when True (boolean) or > 0 (float).

  • shape (Tuple[int, int]) – Logical (num_pre, num_post) shape of the equivalent dense weight matrix.

  • transpose (bool) – If False (default), compute W @ s (fixed post-synaptic connections). If True, compute W^T @ s (fixed pre-synaptic connections, scatter mode).

  • backend (str | None) – Execution backend override ('numba', 'pallas', 'cuda_raw', or None for automatic selection).

  • col_weights (Quantity | Array | None) – Optional column-major weights for the same logical sparse matrix, used by the CUDA transpose=False scatter path. Homogeneous weights must have size 1; heterogeneous weights must have size NNZ.

  • col_indices (Array | None) – Optional column-major row-index array aligned with col_weights. Shape is (NNZ,).

  • col_indptr (Array | None) – Optional column pointer array with shape (num_post + 1,).

Returns:

Result vector. Shape is (num_pre,) when transpose=False or (num_post,) when transpose=True.

Return type:

Array | Quantity

See also

binary_fcnmm

Event-driven sparse matrix–matrix product.

fcnmv

Float (non-event-driven) sparse matrix–vector product.

Notes

The sparse weight matrix W of shape (num_pre, num_post) is stored in fixed-connection-number format where each row i has exactly n_conn non-zero entries at column positions indices[i, :].

The event-driven matrix-vector product computes (when transpose=False):

y[i] = sum_{k=0}^{n_conn-1} weights[i, k] * 1_{spikes[indices[i, k]] active}

where “active” means True for boolean spikes or > 0 for float spikes. For homogeneous weights (weights has shape (1,)):

y[i] = w * sum_{k=0}^{n_conn-1} 1_{spikes[indices[i, k]] active}

When transpose=True, the scatter-mode product computes:

y[indices[i, k]] += weights[i, k] * 1_{spikes[i] active} for all i, k

The event-driven formulation skips inactive neurons entirely, making the computation efficient when the spike vector is sparse.

Examples

>>> import jax.numpy as jnp
>>> from brainevent._fcn.binary import binary_fcnmv
>>>
>>> weights = jnp.ones(1, dtype=jnp.float32)  # homogeneous
>>> indices = jnp.array([[0, 1], [1, 2]])      # (2, 2)
>>> spikes = jnp.array([True, False, True])
>>> y = binary_fcnmv(weights, indices, spikes, shape=(2, 3))
>>> print(y)
[1. 1.]