Automatic Differentiation
 
Loading...
Searching...
No Matches
log_diff_exp.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_LOG_DIFF_EXP_HPP
2#define STAN_MATH_OPENCL_REV_LOG_DIFF_EXP_HPP
3#ifdef STAN_OPENCL
4
15
16namespace stan {
17namespace math {
18
32template <typename T_x, typename T_y,
33 require_all_prim_or_rev_kernel_expression_t<T_x, T_y>* = nullptr,
34 require_any_var_t<T_x, T_y>* = nullptr,
35 require_any_not_stan_scalar_t<T_x, T_y>* = nullptr>
36inline var_value<matrix_cl<double>> log_diff_exp(T_x&& x, T_y&& y) {
37 arena_t<T_x> x_arena = std::forward<T_x>(x);
38 arena_t<T_y> y_arena = std::forward<T_y>(y);
39
40 return make_callback_var(
41 log_diff_exp(value_of(x_arena), value_of(y_arena)),
42 [x_arena, y_arena](const vari_value<matrix_cl<double>>& res) mutable {
43 adjoint_results(x_arena, y_arena) += expressions(
44 -elt_divide(res.adj(),
45 expm1(value_of(y_arena) - value_of(x_arena))),
46 -elt_divide(res.adj(),
47 expm1(value_of(x_arena) - value_of(y_arena))));
48 });
49}
50
51} // namespace math
52} // namespace stan
53
54#endif
55#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
fvar< T > expm1(const fvar< T > &x)
Definition expm1.hpp:13
adjoint_results_cl< T_results... > adjoint_results(T_results &&... results)
Deduces types for constructing adjoint_results_cl object.
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
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...