1#ifndef STAN_MATH_OPENCL_PRIM_POISSON_LOG_GLM_LPMF_HPP
2#define STAN_MATH_OPENCL_PRIM_POISSON_LOG_GLM_LPMF_HPP
50template <
bool propto,
typename T_y_cl,
typename T_x_cl,
typename T_alpha_cl,
53 T_y_cl, T_x_cl, T_alpha_cl, T_beta_cl>* =
nullptr>
55 const T_y_cl& y,
const T_x_cl& x,
const T_alpha_cl& alpha,
56 const T_beta_cl&
beta) {
57 static constexpr const char* function =
"poisson_log_glm_lpmf(OpenCL)";
65 const size_t N = x.rows();
66 const size_t M = x.cols();
74 if (is_alpha_vector) {
88 const auto& alpha_val =
value_of(alpha);
91 T_partials_return logp(0);
96 auto exp_theta_expr =
exp(theta_expr);
97 auto theta_derivative_expr =
select(y_val < 0 || !
isfinite(theta_expr),
103 const int wgs = logp_expr.rows();
110 theta_derivative_expr,
colwise_sum(theta_derivative_expr), logp_expr);
114 if (!std::isfinite(theta_derivative_sum)) {
117 check_cl(function,
"Intercept", alpha_val,
"finite"))
119 check_cl(function,
"Weight vector", beta_val,
"finite")
121 check_cl(function,
"Matrix of independent variables", x_val,
"finite")
128 partials<0>(ops_partials)
132 if (is_alpha_vector) {
133 partials<1>(ops_partials) = theta_derivative_cl;
135 forward_as<internal::broadcast_array<double>>(
136 partials<1>(ops_partials))[0]
137 = theta_derivative_sum;
143 theta_derivative_cl.
buffer(), 1, theta_derivative_cl.
rows());
145 = theta_derivative_transpose_cl * x_val;
146 partials<2>(ops_partials)
148 edge3_partials_transpose_cl.
cols(), 1);
149 if (beta_val.rows() != 0) {
150 edge<2>(ops_partials)
151 .partials_.add_write_event(
155 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.
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)
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 transpose(Arg &&a)
Transposes a kernel generator expression.
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_x_cl, T_alpha_cl, T_beta_cl > poisson_log_glm_lpmf(const T_y_cl &y, const T_x_cl &x, const T_alpha_cl &alpha, const T_beta_cl &beta)
Returns the log PMF of the Generalized Linear Model (GLM) with Poisson distribution and log link func...
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.
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 NOT_A_NUMBER
(Quiet) not-a-number value.
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 matrix_vector_multiply(T_matrix &&matrix, T_vector &&vector)
Multiplies a matrix and a vector on an OpenCL device.
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.
fvar< T > exp(const fvar< T > &x)
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.
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...