1#ifndef STAN_MATH_OPENCL_PRIM_MULTI_NORMAL_CHOLESKY_LPDF_HPP
2#define STAN_MATH_OPENCL_PRIM_MULTI_NORMAL_CHOLESKY_LPDF_HPP
39template <
bool propto,
typename T_y_cl,
typename T_loc_cl,
typename T_covar_cl,
41 T_covar_cl>* =
nullptr>
43 const T_y_cl& y,
const T_loc_cl& mu,
const T_covar_cl& L) {
44 static constexpr const char* function =
"multi_normal_cholesky_lpdf(OpenCL)";
49 "rows of covariance parameter", L.rows());
62 int L_size = L_val_eval.rows();
63 int N_cases = std::max(y_val.cols(), mu_val.cols());
75 =
check_cl(function,
"Location parameter", mu_val,
"finite");
78 =
check_cl(function,
"Random variable", y_val,
"not nan");
79 auto y_not_nan = !isnan(y_val);
88 if (y_val.cols() == 1 && mu_val.cols() == 1) {
89 results(check_mu_finite, check_y_not_nan, y_mu_diff_cl,
90 sum_log_diag_inv_L_cl)
94 }
else if (y_val.cols() == 1) {
99 }
else if (mu_val.cols() == 1) {
102 sum_log_diag_inv_L));
105 sum_log_diag_inv_L_cl = calc_if<include_summand<propto, T_covar_cl>::value>(
107 results(check_mu_finite, check_y_not_nan, y_mu_diff_cl)
122 if (y_val.cols() == 1) {
123 partials<0>(ops_partials) = -
rowwise_sum(scaled_diff);
125 partials<0>(ops_partials) = -scaled_diff;
129 if (mu_val.cols() == 1) {
130 partials<1>(ops_partials) =
rowwise_sum(scaled_diff);
132 partials<1>(ops_partials) = scaled_diff;
136 partials<2>(ops_partials) = scaled_diff * half - N_cases *
transpose(inv_L);
139 return ops_partials.build(logp);
Represents an arithmetic matrix on the OpenCL device.
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.
auto rowwise_sum(T &&a)
Rowwise sum 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.
auto diagonal(T &&a)
Diagonal of a kernel generator expression.
return_type_t< T_y_cl, T_loc_cl, T_covar_cl > multi_normal_cholesky_lpdf(const T_y_cl &y, const T_loc_cl &mu, const T_covar_cl &L)
The log of the multivariate normal density for the given y, mu, and a Cholesky factor L of the varian...
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_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
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 > log(const fvar< T > &x)
const double NEG_LOG_SQRT_TWO_PI
The value of minus the natural logarithm of the square root of , .
auto rowwise_optional_broadcast(T &&a)
Broadcast an expression in rowwise dimmension if the number of columns equals to 1.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
auto dot_self(const T &a)
Returns squared norm of a vector or matrix.
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.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
Eigen::Matrix< value_type_t< T1 >, T1::RowsAtCompileTime, T2::ColsAtCompileTime > mdivide_left_tri_low(const T1 &A, const T2 &b)
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
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...