From a7c7119ed2f98501141d59795a28c2235927e601 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Mon, 21 Apr 2025 13:26:25 +0530 Subject: [PATCH] Added test --- tests/pretty/inherent_impl.pp | 41 +++++++++++++++++++++++++++++++++++ tests/pretty/inherent_impl.rs | 24 ++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/pretty/inherent_impl.pp create mode 100644 tests/pretty/inherent_impl.rs diff --git a/tests/pretty/inherent_impl.pp b/tests/pretty/inherent_impl.pp new file mode 100644 index 000000000000..97ac766b6b99 --- /dev/null +++ b/tests/pretty/inherent_impl.pp @@ -0,0 +1,41 @@ +#![feature(prelude_import)] +#![no_std] +//@ needs-enzyme + +#![feature(autodiff)] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +//@ pretty-mode:expanded +//@ pretty-compare-only +//@ pp-exact:inherent_impl.pp + +use std::autodiff::autodiff; + +struct Foo { + a: f64, +} + +trait MyTrait { + fn f(&self, x: f64) + -> f64; + fn df(&self, x: f64, seed: f64) + -> (f64, f64); +} + +impl MyTrait for Foo { + #[rustc_autodiff] + #[inline(never)] + fn f(&self, x: f64) -> f64 { + self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln()) + } + #[rustc_autodiff(Reverse, 1, Const, Active, Active)] + #[inline(never)] + fn df(&self, x: f64, dret: f64) -> (f64, f64) { + unsafe { asm!("NOP", options(pure, nomem)); }; + ::core::hint::black_box(self.f(x)); + ::core::hint::black_box((dret,)); + ::core::hint::black_box((self.f(x), f64::default())) + } +} diff --git a/tests/pretty/inherent_impl.rs b/tests/pretty/inherent_impl.rs new file mode 100644 index 000000000000..59de93f7e0ff --- /dev/null +++ b/tests/pretty/inherent_impl.rs @@ -0,0 +1,24 @@ +//@ needs-enzyme + +#![feature(autodiff)] +//@ pretty-mode:expanded +//@ pretty-compare-only +//@ pp-exact:inherent_impl.pp + +use std::autodiff::autodiff; + +struct Foo { + a: f64, +} + +trait MyTrait { + fn f(&self, x: f64) -> f64; + fn df(&self, x: f64, seed: f64) -> (f64, f64); +} + +impl MyTrait for Foo { + #[autodiff(df, Reverse, Const, Active, Active)] + fn f(&self, x: f64) -> f64 { + self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln()) + } +}