Dense#
- class brainevent.Dense(data, *, shape=None, backend=None, buffers=None)#
Unit-aware explicit dense matrix.
Densestores a full two-dimensional weight matrix and exposes the same representation contract as the sparse matrix families. It is useful when a caller wants matrix metadata, backend selection, plasticity helpers, and event-driven binary matmul dispatch without converting the matrix to CSR or CSC format.The class is a JAX pytree with a single dynamic leaf,
data. Static metadata such asshape,backend, and registered buffers are carried in the pytree auxiliary data soDensecan be passed throughjax.jitin the same style asCSRandCSC.- Parameters:
data (array_like or brainunit.Quantity) – Dense two-dimensional matrix data. Units are preserved.
shape (
Sequence[int] |None) – Explicit matrix shape. When provided it must matchdata.shape.backend (
str|None) – Backend attached to event-driven binary matmul and plasticity calls. Typical values areNone,'jax_raw','cuda_raw', and'cublas'where supported.buffers (
Dict|None) – Named auxiliary buffers to carry with the representation.
- data#
Full dense matrix data.
- Type:
Data
Notes
Dense @ BinaryArrayandBinaryArray @ Densedispatch to the event-driven dense binary primitives. Dense numeric operands fall back to ordinary JAX matrix multiplication with unit-aware dtype promotion.The per-synapse
dt2tprotocol is intentionally not implemented directly for explicit dense matrices. Materialise a sparse representation first, for exampledense.tocsr().dt2t(y, dense.tocsr().data), when a per-stored synapse output is required.Examples
import jax.numpy as jnp import brainevent weights = jnp.array([[1.0, 0.0], [2.0, 3.0]]) dense = brainevent.Dense(weights, backend='jax_raw') spikes = brainevent.BinaryArray(jnp.array([True, False])) y = dense @ spikes
See also
CSRCompressed sparse row representation.
CSCCompressed sparse column representation.
binary_densemvDense matrix-vector event primitive.
binary_densemmDense matrix-matrix event primitive.
- apply2(other, fn, *, reverse=False)[source]#
Apply a binary elementwise operation while preserving metadata.
- diag_add(other)[source]#
Add values to the main diagonal and return a new
Dense.othermust have lengthmin(self.shape). Units are handled by the underlyingjax.Array/brainunit.Quantityaddition.- Return type:
- dt2t(y_dim_arr, w_dim_arr)[source]#
Report that direct dense
dt2tis not implemented.The dense representation has no compressed per-synapse storage order to target. Convert to CSR/CSC first when a per-synapse
w * youtput is required.- Return type:
Array|Quantity
- dt2t_transposed(y_dim_arr, w_dim_arr)[source]#
Report that direct transposed dense
dt2tis not implemented.Convert to CSR/CSC first when a per-synapse
w * youtput indexed by columns is required.- Return type:
Array|Quantity
- classmethod fromdense(mat, *, backend=None, buffers=None)[source]#
Create a
Denserepresentation from an explicit dense matrix.- Parameters:
- Returns:
A new dense matrix representation containing
mat.- Return type:
- solve(b, tol=1e-06, reorder=1)[source]#
Solve the dense linear system
self @ x = b.The
tolandreorderparameters are accepted for API parity with sparse solvers and are currently unused. Units are propagated asunit(b) / unit(self.data).- Return type:
Array|Quantity
- tocsc(*, nse=None, index_dtype=<class 'jax.numpy.int32'>, precompute_weight_indices=False)[source]#
Convert the dense matrix to
CSC.Parameters mirror
brainevent.CSC.fromdense();backendis propagated from thisDenseinstance.
- tocsr(*, nse=None, index_dtype=<class 'jax.numpy.int32'>, precompute_weight_indices=False)[source]#
Convert the dense matrix to
CSR.Parameters mirror
brainevent.CSR.fromdense();backendis propagated from thisDenseinstance.
- todense()[source]#
Return the explicit dense matrix data.
Unlike sparse representations, no materialisation is needed because the storage format is already dense.
- Return type:
Array|Quantity
- transpose(axes=None)[source]#
Return
self.Tas a newDenserepresentation.Only the standard matrix transpose is supported;
axesmust beNoneto match the two-dimensional data contract.- Return type:
- classmethod tree_unflatten(aux_data, children)[source]#
Rebuild a
Denseinstance from pytree leaves and metadata.
- update_on_post(pre_trace, post_spike, w_min=None, w_max=None)[source]#
Apply a post-spike-triggered dense plasticity update.
Returns a new
Densewith updated data and the same metadata.- Return type: