Automatic Differentiation
 
Loading...
Searching...
No Matches
beta.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_BETA_HPP
2#define STAN_MATH_OPENCL_REV_BETA_HPP
3#ifdef STAN_OPENCL
4
13
14namespace stan {
15namespace math {
16
27template <typename T_a, typename T_b,
28 require_all_prim_or_rev_kernel_expression_t<T_a, T_b>* = nullptr,
29 require_any_var_t<T_a, T_b>* = nullptr,
30 require_any_not_stan_scalar_t<T_a, T_b>* = nullptr>
31inline auto beta(T_a&& a, T_b&& b) {
32 const arena_t<T_a>& a_arena = std::forward<T_a>(a);
33 const arena_t<T_b>& b_arena = std::forward<T_b>(b);
34
35 var_value<matrix_cl<double>> res = beta(value_of(a_arena), value_of(b_arena));
36
37 reverse_pass_callback([a_arena, b_arena, res]() mutable {
38 auto adj_val = elt_multiply(res.adj(), res.val());
39 auto digamma_ab = digamma(value_of(a_arena) + value_of(b_arena));
40 adjoint_results(a_arena, b_arena) += expressions(
41 elt_multiply(adj_val, (digamma(value_of(a_arena)) - digamma_ab)),
42 elt_multiply(adj_val, (digamma(value_of(b_arena)) - digamma_ab)));
43 });
44 return res;
45}
46
47} // namespace math
48} // namespace stan
49
50#endif
51#endif
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
adjoint_results_cl< T_results... > adjoint_results(T_results &&... results)
Deduces types for constructing adjoint_results_cl object.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
Definition beta.hpp:51
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
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 ...