Automatic Differentiation
 
Loading...
Searching...
No Matches
trace.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_TRACE_HPP
2#define STAN_MATH_OPENCL_REV_TRACE_HPP
3#ifdef STAN_OPENCL
4
10
11namespace stan {
12namespace math {
13
21template <typename T,
22 require_all_kernel_expressions_and_none_scalar_t<T>* = nullptr>
23inline var trace(const var_value<T>& x) {
24 return make_callback_var(trace(value_of(x)), [x](vari& res) mutable {
25 diagonal(x.adj()) += res.adj();
26 });
27}
28
29} // namespace math
30} // namespace stan
31
32#endif
33#endif
auto diagonal(T &&a)
Diagonal of a kernel generator expression.
Definition diagonal.hpp:136
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
value_type_t< T > trace(const T &m)
Calculates trace (sum of diagonal) of given kernel generator expression.
Definition trace.hpp:22
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...