Automatic Differentiation
 
Loading...
Searching...
No Matches
offset_multiplier_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_CONSTRAINT_OFFSET_MULTIPLIER_CONSTRAIN_HPP
2#define STAN_MATH_OPENCL_REV_CONSTRAINT_OFFSET_MULTIPLIER_CONSTRAIN_HPP
3#ifdef STAN_OPENCL
4
9
10namespace stan {
11namespace math {
12
36template <typename T, typename M, typename S,
37 require_all_prim_or_rev_kernel_expression_t<T, M, S>* = nullptr,
38 require_any_not_stan_scalar_t<T, M, S>* = nullptr,
39 require_any_var_t<T, M, S>* = nullptr>
41 S&& sigma) {
42 if (A.size() == 0) {
43 return A;
44 }
45 arena_t<T> A_arena = std::forward<T>(A);
46 arena_t<M> mu_arena = std::forward<M>(mu);
47 arena_t<S> sigma_arena = std::forward<S>(sigma);
48 return make_callback_var(
50 value_of(sigma_arena)),
51 [A_arena, mu_arena,
52 sigma_arena](vari_value<matrix_cl<double>>& res) mutable {
53 adjoint_results(A_arena, mu_arena, sigma_arena) += expressions(
54 elt_multiply(res.adj(), value_of(sigma_arena)), res.adj(),
55 elt_multiply(res.adj(), value_of(A_arena)));
56 });
57}
58
83template <typename T, typename M, typename S,
88 S&& sigma,
89 var& lp) {
90 if (A.size() == 0) {
91 return A;
92 }
93 arena_t<T> A_arena = std::forward<T>(A);
94 arena_t<M> mu_arena = std::forward<M>(mu);
95 arena_t<S> sigma_arena = std::forward<S>(sigma);
96
97 double lp_inc = 0;
98 auto res = offset_multiplier_constrain(value_of(A_arena), value_of(mu_arena),
99 value_of(sigma_arena), lp_inc);
100 lp += lp_inc;
101 return make_callback_var(
102 std::move(res), [A_arena, mu_arena, sigma_arena,
103 lp](vari_value<matrix_cl<double>>& res) mutable {
104 adjoint_results(A_arena, mu_arena, sigma_arena) += expressions(
105 elt_multiply(res.adj(), value_of(sigma_arena)), res.adj(),
106 elt_multiply(res.adj(), value_of(A_arena))
107 + elt_divide(lp.adj(), value_of(sigma_arena)));
108 });
109}
110
111} // namespace math
112} // namespace stan
113
114#endif
115#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)
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.
require_all_t< is_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_prim_or_rev_kernel_expression_t
Require type satisfies is_prim_or_rev_kernel_expression.
require_any_not_t< is_stan_scalar< std::decay_t< Types > >... > require_any_not_stan_scalar_t
Require at least one of the types do not satisfy is_stan_scalar.
require_any_t< is_var< std::decay_t< Types > >... > require_any_var_t
Require any of the types satisfy is_var.
Definition is_var.hpp:39
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
auto offset_multiplier_constrain(const T &x, const M &mu, const S &sigma)
Return the linearly transformed value for the specified unconstrained input and specified offset and ...
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 ...