1#ifndef STAN_MATH_OPENCL_PRIM_POISSON_LPMF_HPP
2#define STAN_MATH_OPENCL_PRIM_POISSON_LPMF_HPP
28 bool propto,
typename T_n_cl,
typename T_rate_cl,
29 require_all_prim_or_rev_kernel_expression_t<T_n_cl, T_rate_cl>* =
nullptr,
30 require_any_not_stan_scalar_t<T_n_cl, T_rate_cl>* =
nullptr>
32 const T_rate_cl& lambda) {
33 static constexpr const char* function =
"poisson_lpmf(OpenCL)";
49 const auto& lambda_val =
value_of(lambda_col);
51 T_partials_return logp(0.0);
54 auto check_n_nonnegative
55 =
check_cl(function,
"Random variable", n,
"nonnegative");
56 auto n_nonnegative = 0 <= n;
57 auto check_lambda_nonnegative
58 =
check_cl(function,
"Log rate parameter", lambda_val,
"nonnegative");
59 auto lambda_nonnegative = 0.0 <= lambda_val;
62 cast<char>(isinf(lambda_val) || (lambda_val == 0 && n != 0)));
65 auto logp2 = static_select<include_summand<propto, T_rate_cl>::value>(
66 logp1 - lambda_val, logp1);
68 logp2 -
lgamma(n + 1.0), logp2));
76 results(check_n_nonnegative, check_lambda_nonnegative, return_log_zero_cl,
78 =
expressions(n_nonnegative, lambda_nonnegative, return_log_zero,
89 partials<0>(ops_partials) = deriv_cl;
92 return ops_partials.build(logp);
Represents an arithmetic matrix on the OpenCL device.
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_max(T &&a)
Column wise max - 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_rate_cl > poisson_lpmf(const T_n_cl &n, const T_rate_cl &lambda)
Returns the log PMF of the Poisson 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>>.
static constexpr double LOG_ZERO
The natural logarithm of 0, .
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
constexpr bool any(T x)
Return true if any values in the input are true.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
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 > 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.
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 ...
bool isinf(const stan::math::var &a)
Return 1 if the specified argument is positive infinity or negative infinity and 0 otherwise.
Checks if decayed type is a var, fvar, or arithmetic.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...