JITCScalarC#
- class brainevent.JITCScalarC(weight, prob=None, seed=None, *, shape, corder=False, backend=None, buffers=None)#
Just-In-Time Connectivity Homogeneous matrix with Column-oriented representation.
This class represents a column-oriented homogeneous sparse matrix optimized for JAX-based transformations. It follows the Compressed Sparse Column (CSC) format conceptually, storing a uniform weight value for all non-zero elements in the matrix, along with probability and seed information to determine the sparse structure.
The column-oriented structure makes column-based operations more efficient than row-based ones, making this class the transpose-oriented counterpart to JITCScalarR.
- weight#
The homogeneous value used for all non-zero elements in the matrix. Can be a plain JAX array or a quantity with units.
- Type:
Union[jax.Array, u.Quantity]
- prob#
Probability for each potential connection. Controls the sparsity level with 0.0 meaning no connections and 1.0 meaning all possible connections.
- Type:
Union[float, jax.Array]
- seed#
Random seed used for initialization of the sparse structure. Using the same seed produces identical connectivity patterns.
- Type:
Union[int, jax.Array]
- shape#
The shape of the matrix as a tuple (rows, cols).
- Type:
MatrixShape
- corder#
Flag indicating the memory layout order of the matrix. False (default) for Fortran-order (column-major), True for C-order (row-major).
- Type:
- dtype#
The data type of the matrix elements (property inherited from parent).
Examples
>>> import jax >>> import brainunit as u >>> from brainevent import JITCScalarC # Create a homogeneous matrix with value 1.5, probability 0.1, and seed 42 >>> homo_matrix = JITCScalarC((1.5, 0.1, 42), shape=(10, 10)) >>> homo_matrix JITCHomoC(shape=(10, 10), weight=1.5, prob=0.1, seed=42, corder=False) # Create a matrix with units >>> weighted_matrix = JITCScalarC((1.5 * u.mV, 0.1, 42), shape=(10, 10)) >>> weighted_matrix JITCHomoC(shape=(10, 10), weight=1.5 mV, prob=0.1, seed=42, corder=False) # Perform matrix-vector multiplication >>> vec = jax.numpy.ones(10) >>> result = homo_matrix @ vec >>> result.shape # (10,) # Apply scalar operations >>> scaled = homo_matrix * 2.0 >>> scaled.weight # 3.0 # Arithmetic operations maintain the sparse structure >>> neg_matrix = -homo_matrix >>> neg_matrix.weight # -1.5 # Convert to dense representation >>> dense_matrix = homo_matrix.todense() >>> dense_matrix.shape # (10, 10) # Transpose operation returns a row-oriented matrix >>> row_matrix = homo_matrix.transpose() >>> isinstance(row_matrix, JITCScalarR) # True >>> row_matrix.shape # (10, 10)
Notes
The mathematical model is the same as
JITCScalarR:W[i, j] = w * Bernoulli(p)where
wis the scalar weight,pis the connection probability, and the Bernoulli draw is fully determined by the seed. The column-oriented representation means thatJITCScalarCis conceptually the transpose of aJITCScalarRmatrix with swapped dimensions.Key properties:
JAX PyTree compatible for use with JAX transformations (jit, grad, vmap)
More memory-efficient than dense matrices for sparse connectivity patterns
More efficient than
JITCScalarRfor column-based operationsWell-suited for neural network connectivity matrices with uniform weights
The matrix is implicitly constructed based on the probability and seed; the actual sparse structure is materialized only when needed
When used with units (e.g.,
u.mV), units are preserved through operations
See also
JITCScalarRRow-oriented counterpart of this class.
JITCScalarMatrixBase class providing shared functionality.
- todense()[source]#
Convert the sparse column-oriented scalar-weight matrix to dense format.
Generates a full dense representation of the sparse matrix by materializing all entries
W[i, j] = w * Bernoulli(p)determined by the probability and seed. The generated dense matrix always hasself.shape.- Parameters:
None
- Returns:
A dense matrix with the same shape as the sparse matrix. The data type will match the weight’s data type, and if the weight has units (is a
u.Quantity), the returned array will have the same units.- Return type:
Array|Quantity- Raises:
None –
See also
jitsThe underlying function that materializes the matrix.
Notes
The dense matrix is generated identically to
JITCScalarR.todense():dense[i, j] = w if hash(seed, i, j) < p else 0Examples
>>> import brainunit as u >>> from brainevent import JITCScalarC >>> sparse_matrix = JITCScalarC((1.5 * u.mV, 0.5, 42), shape=(3, 10)) >>> dense_matrix = sparse_matrix.todense() >>> dense_matrix.shape # (3, 10)
- transpose(axes=None)[source]#
Transposes the column-oriented matrix into a row-oriented matrix.
This method returns a row-oriented matrix (JITCScalarR) with rows and columns swapped, preserving the same weight, probability, and seed values. The transpose operation effectively converts between column-oriented and row-oriented sparse matrix formats.
- Parameters:
axes (None) – Not supported. This parameter exists for compatibility with the NumPy API but only None is accepted.
- Returns:
A new row-oriented homogeneous matrix with transposed dimensions.
- Return type:
- Raises:
AssertionError – If axes is not None, since partial axis transposition is not supported.
Examples
>>> import jax >>> import brainunit as u >>> from brainevent import JITCScalarC >>> >>> # Create a column-oriented matrix >>> col_matrix = JITCScalarC((1.5, 0.5, 42), shape=(3, 5)) >>> print(col_matrix.shape) # (3, 5) >>> >>> # Transpose to row-oriented matrix >>> row_matrix = col_matrix.transpose() >>> print(row_matrix.shape) # (5, 3) >>> isinstance(row_matrix, JITCScalarR) # True