1#ifndef STAN_MATH_OPENCL_PRIM_BETA_LPDF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_BETA_LPDF_HPP 
   37template <
bool propto, 
typename T_y_cl, 
typename T_scale_succ_cl,
 
   38          typename T_scale_fail_cl,
 
   40              T_y_cl, T_scale_succ_cl, T_scale_fail_cl>* = 
nullptr,
 
   42                                        T_scale_fail_cl>* = 
nullptr>
 
   44    const T_y_cl& y, 
const T_scale_succ_cl& alpha,
 
   45    const T_scale_fail_cl& 
beta) {
 
   47  static constexpr const char* function = 
"beta_lpdf(OpenCL)";
 
   48  using T_partials_return
 
   52                         "First shape parameter", alpha,
 
   53                         "Second shape parameter", 
beta);
 
   59                       T_scale_fail_cl>::value) {
 
   68  const auto& alpha_val = 
value_of(alpha_col);
 
   69  const auto& beta_val = 
value_of(beta_col);
 
   73  auto check_alpha_pos_finite = 
check_cl(function, 
"First shape parameter",
 
   74                                         alpha_val, 
"positive finite");
 
   75  auto alpha_pos_finite = alpha_val > 0 && 
isfinite(alpha_val);
 
   76  auto check_beta_pos_finite = 
check_cl(function, 
"Second shape parameter",
 
   77                                        beta_val, 
"positive finite");
 
   78  auto beta_pos_finite = beta_val > 0 && 
isfinite(beta_val);
 
   80      = 
check_cl(function, 
"Random variable", y_val, 
"in the interval [0, 1]");
 
   81  auto y_bounded = 0 <= y_val && y_val <= 1;
 
   83  auto log_y_expr = 
log(y_val);
 
   84  auto log1m_y_expr = 
log1p(-y_val);
 
   85  auto alpha_beta_expr = alpha_val + beta_val;
 
   91          -
lgamma(alpha_val), zero_expr)
 
   93          -
lgamma(beta_val), zero_expr)
 
  100          lgamma(alpha_beta_expr), zero_expr));
 
  102  auto y_deriv_expr = calc_if<is_autodiff_v<T_y_cl>>(
 
  105  auto digamma_alpha_beta_expr = 
digamma(alpha_beta_expr);
 
  106  auto alpha_deriv_expr = calc_if<is_autodiff_v<T_scale_succ_cl>>(
 
  107      log_y_expr + digamma_alpha_beta_expr - 
digamma(alpha_val));
 
  108  auto beta_deriv_expr = calc_if<is_autodiff_v<T_scale_fail_cl>>(
 
  109      log1m_y_expr + digamma_alpha_beta_expr - 
digamma(beta_val));
 
  116  results(check_alpha_pos_finite, check_beta_pos_finite, check_y_bounded,
 
  117          logp_cl, y_deriv_cl, alpha_deriv_cl, beta_deriv_cl)
 
  118      = 
expressions(alpha_pos_finite, beta_pos_finite, y_bounded, logp_expr,
 
  119                    y_deriv_expr, alpha_deriv_expr, beta_deriv_expr);
 
  123  if constexpr (is_autodiff_v<T_y_cl>) {
 
  124    partials<0>(ops_partials) = std::move(y_deriv_cl);
 
  126  if constexpr (is_autodiff_v<T_scale_succ_cl>) {
 
  127    partials<1>(ops_partials) = std::move(alpha_deriv_cl);
 
  129  if constexpr (is_autodiff_v<T_scale_fail_cl>) {
 
  130    partials<2>(ops_partials) = std::move(beta_deriv_cl);
 
  133  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)
 
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.
 
T_operation && as_operation_cl(T_operation &&a)
Converts any valid kernel generator expression into an operation.
 
return_type_t< T_y_cl, T_scale_succ_cl, T_scale_fail_cl > beta_lpdf(const T_y_cl &y, const T_scale_succ_cl &alpha, const T_scale_fail_cl &beta)
The log of the beta density for the specified scalar(s) given the specified sample stan::math::size(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.
 
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.
 
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
 
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...