Automatic Differentiation
 
Loading...
Searching...
No Matches
offset_multiplier_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_OFFSET_MULTIPLIER_CONSTRAIN_HPP
2#define STAN_MATH_OPENCL_PRIM_OFFSET_MULTIPLIER_CONSTRAIN_HPP
3#ifdef STAN_OPENCL
4
8
9namespace stan {
10namespace math {
11
35template <typename T, typename M, typename S,
36 require_all_kernel_expressions_t<T, M, S>* = nullptr,
37 require_any_not_stan_scalar_t<T, M, S>* = nullptr>
38inline auto offset_multiplier_constrain(const T& x, const M& mu,
39 const S& sigma) {
40 using std::isfinite;
41 const char* function = "offset_multiplier_constrain(OpenCL)";
42 check_consistent_sizes(function, "offset", mu, "multiplier", sigma,
43 "parameter", x);
44 auto check_mu = check_cl(function, "offset", mu, "finite");
45 auto check_sigma = check_cl(function, "multiplier", sigma, "positive finite");
47 results(check_mu, check_sigma, res) = expressions(
48 isfinite(mu), isfinite(sigma) && sigma > 0, elt_multiply(x, sigma) + mu);
49 return res;
50}
51
76template <typename T, typename M, typename S,
79inline auto offset_multiplier_constrain(const T& x, const M& mu, const S& sigma,
80 double& lp) {
81 using std::isfinite;
82 const char* function = "offset_multiplier_constrain(OpenCL)";
83 check_consistent_sizes(function, "offset", mu, "multiplier", sigma,
84 "parameter", x);
85 auto check_mu = check_cl(function, "offset", mu, "finite");
86 auto check_sigma = check_cl(function, "multiplier", sigma, "positive finite");
88 matrix_cl<double> lp_inc;
89 results(check_mu, check_sigma, res, lp_inc)
90 = expressions(isfinite(mu), isfinite(sigma) && sigma > 0,
91 elt_multiply(x, sigma) + mu, sum_2d(log(sigma)));
92 lp += sum(from_matrix_cl(lp_inc));
93 return res;
94}
95
96} // namespace math
97} // namespace stan
98#endif
99#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)
isfinite_< as_operation_cl_t< T > > isfinite(T &&a)
auto sum_2d(T &&a)
Two dimensional sum - reduction of a kernel generator expression.
auto check_cl(const char *function, const char *var_name, T &&y, const char *must_be)
Constructs a check on opencl matrix or expression.
Definition check_cl.hpp:219
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
require_all_t< is_kernel_expression< Types >... > require_all_kernel_expressions_t
Enables a template if all given types are are a valid kernel generator expressions.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
Definition copy.hpp:61
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.
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:22
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 ...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9