1#ifndef STAN_MATH_OPENCL_PRIM_BETA_PROPORTION_LPDF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_BETA_PROPORTION_LPDF_HPP 
   38template <
bool propto, 
typename T_y_cl, 
typename T_loc_cl, 
typename T_prec_cl,
 
   40                                                      T_prec_cl>* = 
nullptr,
 
   41          require_any_not_stan_scalar_t<T_y_cl, T_loc_cl, T_prec_cl>* = 
nullptr>
 
   43    const T_y_cl& y, 
const T_loc_cl& mu, 
const T_prec_cl& kappa) {
 
   44  static constexpr const char* function = 
"beta_proportion_lpdf(OpenCL)";
 
   49                         mu, 
"Precision parameter", kappa);
 
   50  const size_t N = 
max_size(y, mu, kappa);
 
   63  const auto& mu_val = 
value_of(mu_col);
 
   64  const auto& kappa_val = 
value_of(kappa_col);
 
   67      = 
check_cl(function, 
"Random variable", y_val, 
"in the interval [0, 1]");
 
   68  auto y_bounded_expr = 0 <= y_val && y_val <= 1;
 
   69  auto check_mu_bounded = 
check_cl(function, 
"Location parameter", mu_val,
 
   70                                   "in the interval (0, 1)");
 
   71  auto mu_bounded_expr = 0 < mu_val && mu_val < 1;
 
   72  auto check_kappa_positive_finite = 
check_cl(
 
   73      function, 
"Precision parameter", kappa_val, 
"in the interval [0, 1]");
 
   74  auto kappa_positive_finite = 0 < kappa_val && 
isfinite(kappa_val);
 
   76  auto log_y_expr = 
log(y_val);
 
   77  auto log1m_y_expr = 
log1p(-y_val);
 
   81      + 
elt_multiply(kappa_val - mukappa_expr - 1, log1m_y_expr)
 
   85          lgamma(mukappa_expr) + 
lgamma(kappa_val - mukappa_expr), 0));
 
   86  auto y_deriv_expr = 
elt_divide(mukappa_expr - 1, y_val)
 
   87                      + 
elt_divide(kappa_val - mukappa_expr - 1, y_val - 1);
 
   88  auto digamma_mukappa_expr = 
digamma(mukappa_expr);
 
   89  auto digamma_kappa_mukappa_expr = 
digamma(kappa_val - mukappa_expr);
 
   90  auto mu_deriv_expr = 
elt_multiply(kappa_val, digamma_kappa_mukappa_expr
 
   91                                                   - digamma_mukappa_expr
 
   92                                                   + log_y_expr - log1m_y_expr);
 
   95        + 
elt_multiply(mu_val, log_y_expr - digamma_mukappa_expr)
 
   96        + 
elt_multiply(1 - mu_val, log1m_y_expr - digamma_kappa_mukappa_expr);
 
  103  results(check_y_bounded, check_mu_bounded, check_kappa_positive_finite,
 
  104          logp_cl, y_deriv_cl, mu_deriv_cl, kappa_deriv_cl)
 
  105      = 
expressions(y_bounded_expr, mu_bounded_expr, kappa_positive_finite,
 
  106                    logp_expr, 
calc_if<is_autodiff_v<T_y_cl>>(y_deriv_expr),
 
  107                    calc_if<is_autodiff_v<T_loc_cl>>(mu_deriv_expr),
 
  108                    calc_if<is_autodiff_v<T_prec_cl>>(kappa_deriv_expr));
 
  113  if constexpr (is_autodiff_v<T_y_cl>) {
 
  114    partials<0>(ops_partials) = std::move(y_deriv_cl);
 
  116  if constexpr (is_autodiff_v<T_loc_cl>) {
 
  117    partials<1>(ops_partials) = std::move(mu_deriv_cl);
 
  119  if constexpr (is_autodiff_v<T_prec_cl>) {
 
  120    partials<2>(ops_partials) = std::move(kappa_deriv_cl);
 
  123  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_prec_cl > beta_proportion_lpdf(const T_y_cl &y, const T_loc_cl &mu, const T_prec_cl &kappa)
The log of the beta density for specified y, location, and precision: beta_proportion_lpdf(y | mu,...
 
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.
 
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
 
T value_of(const fvar< T > &v)
Return the value of the specified variable.
 
fvar< T > log(const fvar< T > &x)
 
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 > log1p(const fvar< T > &x)
 
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
 
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 > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
 
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 ...
 
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...