refactor(aura-core): split Scalar into a tag-free Cell + ScalarKind
Motivation
----------
`Scalar` was a tagged enum (I64/F64/Bool/Ts), so every scalar value
physically carried its own kind tag. But the kind is already known from
the schema/port/column the value flows through (C7: the type is a
property of the column, not of the value — the hot path is already
columnar `Column<T>`, and `AnyColumn::get` *reconstructs* the tag from
the column on the way out). The per-value tag was therefore redundant
with the kind the surrounding context already holds.
That redundancy had three costs:
* It baked an implicit `match` (a branch) into every function that read
a Scalar payload — even where the caller statically knew the type.
The tag could never be exploited away.
* Size: a tagged enum is tag + payload = 16 bytes (f64/i64 alignment),
twice the 8 bytes the value needs. A `Column<Scalar>` would be double
the memory and half the cache utilisation.
* It is the shared root of several downstream papercuts we keep hitting
— the lossy f64 manifest field, the `unreachable!` panic on a
non-numeric param, the serde-tag question — all symptoms of "the type
is baked into the value".
Change
------
Introduce `Cell`: a type-erased 64-bit word (`struct Cell(u64)`) that is
not readable without external type context. It is constructed per base
type (`from_i64/from_f64/from_bool/from_ts`) and read only by naming the
type at the call site (`i64()/f64()/bool()/ts()`) — each a branch-free
bit-cast. The hot path resolves the kind once at the boundary (from the
schema) and then reads natively, with no per-value branch. `Cell` knows
nothing of `Scalar` or `ScalarKind`; the dependency is strictly one-way,
and it lives in its own `cell.rs` (more is planned on top of it).
`Scalar` becomes `struct { kind: ScalarKind, cell: Cell }` — the
self-describing form for the dynamic boundaries (builder binding,
serialization, rendering), built on top of `Cell`. Its `as_*` accessors
now `debug_assert` the kind and return the native value (free in
release); calling the wrong accessor is a caller bug, not a checked
`Option`. The variant constructors `Scalar::I64(..)` become associated
fns `Scalar::i64(..)`.
`PartialEq` is hand-written (not derived) to preserve the former enum's
value semantics: kinds must match, then native payloads compare, so f64
keeps IEEE-754 behaviour (`NaN != NaN`, `+0.0 == -0.0`) and a kind
mismatch is never equal even when the raw words coincide. A fixture
(`scalar_eq_is_value_not_bitwise`) pins exactly the cases where bit- and
value-equality diverge, so it can't silently regress. `Cell`'s own
`Eq`/`Hash` stay bitwise — correct for a raw word.
The change is behaviour-preserving: Scalar's observable behaviour is
identical to the pre-Cell enum (the value-equality fixture proves it);
only the internal representation changed. The ~440 call sites across the
workspace are a mechanical constructor rename plus ~12 destructuring
sites (match-arms / `let`-patterns) rewritten to `kind()` + `as_*`.
Verified: cargo build --workspace --all-targets, cargo clippy --workspace
--all-targets -- -D warnings, cargo test --workspace — all green.
This commit is contained in:
@@ -23,7 +23,7 @@ pub struct Add {
|
||||
impl Add {
|
||||
/// Build an `Add` node.
|
||||
pub fn new() -> Self {
|
||||
Self { out: [Scalar::F64(0.0)] }
|
||||
Self { out: [Scalar::f64(0.0)] }
|
||||
}
|
||||
|
||||
/// The param-generic recipe for a blueprint primitive: paramless, builds through
|
||||
@@ -61,7 +61,7 @@ impl Node for Add {
|
||||
if a.is_empty() || b.is_empty() {
|
||||
return None;
|
||||
}
|
||||
self.out[0] = Scalar::F64(a[0] + b[0]);
|
||||
self.out[0] = Scalar::f64(a[0] + b[0]);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -84,12 +84,12 @@ mod tests {
|
||||
];
|
||||
|
||||
// only input 0 present -> None
|
||||
inputs[0].push(Scalar::F64(10.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(10.0)).unwrap();
|
||||
assert_eq!(add.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
||||
|
||||
// both present -> a + b
|
||||
inputs[1].push(Scalar::F64(4.0)).unwrap();
|
||||
assert_eq!(add.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(14.0)].as_slice()));
|
||||
inputs[1].push(Scalar::f64(4.0)).unwrap();
|
||||
assert_eq!(add.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(14.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Ema {
|
||||
warmup_sum: 0.0,
|
||||
count: 0,
|
||||
ema: 0.0,
|
||||
out: [Scalar::F64(0.0)],
|
||||
out: [Scalar::f64(0.0)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Ema {
|
||||
output: vec![FieldSpec { name: "value".into(), kind: ScalarKind::F64 }],
|
||||
params: vec![ParamSpec { name: "length".into(), kind: ScalarKind::I64 }],
|
||||
},
|
||||
|p| Box::new(Ema::new(p[0].as_i64().expect("length slot is I64") as usize)),
|
||||
|p| Box::new(Ema::new(p[0].as_i64() as usize)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ impl Node for Ema {
|
||||
// O(1) recurrence: one sub, one mul, one add.
|
||||
self.ema += self.alpha * (x - self.ema);
|
||||
}
|
||||
self.out[0] = Scalar::F64(self.ema);
|
||||
self.out[0] = Scalar::f64(self.ema);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ mod tests {
|
||||
let expect = [None, None, Some(4.0), Some(7.0)];
|
||||
|
||||
for (v, want) in feed.iter().zip(expect) {
|
||||
inputs[0].push(Scalar::F64(*v)).unwrap();
|
||||
inputs[0].push(Scalar::f64(*v)).unwrap();
|
||||
let got = ema.eval(Ctx::new(&inputs, Timestamp(0)));
|
||||
match want {
|
||||
None => assert_eq!(got, None),
|
||||
Some(m) => assert_eq!(got, Some([Scalar::F64(m)].as_slice())),
|
||||
Some(m) => assert_eq!(got, Some([Scalar::f64(m)].as_slice())),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,11 +140,11 @@ mod tests {
|
||||
let mut ema = Ema::new(1);
|
||||
let mut inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
||||
|
||||
inputs[0].push(Scalar::F64(7.0)).unwrap();
|
||||
assert_eq!(ema.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(7.0)].as_slice()));
|
||||
inputs[0].push(Scalar::f64(7.0)).unwrap();
|
||||
assert_eq!(ema.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(7.0)].as_slice()));
|
||||
|
||||
inputs[0].push(Scalar::F64(9.0)).unwrap();
|
||||
assert_eq!(ema.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(9.0)].as_slice()));
|
||||
inputs[0].push(Scalar::f64(9.0)).unwrap();
|
||||
assert_eq!(ema.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(9.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -19,7 +19,7 @@ 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: [Scalar::F64(0.0)] }
|
||||
Self { scale, out: [Scalar::f64(0.0)] }
|
||||
}
|
||||
|
||||
/// The param-generic recipe for a blueprint primitive: declares `scale` and builds
|
||||
@@ -33,7 +33,7 @@ impl Exposure {
|
||||
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].as_f64().expect("scale slot is F64"))),
|
||||
|p| Box::new(Exposure::new(p[0].as_f64())),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ impl Node for Exposure {
|
||||
if w.is_empty() {
|
||||
return None; // not yet warmed up (C8 filter)
|
||||
}
|
||||
self.out[0] = Scalar::F64((w[0] / self.scale).clamp(-1.0, 1.0));
|
||||
self.out[0] = Scalar::f64((w[0] / self.scale).clamp(-1.0, 1.0));
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ mod tests {
|
||||
(-1.0, -1.0), // saturates low
|
||||
];
|
||||
for (sig, want) in cases {
|
||||
inputs[0].push(Scalar::F64(sig)).unwrap();
|
||||
inputs[0].push(Scalar::f64(sig)).unwrap();
|
||||
assert_eq!(
|
||||
e.eval(Ctx::new(&inputs, Timestamp(0))),
|
||||
Some([Scalar::F64(want)].as_slice())
|
||||
Some([Scalar::f64(want)].as_slice())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ impl LinComb {
|
||||
/// Panics if `weights` is empty.
|
||||
pub fn new(weights: Vec<f64>) -> Self {
|
||||
assert!(!weights.is_empty(), "LinComb needs at least one weight");
|
||||
Self { weights, out: [Scalar::F64(0.0)] }
|
||||
Self { weights, out: [Scalar::f64(0.0)] }
|
||||
}
|
||||
|
||||
/// The param-generic recipe for a blueprint primitive. The `arity` is topology
|
||||
@@ -54,7 +54,7 @@ impl LinComb {
|
||||
"LinComb",
|
||||
NodeSchema { inputs, output: vec![FieldSpec { name: "value".into(), kind: ScalarKind::F64 }], params },
|
||||
|p| Box::new(LinComb::new(
|
||||
p.iter().map(|s| s.as_f64().expect("weight slot is F64")).collect(),
|
||||
p.iter().map(|s| s.as_f64()).collect(),
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl Node for LinComb {
|
||||
}
|
||||
acc += w * w_in[0];
|
||||
}
|
||||
self.out[0] = Scalar::F64(acc);
|
||||
self.out[0] = Scalar::f64(acc);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -97,12 +97,12 @@ mod tests {
|
||||
];
|
||||
|
||||
// only input 0 present -> None
|
||||
inputs[0].push(Scalar::F64(10.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(10.0)).unwrap();
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
||||
|
||||
// both present -> 0.5*10 + 2.0*3 = 11.0
|
||||
inputs[1].push(Scalar::F64(3.0)).unwrap();
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(11.0)].as_slice()));
|
||||
inputs[1].push(Scalar::f64(3.0)).unwrap();
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(11.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -112,10 +112,10 @@ mod tests {
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
];
|
||||
inputs[0].push(Scalar::F64(7.0)).unwrap();
|
||||
inputs[1].push(Scalar::F64(5.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(7.0)).unwrap();
|
||||
inputs[1].push(Scalar::f64(5.0)).unwrap();
|
||||
// unit weights reproduce Add: 7 + 5
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(12.0)].as_slice()));
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(12.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -126,14 +126,14 @@ mod tests {
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
];
|
||||
inputs[0].push(Scalar::F64(1.0)).unwrap();
|
||||
inputs[1].push(Scalar::F64(2.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(1.0)).unwrap();
|
||||
inputs[1].push(Scalar::f64(2.0)).unwrap();
|
||||
// third leg still cold -> None (withheld until every leg is present)
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
||||
|
||||
inputs[2].push(Scalar::F64(3.0)).unwrap();
|
||||
inputs[2].push(Scalar::f64(3.0)).unwrap();
|
||||
// all warm -> 1 + 2 + 3
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(6.0)].as_slice()));
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(6.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -153,33 +153,33 @@ mod tests {
|
||||
fn chained_bind_reconstructs_positional_vector() {
|
||||
// bind BOTH weights, in reverse slot order, to DISTINCT values; build empty.
|
||||
let builder = LinComb::builder(2)
|
||||
.bind("weights[1]", Scalar::F64(2.0))
|
||||
.bind("weights[0]", Scalar::F64(0.5));
|
||||
.bind("weights[1]", Scalar::f64(2.0))
|
||||
.bind("weights[0]", Scalar::f64(0.5));
|
||||
assert!(builder.params().is_empty());
|
||||
let mut lc = builder.build(&[]);
|
||||
let mut inputs = vec![
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
];
|
||||
inputs[0].push(Scalar::F64(10.0)).unwrap();
|
||||
inputs[1].push(Scalar::F64(3.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(10.0)).unwrap();
|
||||
inputs[1].push(Scalar::f64(3.0)).unwrap();
|
||||
// 0.5*10 + 2.0*3 = 11.0 — holds ONLY if each weight landed in its right slot
|
||||
// (a swap would give 2.0*10 + 0.5*3 = 21.5)
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(11.0)].as_slice()));
|
||||
assert_eq!(lc.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(11.0)].as_slice()));
|
||||
|
||||
// partial: bind weights[0], leave weights[1] open → inject it at build
|
||||
let partial = LinComb::builder(2).bind("weights[0]", Scalar::F64(0.5));
|
||||
let partial = LinComb::builder(2).bind("weights[0]", Scalar::f64(0.5));
|
||||
assert_eq!(
|
||||
partial.params().iter().map(|p| p.name.as_str()).collect::<Vec<_>>(),
|
||||
["weights[1]"],
|
||||
);
|
||||
let mut lc2 = partial.build(&[Scalar::F64(2.0)]); // weights[1] = 2.0 injected
|
||||
let mut lc2 = partial.build(&[Scalar::f64(2.0)]); // weights[1] = 2.0 injected
|
||||
let mut inputs2 = vec![
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
AnyColumn::with_capacity(ScalarKind::F64, 1),
|
||||
];
|
||||
inputs2[0].push(Scalar::F64(10.0)).unwrap();
|
||||
inputs2[1].push(Scalar::F64(3.0)).unwrap();
|
||||
assert_eq!(lc2.eval(Ctx::new(&inputs2, Timestamp(0))), Some([Scalar::F64(11.0)].as_slice()));
|
||||
inputs2[0].push(Scalar::f64(10.0)).unwrap();
|
||||
inputs2[1].push(Scalar::f64(3.0)).unwrap();
|
||||
assert_eq!(lc2.eval(Ctx::new(&inputs2, Timestamp(0))), Some([Scalar::f64(11.0)].as_slice()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ impl Node for Recorder {
|
||||
for (i, &kind) in self.kinds.iter().enumerate() {
|
||||
// newest of each column by kind; `?` returns None (warm-up) if cold.
|
||||
let scalar = match kind {
|
||||
ScalarKind::F64 => Scalar::F64(ctx.f64_in(i).get(0)?),
|
||||
ScalarKind::I64 => Scalar::I64(ctx.i64_in(i).get(0)?),
|
||||
ScalarKind::Bool => Scalar::Bool(ctx.bool_in(i).get(0)?),
|
||||
ScalarKind::Timestamp => Scalar::Ts(ctx.ts_in(i).get(0)?),
|
||||
ScalarKind::F64 => Scalar::f64(ctx.f64_in(i).get(0)?),
|
||||
ScalarKind::I64 => Scalar::i64(ctx.i64_in(i).get(0)?),
|
||||
ScalarKind::Bool => Scalar::bool(ctx.bool_in(i).get(0)?),
|
||||
ScalarKind::Timestamp => Scalar::ts(ctx.ts_in(i).get(0)?),
|
||||
};
|
||||
row.push(scalar);
|
||||
}
|
||||
@@ -107,16 +107,16 @@ mod tests {
|
||||
|
||||
// warm: returns None (pure consumer) but records (now, [F64(newest)]).
|
||||
for (t, v) in [(2_i64, 10.0_f64), (3, 20.0), (4, 30.0)] {
|
||||
inputs[0].push(Scalar::F64(v)).unwrap();
|
||||
inputs[0].push(Scalar::f64(v)).unwrap();
|
||||
assert_eq!(rec.eval(Ctx::new(&inputs, Timestamp(t))), None);
|
||||
}
|
||||
let rows: Vec<(Timestamp, Vec<Scalar>)> = rx.try_iter().collect();
|
||||
assert_eq!(
|
||||
rows,
|
||||
vec![
|
||||
(Timestamp(2), vec![Scalar::F64(10.0)]),
|
||||
(Timestamp(3), vec![Scalar::F64(20.0)]),
|
||||
(Timestamp(4), vec![Scalar::F64(30.0)]),
|
||||
(Timestamp(2), vec![Scalar::f64(10.0)]),
|
||||
(Timestamp(3), vec![Scalar::f64(20.0)]),
|
||||
(Timestamp(4), vec![Scalar::f64(30.0)]),
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -131,15 +131,15 @@ mod tests {
|
||||
];
|
||||
|
||||
// only column 0 present -> None, nothing recorded.
|
||||
inputs[0].push(Scalar::F64(1.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(1.0)).unwrap();
|
||||
assert_eq!(rec.eval(Ctx::new(&inputs, Timestamp(1))), None);
|
||||
assert!(rx.try_recv().is_err());
|
||||
|
||||
// both present -> records the full row (still returns None).
|
||||
inputs[1].push(Scalar::F64(2.0)).unwrap();
|
||||
inputs[1].push(Scalar::f64(2.0)).unwrap();
|
||||
assert_eq!(rec.eval(Ctx::new(&inputs, Timestamp(2))), None);
|
||||
let rows: Vec<(Timestamp, Vec<Scalar>)> = rx.try_iter().collect();
|
||||
assert_eq!(rows, vec![(Timestamp(2), vec![Scalar::F64(1.0), Scalar::F64(2.0)])]);
|
||||
assert_eq!(rows, vec![(Timestamp(2), vec![Scalar::f64(1.0), Scalar::f64(2.0)])]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -51,7 +51,7 @@ impl SimBroker {
|
||||
prev_price: None,
|
||||
prev_exposure: 0.0,
|
||||
cum: 0.0,
|
||||
out: [Scalar::F64(0.0)],
|
||||
out: [Scalar::f64(0.0)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ impl Node for SimBroker {
|
||||
}
|
||||
self.prev_price = Some(price);
|
||||
self.prev_exposure = expo; // update AFTER taking PnL — no look-ahead (C2)
|
||||
self.out[0] = Scalar::F64(self.cum);
|
||||
self.out[0] = Scalar::f64(self.cum);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -117,11 +117,11 @@ mod tests {
|
||||
// stays empty) and a price into slot 1, then eval and return the equity.
|
||||
fn step(b: &mut SimBroker, inputs: &mut [AnyColumn], expo: Option<f64>, price: f64) -> f64 {
|
||||
if let Some(e) = expo {
|
||||
inputs[0].push(Scalar::F64(e)).unwrap();
|
||||
inputs[0].push(Scalar::f64(e)).unwrap();
|
||||
}
|
||||
inputs[1].push(Scalar::F64(price)).unwrap();
|
||||
inputs[1].push(Scalar::f64(price)).unwrap();
|
||||
match b.eval(Ctx::new(inputs, Timestamp(0))) {
|
||||
Some([Scalar::F64(v)]) => *v,
|
||||
Some([s]) => s.as_f64(),
|
||||
other => panic!("expected Some([F64]), got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -18,7 +18,7 @@ impl Sma {
|
||||
/// Build an SMA of window `length` (must be >= 1).
|
||||
pub fn new(length: usize) -> Self {
|
||||
assert!(length >= 1, "SMA length must be >= 1");
|
||||
Self { length, out: [Scalar::F64(0.0)] }
|
||||
Self { length, out: [Scalar::f64(0.0)] }
|
||||
}
|
||||
|
||||
/// The param-generic recipe for a blueprint primitive: declares `length` and builds
|
||||
@@ -32,7 +32,7 @@ impl Sma {
|
||||
output: vec![FieldSpec { name: "value".into(), kind: ScalarKind::F64 }],
|
||||
params: vec![ParamSpec { name: "length".into(), kind: ScalarKind::I64 }],
|
||||
},
|
||||
|p| Box::new(Sma::new(p[0].as_i64().expect("length slot is I64") as usize)),
|
||||
|p| Box::new(Sma::new(p[0].as_i64() as usize)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl Node for Sma {
|
||||
for k in 0..self.length {
|
||||
sum += w[k]; // index 0 = newest (financial indexing)
|
||||
}
|
||||
self.out[0] = Scalar::F64(sum / self.length as f64);
|
||||
self.out[0] = Scalar::f64(sum / self.length as f64);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -79,11 +79,11 @@ mod tests {
|
||||
let expect = [None, None, Some(2.0), Some(3.0), Some(4.0)];
|
||||
|
||||
for (v, want) in feed.iter().zip(expect) {
|
||||
inputs[0].push(Scalar::F64(*v)).unwrap();
|
||||
inputs[0].push(Scalar::f64(*v)).unwrap();
|
||||
let got = sma.eval(Ctx::new(&inputs, Timestamp(0)));
|
||||
match want {
|
||||
None => assert_eq!(got, None),
|
||||
Some(m) => assert_eq!(got, Some([Scalar::F64(m)].as_slice())),
|
||||
Some(m) => assert_eq!(got, Some([Scalar::f64(m)].as_slice())),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,11 +93,11 @@ mod tests {
|
||||
let mut sma = Sma::new(1);
|
||||
let mut inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
||||
|
||||
inputs[0].push(Scalar::F64(7.0)).unwrap();
|
||||
assert_eq!(sma.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(7.0)].as_slice()));
|
||||
inputs[0].push(Scalar::f64(7.0)).unwrap();
|
||||
assert_eq!(sma.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(7.0)].as_slice()));
|
||||
|
||||
inputs[0].push(Scalar::F64(9.0)).unwrap();
|
||||
assert_eq!(sma.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(9.0)].as_slice()));
|
||||
inputs[0].push(Scalar::f64(9.0)).unwrap();
|
||||
assert_eq!(sma.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(9.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -160,7 +160,7 @@ mod tests {
|
||||
fn bind_removes_slot_from_param_space() {
|
||||
// a bound param-bearing node reports an empty param surface — parity with the
|
||||
// SimBroker precedent (nodes_declare_expected_params, this file)
|
||||
let sma2 = Sma::builder().named("bias").bind("length", Scalar::I64(2));
|
||||
let sma2 = Sma::builder().named("bias").bind("length", Scalar::i64(2));
|
||||
assert!(sma2.schema().params.is_empty());
|
||||
// contrast: the length-generic SMA keeps `length` open
|
||||
assert_eq!(Sma::builder().named("bias").params().len(), 1);
|
||||
@@ -169,7 +169,7 @@ mod tests {
|
||||
#[test]
|
||||
fn bound_node_builds_with_injected_value() {
|
||||
// built with an empty open slice, the bound builder yields SMA(2)
|
||||
let node = Sma::builder().bind("length", Scalar::I64(2)).build(&[]);
|
||||
let node = Sma::builder().bind("length", Scalar::i64(2)).build(&[]);
|
||||
assert_eq!(node.label(), "SMA(2)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct Sub {
|
||||
impl Sub {
|
||||
/// Build a `Sub` node.
|
||||
pub fn new() -> Self {
|
||||
Self { out: [Scalar::F64(0.0)] }
|
||||
Self { out: [Scalar::f64(0.0)] }
|
||||
}
|
||||
|
||||
/// The param-generic recipe for a blueprint primitive: paramless, builds through
|
||||
@@ -52,7 +52,7 @@ impl Node for Sub {
|
||||
if a.is_empty() || b.is_empty() {
|
||||
return None;
|
||||
}
|
||||
self.out[0] = Scalar::F64(a[0] - b[0]);
|
||||
self.out[0] = Scalar::f64(a[0] - b[0]);
|
||||
Some(&self.out)
|
||||
}
|
||||
|
||||
@@ -75,12 +75,12 @@ mod tests {
|
||||
];
|
||||
|
||||
// only input 0 present -> None
|
||||
inputs[0].push(Scalar::F64(10.0)).unwrap();
|
||||
inputs[0].push(Scalar::f64(10.0)).unwrap();
|
||||
assert_eq!(sub.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
||||
|
||||
// both present -> a - b
|
||||
inputs[1].push(Scalar::F64(4.0)).unwrap();
|
||||
assert_eq!(sub.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::F64(6.0)].as_slice()));
|
||||
inputs[1].push(Scalar::f64(4.0)).unwrap();
|
||||
assert_eq!(sub.eval(Ctx::new(&inputs, Timestamp(0))), Some([Scalar::f64(6.0)].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user