1#ifndef STAN_MATH_OPENCL_PRIM_ORDERED_LOGISTIC_GLM_LPMF_HPP
2#define STAN_MATH_OPENCL_PRIM_ORDERED_LOGISTIC_GLM_LPMF_HPP
48template <
bool propto,
typename T_y,
typename T_x,
typename T_beta,
53 const T_y& y,
const T_x& x,
const T_beta&
beta,
const T_cuts& cuts) {
57 using Eigen::VectorXd;
62 static constexpr const char* function =
"ordered_logistic_glm_lpmf";
64 const size_t N_instances = x.rows();
65 const size_t N_attributes = x.cols();
79 check_cl(function,
"Cuts", cuts_head,
"ordered and finite")
85 if (N_instances == 0 || N_classes == 1) {
100 const int wgs = (N_instances + local_size - 1) / local_size;
109 need_cuts_derivative ? wgs : 0);
113 cl::NDRange(local_size * wgs), cl::NDRange(local_size), location_sum_cl,
114 logp_cl, location_derivative_cl, cuts_derivative_cl, y_val_cl, x_val,
115 beta_val, cuts_val, N_instances, N_attributes, N_classes, is_y_vector,
116 need_location_derivative, need_cuts_derivative);
117 }
catch (
const cl::Error&
e) {
124 check_cl(function,
"Vector of dependent variables", y_val,
125 "between 0 and number of classes")
126 = y_val >= 1 && y_val <= static_cast<int>(N_classes);
128 check_cl(function,
"Weight vector", beta_val,
"finite")
134 partials<0>(ops_partials)
140 edge2_partials_transpose.
buffer(), edge2_partials_transpose.
cols(),
141 edge2_partials_transpose.
rows());
142 if (
beta.rows() != 0) {
143 edge<1>(ops_partials)
144 .partials_.add_write_event(
150 partials<2>(ops_partials) = std::move(cuts_derivative_cl);
152 partials<2>(ops_partials) =
rowwise_sum(cuts_derivative_cl);
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.
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.
auto block_zero_based(T &&a, int start_row, int start_col, int rows, int cols)
Block of a kernel generator expression.
auto transpose(Arg &&a)
Transposes a kernel generator expression.
auto rowwise_sum(T &&a)
Rowwise sum reduction of a kernel generator expression.
const kernel_cl< out_buffer, out_buffer, out_buffer, out_buffer, in_buffer, in_buffer, in_buffer, in_buffer, int, int, int, int, int, int > ordered_logistic_glm("ordered_logistic_glm", {log1p_exp_device_function, log1m_exp_device_function, inv_logit_device_function, ordered_logistic_glm_kernel_code}, {{"REDUCTION_STEP_SIZE", 4}, {"LOCAL_SIZE_", 64}})
See the docs for ordered_logistic_glm() .
return_type_t< T_x, T_beta, T_cuts > ordered_logistic_glm_lpmf(const T_y &y, const T_x &x, const T_beta &beta, const T_cuts &cuts)
Returns the log PMF of the ordinal regression Generalized Linear Model (GLM).
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...
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 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.
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.
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...