vjp
Stable function · Evaluate the Jacobian
Tier: stable · Kind: function · Topic: Evaluate the Jacobian
| Julia | Python | Rust |
|---|---|---|
vjp! | vjp | vjp |
Julia
vjp!(ḡ::AbstractVector, jac::JacobianEvaluator, λ::AbstractVector, u::AbstractVector, p, t::Real)
vjp!(ḡ, jac::JacobianEvaluator, λ, u, p, t) -> ḡ
The transposed product ḡ += Jᵀ λ at (u, p, t), as a scatter-add over the
band points: ḡ[col] += coef · λ[row] for every point, with no matrix (and
no transpose) formed. λ is indexed like the rows (jac.rownames, the
state vector) and ḡ like the columns (jac.colnames); ḡ ACCUMULATES —
zero it first for a single product.
Python
vjp(g, obj, lam: dict, model_name: str | None = None, wrt: str | None = None, states: dict | None = None, params: dict | None = None, t: float = 0.0, forcing=None)
The transposed product g += Jᵀ λ at a point, as a scatter-add over
the band points: g[col] += coef · λ[row], with no matrix formed.
obj is a JacobianEvaluator
(built once with
prepare_jacobian
; its axis and forcing set apply) or anything
assemble_jacobian
takes, prepared for this one call with wrt
(default "forcing"). lam maps row (state cell) names to values; a
row a band point needs that lam does not bind raises ValueError.
g is a flat mutable sequence (list or numpy vector) over the
canonical column ordinal of the "parameters" / "forcing" axis
(jacobian_columns
, cells column-major) or of "time" ([t]).
g ACCUMULATES — zero it first for a single product. Returns g.
Rust
pub fn vjp(file: &EsmFile, model_name: Option<&str>, wrt: Wrt, forcing: Option<&[String]>, env: &Env, lambda: &HashMap<String, f64>, gbar: &mut [f64]) -> Result<(), BandError>
The transposed product ḡ += Jᵀ λ at a point, as a scatter-add over the
band points: ḡ[col] += coef · λ[row] for every point, with no matrix
(and no transpose) formed. lambda is keyed by row cell name ("c[2]",
"S"); a row it does not bind is an error. gbar is indexed by the
canonical column ordinal of a parameters or forcing axis
(crate::jacobian::column_names of crate::jacobian_columns
) and
ACCUMULATES — zero it first for a single product. This prepares the
evaluator for one call; a loop calls JacobianEvaluator::vjp on one
prepare_jacobian
instead.