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 delay d start in row i. 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 than csr_delay_deliver() when the ring does not fit in the L2 cache.

Build it once with build() (or CSR.delay_layout()). The weights live in layout order: train or update layout.data directly, use with_data() to load weights given in the original edge order and original_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,), int32 or int64.

  • delays (jax.Array) – Delays in layout order, shape (nse,), int32, in [1, L).

  • delay_ptr (jax.Array) – Shape (n_pre, L), same dtype as indptr: first position of delay d in row i.

  • perm (jax.Array) – Shape (nse,): perm[k] is the original index of the edge at layout position k.

  • shape (Tuple[int, int]) – (n_pre, n_post).

n_slots#

Ring length L the layout was built for.

Type:

int

nse#

Number of stored edges.

Type:

int

See also

csr_delay_deliver_layout

Delivery on a layout.

csr_delay_deliver

Delivery on a plain CSR (no precomputation).

Notes

Every array is a pytree leaf, so a layout can be passed through jax.jit; shape is static. delay_ptr costs n_pre * L * indptr.itemsize bytes.

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)
__init__(data, indices, indptr, delays, delay_ptr, perm, *, shape)[source]#

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; see csr_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 data given in the original edge order.

Attributes

n_slots

Ring length L the layout was built for.

nse

Number of stored edges.