1#ifndef STAN_MATH_OPENCL_PRIM_BERNOULLI_LPMF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_BERNOULLI_LPMF_HPP 
   29    bool propto, 
typename T_n_cl, 
typename T_prob_cl,
 
   30    require_all_prim_or_rev_kernel_expression_t<T_n_cl, T_prob_cl>* = 
nullptr,
 
   31    require_any_not_stan_scalar_t<T_n_cl, T_prob_cl>* = 
nullptr>
 
   33                                               const T_prob_cl& theta) {
 
   34  static constexpr const char* function = 
"bernoulli_lpmf(OpenCL)";
 
   40                         "Probability parameter", theta);
 
   50  const auto& theta_val = 
value_of(theta_col);
 
   52  T_partials_return logp(0.0);
 
   55  auto check_n_bounded = 
check_cl(function, 
"n", n, 
"in the interval [0, 1]");
 
   56  auto n_bounded_expr = 0 <= n && n <= 1;
 
   58  if constexpr (is_theta_vector) {
 
   61    auto deriv_expr = 
inv(theta_val + 
select(n == 1, 0, -1));
 
   63    auto check_theta_bounded = 
check_cl(function, 
"Probability parameter",
 
   64                                        theta_val, 
"in the interval [0, 1]");
 
   65    auto theta_bounded_expr = 0 <= theta_val && theta_val <= 1;
 
   70    results(logp_cl, deriv_cl, check_n_bounded, check_theta_bounded)
 
   72                      n_bounded_expr, theta_bounded_expr);
 
   76    if constexpr (is_autodiff_v<T_prob_cl>) {
 
   77      partials<0>(ops_partials) = deriv_cl;
 
   84    results(n_sum_cl, check_n_bounded)
 
   88    double theta_val_scal = theta_val;
 
   90      logp = N * 
log(theta_val_scal);
 
   91    } 
else if (n_sum == 0) {
 
   92      logp = N * 
log1m(theta_val_scal);
 
   94      logp = n_sum * 
log(theta_val_scal) + (N - n_sum) * 
log1m(theta_val_scal);
 
   96    if constexpr (is_autodiff_v<T_prob_cl>) {
 
   97      double& edge1_partial = partials<0>(ops_partials)[0];
 
   99        edge1_partial += N / theta_val_scal;
 
  100      } 
else if (n_sum == 0) {
 
  101        edge1_partial += N / (theta_val_scal - 1);
 
  104            += n_sum / theta_val_scal + (N - n_sum) / (theta_val_scal - 1);
 
  108  return ops_partials.build(logp);
 
Represents an arithmetic matrix on the OpenCL device.
 
select_< as_operation_cl_t< T_condition >, as_operation_cl_t< T_then >, as_operation_cl_t< T_else > > select(T_condition &&condition, T_then &&then, T_else &&els)
Selection operation on kernel generator expressions.
 
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 rowwise_sum(T &&a)
Rowwise sum reduction of a kernel generator expression.
 
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_prob_cl > bernoulli_lpmf(const T_n_cl &n, const T_prob_cl &theta)
Returns the log PMF of the Bernoulli distribution.
 
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
 
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
 
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
 
T value_of(const fvar< T > &v)
Return the value of the specified variable.
 
fvar< T > log(const fvar< T > &x)
 
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
 
fvar< T > log1p(const fvar< T > &x)
 
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
 
fvar< T > log1m(const fvar< T > &x)
 
fvar< T > inv(const fvar< T > &x)
 
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
 
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 ...
 
Checks if decayed type is a var, fvar, or arithmetic.
 
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...