|
| 1 | +// Problem: The user might want to pass either [f64; 4], (f64, f64, f64, f64), or S to the |
| 2 | +// function. All of these are valid (modulo we have to force the user to set the right repr). |
| 3 | +// Our current design doesn't allow users to specify those, so we will want at least one iteration. |
| 4 | +// However, for the sake of similarity to the current autodiff (where we'd also want a change), |
| 5 | +// leave it as is. |
| 6 | + |
| 7 | +struct _S { |
| 8 | + x1: f64, |
| 9 | + x2: f64, |
| 10 | + x3: f64, |
| 11 | + x4: f64, |
| 12 | +} |
| 13 | + |
| 14 | +#[batch(bsquare4, 4, Const, Leaf(8))] |
| 15 | +#[batch(vsquare4, 4, Const, Vector)] |
| 16 | +fn square(multiplier: f64, x: f64) -> f64 { |
| 17 | + x * x * multiplier |
| 18 | +} |
| 19 | + |
| 20 | +fn main() { |
| 21 | + let vals = [23.1, 10.0, 100.0, 3.14]; |
| 22 | + let expected = [square(3.14, vals[0]), square(3.14, vals[1]), square(3.14, vals[2]), square(3.14, vals[3])]; |
| 23 | + let result1 = bsquare4(3.14, vals[0], vals[1], vals[2], vals[3]); |
| 24 | + let result2 = vsquare4(3.14, vals); |
| 25 | + assert_eq!(result.x1, expected[0]); |
| 26 | + assert_eq!(result.x2, expected[1]); |
| 27 | + assert_eq!(result.x3, expected[2]); |
| 28 | + assert_eq!(result.x4, expected[3]); |
| 29 | + assert_eq!(result2.x1, expected[0]); |
| 30 | + assert_eq!(result2.x2, expected[1]); |
| 31 | + assert_eq!(result2.x3, expected[2]); |
| 32 | + assert_eq!(result2.x4, expected[3]); |
| 33 | +} |
0 commit comments