FixedNumPerPre#

class brainevent.FixedNumPerPre(data, indices=None, *, shape, backend=None, precompute_weight_indices=False, buffers=None)#

Sparse matrix with a fixed number of post-synaptic connections per pre-synaptic neuron (row-major ELL; structurally equivalent to brainevent.CSR).

data and indices have shape (num_pre, num_conn); the equivalent dense matrix is W[i, indices[i, k]] = data[i, k].

Examples

>>> import jax.numpy as jnp
>>> from brainevent import FixedNumPerPre
>>>
>>> data = jnp.array([[1., 2.], [3., 4.]])
>>> indices = jnp.array([[0, 1], [1, 2]])
>>> mat = FixedNumPerPre(data, indices, shape=(2, 3))
>>> mat.shape
(2, 3)
classmethod fromdense(mat, *, num_conn=None, backend=None)[source]#

Construct from a dense matrix with a fixed number of connections per pre.

Each pre-synaptic row of mat is encoded with num_conn outgoing connections (post-synaptic ids).

Parameters:
  • mat (jax.Array or brainunit.Quantity) – Dense (num_pre, num_post) matrix. Explicit zeros are treated as absent connections.

  • num_conn (int, optional) – Connections per pre-synaptic neuron. If None (default), inferred from the matrix, which must then have a uniform per-row non-zero count; otherwise short rows are padded with a zero-weight sentinel and a row with more non-zeros than num_conn raises ValueError.

  • backend (str, optional) – Backend tag forwarded to the constructor.

Returns:

Encoded fixed-connection matrix, shape equal to mat.shape.

Return type:

FixedNumPerPre

Raises:

ValueError – If mat is not 2-D, if per-row counts are non-uniform and num_conn is omitted, or if a row exceeds num_conn.

See also

tocsr

Inverse-direction conversion to CSR.

brainevent.CSR.fromdense

For irregular matrices.

slice_rows(index)[source]#

Return W[rows, :] as a new FixedNumPerPre.

Selecting pre-synaptic rows preserves the fixed-connection invariant (each selected row keeps its num_conn entries), so this is a static gather and is safe under jax.jit.

Parameters:

index (int, list, tuple, array, or slice) – Row selector along axis 0 (pre-synaptic).

Returns:

Sparse sub-matrix of shape (len(rows), num_post).

Return type:

FixedNumPerPre

todense()[source]#

Convert to a dense matrix of shape (num_pre, num_post).

transpose(axes=None)[source]#

Transpose to a FixedNumPerPost (O(1); reinterprets indices).

Orientation flips, so the cached 'csc' mirror is not carried over; the new matrix rebuilds its own mirror lazily on first need.

Return type:

FixedNumPerPost

update_on_post(pre_trace, post_spike, w_min=None, w_max=None)[source]#

Post-spike STDP (unfavorable) – mirrors brainevent.CSR.update_on_post() (perm-fused).

update_on_pre(pre_spike, post_trace, w_min=None, w_max=None)[source]#

Pre-spike STDP (favorable, row-driven) – mirrors brainevent.CSR.update_on_pre().

with_data(data)[source]#

Return a new matrix with the same connectivity and replaced values.

Return type:

FixedNumPerPre