Version: dev

detect_structure

Stable function · Sparsity and structure

Tier: stable · Kind: function · Topic: Sparsity and structure

JuliaPythonRust
detect_structuredetect_structuredetect_structure

Julia

detect_structure(entries::Vector{JacEntry}, sv::SysView)
detect_structure(entries, sv::SysView) -> Symbol

Classify the Jacobian’s structure from the band list:

  • :empty — no bands.
  • :block_diagonal — every array-state band is diagonal (col == row in every dimension) and no band couples a scalar state to an array state: after the species-major → cell-major permutation the matrix is block-diagonal with one dense-patterned block per cell.
  • :banded — off-diagonal couplings exist but every column index is row ± literal (bounded stencil offsets): banded/block-banded once strides are fixed by the layout.
  • :general — anything else (fixed boundary columns, periodic wrap corners, indirect gathers): use a general sparse type.

This is a CLASSIFICATION of the exact pattern, not an approximation — the pattern itself is always available via jacobian_pattern .

Source

Example (structure)

@assert detect_structure(entries, view) == :block_diagonal
plan = plan_factorization(entries, view)
@assert sort(plan.block_vars) == ["A", "B", "C"]

From docs/api/examples/julia/jacobians.jl

Python

detect_structure(entries: list[JacEntry], sv: SysView) -> str

Classify the band list: "block_diagonal", "banded", "general" (or "empty" / "other"), read off the column-index expressions without evaluating anything. Use it to choose a matrix type.

Source

Example (structure)

assert earthsci_astdiff.detect_structure(entries, view) == "block_diagonal"
plan = earthsci_astdiff.plan_factorization(entries, view)
assert sorted(plan.block_vars) == ["A", "B", "C"]

From docs/api/examples/python/jacobians.py

Rust

pub fn detect_structure(entries: &[JacEntry], ctx: &Ctx) -> &'static str

Classify the band list as "block_diagonal", "banded" or "general" (or "empty" / "other"), read off the column-index expressions without evaluating anything. Use it to choose a matrix type.

Source · Rust docs

Example (structure)

let ctx = ctx_of(&view)?;
assert_eq!(detect_structure(&entries, &ctx), "block_diagonal");
let plan = block_diagonal_lu(&entries);
let mut vars = plan.block_vars.clone();
vars.sort();
assert_eq!(vars, ["A", "B", "C"]);

From docs/api/examples/rust/jacobians.rs