pub struct TruncatedExp4WithCache { /* private fields */ }Expand description
TruncatedExp4thDiffusionChernoff with pre-evaluated a(x) half-node cache.
Implements ChernoffFunction identically to the wrapped type but replaces
the 4-per-node function-pointer dispatches in apply_g4_at_node_f64 with
direct Vec<f64> index reads.
§Construction
use semiflow::{chernoff::ApplyChernoffExt, Grid1D, GridFn1D, TruncatedExp4WithCache};
let grid = Grid1D::new(-4.0, 4.0, 64).unwrap();
let me4c = TruncatedExp4WithCache::with_cached_coefficients(
|_| 1.0, |_| 0.0, |_| 0.0, 1.0, grid,
);
let u0 = GridFn1D::from_fn(grid, |x| (-x * x).exp());
let u1 = me4c.apply_chernoff(0.001, &u0).unwrap();
assert_eq!(u1.values.len(), 64);§Caller invariants
Same as TruncatedExp4thDiffusionChernoff. Additionally, a(x) MUST be
pure and deterministic — see HalfNodeCoeffCache doc.
See ADR-0034 Amendment 1.
Implementations§
Source§impl TruncatedExp4WithCache
impl TruncatedExp4WithCache
Sourcepub fn with_cached_coefficients(
a: fn(f64) -> f64,
a_prime: fn(f64) -> f64,
a_double_prime: fn(f64) -> f64,
a_norm_bound: f64,
grid: Grid1D<f64>,
) -> Self
pub fn with_cached_coefficients( a: fn(f64) -> f64, a_prime: fn(f64) -> f64, a_double_prime: fn(f64) -> f64, a_norm_bound: f64, grid: Grid1D<f64>, ) -> Self
Construct with pre-evaluated a(x) half-node coefficients.
The hot loop indexes the cache instead of calling the closure, enabling SIMD lane saturation in Wave B3.
Memory cost: 4N × 8 bytes ≈ 16 KB at N=512, negligible vs the 2.8 MB per-call baseline measured in iter-3 benchmarks.
§Panics
Does not panic. All grid operations are deterministic.
Trait Implementations§
Source§impl ChernoffFunction for TruncatedExp4WithCache
impl ChernoffFunction for TruncatedExp4WithCache
Source§fn apply_into(
&self,
tau: f64,
src: &GridFn1D<f64>,
dst: &mut GridFn1D<f64>,
_scratch: &mut ScratchPool<f64>,
) -> Result<(), SemiflowError>
fn apply_into( &self, tau: f64, src: &GridFn1D<f64>, dst: &mut GridFn1D<f64>, _scratch: &mut ScratchPool<f64>, ) -> Result<(), SemiflowError>
Allocation-free output override using pre-evaluated coefficient cache.
Uses the same precompute_g4_grids_cached stencil path (including SIMD
dispatch) as apply to guarantee bit-identical results. The only savings vs
the default bridge: output is written directly into dst instead of returning
a new GridFn1D allocation.
The four g-grid GridFn1D intermediates are still heap-allocated per call.
Scratch is accepted but unused (GridFn1D state cannot be stored in ScratchPool).
Source§fn apply_adjoint_into(
&self,
tau: F,
src: &Self::S,
dst: &mut Self::S,
scratch: &mut ScratchPool<F>,
) -> Result<(), SemiflowError>
fn apply_adjoint_into( &self, tau: F, src: &Self::S, dst: &mut Self::S, scratch: &mut ScratchPool<F>, ) -> Result<(), SemiflowError>
Source§fn plan_len(&self, tau: F, proto: &Self::S) -> Option<(usize, usize)>
fn plan_len(&self, tau: F, proto: &Self::S) -> Option<(usize, usize)>
(data, work) of a τ-keyed step plan for states shaped like proto
(ADR-0215), or None (default) when the engine has no plan. Read moreSource§fn apply_planned_into(
&self,
tau: F,
data: &[F],
work: &mut [F],
src: &Self::S,
dst: &mut Self::S,
scratch: &mut ScratchPool<F>,
) -> Result<(), SemiflowError>
fn apply_planned_into( &self, tau: F, data: &[F], work: &mut [F], src: &Self::S, dst: &mut Self::S, scratch: &mut ScratchPool<F>, ) -> Result<(), SemiflowError>
dst := S(τ) src with a plan data filled by THIS engine for τ, and a
work area of length plan_len(..).1. A plan that does not match — another
τ, sampling grid, length or engine state, or a truncated buffer — falls
back to apply_into. Default: apply_into. Read moreAuto Trait Implementations§
impl Freeze for TruncatedExp4WithCache
impl RefUnwindSafe for TruncatedExp4WithCache
impl Send for TruncatedExp4WithCache
impl Sync for TruncatedExp4WithCache
impl Unpin for TruncatedExp4WithCache
impl UnsafeUnpin for TruncatedExp4WithCache
impl UnwindSafe for TruncatedExp4WithCache
Blanket Implementations§
Source§impl<C, F> Adjointable<F, 1> for Cwhere
C: ChernoffFunction<F>,
F: SemiflowFloat,
impl<C, F> Adjointable<F, 1> for Cwhere
C: ChernoffFunction<F>,
F: SemiflowFloat,
Source§fn apply_adjoint_into(
&self,
tau: F,
a: F,
b: F,
c: F,
src: &MeasureState<F, 1>,
dst: &mut MeasureState<F, 1>,
) -> Result<(), SemiflowError>
fn apply_adjoint_into( &self, tau: F, a: F, b: F, c: F, src: &MeasureState<F, 1>, dst: &mut MeasureState<F, 1>, ) -> Result<(), SemiflowError>
Source§impl<C, F> ApplyChernoffExt<F> for C
impl<C, F> ApplyChernoffExt<F> for C
Source§fn apply_chernoff(
&self,
tau: F,
src: &Self::S,
) -> Result<Self::S, SemiflowError>
fn apply_chernoff( &self, tau: F, src: &Self::S, ) -> Result<Self::S, SemiflowError>
S(tau) src as a fresh state. Read more