1#ifndef STAN_MATH_OPENCL_PRIM_DOUBLE_EXP_MOD_NORMAL_CDF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_DOUBLE_EXP_MOD_NORMAL_CDF_HPP 
   30template <
typename T_y_cl, 
typename T_loc_cl, 
typename T_scale_cl,
 
   31          typename T_inv_scale_cl,
 
   33              T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl>* = 
nullptr,
 
   35                                        T_inv_scale_cl>* = 
nullptr>
 
   36inline return_type_t<T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl>
 
   38                   const T_inv_scale_cl& lambda) {
 
   39  static constexpr const char* function = 
"exp_mod_normal_cdf(OpenCL)";
 
   40  using T_partials_return
 
   46                         mu, 
"Scale parameter", sigma);
 
   47  const size_t N = 
max_size(y, mu, sigma);
 
   58  const auto& mu_val = 
value_of(mu_col);
 
   59  const auto& sigma_val = 
value_of(sigma_col);
 
   60  const auto& lambda_val = 
value_of(lambda_col);
 
   63      = 
check_cl(function, 
"Random variable", y_val, 
"not NaN");
 
   64  auto y_not_nan_expr = !isnan(y_val);
 
   66      = 
check_cl(function, 
"Location parameter", mu_val, 
"finite");
 
   67  auto mu_finite_expr = 
isfinite(mu_val);
 
   68  auto check_sigma_positive_finite
 
   69      = 
check_cl(function, 
"Scale parameter", sigma_val, 
"positive finite");
 
   70  auto sigma_positive_finite_expr = 0 < sigma_val && 
isfinite(sigma_val);
 
   71  auto check_lambda_positive_finite
 
   72      = 
check_cl(function, 
"Inv_cale parameter", lambda_val, 
"positive finite");
 
   73  auto lambda_positive_finite_expr = 0 < lambda_val && 
isfinite(lambda_val);
 
   77  auto diff = y_val - mu_val;
 
   81  auto erf_calc = 0.5 * (1.0 + 
erf(scaled_diff_diff));
 
   83  auto cdf_n = 0.5 + 0.5 * 
erf(scaled_diff) - 
elt_multiply(exp_term, erf_calc);
 
   86  auto exp_term_2 = 
exp(-
square(scaled_diff_diff));
 
   92  auto mu_deriv1 = 
elt_divide(deriv_2 - deriv_1 - deriv_3, cdf_n);
 
  111  results(check_y_not_nan, check_mu_finite, check_sigma_positive_finite,
 
  112          check_lambda_positive_finite, any_y_neg_inf_cl, cdf_cl, y_deriv_cl,
 
  113          mu_deriv_cl, sigma_deriv_cl, lambda_deriv_cl)
 
  114      = 
expressions(y_not_nan_expr, mu_finite_expr, sigma_positive_finite_expr,
 
  115                    lambda_positive_finite_expr, any_y_neg_inf, cdf_expr,
 
  117                                              T_inv_scale_cl>>(cdf_n),
 
  118                    calc_if<is_any_autodiff_v<T_y_cl, T_loc_cl>>(mu_deriv1),
 
  119                    calc_if<is_autodiff_v<T_scale_cl>>(sigma_deriv1),
 
  120                    calc_if<is_autodiff_v<T_inv_scale_cl>>(lambda_deriv1));
 
  135    auto y_deriv = -mu_deriv;
 
  137        static_select<is_constant_v<T_scale_cl>>(0, sigma_deriv_cl), cdf);
 
  139        static_select<is_constant_v<T_inv_scale_cl>>(0, lambda_deriv_cl), cdf);
 
  141    results(y_deriv_cl, mu_deriv_cl, sigma_deriv_cl, lambda_deriv_cl)
 
  143                      calc_if<is_autodiff_v<T_loc_cl>>(mu_deriv),
 
  144                      calc_if<is_autodiff_v<T_scale_cl>>(sigma_deriv),
 
  145                      calc_if<is_autodiff_v<T_inv_scale_cl>>(lambda_deriv));
 
  147    if constexpr (is_autodiff_v<T_y_cl>) {
 
  148      partials<0>(ops_partials) = std::move(y_deriv_cl);
 
  150    if constexpr (is_autodiff_v<T_loc_cl>) {
 
  151      partials<1>(ops_partials) = std::move(mu_deriv_cl);
 
  153    if constexpr (is_autodiff_v<T_scale_cl>) {
 
  154      partials<2>(ops_partials) = std::move(sigma_deriv_cl);
 
  156    if constexpr (is_autodiff_v<T_inv_scale_cl>) {
 
  157      partials<3>(ops_partials) = std::move(lambda_deriv_cl);
 
  160  return ops_partials.build(cdf);
 
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.
 
auto colwise_prod(T &&a)
Column wise product - reduction 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)
 
auto colwise_max(T &&a)
Column wise max - reduction of a kernel generator expression.
 
calc_if_< true, as_operation_cl_t< T > > calc_if(T &&a)
 
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_inv_scale_cl > exp_mod_normal_cdf(const T_y_cl &y, const T_loc_cl &mu, const T_scale_cl &sigma, const T_inv_scale_cl &lambda)
Returns the double exponential cumulative density function.
 
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.
 
value_type_t< T > prod(const T &m)
Calculates product of given kernel generator expression elements.
 
T value_of(const fvar< T > &v)
Return the value of the specified variable.
 
fvar< T > erf(const fvar< T > &x)
 
static constexpr double INV_SQRT_TWO
The value of 1 over the square root of 2, .
 
static constexpr double INV_SQRT_TWO_PI
The value of 1 over the square root of , .
 
static constexpr double NEGATIVE_INFTY
Negative infinity.
 
static constexpr double SQRT_TWO
The value of 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.
 
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 > square(const fvar< T > &x)
 
fvar< T > exp(const fvar< T > &x)
 
constexpr bool is_any_autodiff_v
 
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.
 
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...