1#ifndef STAN_MATH_OPENCL_PRIM_EXP_MOD_NORMAL_LPDF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_EXP_MOD_NORMAL_LPDF_HPP 
   33template <
bool propto, 
typename T_y_cl, 
typename T_loc_cl, 
typename T_scale_cl,
 
   34          typename T_inv_scale_cl,
 
   36              T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl>* = 
nullptr,
 
   38                                        T_inv_scale_cl>* = 
nullptr>
 
   39inline return_type_t<T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl>
 
   41                    const T_scale_cl& sigma, 
const T_inv_scale_cl& lambda) {
 
   42  static constexpr const char* function = 
"exp_mod_normal_lpdf(OpenCL)";
 
   43  using T_partials_return
 
   49                         mu, 
"Scale parameter", sigma, 
"Inv_scale paramter",
 
   51  const size_t N = 
max_size(y, mu, sigma, lambda);
 
   56                       T_inv_scale_cl>::value) {
 
   66  const auto& mu_val = 
value_of(mu_col);
 
   67  const auto& sigma_val = 
value_of(sigma_col);
 
   68  const auto& lambda_val = 
value_of(lambda_col);
 
   71      = 
check_cl(function, 
"Random variable", y_val, 
"not_nan");
 
   72  auto y_not_nan_expr = !isnan(y_val);
 
   74      = 
check_cl(function, 
"Location parameter", mu_val, 
"finite");
 
   75  auto mu_finite_expr = 
isfinite(mu_val);
 
   76  auto check_sigma_positive_finite
 
   77      = 
check_cl(function, 
"Scale parameter", sigma_val, 
"positive finite");
 
   78  auto sigma_positive_finite_expr = 
isfinite(sigma_val) && sigma_val > 0;
 
   79  auto check_lambda_positive_finite = 
check_cl(function, 
"Inv_scale parameter",
 
   80                                               lambda_val, 
"positive finite");
 
   81  auto lambda_positive_finite_expr = 
isfinite(lambda_val) && lambda_val > 0;
 
   83  auto inv_sigma_expr = 
elt_divide(1.0, sigma_val);
 
   85  auto lambda_sigma_sq_expr = 
elt_multiply(lambda_val, sigma_sq_expr);
 
   86  auto mu_minus_y_expr = mu_val - y_val;
 
   87  auto inner_term_expr = 
elt_multiply(mu_minus_y_expr + lambda_sigma_sq_expr,
 
   89  auto erfc_calc_expr = 
erfc(inner_term_expr);
 
   91      = 
elt_multiply(lambda_val, mu_minus_y_expr + 0.5 * lambda_sigma_sq_expr)
 
   92        + 
log(erfc_calc_expr);
 
   95          logp1_expr + 
log(lambda_val), logp1_expr));
 
   97  auto deriv_logerfc_expr
 
  102      = lambda_val + 
elt_multiply(deriv_logerfc_expr, inv_sigma_expr);
 
  103  auto deriv_sigma_expr
 
  107            (lambda_val - 
elt_divide(mu_minus_y_expr, sigma_sq_expr)));
 
  108  auto deriv_lambda_expr = 
elt_divide(1.0, lambda_val) + lambda_sigma_sq_expr
 
  118  results(check_y_not_nan, check_mu_finite, check_sigma_positive_finite,
 
  119          check_lambda_positive_finite, logp_cl, y_deriv_cl, mu_deriv_cl,
 
  120          sigma_deriv_cl, lambda_deriv_cl)
 
  121      = 
expressions(y_not_nan_expr, mu_finite_expr, sigma_positive_finite_expr,
 
  122                    lambda_positive_finite_expr, logp_expr,
 
  123                    calc_if<is_autodiff_v<T_y_cl>>(-deriv_expr),
 
  124                    calc_if<is_autodiff_v<T_loc_cl>>(deriv_expr),
 
  125                    calc_if<is_autodiff_v<T_scale_cl>>(deriv_sigma_expr),
 
  126                    calc_if<is_autodiff_v<T_inv_scale_cl>>(deriv_lambda_expr));
 
  135  if constexpr (is_autodiff_v<T_y_cl>) {
 
  136    partials<0>(ops_partials) = std::move(y_deriv_cl);
 
  138  if constexpr (is_autodiff_v<T_loc_cl>) {
 
  139    partials<1>(ops_partials) = std::move(mu_deriv_cl);
 
  141  if constexpr (is_autodiff_v<T_scale_cl>) {
 
  142    partials<2>(ops_partials) = std::move(sigma_deriv_cl);
 
  144  if constexpr (is_autodiff_v<T_inv_scale_cl>) {
 
  145    partials<3>(ops_partials) = std::move(lambda_deriv_cl);
 
  147  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.
 
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
 
return_type_t< T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl > exp_mod_normal_lpdf(const T_y_cl &y, const T_loc_cl &mu, const T_scale_cl &sigma, const T_inv_scale_cl &lambda)
Returns the log PMF of the exp mod normal distribution.
 
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.
 
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, .
 
static constexpr double LOG_TWO
The natural logarithm 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.
 
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.
 
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...