bcoo_helpers
BCOO utilities for fixed sparsity patterns (jax.experimental.sparse).
These helpers build sparse matrices from dense batched data by indexing only precomputed structural nonzeros — useful wherever a sparsity pattern is known statically (not only for Jacobians).
precompute_sparse_indices(pattern: np.ndarray) -> Tuple[jnp.ndarray, jnp.ndarray, int]
¶
Pre-compute BCOO index arrays from a boolean sparsity pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
ndarray
|
Boolean |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray, int]
|
|
Source code in openscvx/discretization/sparse_utils/bcoo_helpers.py
sparse_matmul_batched(dense_jac: jnp.ndarray, rhs: jnp.ndarray, nz_rows: jnp.ndarray, nz_cols: jnp.ndarray, m: int, n: int) -> jnp.ndarray
¶
Sparse-dense batched matmul: sparse(dense_jac) @ rhs.
Extracts nonzero values from the dense batch using pre-computed indices, constructs a BCOO matrix per batch item, and multiplies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dense_jac
|
ndarray
|
|
required |
rhs
|
ndarray
|
|
required |
nz_rows
|
ndarray
|
Row indices of structural nonzeros. |
required |
nz_cols
|
ndarray
|
Column indices of structural nonzeros. |
required |
m
|
int
|
Number of rows of the sparse matrix. |
required |
n
|
int
|
Number of columns of the sparse matrix. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|