File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ //@ compile-flags: -Zautodiff=Enable -Zautodiff=NoPostopt -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
+ // Ensure that `d_square::<f64>` code is generated even if `square::<f64>` was never called
14
+ //
15
+ // CHECK: ; generic::square
16
+ // CHECK-NEXT: ; Function Attrs:
17
+ // CHECK-NEXT: define internal {{.*}} double
18
+ // CHECK-NEXT: start:
19
+ // CHECK-NOT: ret
20
+ // CHECK: fmul double
21
+
22
+ // Ensure that `d_square::<f32>` code is generated
23
+ //
24
+ // CHECK: ; generic::square
25
+ // CHECK-NEXT: ; Function Attrs: {{.*}}
26
+ // CHECK-NEXT: define internal {{.*}} float
27
+ // CHECK-NEXT: start:
28
+ // CHECK-NOT: ret
29
+ // CHECK: fmul float
30
+
31
+ fn main ( ) {
32
+ let xf32: f32 = std:: hint:: black_box ( 3.0 ) ;
33
+ let xf64: f64 = std:: hint:: black_box ( 3.0 ) ;
34
+
35
+ let outputf32 = square :: < f32 > ( & xf32) ;
36
+ assert_eq ! ( 9.0 , outputf32) ;
37
+
38
+ let mut df_dxf64: f64 = std:: hint:: black_box ( 0.0 ) ;
39
+
40
+ let output_f64 = d_square :: < f64 > ( & xf64, & mut df_dxf64, 1.0 ) ;
41
+ assert_eq ! ( 6.0 , df_dxf64) ;
42
+ }
You can’t perform that action at this time.
0 commit comments