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
use crate::tensor_ops::cpu_kernels::UnaryDerivative;

impl<F: num_traits::Float> UnaryDerivative<F> for super::PowiKernelOp {
    const DF_USES_FX: bool = false;
    const HAS_CONST_DF: bool = false;
    #[inline(always)]
    fn f(&self, x: &F) -> F {
        x.powi(self.0)
    }
    #[inline(always)]
    fn df(&self, x: &F) -> F {
        F::from(self.0).unwrap() * x.powi(self.0 - 1)
    }
}

impl<F: num_traits::Float> UnaryDerivative<F> for super::PowfKernelOp<F> {
    const DF_USES_FX: bool = false;
    const HAS_CONST_DF: bool = false;
    #[inline(always)]
    fn f(&self, x: &F) -> F {
        x.powf(self.0)
    }
    #[inline(always)]
    fn df(&self, x: &F) -> F {
        self.0 * x.powf(self.0 - F::one())
    }
}