From db17934fcf3ac6535aee9757720326802d2b7b57 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Sat, 26 Oct 2024 21:33:26 -0400 Subject: [PATCH] move tests to use std::autodiff::autodiff (#30) --- integration/tests/examples/array.rs | 1 + integration/tests/examples/boxed.rs | 1 + integration/tests/examples/enum1.rs | 1 + integration/tests/examples/foo.rs | 1 + integration/tests/examples/hessian_sin.rs | 1 + integration/tests/examples/mod.rs | 2 +- samples/tests/forward/mod.rs | 3 +++ samples/tests/neohookean/mod.rs | 1 + samples/tests/reverse/mod.rs | 7 +++++++ samples/tests/second/mod.rs | 2 ++ samples/tests/traits/mod.rs | 1 + ui/tests/ui/wrong_activity1.rs | 1 + ui/tests/ui/wrong_num.rs | 1 + 13 files changed, 22 insertions(+), 1 deletion(-) diff --git a/integration/tests/examples/array.rs b/integration/tests/examples/array.rs index 8cbfb73..f0bfd25 100644 --- a/integration/tests/examples/array.rs +++ b/integration/tests/examples/array.rs @@ -1,5 +1,6 @@ samples::test! { reverse_duplicated_active; + use std::autodiff::autodiff; #[autodiff(d_array, Reverse, Duplicated, Active)] fn array(arr: &[[[f32; 2]; 2]; 2]) -> f32 { arr[0][0][0] * arr[1][1][1] diff --git a/integration/tests/examples/boxed.rs b/integration/tests/examples/boxed.rs index 03d0866..876d193 100644 --- a/integration/tests/examples/boxed.rs +++ b/integration/tests/examples/boxed.rs @@ -1,5 +1,6 @@ samples::test! { duplicated_active; + use std::autodiff::autodiff; #[autodiff(cos_box, Reverse, Duplicated, Active)] fn sin(x: &Box) -> f32 { f32::sin(**x) diff --git a/integration/tests/examples/enum1.rs b/integration/tests/examples/enum1.rs index b5e5161..9e25e74 100644 --- a/integration/tests/examples/enum1.rs +++ b/integration/tests/examples/enum1.rs @@ -1,6 +1,7 @@ #[cfg(broken)] samples::test! { f32_i32; + use std::autodiff::autodiff; enum Foo { A(f32), B(i32), diff --git a/integration/tests/examples/foo.rs b/integration/tests/examples/foo.rs index 02e2304..9dccf68 100644 --- a/integration/tests/examples/foo.rs +++ b/integration/tests/examples/foo.rs @@ -1,5 +1,6 @@ samples::test! { foo; + use std::autodiff::autodiff; #[autodiff(df, Forward, Dual, Dual)] fn f(x: &[f32; 2]) -> f32 { x[0] * x[0] + x[1] * x[0] } diff --git a/integration/tests/examples/hessian_sin.rs b/integration/tests/examples/hessian_sin.rs index 95ab9f9..4f8dd45 100644 --- a/integration/tests/examples/hessian_sin.rs +++ b/integration/tests/examples/hessian_sin.rs @@ -1,5 +1,6 @@ samples::test! { vec; + use std::autodiff::autodiff; #[autodiff(jac, ReverseFirst, Duplicated, Duplicated)] fn sin(x: &Vec, y: &mut f32) { *y = x.into_iter().map(|x| f32::sin(*x)).sum() diff --git a/integration/tests/examples/mod.rs b/integration/tests/examples/mod.rs index f1f2d8c..6220d97 100644 --- a/integration/tests/examples/mod.rs +++ b/integration/tests/examples/mod.rs @@ -2,4 +2,4 @@ mod array; mod boxed; mod enum1; mod foo; -mod hessian_sin; +//mod hessian_sin; diff --git a/samples/tests/forward/mod.rs b/samples/tests/forward/mod.rs index 4e02414..b5b98cd 100644 --- a/samples/tests/forward/mod.rs +++ b/samples/tests/forward/mod.rs @@ -1,6 +1,7 @@ samples::test! { empty_return; // ANCHOR: empty_return + use std::autodiff::autodiff; #[autodiff(df, Forward, Dual, Dual)] fn f(x: &[f32; 2], y: &mut f32) { *y = x[0] * x[0] + x[1] * x[0]; @@ -21,6 +22,7 @@ samples::test! { samples::test! { dual_return; // ANCHOR: dual_return + use std::autodiff::autodiff; #[autodiff(df, Forward, Dual, Dual)] fn f(x: &[f32; 2]) -> f32 { x[0] * x[0] + x[1] * x[0] } @@ -37,6 +39,7 @@ samples::test! { samples::test! { dual_only_return; // ANCHOR: dual_only_return + use std::autodiff::autodiff; #[autodiff(df, Forward, Dual, Dual)] #[autodiff(df2, Forward, Dual, DualOnly)] fn f(x: &[f32; 2]) -> f32 { x[0] * x[0] + x[1] * x[0] } diff --git a/samples/tests/neohookean/mod.rs b/samples/tests/neohookean/mod.rs index 8898ddf..cf43d3a 100644 --- a/samples/tests/neohookean/mod.rs +++ b/samples/tests/neohookean/mod.rs @@ -1,4 +1,5 @@ #![allow(non_snake_case)] +use std::autodiff::autodiff; use std::ops::{Add, Mul, Sub}; diff --git a/samples/tests/reverse/mod.rs b/samples/tests/reverse/mod.rs index 175d075..cf582ca 100644 --- a/samples/tests/reverse/mod.rs +++ b/samples/tests/reverse/mod.rs @@ -1,6 +1,7 @@ samples::test! { square; // ANCHOR: square + use std::autodiff::autodiff; #[autodiff(d_square, Reverse, Duplicated, Active)] fn square(x: &f64) -> f64 { x * x @@ -22,6 +23,7 @@ samples::test! { samples::test! { active_only; // ANCHOR: active_only + use std::autodiff::autodiff; #[autodiff(d_f, Reverse, Active, Active)] #[autodiff(d_f2, Reverse, Active, ActiveOnly)] fn f(x: f64) -> f64 { @@ -44,6 +46,7 @@ samples::test! { samples::test! { self_duplicated; // ANCHOR: self_duplicated + use std::autodiff::autodiff; struct Ogden { k: f64, } @@ -68,6 +71,7 @@ samples::test! { samples::test! { empty_return; // ANCHOR: empty_return + use std::autodiff::autodiff; #[autodiff(df, Reverse, Duplicated, Duplicated)] fn f(x: &[f32; 2], y: &mut f32) { *y = x[0] * x[0] + x[1] * x[0]; @@ -90,6 +94,7 @@ samples::test! { samples::test! { active_return; // ANCHOR: active_return + use std::autodiff::autodiff; #[autodiff(df, Reverse, Duplicated, Active)] fn f(x: &[f32; 2]) -> f32 { x[0] * x[0] + x[1] * x[0] @@ -109,6 +114,7 @@ samples::test! { samples::test! { forward_and_reverse; // ANCHOR: forward_and_reverse + use std::autodiff::autodiff; #[autodiff(df_fwd, Forward, Dual, Dual)] #[autodiff(df_rev, Reverse, Duplicated, Duplicated)] fn f(x: &[f32; 2], y: &mut f32) { @@ -143,6 +149,7 @@ samples::test! { samples::test! { all_active; // ANCHOR: all_active + use std::autodiff::autodiff; #[autodiff(df, Reverse, Active, Active, Active)] fn f(x: f32, y: f32) -> f32 { x * x + 3.0 * y diff --git a/samples/tests/second/mod.rs b/samples/tests/second/mod.rs index 0a8b43f..8a211c7 100644 --- a/samples/tests/second/mod.rs +++ b/samples/tests/second/mod.rs @@ -1,6 +1,7 @@ samples::test! { forward_of_reverse; // ANCHOR: forward_of_reverse + use std::autodiff::autodiff; #[autodiff(df, ReverseFirst, Duplicated, Active)] fn f(x: &[f32; 2]) -> f32 { x[0] * x[0] + x[1] * x[0] @@ -31,6 +32,7 @@ samples::test! { samples::test! { higher; + use std::autodiff::autodiff; // A direct translation of // https://enzyme.mit.edu/index.fcgi/julia/stable/generated/autodiff/#Forward-over-reverse diff --git a/samples/tests/traits/mod.rs b/samples/tests/traits/mod.rs index 65e8f5e..6d59459 100644 --- a/samples/tests/traits/mod.rs +++ b/samples/tests/traits/mod.rs @@ -1,6 +1,7 @@ samples::test! { volumetric; /// ANCHOR: volumetric + use std::autodiff::autodiff; trait Volumetric { /// Strain energy density fn psi(&self, j: f64) -> f64; diff --git a/ui/tests/ui/wrong_activity1.rs b/ui/tests/ui/wrong_activity1.rs index 1180781..3e9c4d9 100644 --- a/ui/tests/ui/wrong_activity1.rs +++ b/ui/tests/ui/wrong_activity1.rs @@ -1,4 +1,5 @@ #![feature(autodiff)] +use std::autodiff::autodiff; #[autodiff(d_f1, Reverse, Active, Active)] fn f1(x: &f64) -> f64 { diff --git a/ui/tests/ui/wrong_num.rs b/ui/tests/ui/wrong_num.rs index 2916cc1..806d0b9 100644 --- a/ui/tests/ui/wrong_num.rs +++ b/ui/tests/ui/wrong_num.rs @@ -1,4 +1,5 @@ #![feature(autodiff)] +use std::autodiff::autodiff; #[autodiff(d_square, Reverse, Duplicated, Const, Active)] fn square(x: &f64) -> f64 {