File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ //@ compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=fat
2+ //@ no-prefer-dynamic
3+ //@ needs-enzyme
4+ #![ feature( autodiff) ]
5+
6+ use std:: autodiff:: autodiff;
7+
8+ #[ autodiff( d_square, Reverse , Duplicated , Active ) ]
9+ fn square < T : std:: ops:: Mul < Output = T > + Copy > ( x : & T ) -> T {
10+ * x * * x
11+ }
12+
13+ fn main ( ) {
14+ let xf32: f32 = std:: hint:: black_box ( 3.0 ) ;
15+ let xf64: f64 = std:: hint:: black_box ( 3.0 ) ;
16+
17+ // Ensure that `square::<f32>` is generated.
18+ //
19+ // f32
20+ // | | |
21+ // V V V
22+ // CHECK: fmul float %{{.+}}, %{{.+}}
23+
24+ let outputf32 = square :: < f32 > ( & xf32) ;
25+ assert_eq ! ( 9.0 , outputf32) ;
26+
27+ let mut df_dxf64: f64 = std:: hint:: black_box ( 0.0 ) ;
28+
29+ // Ensure that `d_square::<f64>` code is generated even if `square::<f64>` was never called
30+ // f64
31+ // | | |
32+ // V V V
33+ // CHECK: fadd fast double %x.0.val, %x.0.val
34+
35+ let output_f64 = d_square :: < f64 > ( & xf64, & mut df_dxf64, 1.0 ) ;
36+ assert_eq ! ( 6.0 , df_dxf64) ;
37+ }
You can’t perform that action at this time.
0 commit comments