Skip to content

Commit 11bd84e

Browse files
committed
Added test
1 parent c0c6d42 commit 11bd84e

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Diff for: tests/pretty/autodiff.pp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
//@ needs-enzyme
4+
5+
#![feature(autodiff)]
6+
#[prelude_import]
7+
use ::std::prelude::rust_2015::*;
8+
#[macro_use]
9+
extern crate std;
10+
//@ pretty-mode:expanded
11+
//@ pretty-compare-only
12+
//@ pp-exact:autodiff.pp
13+
14+
use std::autodiff::autodiff;
15+
16+
struct Foo {
17+
a: f64,
18+
}
19+
20+
trait MyTrait {
21+
fn f(&self, x: f64)
22+
-> f64;
23+
fn df(&self, x: f64, seed: f64)
24+
-> (f64, f64);
25+
}
26+
27+
impl MyTrait for Foo {
28+
#[rustc_autodiff]
29+
#[inline(never)]
30+
fn f(&self, x: f64) -> f64 {
31+
self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln())
32+
}
33+
#[rustc_autodiff(Reverse, 1, Const, Active, Active)]
34+
#[inline(never)]
35+
fn df(&self, x: f64, dret: f64) -> (f64, f64) {
36+
unsafe { asm!("NOP", options(pure, nomem)); };
37+
::core::hint::black_box(self.f(x));
38+
::core::hint::black_box((dret,));
39+
::core::hint::black_box((self.f(x), f64::default()))
40+
}
41+
}

Diff for: tests/pretty/autodiff.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ needs-enzyme
2+
3+
#![feature(autodiff)]
4+
//@ pretty-mode:expanded
5+
//@ pretty-compare-only
6+
//@ pp-exact:autodiff.pp
7+
8+
use std::autodiff::autodiff;
9+
10+
struct Foo {
11+
a: f64,
12+
}
13+
14+
trait MyTrait {
15+
fn f(&self, x: f64) -> f64;
16+
fn df(&self, x: f64, seed: f64) -> (f64, f64);
17+
}
18+
19+
impl MyTrait for Foo {
20+
#[autodiff(df, Reverse, Const, Active, Active)]
21+
fn f(&self, x: f64) -> f64 {
22+
self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln())
23+
}
24+
}

0 commit comments

Comments
 (0)