pub struct CasDiffRegistry {
pub rules: BTreeMap<Symbol, DiffRule>,
}Expand description
A registry of per-operator differentiation rules.
§Examples
use sim_kernel::Symbol;
use sim_lib_numbers_cas::CasExpr;
use sim_lib_numbers_cas_diff::CasDiffRegistry;
let mut registry = CasDiffRegistry::new();
registry.register_rule(
Symbol::new("id"),
Box::new(|args: &[CasExpr], _var: &Symbol| args.first().cloned()),
);
let out = registry.apply(
&Symbol::new("id"),
&[CasExpr::Var(Symbol::new("x"))],
&Symbol::new("x"),
);
assert!(matches!(out, Some(CasExpr::Var(_))));
// An unregistered operator yields `None`.
assert!(registry.apply(&Symbol::new("nope"), &[], &Symbol::new("x")).is_none());Fields§
§rules: BTreeMap<Symbol, DiffRule>The registered rules, keyed by operator symbol.
Implementations§
Source§impl CasDiffRegistry
impl CasDiffRegistry
Trait Implementations§
Source§impl Default for CasDiffRegistry
impl Default for CasDiffRegistry
Source§fn default() -> CasDiffRegistry
fn default() -> CasDiffRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for CasDiffRegistry
impl !UnwindSafe for CasDiffRegistry
impl Freeze for CasDiffRegistry
impl Send for CasDiffRegistry
impl Sync for CasDiffRegistry
impl Unpin for CasDiffRegistry
impl UnsafeUnpin for CasDiffRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more