brainevent.csr_delay_deliver_layout

brainevent.csr_delay_deliver_layout#

brainevent.csr_delay_deliver_layout(ring, events, layout, t, *, weighted=None, backend=None)[source]#

Deliver spikes with per-edge delays using a precomputed layout.

Computes the same result as csr_delay_deliver() on the CSR the layout was built from:

ring_new[(t + d_e) % L, indices[e]] += w_e * f(x)[row(e)]

with f(x) the activity mask (binary mode, x != 0) or the event value (weighted mode), but processes the active rows delay by delay.

Parameters:
  • ring (Array | ndarray | Quantity | Number) – Arrival buffer of shape (layout.n_slots, n_post), dtype float16, bfloat16, float32 or float64. When the weights or events carry units, ring must carry unit(data) * unit(events).

  • events (Any) – Presynaptic events of shape (n_pre,); a WeightedArray selects weighted delivery.

  • layout (CSRDelayLayout) – Connectivity built by CSRDelayLayout.build().

  • t (Any) – Current integer time step; may be traced.

  • weighted (bool | None) – False: binary, True: weighted, None (default): inferred from the event type.

  • backend (str | None) – 'cuda_raw' (GPU default), 'numba' (CPU default) or 'jax_raw'.

Returns:

ring_new – Updated ring, same shape, dtype and unit as ring.

Return type:

Array | ndarray | Quantity | Number

Raises:
  • ValueError – If ring does not have layout.n_slots rows.

  • TypeError – If t is not an integer scalar.

See also

CSRDelayLayout

The layout and how to build it.

csr_delay_deliver

Delivery without precomputation.

Notes

On cuda_raw the active rows are compacted first, then a persistent grid processes the items (d, active row) in delay-major order, so concurrent writes share the ring row (t + d) mod L. numba and jax_raw run the csr_delay_deliver() kernels on the layout arrays. Derivatives follow csr_delay_deliver(): the gradient with respect to layout.data is in layout order.

Examples

>>> import jax.numpy as jnp
>>> from brainevent import CSRDelayLayout, csr_delay_deliver_layout
>>> layout = CSRDelayLayout.build(
...     jnp.array([0.5]), jnp.array([0, 2, 1], dtype=jnp.int32),
...     jnp.array([0, 2, 3], dtype=jnp.int32), jnp.array([1, 2, 1], dtype=jnp.int32),
...     n_slots=3, shape=(2, 3))
>>> ring = jnp.zeros((3, 3), dtype=jnp.float32)
>>> csr_delay_deliver_layout(ring, jnp.array([True, False]), layout, 0, backend='jax_raw')
Array([[0. , 0. , 0. ],
       [0.5, 0. , 0. ],
       [0. , 0. , 0.5]], dtype=float32)