Skip to content

Commit 72091ed

Browse files
committed
feat: add test to validate autodiff macro expansion
1 parent 13bf79c commit 72091ed

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
@@ -29,6 +29,8 @@
2929
// Make sure, that we add the None for the default return.
3030

3131

32+
// We want to make sure that we can use the macro for functions defined inside of functions
33+
3234
::core::panicking::panic("not implemented")
3335
}
3436
#[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
@@ -158,4 +160,17 @@
158160
::core::hint::black_box((bx_0,));
159161
::core::hint::black_box(<f32>::default())
160162
}
163+
pub fn f9() {
164+
#[rustc_autodiff]
165+
#[inline(never)]
166+
fn inner(x: f32) -> f32 { x * x }
167+
#[rustc_autodiff(Forward, 1, Dual, DualOnly)]
168+
#[inline(never)]
169+
fn d_inner(x: f32, bx_0: f32) -> f32 {
170+
unsafe { asm!("NOP", options(pure, nomem)); };
171+
::core::hint::black_box(inner(x));
172+
::core::hint::black_box((bx_0,));
173+
::core::hint::black_box(<f32>::default())
174+
}
175+
}
161176
fn main() {}

tests/pretty/autodiff_forward.rs

+8
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,12 @@ fn f8(x: &f32) -> f32 {
5454
unimplemented!()
5555
}
5656

57+
// We want to make sure that we can use the macro for functions defined inside of functions
58+
pub fn f9() {
59+
#[autodiff(d_inner, Forward, Dual, DualOnly)]
60+
fn inner(x: f32) -> f32 {
61+
x * x
62+
}
63+
}
64+
5765
fn main() {}

0 commit comments

Comments
 (0)