TCSR#
- class brainevent.TCSR(source, *, backend=None, binary_backend=None, backward_algorithm='bptt')#
Represent a unit-aware sparse matrix in tiled CSR storage.
TCSR stores a logical matrix
Wwith shape(num_pre, num_post)in a canonical tiled CSR structure.W.Tis an O(1) logical view sharing the same values, tile metadata, workspaces, and lazily materialized TCSC mirror.- Parameters:
source (
CSR) – Plain CSR whose column indices are nondecreasing within every row. Direct construction trusts this ordering and does not verify it.backend (
str|None) – Backend used by floating-point sparse operations.binary_backend (
str|None) – Backend used by event-driven binary sparse operations.backward_algorithm (
str) – Weight-gradient interpretation for floating event operands. Default is"bptt".
- data#
Current-view compressed values. Heterogeneous storage has one value per entry; homogeneous storage has one shared value.
- Type:
jax.Array or brainunit.Quantity
- indices#
Current-view minor-axis coordinates.
- Type:
jax.Array
- indptr#
Current-view int64 row pointers.
- Type:
jax.Array
Notes
Enable JAX x64 before construction:
jax.config.update("jax_enable_x64", True). TCSR requires int64 row pointers for both canonical and mirror storage.Use
fromcsr()when CSR row ordering is unknown. Use direct construction orfrom_sorted_csr()only when every row is already sorted by nondecreasing column index.For a logical shape
(m, n), public matrix multiplication follows normal array conventions:W @ XacceptsX.shape == (n, batch)and returns(m, batch), whileX @ WacceptsX.shape == (batch, m)and returns(batch, n). The same rule applies toW.Tusing its reversed logical shape. Internal neuron-batch and batch-neuron service layouts are selected automatically.See also
fromcsrBuild from CSR while enforcing row-local ordering.
from_sorted_csrBuild from a CSR already known to be sorted.
brainevent.CSRPlain compressed sparse row representation.
Examples
>>> import jax >>> import jax.numpy as jnp >>> import brainevent >>> jax.config.update("jax_enable_x64", True) >>> source = brainevent.CSR( ... ( ... jnp.asarray([2.0, 1.0], dtype=jnp.float32), ... jnp.asarray([1, 0], dtype=jnp.int32), ... jnp.asarray([0, 2], dtype=jnp.int64), ... ), ... shape=(1, 2), ... ) >>> matrix = brainevent.TCSR.fromcsr(source) >>> matrix.todense() Array([[1., 2.]], dtype=float32)
- property T: TCSR#
Return the transposed TCSR view.
- Returns:
O(1) logical transpose sharing all underlying TCS storage.
- Return type:
See also
transposeMethod form with optional axes validation.
- dt2t(y_dim_arr, w_dim_arr)[source]#
Expand logical row values over the current view’s sparse slots.
- Parameters:
y_dim_arr (
Array|ndarray|Quantity) – Logical row values with shape(self.shape[0],).w_dim_arr (
Array|ndarray|Quantity) – Per-slot values in the current view’s compressed order.
- Returns:
Per-slot products in the same order as
w_dim_arr.- Return type:
Array|Quantity
See also
dt2t_transposedExpand logical column values over sparse slots.
- dt2t_transposed(y_dim_arr, w_dim_arr)[source]#
Expand logical column values over the current view’s sparse slots.
- Parameters:
y_dim_arr (
Array|ndarray|Quantity) – Logical column values with shape(self.shape[1],).w_dim_arr (
Array|ndarray|Quantity) – Per-slot values in the current view’s compressed order.
- Returns:
Per-slot products in the same order as
w_dim_arr.- Return type:
Array|Quantity
See also
dt2tExpand logical row values over sparse slots.
- solve(b, *args, **kwargs)[source]#
Reject sparse solve until TCSR has a supported solver contract.
- Parameters:
- Raises:
NotImplementedError – Always, because TCSR solve is not implemented.
- Return type:
Array|ndarray|Quantity|Number
- tocsc()[source]#
Materialize the current logical matrix as a plain CSC matrix.
- Returns:
Plain CSC matrix with the same logical values and shape.
- Return type:
Notes
A canonical TCSR view materializes the shared TCSC mirror lazily. A transposed view can reuse canonical CSR structure directly. Homogeneous data remains a size-one value buffer.
- transpose(axes=None)[source]#
Return a transposed TCSR view sharing the same storage.
- Parameters:
axes (
Any) – Accepted transpose axes. OnlyNoneand(1, 0)are valid.- Returns:
TCSR view with reversed logical shape and orientation state.
- Return type:
- Raises:
ValueError – If
axesdoes not describe a matrix transpose.
Notes
The returned view shares canonical values, tile metadata, workspace, and mirror state. No sparse coordinates are rebuilt.
- update_on_post(pre_trace, post_spike, w_min=None, w_max=None)[source]#
Reject postsynaptic-triggered STDP until TCSR supports it.
- Parameters:
- Raises:
NotImplementedError – Always, because TCSR postsynaptic STDP is not implemented.
- Return type:
Self
- update_on_pre(pre_spike, post_trace, w_min=None, w_max=None)[source]#
Reject presynaptic-triggered STDP until TCSR supports it.
- Parameters:
- Raises:
NotImplementedError – Always, because TCSR presynaptic STDP is not implemented.
- Return type:
Self