about summary refs log tree commit diff
path: root/tests/pretty/autodiff/inherent_impl.pp
blob: 36a9222640ae5e5d0779058090d786cd68947b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![feature(prelude_import)]
#![no_std]
//@ needs-enzyme

#![feature(autodiff)]
#[macro_use]
extern crate std;
#[prelude_import]
use ::std::prelude::rust_2015::*;
//@ pretty-mode:expanded
//@ pretty-compare-only
//@ pp-exact:inherent_impl.pp

use std::autodiff::autodiff_reverse;

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]
    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)]
    fn df(&self, x: f64, dret: f64) -> (f64, f64) {
        ::core::intrinsics::autodiff(Self::f::<>, Self::df::<>,
            (self, x, dret))
    }
}