Fermat
Classes | Functions
Automatic-Differentiation

Detailed Description

This module defines classes to perform automatic differentiation

Classes

struct  cugar::static_min< O1, O2 >
 
struct  cugar::diff_var< ValType, N, O >
 
struct  cugar::diff_var< ValType, N, 0 >
 
struct  cugar::diff_var< ValType, 1, O >
 
struct  cugar::diff_var< ValType, 1, 0 >
 

Functions

template<typename VT , uint32 O>
CUGAR_HOST_DEVICE void cugar::set_primary (diff_var< VT, 1, O > &var, const VT deriv=VT(1.0))
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE void cugar::set_primary (const uint32 i, diff_var< VT, N, O > &var, const VT deriv=VT(1.0))
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::decrease_order (const diff_var< VT, N, 1 > &op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O-1 > cugar::decrease_order (const diff_var< VT, N, O > &op)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 1 > cugar::raise_order (const diff_var< VT, N, 0 > &op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O+1 > cugar::raise_order (const diff_var< VT, N, O > &op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Vector< diff_var< VT, N, O+1 >, N > cugar::raise_order (const Vector< diff_var< VT, N, O >, N > &op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< diff_var< VT, N, O+1 >, 1, N > cugar::raise_order (const Tensor< diff_var< VT, N, O >, 1, N > &op)
 
template<typename VT , uint32 N, uint32 O, uint32 TO>
CUGAR_HOST_DEVICE Tensor< diff_var< VT, N, O+1 >, TO, N > cugar::raise_order (const Tensor< diff_var< VT, N, O >, TO, N > &op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O >::diff_type cugar::diff (const diff_var< VT, N, O > op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< diff_var< VT, N, O-2 >, 2, N > cugar::diff_hessian (const diff_var< VT, N, O > op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< VT, 1, N > cugar::gradient (const diff_var< VT, N, O > op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< VT, 1, N > cugar::jacobian (const diff_var< VT, N, O > op)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< VT, 2, N > cugar::hessian (const diff_var< VT, N, O > op)
 
template<uint32 ORDER, typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor< VT, ORDER, N > cugar::diff_tensor (const diff_var< VT, N, O > op)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator- (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator- (const diff_var< VT, N, 0 > a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator- (const diff_var< VT, N, 0 > a, const VT b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator- (const VT a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator+ (const diff_var< VT, N, 0 > a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator+ (const diff_var< VT, N, 0 > a, const VT b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator+ (const VT a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator* (const diff_var< VT, N, 0 > a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator* (const diff_var< VT, N, 0 > a, const VT b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator* (const VT a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator/ (const diff_var< VT, N, 0 > a, const diff_var< VT, N, 0 > b)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::operator/ (const diff_var< VT, N, 0 > a, const VT b)
 
template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var< VT, N, detail::dispatch_sum< VT, N, O1, O2 >::RO > cugar::operator+ (const diff_var< VT, N, O1 > a, const diff_var< VT, N, O2 > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator+ (const diff_var< VT, N, O > a, const VT b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator+ (const VT a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator- (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator- (const diff_var< VT, N, O > a, const VT b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator- (const VT a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var< VT, N, detail::dispatch_sum< VT, N, O1, O2 >::RO > cugar::operator- (const diff_var< VT, N, O1 > a, const diff_var< VT, N, O2 > b)
 
template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var< VT, N, detail::dispatch_mul< VT, N, O1, O2 >::RO > cugar::operator* (const diff_var< VT, N, O1 > a, const diff_var< VT, N, O2 > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator* (const diff_var< VT, N, O > a, const VT b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator* (const VT a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var< VT, N, detail::dispatch_div< VT, N, O1, O2 >::RO > cugar::operator/ (const diff_var< VT, N, O1 > a, const diff_var< VT, N, O2 > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator/ (const diff_var< VT, N, O > a, const VT b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::operator/ (const VT a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > & cugar::operator+= (diff_var< VT, N, O > &a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > & cugar::operator-= (diff_var< VT, N, O > &a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > & cugar::operator*= (diff_var< VT, N, O > &a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > & cugar::operator/= (diff_var< VT, N, O > &a, const diff_var< VT, N, O > b)
 
template<uint32 N>
CUGAR_HOST_DEVICE diff_var< float, N, 0 > cugar::sin (const diff_var< float, N, 0 > a)
 
template<uint32 N>
CUGAR_HOST_DEVICE diff_var< float, N, 0 > cugar::cos (const diff_var< float, N, 0 > a)
 
template<uint32 N>
CUGAR_HOST_DEVICE diff_var< float, N, 0 > cugar::log (const diff_var< float, N, 0 > a)
 
template<uint32 N>
CUGAR_HOST_DEVICE diff_var< float, N, 0 > cugar::exp (const diff_var< float, N, 0 > a)
 
template<uint32 N>
CUGAR_HOST_DEVICE diff_var< float, N, 0 > cugar::sqrt (const diff_var< float, N, 0 > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::sin (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::cos (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::log (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::exp (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::sqrt (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::sinf (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::cosf (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::logf (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::expf (const diff_var< float, N, O > a)
 
template<uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< float, N, O > cugar::sqrtf (const diff_var< float, N, O > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::sin (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::cos (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::log (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::exp (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var< VT, N, 0 > cugar::sqrt (const diff_var< VT, N, 0 > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::sin (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::cos (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::log (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::exp (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::sqrt (const diff_var< VT, N, O > a)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::max (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var< VT, N, O > cugar::min (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE bool cugar::operator< (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE bool cugar::operator<= (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE bool cugar::operator> (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 
template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE bool cugar::operator>= (const diff_var< VT, N, O > a, const diff_var< VT, N, O > b)
 

Function Documentation

◆ decrease_order() [1/2]

template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var<VT, N, 0> cugar::decrease_order ( const diff_var< VT, N, 1 > &  op)
inline

given a variable with order 1 differentials, return a copy of order 0.

◆ decrease_order() [2/2]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT, N, O-1> cugar::decrease_order ( const diff_var< VT, N, O > &  op)
inline

given a variable with differentials up to order O, return a copy of order O-1.

◆ diff()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT, N, O>::diff_type cugar::diff ( const diff_var< VT, N, O >  op)
inline

return the differential of a given variable

◆ diff_hessian()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<diff_var<VT, N, O-2>, 2, N> cugar::diff_hessian ( const diff_var< VT, N, O >  op)
inline

return the differentiable Hessian of a given variable

◆ diff_tensor()

template<uint32 ORDER, typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<VT, ORDER, N> cugar::diff_tensor ( const diff_var< VT, N, O >  op)
inline

return the differential tensor of order M of a given variable as a plain (i.e. non-differentiable) M-tensor

Template Parameters
ORDERorder of the differential

◆ gradient()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<VT, 1, N> cugar::gradient ( const diff_var< VT, N, O >  op)
inline

return the gradient of a given variable as a plain (i.e. non-differentiable) 1-tensor

◆ hessian()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<VT, 2, N> cugar::hessian ( const diff_var< VT, N, O >  op)
inline

return the Hessian of a given variable as a plain (i.e. non-differentiable) 2-tensor

◆ jacobian()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<VT, 1, N> cugar::jacobian ( const diff_var< VT, N, O >  op)
inline

return the Jacobian of a given variable as a plain (i.e. non-differentiable) 1-tensor

◆ operator*() [1/3]

template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var<VT,N,detail::dispatch_mul<VT,N,O1,O2>::RO> cugar::operator* ( const diff_var< VT, N, O1 >  a,
const diff_var< VT, N, O2 >  b 
)
inline

multiplication of arbitrary order vars

◆ operator*() [2/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator* ( const diff_var< VT, N, O >  a,
const VT  b 
)
inline

right-multiplication by scalar

◆ operator*() [3/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator* ( const VT  a,
const diff_var< VT, N, O >  b 
)
inline

left-multiplication by scalar

◆ operator*=()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O>& cugar::operator*= ( diff_var< VT, N, O > &  a,
const diff_var< VT, N, O >  b 
)
inline

*= operator

◆ operator+() [1/3]

template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var<VT,N,detail::dispatch_sum<VT,N,O1,O2>::RO> cugar::operator+ ( const diff_var< VT, N, O1 >  a,
const diff_var< VT, N, O2 >  b 
)
inline

addition of arbitrary order vars

◆ operator+() [2/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator+ ( const diff_var< VT, N, O >  a,
const VT  b 
)
inline

right-addition with a scalar

◆ operator+() [3/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator+ ( const VT  a,
const diff_var< VT, N, O >  b 
)
inline

left-addition with a scalar

◆ operator+=()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O>& cugar::operator+= ( diff_var< VT, N, O > &  a,
const diff_var< VT, N, O >  b 
)
inline

+= operator

◆ operator-() [1/4]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator- ( const diff_var< VT, N, O >  a)
inline

negation

◆ operator-() [2/4]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator- ( const diff_var< VT, N, O >  a,
const VT  b 
)
inline

right-subtraction of scalar

◆ operator-() [3/4]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator- ( const VT  a,
const diff_var< VT, N, O >  b 
)
inline

left-subtraction of scalar

◆ operator-() [4/4]

template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var<VT,N,detail::dispatch_sum<VT,N,O1,O2>::RO> cugar::operator- ( const diff_var< VT, N, O1 >  a,
const diff_var< VT, N, O2 >  b 
)
inline

subtraction of arbitrary order vars

◆ operator-=()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O>& cugar::operator-= ( diff_var< VT, N, O > &  a,
const diff_var< VT, N, O >  b 
)
inline

-= operator

◆ operator/() [1/3]

template<typename VT , uint32 N, uint32 O1, uint32 O2>
CUGAR_HOST_DEVICE diff_var<VT,N,detail::dispatch_div<VT,N,O1,O2>::RO> cugar::operator/ ( const diff_var< VT, N, O1 >  a,
const diff_var< VT, N, O2 >  b 
)
inline

division of arbitrary order vars

◆ operator/() [2/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator/ ( const diff_var< VT, N, O >  a,
const VT  b 
)
inline

division by scalar

◆ operator/() [3/3]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O> cugar::operator/ ( const VT  a,
const diff_var< VT, N, O >  b 
)
inline

scalar divided by arbitrary order

◆ operator/=()

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT,N,O>& cugar::operator/= ( diff_var< VT, N, O > &  a,
const diff_var< VT, N, O >  b 
)
inline

/= operator

◆ raise_order() [1/5]

template<typename VT , uint32 N>
CUGAR_HOST_DEVICE diff_var<VT, N, 1> cugar::raise_order ( const diff_var< VT, N, 0 > &  op)
inline

given a variable with differentials up to order 0, return a copy of order 1.

◆ raise_order() [2/5]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE diff_var<VT, N, O+1> cugar::raise_order ( const diff_var< VT, N, O > &  op)
inline

given a variable with differentials up to order O, return a copy of order O+1.

◆ raise_order() [3/5]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Vector<diff_var<VT, N, O+1>, N> cugar::raise_order ( const Vector< diff_var< VT, N, O >, N > &  op)
inline

given a tensor variable with differentials up to order O, return a copy of order O+1.

◆ raise_order() [4/5]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE Tensor<diff_var<VT, N, O+1>, 1, N> cugar::raise_order ( const Tensor< diff_var< VT, N, O >, 1, N > &  op)
inline

given a tensor variable with differentials up to order O, return a copy of order O+1.

◆ raise_order() [5/5]

template<typename VT , uint32 N, uint32 O, uint32 TO>
CUGAR_HOST_DEVICE Tensor<diff_var<VT, N, O+1>, TO, N> cugar::raise_order ( const Tensor< diff_var< VT, N, O >, TO, N > &  op)
inline

given a tensor variable with differentials up to order O, return a copy of order O+1.

◆ set_primary() [1/2]

template<typename VT , uint32 O>
CUGAR_HOST_DEVICE void cugar::set_primary ( diff_var< VT, 1, O > &  var,
const VT  deriv = VT(1.0) 
)
inline

a utility function to mark a variable as "primary", i.e. to mark it as a variable we want to differentiate against: this is exactly equivalent to setting its derivative to 1

◆ set_primary() [2/2]

template<typename VT , uint32 N, uint32 O>
CUGAR_HOST_DEVICE void cugar::set_primary ( const uint32  i,
diff_var< VT, N, O > &  var,
const VT  deriv = VT(1.0) 
)
inline

a utility function to mark a variable as the i-th "primary", i.e. to mark it as a variable we want to differentiate against: this is exactly equivalent to setting the i-th component of its gradient to 1