1#ifndef STAN_MATH_OPENCL_PRIM_NEG_BINOMIAL_2_LOG_GLM_LPMF_HPP 
    2#define STAN_MATH_OPENCL_PRIM_NEG_BINOMIAL_2_LOG_GLM_LPMF_HPP 
   64template <
bool propto, 
typename T_y_cl, 
typename T_x_cl, 
typename T_alpha_cl,
 
   65          typename T_beta_cl, 
typename T_phi_cl,
 
   67              T_x_cl, T_y_cl, T_alpha_cl, T_beta_cl, T_phi_cl>* = 
nullptr>
 
   68inline return_type_t<T_x_cl, T_alpha_cl, T_beta_cl, T_phi_cl>
 
   70                            const T_alpha_cl& alpha, 
const T_beta_cl& 
beta,
 
   71                            const T_phi_cl& phi) {
 
   72  static constexpr const char* function = 
"neg_binomial_2_log_glm_lpmf(OpenCL)";
 
   73  using T_partials_return
 
   81  const size_t N = x.rows();
 
   82  const size_t M = x.cols();
 
   84  if constexpr (is_y_vector) {
 
   90  if constexpr (is_phi_vector) {
 
   94  if constexpr (is_alpha_vector) {
 
  119  const int wgs = (N + local_size - 1) / local_size;
 
  121  const bool need_theta_derivative
 
  122      = is_any_autodiff_v<T_x_cl, T_beta_cl, T_alpha_cl>;
 
  124  const bool need_theta_derivative_sum
 
  125      = need_theta_derivative && !is_alpha_vector;
 
  127  const bool need_phi_derivative_sum = !is_alpha_vector;
 
  128  const bool need_phi_derivative
 
  129      = is_autodiff_v<T_phi_cl> || need_phi_derivative_sum;
 
  131      need_phi_derivative ? (need_phi_derivative_sum ? wgs : N) : 0, 1);
 
  133  const bool need_logp2
 
  135  const bool need_logp3
 
  138                          && (is_y_vector || is_phi_vector);
 
  143        cl::NDRange(local_size * wgs), cl::NDRange(local_size), logp_cl,
 
  144        theta_derivative_cl, theta_derivative_sum_cl, phi_derivative_cl,
 
  145        y_val_cl, x_val, alpha_val_cl, beta_val, phi_val_cl, N, M, is_y_vector,
 
  146        is_alpha_vector, is_phi_vector, need_theta_derivative,
 
  147        need_theta_derivative_sum, need_phi_derivative, need_phi_derivative_sum,
 
  148        need_logp1, need_logp2, need_logp3, need_logp4);
 
  149  } 
catch (
const cl::Error& 
e) {
 
  154  if (!std::isfinite(logp)) {
 
  156        check_cl(function, 
"Vector of dependent variables", y_val,
 
  158        check_cl(function, 
"Intercept", alpha_val, 
"finite"),
 
  159        check_cl(function, 
"Precision parameter", phi_val, 
"positive finite"))
 
  163    check_cl(function, 
"Weight vector", beta_val, 
"finite")
 
  166    check_cl(function, 
"Precision parameter", phi_val, 
"positive finite")
 
  175    logp += 
lgamma(y_val + phi_val) * N;
 
  180  if constexpr (is_autodiff_v<T_x_cl>) {
 
  181    partials<0>(ops_partials)
 
  184  if constexpr (is_autodiff_v<T_beta_cl>) {
 
  187        theta_derivative_cl.
buffer(), 1, theta_derivative_cl.
rows());
 
  189        = theta_derivative_transpose_cl * x_val;
 
  190    partials<2>(ops_partials)
 
  192                            edge3_partials_transpose_cl.
cols(), 1);
 
  193    if (beta_val.rows() != 0) {
 
  194      edge<2>(ops_partials)
 
  195          .partials_.add_write_event(
 
  199  if constexpr (is_autodiff_v<T_alpha_cl>) {
 
  200    if constexpr (is_alpha_vector) {
 
  201      partials<1>(ops_partials) = std::move(theta_derivative_cl);
 
  203      partials<1>(ops_partials)[0]
 
  207  if constexpr (is_autodiff_v<T_phi_cl>) {
 
  208    if constexpr (is_phi_vector) {
 
  209      partials<3>(ops_partials) = std::move(phi_derivative_cl);
 
  214  return ops_partials.build(logp);
 
const cl::Buffer & buffer() const
 
const tbb::concurrent_vector< cl::Event > & write_events() const
Get the events from the event stacks.
 
Represents an arithmetic matrix on the OpenCL device.
 
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occurred.
 
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 transpose(Arg &&a)
Transposes a kernel generator expression.
 
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
 
const kernel_cl< out_buffer, out_buffer, out_buffer, out_buffer, in_buffer, in_buffer, in_buffer, in_buffer, in_buffer, int, int, int, int, int, int, int, int, int, int, int, int, int > neg_binomial_2_log_glm("neg_binomial_2_log_glm", {digamma_device_function, log1p_exp_device_function, neg_binomial_2_log_glm_kernel_code}, {{"REDUCTION_STEP_SIZE", 4}, {"LOCAL_SIZE_", 64}})
See the docs for neg_binomial_2_log_glm_lpmf() .
 
matrix_cl< scalar_type_t< T > > to_matrix_cl(T &&src)
Copies the source Eigen matrix, std::vector or scalar to the destination matrix that is stored on the...
 
return_type_t< T_x_cl, T_alpha_cl, T_beta_cl, T_phi_cl > neg_binomial_2_log_glm_lpmf(const T_y_cl &y, const T_x_cl &x, const T_alpha_cl &alpha, const T_beta_cl &beta, const T_phi_cl &phi)
Returns the log PMF of the Generalized Linear Model (GLM) with Negative-Binomial-2 distribution and l...
 
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.
 
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
 
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
 
static constexpr double e()
Return the base of the natural logarithm.
 
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
 
T value_of(const fvar< T > &v)
Return the value of the specified variable.
 
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.
 
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
 
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.
 
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...