Skip to content

Commit c4cbe4f

Browse files
committed
Added test
1 parent c0c6d42 commit c4cbe4f

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

Diff for: tests/pretty/autodiff.pp

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

Diff for: tests/pretty/autodiff.rs

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

0 commit comments

Comments
 (0)