Added test
This commit is contained in:
parent
c0c6d4280c
commit
a7c7119ed2
2 changed files with 65 additions and 0 deletions
41
tests/pretty/inherent_impl.pp
Normal file
41
tests/pretty/inherent_impl.pp
Normal file
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
24
tests/pretty/inherent_impl.rs
Normal file
24
tests/pretty/inherent_impl.rs
Normal file
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue