43716be10e
Cell becomes the carrier of the construction path; Scalar narrows to the author/render boundaries. The validated/enumerated param point carries no redundant kind (it lives once, in the declared param-space); at the author edge the kind is a checksum — two independent sources, the typed value vs. the slot — so the self-describing Scalar stays there. The name->slot binding is dynamic (C23), so the check is necessarily a runtime one and the value must self-describe for it. Base/frontend split (the AnyColumn push/push_cell pattern one level up): compile_with_cells / bootstrap_with_cells are the kind-check-free base; compile_with_params / bootstrap_with_params are the frontend that adds only the per-value kind checksum, strips to cells (new Scalar::cell(), the partner of Scalar::from_cell), and delegates. lower_items loses its per-primitive kind-check; PrimitiveBuilder::build and the std node builders (sma/ema/exposure/lincomb) read cells. Boundary: construction -> Cell (PrimitiveBuilder::build, lower_items, GridSpace.axes/points, SweepPoint.params, the sweep closure). Author edges stay Scalar (GridSpace::new, bind, compile_with_params/bootstrap_with_params). walkforward chosen_params stays a self-describing Scalar report record (Option A — WalkForwardResult carries no space); the cell winner is reconstructed once at the WindowRun site via from_cell. injective-check moved ahead of the arity-check in the frontend to preserve the pre-split error order (DuplicateParamPath before ParamArity). The lossy i64->f64 param projection (scalar_as_f64 / scalar_as_param_f64) is deliberately untouched — a separate follow-up. Behaviour-preserving (C1): build --all-targets / test / clippy -D warnings / doc all clean across the workspace.
98 lines
3.3 KiB
Rust
98 lines
3.3 KiB
Rust
//! `Exposure` — shapes a raw signal score into a bounded exposure (intent).
|
|
//! The decision/sizing node of C10's chain `signals -> decision/sizing node ->
|
|
//! exposure stream`: one f64 input, one f64 output `clamp(signal / scale, -1, +1)`.
|
|
//! `scale` sets which signal magnitude maps to full exposure (sizing lives here).
|
|
|
|
use aura_core::{
|
|
Cell, Ctx, FieldSpec, Firing, Node, NodeSchema, ParamSpec, PortSpec, PrimitiveBuilder,
|
|
ScalarKind,
|
|
};
|
|
|
|
/// Bounded exposure from a raw signal score: `clamp(signal / scale, -1.0, +1.0)`.
|
|
/// Emits `None` until its input is present (warm-up filter, C8).
|
|
pub struct Exposure {
|
|
scale: f64,
|
|
out: [Cell; 1],
|
|
}
|
|
|
|
impl Exposure {
|
|
/// Build an exposure node with saturation magnitude `scale` (must be > 0).
|
|
pub fn new(scale: f64) -> Self {
|
|
assert!(scale > 0.0, "Exposure scale must be > 0");
|
|
Self { scale, out: [Cell::from_f64(0.0)] }
|
|
}
|
|
|
|
/// The param-generic recipe for a blueprint primitive: declares `scale` and builds
|
|
/// through `Exposure::new` (the single sizing/validation gate; the slice is
|
|
/// kind-checked before `build` runs, so the typed read is total).
|
|
pub fn builder() -> PrimitiveBuilder {
|
|
PrimitiveBuilder::new(
|
|
"Exposure",
|
|
NodeSchema {
|
|
inputs: vec![PortSpec { kind: ScalarKind::F64, firing: Firing::Any, name: "signal".into() }],
|
|
output: vec![FieldSpec { name: "exposure".into(), kind: ScalarKind::F64 }],
|
|
params: vec![ParamSpec { name: "scale".into(), kind: ScalarKind::F64 }],
|
|
},
|
|
|p| Box::new(Exposure::new(p[0].f64())),
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Node for Exposure {
|
|
fn lookbacks(&self) -> Vec<usize> {
|
|
vec![1]
|
|
}
|
|
|
|
fn eval(&mut self, ctx: Ctx<'_>) -> Option<&[Cell]> {
|
|
let w = ctx.f64_in(0);
|
|
if w.is_empty() {
|
|
return None; // not yet warmed up (C8 filter)
|
|
}
|
|
self.out[0] = Cell::from_f64((w[0] / self.scale).clamp(-1.0, 1.0));
|
|
Some(&self.out)
|
|
}
|
|
|
|
fn label(&self) -> String {
|
|
format!("Exposure({})", self.scale)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use aura_core::{AnyColumn, Scalar, Timestamp};
|
|
|
|
#[test]
|
|
fn exposure_clamps_to_unit_band() {
|
|
let mut e = Exposure::new(0.5);
|
|
let mut inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
|
// (raw signal, expected clamped exposure) for scale 0.5
|
|
let cases = [
|
|
(0.1_f64, 0.2_f64), // within band
|
|
(0.5, 1.0), // at the high edge
|
|
(1.0, 1.0), // saturates high
|
|
(-0.1, -0.2), // within band, negative
|
|
(-1.0, -1.0), // saturates low
|
|
];
|
|
for (sig, want) in cases {
|
|
inputs[0].push(Scalar::f64(sig)).unwrap();
|
|
assert_eq!(
|
|
e.eval(Ctx::new(&inputs, Timestamp(0))),
|
|
Some([Cell::from_f64(want)].as_slice())
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn exposure_is_none_until_input_present() {
|
|
let mut e = Exposure::new(0.5);
|
|
let inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
|
assert_eq!(e.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
|
}
|
|
|
|
#[test]
|
|
fn input_slot_is_named_signal() {
|
|
assert_eq!(Exposure::builder().schema().inputs[0].name, "signal");
|
|
}
|
|
}
|