braintrace.sparse_matmul#
- braintrace.sparse_matmul(x, weight, *, sparse_mat, bias=None, weight_fn=None, bias_fn=None)#
ETP-aware sparse matrix multiplication.
Computes \(y = x \mathbin{@} \mathrm{sparse}(f(w)) \; (+ g(b))\), where only the non-zero entries (
weight) of the fixed sparse pattern are trainable and participate in eligibility-trace computation. Auto-dispatches batched/unbatched based onx.ndim.- Parameters:
x (ArrayLike) – Input array.
weight (ArrayLike) – Sparse-matrix data, i.e. the non-zero values, shape
(nnz,).sparse_mat (brainevent.DataRepresentation) – Sparse-matrix structure (e.g. a
brainevent.CSR). Must be abrainevent.DataRepresentation, which implements the ETP online-learning protocol:with_data(substitute new data into the structure),dt2t_transposed(apply the transposed sparse pattern to a trace) anddt2t(its non-transposed counterpart). Passing any other object raisesTypeError.bias (ArrayLike or None, optional) – Bias vector. Default
None.weight_fn (callable or None, optional) – Elementwise transform applied to the non-zero
weightdata before the matmul.Nonemeans identity (no transform). When provided, the transform is applied inside the primitive so thatxy_to_dwauto-composes the derivative viajax.vjp, returning the gradient w.r.t. the raw data. The transform operates on the unitless mantissa; physical units are split off before and recombined after.bias_fn (callable or None, optional) – Elementwise transform applied to
biasbefore it is added to the output.Nonemeans identity. The derivative is composed by the samejax.vjpcall asweight_fn. The transform operates on the unitless mantissa; physical units are split off before and recombined after.
- Returns:
ArrayLike – Output array.
- Raises:
TypeError – If
sparse_matis not abrainevent.DataRepresentation.