1#ifndef STAN_MATH_OPENCL_PRIM_CHI_SQUARE_LPDF_HPP
2#define STAN_MATH_OPENCL_PRIM_CHI_SQUARE_LPDF_HPP
35 bool propto,
typename T_y_cl,
typename T_dof_cl,
36 require_all_prim_or_rev_kernel_expression_t<T_y_cl, T_dof_cl>* =
nullptr,
37 require_any_not_stan_scalar_t<T_y_cl, T_dof_cl>* =
nullptr>
40 static constexpr const char* function =
"chi_square_lpdf(OpenCL)";
45 "Degrees of freedom parameter", nu);
58 const auto& nu_val =
value_of(nu_col);
60 auto check_y_nonnegative
61 =
check_cl(function,
"Random variable", y_val,
"nonnegative");
62 auto y_nonnegative_expr = 0 <= y_val;
63 auto check_nu_positive_finite =
check_cl(
64 function,
"Degrees of freedom parameter", nu_val,
"positive finite");
65 auto nu_positive_finite_expr = 0 < nu_val &&
isfinite(nu_val);
67 auto log_y_expr =
log(y_val);
68 auto half_nu_expr = 0.5 * nu_val;
70 auto logp1_expr =
elt_multiply(half_nu_expr - 1, log_y_expr);
71 auto logp2_expr = static_select<include_summand<propto, T_dof_cl>::value>(
75 logp2_expr - 0.5 * y_val, logp2_expr));
77 auto y_deriv_expr =
elt_divide(half_nu_expr - 1, y_val) - 0.5;
85 results(check_y_nonnegative, check_nu_positive_finite, logp_cl, y_deriv_cl,
87 =
expressions(y_nonnegative_expr, nu_positive_finite_expr, logp_expr,
96 partials<0>(ops_partials) = std::move(y_deriv_cl);
99 partials<1>(ops_partials) = std::move(nu_deriv_cl);
101 return ops_partials.build(logp);
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.
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)
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_y_cl, T_dof_cl > chi_square_lpdf(const T_y_cl &y, const T_dof_cl &nu)
The log of a chi-squared density for y with the specified degrees of freedom parameter.
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.
static constexpr double HALF_LOG_TWO
The value of half the natural logarithm 2, .
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
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.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
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 ...
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...