use super::*;
#[test]
fn velocity_round_trip_recovers_both_endpoints() {
let level = CosineSchedule::default().level(0.4).unwrap();
let x0 = tensor([2, 2], vec![0.5, -1.0, 2.25, 3.0]);
let eps = tensor([2, 2], vec![-0.25, 1.5, 0.75, -2.0]);
let x_t = level.diffuse(&x0, &eps).unwrap();
let v = level.velocity_target(&x0, &eps).unwrap();
let x0_hat = level.signal_from_velocity(&x_t, &v).unwrap();
let eps_hat = level.noise_from_velocity(&x_t, &v).unwrap();
for (a, b) in x0.data().iter().zip(x0_hat.data()) {
assert!((a - b).abs() < 1e-5, "x0 {a} vs {b}");
}
for (a, b) in eps.data().iter().zip(eps_hat.data()) {
assert!((a - b).abs() < 1e-5, "eps {a} vs {b}");
}
}
#[test]
fn operations_reject_shape_mismatch() {
let level = NoiseLevel::pure_signal();
let a = tensor([2, 2], vec![0.0, 1.0, 2.0, 3.0]);
let b = tensor([1, 2], vec![0.0, 1.0]);
assert!(matches!(
level.diffuse(&a, &b),
Err(Error::Shape { expected, actual }) if expected == vec![2, 2] && actual == vec![1, 2]
));
assert!(matches!(
level.velocity_target(&a, &b),
Err(Error::Shape { .. })
));
assert!(matches!(
level.signal_from_velocity(&a, &b),
Err(Error::Shape { .. })
));
assert!(matches!(
level.noise_from_velocity(&a, &b),
Err(Error::Shape { .. })
));
}