1#ifndef STAN_MATH_OPENCL_PRIM_BINOMIAL_LOGIT_GLM_LPMF_HPP
2#define STAN_MATH_OPENCL_PRIM_BINOMIAL_LOGIT_GLM_LPMF_HPP
28template <
bool propto,
typename T_n_cl,
typename T_N_cl,
typename T_x_cl,
29 typename T_alpha_cl,
typename T_beta_cl,
31 T_n_cl, T_N_cl, T_x_cl, T_alpha_cl, T_beta_cl>* =
nullptr>
33 const T_n_cl& n,
const T_N_cl& N,
const T_x_cl& x,
const T_alpha_cl& alpha,
34 const T_beta_cl&
beta) {
35 static const char* function =
"binomial_logit_glm_lpmf(OpenCL)";
40 const size_t N_instances
41 =
max(
max_size(n, N, alpha),
static_cast<int64_t
>(x.rows()));
42 const size_t N_attributes = x.cols();
45 "Population size parameter", N);
51 if (N_instances == 0 || N_attributes == 0) {
63 =
check_cl(function,
"Successes variable", n,
"in the interval [0, N]");
64 auto n_bounded = 0 <= n && n <= N;
65 auto check_N_nonnegative
66 =
check_cl(function,
"Population size variable", n,
"nonnegative");
67 auto N_nonnegative = N >= 0;
76 = static_select<include_summand<propto, T_n_cl, T_N_cl>::value>(
79 constexpr bool need_theta_deriv
83 constexpr bool need_theta_deriv_sum = need_theta_deriv && !is_alpha_vector;
88 results(check_n_bounded, check_N_nonnegative, logp_cl, theta_deriv_cl,
91 n_bounded, N_nonnegative, logp_expr,
92 calc_if<need_theta_deriv>(theta_deriv_expr),
93 calc_if<need_theta_deriv_sum>(
colwise_sum(theta_deriv_expr)));
99 check_cl(function,
"Weight vector", beta_val,
"finite")
101 check_cl(function,
"Matrix of independent variables", x_val,
"finite")
110 if (is_alpha_vector) {
111 partials<1>(ops_partials) = theta_deriv_cl;
113 forward_as<internal::broadcast_array<double>>(
114 partials<1>(ops_partials))[0]
121 theta_deriv_cl.
buffer(), 1, theta_deriv_cl.
rows());
123 = theta_derivative_transpose_cl * x_val;
124 partials<2>(ops_partials)
126 edge3_partials_transpose_cl.
cols(), 1);
127 if (beta_val.rows() != 0) {
128 edge<2>(ops_partials)
129 .partials_.add_write_event(
133 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)
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.
binomial_coefficient_log_< as_operation_cl_t< T1 >, as_operation_cl_t< T2 > > binomial_coefficient_log(T1 &&a, T2 &&b)
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.
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.
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if x is consistent with size expected_size.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log_inv_logit(const fvar< T > &x)
auto max(T1 x, T2 y)
Returns the maximum value of the two specified scalar arguments.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
return_type_t< T_x_cl, T_alpha_cl, T_beta_cl > binomial_logit_glm_lpmf(const T_n_cl &n, const T_N_cl &N, const T_x_cl &x, const T_alpha_cl &alpha, const T_beta_cl &beta)
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.
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.
fvar< T > log1m_inv_logit(const fvar< T > &x)
Return the natural logarithm of one minus the inverse logit of the specified argument.
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...