Skip to content

Commit 35812e2

Browse files
committed
feat: add test to validate autodiff macro expansion
1 parent 7da1759 commit 35812e2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/pretty/autodiff_forward.pp

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
// We want to be sure that the same function can be differentiated in different ways
2727

28+
// We want to make sure that we can use the macro for functions defined inside of functions
29+
2830
::core::panicking::panic("not implemented")
2931
}
3032
#[rustc_autodiff(Forward, Dual, Const, Dual,)]
@@ -100,4 +102,17 @@
100102
::core::hint::black_box((dx, dret));
101103
::core::hint::black_box(f5(x, y))
102104
}
105+
pub fn f6() {
106+
#[rustc_autodiff]
107+
#[inline(never)]
108+
fn inner(x: f32) -> f32 { x * x }
109+
#[rustc_autodiff(Forward, Dual, DualOnly,)]
110+
#[inline(never)]
111+
fn d_inner(x: f32, bx: f32) -> f32 {
112+
unsafe { asm!("NOP", options(pure, nomem)); };
113+
::core::hint::black_box(inner(x));
114+
::core::hint::black_box((bx,));
115+
::core::hint::black_box(inner(x))
116+
}
117+
}
103118
fn main() {}

tests/pretty/autodiff_forward.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ pub fn f5(x: &[f64], y: f64) -> f64 {
3636
unimplemented!()
3737
}
3838

39+
// We want to make sure that we can use the macro for functions defined inside of functions
40+
pub fn f6() {
41+
#[autodiff(d_inner, Forward, Dual, DualOnly)]
42+
fn inner(x: f32) -> f32 {
43+
x * x
44+
}
45+
}
46+
3947
fn main() {}

0 commit comments

Comments
 (0)