1#ifndef STAN_MATH_OPENCL_PRIM_SKEW_NORMAL_LPDF_HPP
2#define STAN_MATH_OPENCL_PRIM_SKEW_NORMAL_LPDF_HPP
36template <
bool propto,
typename T_y_cl,
typename T_loc_cl,
typename T_scale_cl,
39 T_y_cl, T_loc_cl, T_scale_cl, T_shape_cl>* =
nullptr,
41 T_shape_cl>* =
nullptr>
43 const T_y_cl& y,
const T_loc_cl& mu,
const T_scale_cl& sigma,
44 const T_shape_cl& alpha) {
45 static constexpr const char* function =
"skew_normal_lpdf(OpenCL)";
46 using T_partials_return
52 mu,
"Scale parameter", sigma,
"Shape paramter", alpha);
53 const size_t N =
max_size(y, mu, sigma, alpha);
68 const auto& mu_val =
value_of(mu_col);
69 const auto& sigma_val =
value_of(sigma_col);
70 const auto& alpha_val =
value_of(alpha_col);
73 =
check_cl(function,
"Random variable", y_val,
"not NaN");
74 auto y_not_nan = !isnan(y_val);
76 =
check_cl(function,
"Location parameter", mu_val,
"finite");
78 auto check_sigma_positive
79 =
check_cl(function,
"Scale parameter", sigma_val,
"positive");
80 auto sigma_positive = 0 < sigma_val;
81 auto check_alpha_finite
82 =
check_cl(function,
"Shape parameter", alpha_val,
"finite");
83 auto alpha_finite =
isfinite(alpha_val);
86 auto y_minus_mu_over_sigma =
elt_multiply((y_val - mu_val), inv_sigma);
87 auto log_erfc_alpha_z =
log(
90 auto logp1 = log_erfc_alpha_z;
91 auto logp2 = static_select<include_summand<propto, T_scale_cl>::value>(
92 logp1 -
log(sigma_val), logp1);
97 -
elt_multiply(y_minus_mu_over_sigma, y_minus_mu_over_sigma)
105 y_minus_mu_over_sigma -
elt_multiply(deriv_logerf, alpha_val), inv_sigma);
109 y_minus_mu_over_sigma)
112 auto alpha_deriv =
elt_multiply(deriv_logerf, y_minus_mu_over_sigma);
120 results(check_y_not_nan, check_mu_finite, check_sigma_positive,
121 check_alpha_finite, logp_cl, y_deriv_cl, mu_deriv_cl, sigma_deriv_cl,
123 =
expressions(y_not_nan, mu_finite, sigma_positive, alpha_finite,
140 partials<0>(ops_partials) = std::move(y_deriv_cl);
143 partials<1>(ops_partials) = std::move(mu_deriv_cl);
146 partials<2>(ops_partials) = std::move(sigma_deriv_cl);
149 partials<3>(ops_partials) = std::move(alpha_deriv_cl);
151 return ops_partials.build(logp);
Represents an arithmetic matrix on the OpenCL device.
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 check_cl(const char *function, const char *var_name, T &&y, const char *must_be)
Constructs a check on opencl matrix or expression.
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
calc_if_< true, as_operation_cl_t< T > > calc_if(T &&a)
auto colwise_sum(T &&a)
Column wise sum - reduction of a kernel generator expression.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
return_type_t< T_y_cl, T_loc_cl, T_scale_cl, T_shape_cl > skew_normal_lpdf(const T_y_cl &y, const T_loc_cl &mu, const T_scale_cl &sigma, const T_shape_cl &alpha)
The log of the skew normal density for the specified scalar(s) given the specified mean(s),...
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
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.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
static constexpr double SQRT_TWO_OVER_SQRT_PI
The square root of 2 divided by the square root of , .
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
static constexpr double INV_SQRT_TWO
The value of 1 over the square root of 2, .
T1 static_select(T1 &&a, T2 &&b)
Returns one of the arguments that can be of different type, depending on the compile time condition.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > erfc(const fvar< T > &x)
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
static constexpr double HALF_LOG_TWO_PI
The value of half the natural logarithm , .
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
fvar< T > exp(const fvar< T > &x)
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
bool isnan(const stan::math::var &a)
Checks if the given number is NaN.
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...