cms: keep NaN propagation in multilinear interpolation

A NaN input gives a NaN fraction, which the active-dimension check dropped, returning a
finite node value. Keep any nonzero fraction, NaN included (CodeRabbit review).
This commit is contained in:
Dylan M. Taylor committed 2026-10-22 22:22:39 -04:00
1 parent c900c69553
commit bc8fe0eb53
1 file changed
+10 -1
+10 -1
View File
@@ -233,7 +233,8 @@ impl Clut {
for (d, &v) in input.iter().enumerate().take(self.inputs) {
let (b, rr, ss) = self.locate(d, v);
base += b;
if ss > 0 && rr > 0.0 {
// `!= 0.0` keeps a NaN fraction, so a NaN input still gives a NaN result.
if ss > 0 && rr != 0.0 {
r[n] = rr;
s[n] = ss;
n += 1;
@@ -316,6 +317,14 @@ mod tests {
assert!((o[0] - 0.75).abs() < 1e-6);
}
#[test]
fn a_nan_input_still_gives_nan() {
let c = Clut::sample(vec![2; 5], 1, |p, o| o[0] = p.iter().sum()).unwrap();
let mut o = [0.0];
c.eval_multilinear(&[0.5, f32::NAN, 0.5, 0.5, 0.5], &mut o).unwrap();
assert!(o[0].is_nan(), "{o:?}");
}
#[test]
fn singleton_dimensions_do_not_multiply_corners() {
// Fifteen inputs, all but two on a single grid point: the result interpolates only those