1#ifndef STAN_MATH_OPENCL_PRIM_FRECHET_LPDF_HPP
2#define STAN_MATH_OPENCL_PRIM_FRECHET_LPDF_HPP
35 bool propto,
typename T_y_cl,
typename T_shape_cl,
typename T_scale_cl,
37 T_scale_cl>* =
nullptr,
38 require_any_not_stan_scalar_t<T_y_cl, T_shape_cl, T_scale_cl>* =
nullptr>
40 const T_y_cl& y,
const T_shape_cl& alpha,
const T_scale_cl& sigma) {
42 static constexpr const char* function =
"frechet_lpdf(OpenCL)";
46 alpha,
"Scale parameter", sigma);
47 const size_t N =
max_size(y, alpha, sigma);
60 const auto& alpha_val =
value_of(alpha_col);
61 const auto& sigma_val =
value_of(sigma_col);
66 =
check_cl(function,
"Random variable", y_val,
"positive");
67 auto y_positive_expr = 0 < y_val;
68 auto check_alpha_pos_finite
69 =
check_cl(function,
"Shape parameter", alpha_val,
"positive finite");
70 auto alpha_pos_finite_expr = alpha_val > 0 &&
isfinite(alpha_val);
71 auto check_sigma_pos_finite
72 =
check_cl(function,
"Scale parameter", sigma_val,
"positive finite");
73 auto sigma_pos_finite_expr = sigma_val > 0 &&
isfinite(sigma_val);
75 auto log_y_expr =
log(y_val);
76 auto sigma_div_y_pow_alpha_expr
78 auto log_sigma_expr =
log(sigma_val);
79 auto logp1_expr = -sigma_div_y_pow_alpha_expr;
80 auto logp2_expr = static_select<include_summand<propto, T_shape_cl>::value>(
81 logp1_expr +
log(alpha_val), logp1_expr);
83 = static_select<include_summand<propto, T_y_cl, T_shape_cl>::value>(
84 logp2_expr -
elt_multiply(alpha_val + 1.0, log_y_expr), logp2_expr);
87 logp3_expr +
elt_multiply(alpha_val, log_sigma_expr), logp3_expr));
89 auto alpha_deriv_expr =
elt_divide(1.0, alpha_val)
91 log_sigma_expr - log_y_expr);
93 elt_multiply(alpha_val, sigma_div_y_pow_alpha_expr) - alpha_val - 1,
96 1 - sigma_div_y_pow_alpha_expr);
103 results(check_y_positive, check_alpha_pos_finite, check_sigma_pos_finite,
104 logp_cl, y_deriv_cl, alpha_deriv_cl, sigma_deriv_cl)
105 =
expressions(y_positive_expr, alpha_pos_finite_expr,
106 sigma_pos_finite_expr, logp_expr, y_deriv_expr,
107 alpha_deriv_expr, sigma_deriv_expr);
112 partials<0>(ops_partials) = std::move(y_deriv_cl);
115 partials<1>(ops_partials) = std::move(alpha_deriv_cl);
118 partials<2>(ops_partials) = std::move(sigma_deriv_cl);
121 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)
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_shape_cl, T_scale_cl > frechet_lpdf(const T_y_cl &y, const T_shape_cl &alpha, const T_scale_cl &sigma)
The log of the frechet density for the specified scalar(s) given the specified sample stan::math::siz...
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.
auto pow(const T1 &x1, const T2 &x2)
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.
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.
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...