dscalar
Stable function · Differentiate a model
Tier: stable · Kind: function · Topic: Differentiate a model
| Julia | Python | Rust |
|---|---|---|
dscalar | dscalar | dscalar |
Julia
dscalar(e::EarthSciAST.ASTExpr, s::Site)
dscalar(e::EarthSciAST.ASTExpr, s::Site, occ::Union{IdDict{EarthSciAST.OpExpr, Bool}, EarthSciASTDiff._SiteScan})
dscalar(e::ASTExpr, s::Site) -> ASTExpr
Derivative of the scalar expression e with respect to site s, as a new
ESM expression. Structural rules only; a subtree in which s does not occur
differentiates to a literal zero without descent. Throws
DerivativeRuleError
on an op with no rule (rewrite targets,
joined or value-invention faq nodes in scalar position, unknown closed
functions).
Rust
pub fn dscalar(e: &Expr, s: &Site) -> Result<Expr, DerivativeRuleError>
The derivative of the scalar expression e with respect to the site s
(a variable or an indexed read), by the §3 rule table.
A one-shot call scans plainly: occurrence by occurs, which stops at the
first hit, and a derivative memo private to the call. Building a shared
occurrence index (a pass over the whole tree with a bit set per node)
pays only when many scans share it, as a band computation’s do.