brainevent.csr_delay_deliver#
- brainevent.csr_delay_deliver(ring, events, data, indices, indptr, delays, t, *, shape, weighted=None, backend=None)[source]#
Deliver spikes through a CSR matrix with per-edge delays into a ring buffer.
For every edge
eof every active presynaptic rowi, adds the edge weight into the post-side arrival ring at the slot the spike will arrive in,(t + delays[e]) mod L:ring_new[(t + d_e) % L, indices[e]] += w_e * f(x)[i]
where
f(x)is the activity mask of the events (binary mode; a numeric event is active iffx != 0) or the event value itself (weighted mode). Only the rows of active events are visited.- Parameters:
ring (
Array|ndarray|Quantity|Number) – Arrival buffer of shape(L, n_post)with a floating-point dtype (float16,bfloat16,float32orfloat64). Its dtype is the output dtype. Whendataoreventscarry units,ringmust carryunit(data) * unit(events).events (
Any) – Presynaptic events of shape(n_pre,). Event wrappers are unwrapped; aWeightedArrayselects weighted delivery. Any boolean, integer or floating dtype.data (
Array|ndarray|Quantity|Number) – Synaptic weights: a scalar / shape(1,)(homogeneous) or shape(nse,)(heterogeneous). Cast toring.dtype.indices (
Array|ndarray) – CSR column (postsynaptic) indices, shape(nse,),int32.indptr (
Array|ndarray) – CSR row pointers, shape(n_pre + 1,),int32orint64.delays (
Any) – Integer per-edge delays in steps, shape(nse,), or a scalar broadcast to every edge.t (
Any) – Current integer time step. May be traced (e.g. the step counter of ajax.lax.scan()).shape (
Tuple[int,int]) –(n_pre, n_post), the logical shape of the CSR matrix.weighted (
bool|None) –False: binary delivery, each active row addsw_e.True: weighted delivery, each row addsx[i] * w_e.None(default):Truefor aWeightedArray,Falseotherwise.backend (
str|None) –'jax_raw','numba'(CPU) or'cuda_raw'(GPU), orNonefor the platform default.
- Returns:
ring_new – Updated ring of shape
(L, n_post), same dtype and unit asring.- Return type:
Array|ndarray|Quantity|Number- Raises:
ValueError – If
delaysis concrete and any value is outside[1, L).TypeError – If
tordelaysis not an integer array.AssertionError – On shape or dtype mismatches of the CSR operands.
See also
binary_csrmvScalar-delay (no ring) event-driven delivery.
CSR.delay_deliverMethod form on a
CSRmatrix.
Notes
modis the floor modulo, so the slot is in[0, L)for anyt(tmay grow without bound).tand eachdare reduced moduloLseparately, sot + dnever overflows.A delay of
0would write into the slot being read in the current step and a delay>= Lwould alias a later arrival, so concrete delays are validated to lie in[1, L). Whendelaysis traced the check is impossible; out-of-range values then wrap moduloLidentically on every backend.The output is linear in
ringanddata(and, in weighted mode, inevents). Withs_e = (t + d_e) mod Land output cotangentg:d ring = g,d data[e] = f(x)[row(e)] * g[s_e, indices[e]](summed for homogeneous weights) andd x[i] = sum_{e in row i} w_e * g[s_e, indices[e]], which is exact in weighted mode and the straight-through estimator in binary mode.delays,t,indicesandindptrare not differentiable.Examples
>>> import jax.numpy as jnp >>> from brainevent import csr_delay_deliver >>> # 2 presynaptic, 3 postsynaptic neurons; row 0 -> {0, 2}, row 1 -> {1} >>> indices = jnp.array([0, 2, 1], dtype=jnp.int32) >>> indptr = jnp.array([0, 2, 3], dtype=jnp.int32) >>> delays = jnp.array([1, 2, 1], dtype=jnp.int32) >>> ring = jnp.zeros((3, 3), dtype=jnp.float32) >>> spikes = jnp.array([True, False]) >>> csr_delay_deliver(ring, spikes, jnp.array([0.5]), indices, indptr, ... delays, 0, shape=(2, 3), backend='jax_raw') Array([[0. , 0. , 0. ], [0.5, 0. , 0. ], [0. , 0. , 0.5]], dtype=float32)