|
| 1 | +#![feature(prelude_import)] |
| 2 | +#![no_std] |
| 3 | +//@ needs-enzyme |
| 4 | + |
| 5 | +#![feature(autodiff)] |
| 6 | +#[prelude_import] |
| 7 | +use ::std::prelude::rust_2015::*; |
| 8 | +#[macro_use] |
| 9 | +extern crate std; |
| 10 | +//@ pretty-mode:expanded |
| 11 | +//@ pretty-compare-only |
| 12 | +//@ pp-exact:autodiff_forward.pp |
| 13 | + |
| 14 | +// Test that forward mode ad macros are expanded correctly. |
| 15 | + |
| 16 | +use std::autodiff::autodiff; |
| 17 | + |
| 18 | +#[rustc_autodiff] |
| 19 | +#[inline(never)] |
| 20 | +pub fn f1(x: &[f64], y: f64) -> f64 { |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + // Not the most interesting derivative, but who are we to judge |
| 25 | + |
| 26 | + // We want to be sure that the same function can be differentiated in different ways |
| 27 | + |
| 28 | + ::core::panicking::panic("not implemented") |
| 29 | +} |
| 30 | +#[rustc_autodiff(Forward, Dual, Const, Dual,)] |
| 31 | +#[inline(never)] |
| 32 | +pub fn df1(x: &[f64], bx: &[f64], y: f64) -> (f64, f64) { |
| 33 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 34 | + ::core::hint::black_box(f1(x, y)); |
| 35 | + ::core::hint::black_box((bx,)); |
| 36 | + ::core::hint::black_box((f1(x, y), f64::default())) |
| 37 | +} |
| 38 | +#[rustc_autodiff] |
| 39 | +#[inline(never)] |
| 40 | +pub fn f2(x: &[f64], y: f64) -> f64 { |
| 41 | + ::core::panicking::panic("not implemented") |
| 42 | +} |
| 43 | +#[rustc_autodiff(Forward, Dual, Const, Const,)] |
| 44 | +#[inline(never)] |
| 45 | +pub fn df2(x: &[f64], bx: &[f64], y: f64) -> f64 { |
| 46 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 47 | + ::core::hint::black_box(f2(x, y)); |
| 48 | + ::core::hint::black_box((bx,)); |
| 49 | + ::core::hint::black_box(f2(x, y)) |
| 50 | +} |
| 51 | +#[rustc_autodiff] |
| 52 | +#[inline(never)] |
| 53 | +pub fn f3(x: &[f64], y: f64) -> f64 { |
| 54 | + ::core::panicking::panic("not implemented") |
| 55 | +} |
| 56 | +#[rustc_autodiff(ForwardFirst, Dual, Const, Const,)] |
| 57 | +#[inline(never)] |
| 58 | +pub fn df3(x: &[f64], bx: &[f64], y: f64) -> f64 { |
| 59 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 60 | + ::core::hint::black_box(f3(x, y)); |
| 61 | + ::core::hint::black_box((bx,)); |
| 62 | + ::core::hint::black_box(f3(x, y)) |
| 63 | +} |
| 64 | +#[rustc_autodiff] |
| 65 | +#[inline(never)] |
| 66 | +pub fn f4() {} |
| 67 | +#[rustc_autodiff(Forward, None)] |
| 68 | +#[inline(never)] |
| 69 | +pub fn df4() { |
| 70 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 71 | + ::core::hint::black_box(f4()); |
| 72 | + ::core::hint::black_box(()); |
| 73 | +} |
| 74 | +#[rustc_autodiff] |
| 75 | +#[inline(never)] |
| 76 | +#[rustc_autodiff] |
| 77 | +#[inline(never)] |
| 78 | +#[rustc_autodiff] |
| 79 | +#[inline(never)] |
| 80 | +pub fn f5(x: &[f64], y: f64) -> f64 { |
| 81 | + ::core::panicking::panic("not implemented") |
| 82 | +} |
| 83 | +#[rustc_autodiff(Forward, Const, Dual, Const,)] |
| 84 | +#[inline(never)] |
| 85 | +pub fn df5_y(x: &[f64], y: f64, by: f64) -> f64 { |
| 86 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 87 | + ::core::hint::black_box(f5(x, y)); |
| 88 | + ::core::hint::black_box((by,)); |
| 89 | + ::core::hint::black_box(f5(x, y)) |
| 90 | +} |
| 91 | +#[rustc_autodiff(Forward, Dual, Const, Const,)] |
| 92 | +#[inline(never)] |
| 93 | +pub fn df5_x(x: &[f64], bx: &[f64], y: f64) -> f64 { |
| 94 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 95 | + ::core::hint::black_box(f5(x, y)); |
| 96 | + ::core::hint::black_box((bx,)); |
| 97 | + ::core::hint::black_box(f5(x, y)) |
| 98 | +} |
| 99 | +#[rustc_autodiff(Reverse, Duplicated, Const, Active,)] |
| 100 | +#[inline(never)] |
| 101 | +pub fn df5_rev(x: &[f64], dx: &mut [f64], y: f64, dret: f64) -> f64 { |
| 102 | + unsafe { asm!("NOP", options(pure, nomem)); }; |
| 103 | + ::core::hint::black_box(f5(x, y)); |
| 104 | + ::core::hint::black_box((dx, dret)); |
| 105 | + ::core::hint::black_box(f5(x, y)) |
| 106 | +} |
| 107 | +fn main() {} |
0 commit comments