brainevent.CSRDelayLayout#
- class brainevent.CSRDelayLayout(data, indices, indptr, delays, delay_ptr, perm, *, shape)[source]#
CSR connectivity with per-edge delays, reordered for fast delivery.
The edges of every row are sorted by delay (ties keep their original order) and
delay_ptr[i, d]records where the edges of delaydstart in rowi.csr_delay_deliver_layout()uses this to deliver all active rows delay by delay, so that concurrent writes share one ring row; on the GPU this is several times faster thancsr_delay_deliver()when the ring does not fit in the L2 cache.Build it once with
build()(orCSR.delay_layout()). The weights live in layout order: train or updatelayout.datadirectly, usewith_data()to load weights given in the original edge order andoriginal_data()to read them back in that order.- Parameters:
data (jax.Array or brainunit.Quantity) – Weights in layout order, shape
(1,)(homogeneous) or(nse,).indices (jax.Array) – Column indices in layout order, shape
(nse,),int32.indptr (jax.Array) – Row pointers, shape
(n_pre + 1,),int32orint64.delays (jax.Array) – Delays in layout order, shape
(nse,),int32, in[1, L).delay_ptr (jax.Array) – Shape
(n_pre, L), same dtype asindptr: first position of delaydin rowi.perm (jax.Array) – Shape
(nse,):perm[k]is the original index of the edge at layout positionk.
See also
csr_delay_deliver_layoutDelivery on a layout.
csr_delay_deliverDelivery on a plain CSR (no precomputation).
Notes
Every array is a pytree leaf, so a layout can be passed through
jax.jit;shapeis static.delay_ptrcostsn_pre * L * indptr.itemsizebytes.Examples
>>> import jax.numpy as jnp >>> from brainevent import CSRDelayLayout >>> # row 0 -> {0 (delay 2), 2 (delay 1)}, row 1 -> {1 (delay 1)} >>> layout = CSRDelayLayout.build( ... jnp.array([1., 2., 3.]), jnp.array([0, 2, 1], dtype=jnp.int32), ... jnp.array([0, 2, 3], dtype=jnp.int32), jnp.array([2, 1, 1], dtype=jnp.int32), ... n_slots=3, shape=(2, 3)) >>> layout.indices Array([2, 0, 1], dtype=int32) >>> layout.original_data() Array([1., 2., 3.], dtype=float32)
Methods
__init__(data, indices, indptr, delays, ...)build(data, indices, indptr, delays, *, ...)Build a layout from a CSR matrix and its per-edge delays.
deliver(ring, events, t, *[, weighted, backend])Deliver events into
ring; seecsr_delay_deliver_layout().original_data()Return the weights in the original edge order.
tree_flatten()tree_unflatten(shape, children)with_data(data)Return a copy holding
datagiven in the original edge order.Attributes