Skip to content

Commit

Permalink
move tests to use std::autodiff::autodiff (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 authored Oct 27, 2024
1 parent 739fed4 commit db17934
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration/tests/examples/array.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 1 addition & 0 deletions integration/tests/examples/boxed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
samples::test! {
duplicated_active;
use std::autodiff::autodiff;
#[autodiff(cos_box, Reverse, Duplicated, Active)]
fn sin(x: &Box<f32>) -> f32 {
f32::sin(**x)
Expand Down
1 change: 1 addition & 0 deletions integration/tests/examples/enum1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(broken)]
samples::test! {
f32_i32;
use std::autodiff::autodiff;
enum Foo {
A(f32),
B(i32),
Expand Down
1 change: 1 addition & 0 deletions integration/tests/examples/foo.rs
Original file line number Diff line number Diff line change
@@ -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] }

Expand Down
1 change: 1 addition & 0 deletions integration/tests/examples/hessian_sin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
samples::test! {
vec;
use std::autodiff::autodiff;
#[autodiff(jac, ReverseFirst, Duplicated, Duplicated)]
fn sin(x: &Vec<f32>, y: &mut f32) {
*y = x.into_iter().map(|x| f32::sin(*x)).sum()
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/examples/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod array;
mod boxed;
mod enum1;
mod foo;
mod hessian_sin;
//mod hessian_sin;
3 changes: 3 additions & 0 deletions samples/tests/forward/mod.rs
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -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] }

Expand All @@ -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] }
Expand Down
1 change: 1 addition & 0 deletions samples/tests/neohookean/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_snake_case)]
use std::autodiff::autodiff;

use std::ops::{Add, Mul, Sub};

Expand Down
7 changes: 7 additions & 0 deletions samples/tests/reverse/mod.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -44,6 +46,7 @@ samples::test! {
samples::test! {
self_duplicated;
// ANCHOR: self_duplicated
use std::autodiff::autodiff;
struct Ogden {
k: f64,
}
Expand All @@ -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];
Expand All @@ -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]
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions samples/tests/second/mod.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions samples/tests/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
samples::test! {
volumetric;
/// ANCHOR: volumetric
use std::autodiff::autodiff;
trait Volumetric {
/// Strain energy density
fn psi(&self, j: f64) -> f64;
Expand Down
1 change: 1 addition & 0 deletions ui/tests/ui/wrong_activity1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(autodiff)]
use std::autodiff::autodiff;

#[autodiff(d_f1, Reverse, Active, Active)]
fn f1(x: &f64) -> f64 {
Expand Down
1 change: 1 addition & 0 deletions ui/tests/ui/wrong_num.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(autodiff)]
use std::autodiff::autodiff;

#[autodiff(d_square, Reverse, Duplicated, Const, Active)]
fn square(x: &f64) -> f64 {
Expand Down

0 comments on commit db17934

Please sign in to comment.