Automatic Differentiation
 
Loading...
Searching...
No Matches
pow.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_POW_HPP
2#define STAN_MATH_OPENCL_REV_POW_HPP
3#ifdef STAN_OPENCL
4
15
16namespace stan {
17namespace math {
18
29template <typename T_a, typename T_b,
30 require_all_prim_or_rev_kernel_expression_t<T_a, T_b>* = nullptr,
31 require_any_var_t<T_a, T_b>* = nullptr,
32 require_any_not_stan_scalar_t<T_a, T_b>* = nullptr>
33inline var_value<matrix_cl<double>> pow(T_a&& a, T_b&& b) {
34 const arena_t<T_a>& a_arena = std::forward<T_a>(a);
35 const arena_t<T_b>& b_arena = std::forward<T_b>(b);
36
37 matrix_cl<double> res_val = pow(value_of(a_arena), value_of(b_arena));
38
39 return make_callback_var(
40 res_val,
41 [a_arena, b_arena](const vari_value<matrix_cl<double>>& res) mutable {
42 auto isnan_res = isnan(res.val());
43 auto zero_a_arena = value_of(a_arena) == 0.0;
44 auto res_adj_times_val = elt_multiply(res.adj(), res.val());
45 auto a_deriv = select(
46 isnan_res, NOT_A_NUMBER,
47 select(zero_a_arena, 0.0,
49 res_adj_times_val,
50 elt_divide(value_of(b_arena), value_of(a_arena)))));
51 auto b_deriv = select(
52 isnan_res, NOT_A_NUMBER,
53 select(zero_a_arena, 0.0,
54 elt_multiply(res_adj_times_val, log(value_of(a_arena)))));
55
56 adjoint_results(a_arena, b_arena) += expressions(a_deriv, b_deriv);
57 });
58}
59
60} // namespace math
61} // namespace stan
62
63#endif
64#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
select_< as_operation_cl_t< T_condition >, as_operation_cl_t< T_then >, as_operation_cl_t< T_else > > select(T_condition &&condition, T_then &&then, T_else &&els)
Selection operation on kernel generator expressions.
Definition select.hpp:148
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.
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
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...
auto pow(const T1 &x1, const T2 &x2)
Definition pow.hpp:32
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
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 ...