diff --git a/stan/math/prim/prob/normal_cdf.hpp b/stan/math/prim/prob/normal_cdf.hpp index bd6d9a77db6..65bccb157b4 100644 --- a/stan/math/prim/prob/normal_cdf.hpp +++ b/stan/math/prim/prob/normal_cdf.hpp @@ -37,24 +37,30 @@ inline return_type_t normal_cdf(const T_y& y, const T_scale& sigma) { using T_partials_return = partials_return_t; using std::exp; + using T_y_ref = ref_type_t; + using T_mu_ref = ref_type_t; + using T_sigma_ref = ref_type_t; static const char* function = "normal_cdf"; - check_not_nan(function, "Random variable", y); - check_finite(function, "Location parameter", mu); - check_not_nan(function, "Scale parameter", sigma); - check_positive(function, "Scale parameter", sigma); check_consistent_sizes(function, "Random variable", y, "Location parameter", mu, "Scale parameter", sigma); + T_y_ref y_ref = y; + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + check_not_nan(function, "Random variable", y_ref); + check_finite(function, "Location parameter", mu_ref); + check_positive(function, "Scale parameter", sigma_ref); if (size_zero(y, mu, sigma)) { return 1.0; } T_partials_return cdf(1.0); - operands_and_partials ops_partials(y, mu, sigma); + operands_and_partials ops_partials( + y_ref, mu_ref, sigma_ref); - scalar_seq_view y_vec(y); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); + scalar_seq_view y_vec(y_ref); + scalar_seq_view mu_vec(mu_ref); + scalar_seq_view sigma_vec(sigma_ref); size_t N = max_size(y, mu, sigma); for (size_t n = 0; n < N; n++) { diff --git a/stan/math/prim/prob/normal_lccdf.hpp b/stan/math/prim/prob/normal_lccdf.hpp index f91a009c924..9432ecec0a6 100644 --- a/stan/math/prim/prob/normal_lccdf.hpp +++ b/stan/math/prim/prob/normal_lccdf.hpp @@ -24,24 +24,30 @@ inline return_type_t normal_lccdf(const T_y& y, using T_partials_return = partials_return_t; using std::exp; using std::log; + using T_y_ref = ref_type_t; + using T_mu_ref = ref_type_t; + using T_sigma_ref = ref_type_t; static const char* function = "normal_lccdf"; - check_not_nan(function, "Random variable", y); - check_finite(function, "Location parameter", mu); - check_not_nan(function, "Scale parameter", sigma); - check_positive(function, "Scale parameter", sigma); check_consistent_sizes(function, "Random variable", y, "Location parameter", mu, "Scale parameter", sigma); + T_y_ref y_ref = y; + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + check_not_nan(function, "Random variable", y_ref); + check_finite(function, "Location parameter", mu_ref); + check_positive(function, "Scale parameter", sigma_ref); if (size_zero(y, mu, sigma)) { return 0; } T_partials_return ccdf_log(0.0); - operands_and_partials ops_partials(y, mu, sigma); + operands_and_partials ops_partials( + y_ref, mu_ref, sigma_ref); - scalar_seq_view y_vec(y); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); + scalar_seq_view y_vec(y_ref); + scalar_seq_view mu_vec(mu_ref); + scalar_seq_view sigma_vec(sigma_ref); size_t N = max_size(y, mu, sigma); for (size_t n = 0; n < N; n++) { diff --git a/stan/math/prim/prob/normal_lcdf.hpp b/stan/math/prim/prob/normal_lcdf.hpp index ceea83c798c..bf6a945931f 100644 --- a/stan/math/prim/prob/normal_lcdf.hpp +++ b/stan/math/prim/prob/normal_lcdf.hpp @@ -30,24 +30,30 @@ inline return_type_t normal_lcdf(const T_y& y, using std::log; using std::pow; using std::sqrt; + using T_y_ref = ref_type_t; + using T_mu_ref = ref_type_t; + using T_sigma_ref = ref_type_t; static const char* function = "normal_lcdf"; - check_not_nan(function, "Random variable", y); - check_finite(function, "Location parameter", mu); - check_not_nan(function, "Scale parameter", sigma); - check_positive(function, "Scale parameter", sigma); check_consistent_sizes(function, "Random variable", y, "Location parameter", mu, "Scale parameter", sigma); + T_y_ref y_ref = y; + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + check_not_nan(function, "Random variable", y_ref); + check_finite(function, "Location parameter", mu_ref); + check_positive(function, "Scale parameter", sigma_ref); if (size_zero(y, mu, sigma)) { return 0; } T_partials_return cdf_log(0.0); - operands_and_partials ops_partials(y, mu, sigma); + operands_and_partials ops_partials( + y_ref, mu_ref, sigma_ref); - scalar_seq_view y_vec(y); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); + scalar_seq_view y_vec(y_ref); + scalar_seq_view mu_vec(mu_ref); + scalar_seq_view sigma_vec(sigma_ref); size_t N = max_size(y, mu, sigma); for (size_t n = 0; n < N; n++) { diff --git a/stan/math/prim/prob/normal_lpdf.hpp b/stan/math/prim/prob/normal_lpdf.hpp index 26e6e13c6eb..db57feafbd4 100644 --- a/stan/math/prim/prob/normal_lpdf.hpp +++ b/stan/math/prim/prob/normal_lpdf.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -39,13 +40,31 @@ inline return_type_t normal_lpdf(const T_y& y, const T_loc& mu, const T_scale& sigma) { using T_partials_return = partials_return_t; - using std::log; + using T_y_ref = ref_type_if_t::value, T_y>; + using T_mu_ref = ref_type_if_t::value, T_loc>; + using T_sigma_ref = ref_type_if_t::value, T_scale>; static const char* function = "normal_lpdf"; - check_not_nan(function, "Random variable", y); - check_finite(function, "Location parameter", mu); - check_positive(function, "Scale parameter", sigma); check_consistent_sizes(function, "Random variable", y, "Location parameter", mu, "Scale parameter", sigma); + T_y_ref y_ref = y; + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + + const auto& y_col = as_column_vector_or_scalar(y_ref); + const auto& mu_col = as_column_vector_or_scalar(mu_ref); + const auto& sigma_col = as_column_vector_or_scalar(sigma_ref); + + const auto& y_arr = as_array_or_scalar(y_col); + const auto& mu_arr = as_array_or_scalar(mu_col); + const auto& sigma_arr = as_array_or_scalar(sigma_col); + + ref_type_t y_val = value_of(y_arr); + ref_type_t mu_val = value_of(mu_arr); + ref_type_t sigma_val = value_of(sigma_arr); + + check_not_nan(function, "Random variable", y_val); + check_finite(function, "Location parameter", mu_val); + check_positive(function, "Scale parameter", sigma_val); if (size_zero(y, mu, sigma)) { return 0.0; @@ -54,54 +73,37 @@ inline return_type_t normal_lpdf(const T_y& y, return 0.0; } - T_partials_return logp(0.0); - operands_and_partials ops_partials(y, mu, sigma); + operands_and_partials ops_partials( + y_ref, mu_ref, sigma_ref); - scalar_seq_view y_vec(y); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); - size_t N = max_size(y, mu, sigma); + const auto& inv_sigma + = to_ref_if::value>(inv(sigma_val)); + const auto& y_scaled = to_ref((y_val - mu_val) * inv_sigma); + const auto& y_scaled_sq + = to_ref_if::value>(y_scaled * y_scaled); - VectorBuilder inv_sigma(size(sigma)); - VectorBuilder::value, T_partials_return, - T_scale> - log_sigma(size(sigma)); - for (size_t i = 0; i < stan::math::size(sigma); i++) { - inv_sigma[i] = 1.0 / value_of(sigma_vec[i]); - if (include_summand::value) { - log_sigma[i] = log(value_of(sigma_vec[i])); - } + size_t N = max_size(y, mu, sigma); + T_partials_return logp = -0.5 * sum(y_scaled_sq); + if (include_summand::value) { + logp += NEG_LOG_SQRT_TWO_PI * N; + } + if (include_summand::value) { + logp -= sum(log(sigma_val)) * N / size(sigma); } - for (size_t n = 0; n < N; n++) { - const T_partials_return y_dbl = value_of(y_vec[n]); - const T_partials_return mu_dbl = value_of(mu_vec[n]); - - const T_partials_return y_minus_mu_over_sigma - = (y_dbl - mu_dbl) * inv_sigma[n]; - const T_partials_return y_minus_mu_over_sigma_squared - = y_minus_mu_over_sigma * y_minus_mu_over_sigma; - - static double NEGATIVE_HALF = -0.5; - - if (include_summand::value) { - logp += NEG_LOG_SQRT_TWO_PI; - } - if (include_summand::value) { - logp -= log_sigma[n]; - } - logp += NEGATIVE_HALF * y_minus_mu_over_sigma_squared; - - T_partials_return scaled_diff = inv_sigma[n] * y_minus_mu_over_sigma; + if (!is_constant_all::value) { + const auto& scaled_diff = to_ref_if::value + + !is_constant_all::value + + !is_constant_all::value + >= 2>(inv_sigma * y_scaled); if (!is_constant_all::value) { - ops_partials.edge1_.partials_[n] -= scaled_diff; - } - if (!is_constant_all::value) { - ops_partials.edge2_.partials_[n] += scaled_diff; + ops_partials.edge1_.partials_ = -scaled_diff; } if (!is_constant_all::value) { - ops_partials.edge3_.partials_[n] - += -inv_sigma[n] + inv_sigma[n] * y_minus_mu_over_sigma_squared; + ops_partials.edge3_.partials_ = inv_sigma * y_scaled_sq - inv_sigma; + } + if (!is_constant_all::value) { + ops_partials.edge2_.partials_ = std::move(scaled_diff); } } return ops_partials.build(logp); diff --git a/stan/math/prim/prob/normal_rng.hpp b/stan/math/prim/prob/normal_rng.hpp index 37b7c9af42c..9356d9c9aea 100644 --- a/stan/math/prim/prob/normal_rng.hpp +++ b/stan/math/prim/prob/normal_rng.hpp @@ -33,14 +33,18 @@ inline typename VectorBuilder::type normal_rng( const T_loc& mu, const T_scale& sigma, RNG& rng) { using boost::normal_distribution; using boost::variate_generator; + using T_mu_ref = ref_type_t; + using T_sigma_ref = ref_type_t; static const char* function = "normal_rng"; - check_finite(function, "Location parameter", mu); - check_positive_finite(function, "Scale parameter", sigma); check_consistent_sizes(function, "Location parameter", mu, "Scale Parameter", sigma); + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + check_finite(function, "Location parameter", mu_ref); + check_positive_finite(function, "Scale parameter", sigma_ref); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); + scalar_seq_view mu_vec(mu_ref); + scalar_seq_view sigma_vec(sigma_ref); size_t N = max_size(mu, sigma); VectorBuilder output(N); diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 546bf45502b..c3a3aa12904 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -50,23 +52,52 @@ return_type_t normal_sufficient_lpdf( const T_y& y_bar, const T_s& s_squared, const T_n& n_obs, const T_loc& mu, const T_scale& sigma) { using T_partials_return = partials_return_t; - using std::log; - using std::pow; + using T_y_ref = ref_type_if_t::value, T_y>; + using T_s_ref = ref_type_if_t::value, T_s>; + using T_n_ref = ref_type_if_t::value, T_n>; + using T_mu_ref = ref_type_if_t::value, T_loc>; + using T_sigma_ref = ref_type_if_t::value, T_scale>; static const char* function = "normal_sufficient_lpdf"; - check_finite(function, "Location parameter sufficient statistic", y_bar); - check_finite(function, "Scale parameter sufficient statistic", s_squared); - check_nonnegative(function, "Scale parameter sufficient statistic", - s_squared); - check_finite(function, "Number of observations", n_obs); - check_positive(function, "Number of observations", n_obs); - check_finite(function, "Location parameter", mu); - check_finite(function, "Scale parameter", sigma); - check_positive(function, "Scale parameter", sigma); check_consistent_sizes(function, "Location parameter sufficient statistic", y_bar, "Scale parameter sufficient statistic", s_squared, "Number of observations", n_obs, "Location parameter", mu, "Scale parameter", sigma); + T_y_ref y_ref = y_bar; + T_s_ref s_squared_ref = s_squared; + T_n_ref n_obs_ref = n_obs; + T_mu_ref mu_ref = mu; + T_sigma_ref sigma_ref = sigma; + + const auto& y_col = as_column_vector_or_scalar(y_ref); + const auto& s_squared_col = as_column_vector_or_scalar(s_squared_ref); + const auto& n_obs_col = as_column_vector_or_scalar(n_obs_ref); + const auto& mu_col = as_column_vector_or_scalar(mu_ref); + const auto& sigma_col = as_column_vector_or_scalar(sigma_ref); + + const auto& y_arr = as_array_or_scalar(y_col); + const auto& s_squared_arr = as_array_or_scalar(s_squared_col); + const auto& n_obs_arr = as_array_or_scalar(n_obs_col); + const auto& mu_arr = as_array_or_scalar(mu_col); + const auto& sigma_arr = as_array_or_scalar(sigma_col); + + ref_type_t y_val = value_of(y_arr); + ref_type_t s_squared_val + = value_of(s_squared_arr); + const auto& n_obs_val_int = value_of(n_obs_arr); + ref_type_t(n_obs_arr))> n_obs_val + = promote_scalar(n_obs_arr); + ref_type_t mu_val = value_of(mu_arr); + ref_type_t sigma_val = value_of(sigma_arr); + + check_finite(function, "Location parameter sufficient statistic", y_val); + check_finite(function, "Scale parameter sufficient statistic", s_squared_val); + check_nonnegative(function, "Scale parameter sufficient statistic", + s_squared_val); + check_positive_finite(function, "Number of observations", n_obs_val); + check_finite(function, "Location parameter", mu_val); + check_positive_finite(function, "Scale parameter", sigma_val); + if (size_zero(y_bar, s_squared, n_obs, mu, sigma)) { return 0.0; } @@ -74,55 +105,57 @@ return_type_t normal_sufficient_lpdf( return 0.0; } - T_partials_return logp(0.0); - operands_and_partials ops_partials(y_bar, s_squared, - mu, sigma); - scalar_seq_view y_bar_vec(y_bar); - scalar_seq_view s_squared_vec(s_squared); - scalar_seq_view n_obs_vec(n_obs); - scalar_seq_view mu_vec(mu); - scalar_seq_view sigma_vec(sigma); - size_t N = max_size(y_bar, s_squared, n_obs, mu, sigma); + const auto& sigma_squared + = to_ref_if::value>( + square(sigma_val)); + const auto& diff = to_ref(mu_val - y_val); + const auto& cons_expr = to_ref_if::value>( + s_squared_val + n_obs_val * diff * diff); - for (size_t i = 0; i < N; i++) { - const T_partials_return y_bar_dbl = value_of(y_bar_vec[i]); - const T_partials_return s_squared_dbl = value_of(s_squared_vec[i]); - const T_partials_return n_obs_dbl = n_obs_vec[i]; - const T_partials_return mu_dbl = value_of(mu_vec[i]); - const T_partials_return sigma_dbl = value_of(sigma_vec[i]); - const T_partials_return sigma_squared = pow(sigma_dbl, 2); + size_t N = max_size(y_bar, s_squared, n_obs, mu, sigma); + T_partials_return logp = -sum(cons_expr / (2 * sigma_squared)); + if (include_summand::value) { + logp += NEG_LOG_SQRT_TWO_PI * sum(n_obs_val) * N / size(n_obs); + } + if (include_summand::value) { + logp -= sum(n_obs_val * log(sigma_val)) * N / max_size(n_obs, sigma); + } - if (include_summand::value) { - logp += NEG_LOG_SQRT_TWO_PI * n_obs_dbl; + operands_and_partials ops_partials( + y_ref, s_squared_ref, mu_ref, sigma_ref); + if (!is_constant_all::value) { + const auto& common_derivative = to_ref_if<( + !is_constant_all::value && !is_constant_all::value)>( + N / max_size(y_bar, mu, n_obs, sigma) * n_obs_val / sigma_squared + * diff); + if (!is_constant_all::value) { + ops_partials.edge3_.partials_ = -common_derivative; } - - if (include_summand::value) { - logp -= n_obs_dbl * log(sigma_dbl); + if (!is_constant_all::value) { + ops_partials.edge1_.partials_ = std::move(common_derivative); } - - const T_partials_return cons_expr - = (s_squared_dbl + n_obs_dbl * pow(y_bar_dbl - mu_dbl, 2)); - - logp -= cons_expr / (2 * sigma_squared); - - // gradients - if (!is_constant_all::value) { - const T_partials_return common_derivative - = n_obs_dbl * (mu_dbl - y_bar_dbl) / sigma_squared; - if (!is_constant_all::value) { - ops_partials.edge1_.partials_[i] += common_derivative; - } - if (!is_constant_all::value) { - ops_partials.edge3_.partials_[i] -= common_derivative; + } + if (!is_constant_all::value) { + using T_sigma_value_scalar = scalar_type_t; + using T_sigma_value_vector + = Eigen::Array; + if (is_vector::value) { + ops_partials.edge2_.partials_ + = -0.5 / forward_as(sigma_squared); + } else { + if (is_vector::value) { + ops_partials.edge2_.partials_ = T_sigma_value_vector::Constant( + N, -0.5 / forward_as(sigma_squared)); + } else { + forward_as>( + ops_partials.edge2_.partials_) + = -0.5 / sigma_squared * N / size(sigma); } } - if (!is_constant_all::value) { - ops_partials.edge2_.partials_[i] -= 0.5 / sigma_squared; - } - if (!is_constant_all::value) { - ops_partials.edge4_.partials_[i] - += cons_expr / pow(sigma_dbl, 3) - n_obs_dbl / sigma_dbl; - } + } + if (!is_constant_all::value) { + ops_partials.edge4_.partials_ + = (cons_expr / sigma_squared - n_obs_val) / sigma_val; } return ops_partials.build(logp); } diff --git a/test/expressions/stan_math_sigs_exceptions.expected b/test/expressions/stan_math_sigs_exceptions.expected index def5b03c468..f65f972d44c 100644 --- a/test/expressions/stan_math_sigs_exceptions.expected +++ b/test/expressions/stan_math_sigs_exceptions.expected @@ -280,418 +280,6 @@ real multinomial_log(int[], vector) real multinomial_lpmf(int[], vector) int[] multinomial_rng(vector, int) matrix multiply_lower_tri_self_transpose(matrix) -real normal_ccdf_log(real, real, vector) -real normal_ccdf_log(real, real, row_vector) -real normal_ccdf_log(real, vector, real) -real normal_ccdf_log(real, vector, vector) -real normal_ccdf_log(real, vector, row_vector) -real normal_ccdf_log(real, vector, real[]) -real normal_ccdf_log(real, row_vector, real) -real normal_ccdf_log(real, row_vector, vector) -real normal_ccdf_log(real, row_vector, row_vector) -real normal_ccdf_log(real, row_vector, real[]) -real normal_ccdf_log(real, real[], vector) -real normal_ccdf_log(real, real[], row_vector) -real normal_ccdf_log(vector, real, real) -real normal_ccdf_log(vector, real, vector) -real normal_ccdf_log(vector, real, row_vector) -real normal_ccdf_log(vector, real, real[]) -real normal_ccdf_log(vector, vector, real) -real normal_ccdf_log(vector, vector, vector) -real normal_ccdf_log(vector, vector, row_vector) -real normal_ccdf_log(vector, vector, real[]) -real normal_ccdf_log(vector, row_vector, real) -real normal_ccdf_log(vector, row_vector, vector) -real normal_ccdf_log(vector, row_vector, row_vector) -real normal_ccdf_log(vector, row_vector, real[]) -real normal_ccdf_log(vector, real[], real) -real normal_ccdf_log(vector, real[], vector) -real normal_ccdf_log(vector, real[], row_vector) -real normal_ccdf_log(vector, real[], real[]) -real normal_ccdf_log(row_vector, real, real) -real normal_ccdf_log(row_vector, real, vector) -real normal_ccdf_log(row_vector, real, row_vector) -real normal_ccdf_log(row_vector, real, real[]) -real normal_ccdf_log(row_vector, vector, real) -real normal_ccdf_log(row_vector, vector, vector) -real normal_ccdf_log(row_vector, vector, row_vector) -real normal_ccdf_log(row_vector, vector, real[]) -real normal_ccdf_log(row_vector, row_vector, real) -real normal_ccdf_log(row_vector, row_vector, vector) -real normal_ccdf_log(row_vector, row_vector, row_vector) -real normal_ccdf_log(row_vector, row_vector, real[]) -real normal_ccdf_log(row_vector, real[], real) -real normal_ccdf_log(row_vector, real[], vector) -real normal_ccdf_log(row_vector, real[], row_vector) -real normal_ccdf_log(row_vector, real[], real[]) -real normal_ccdf_log(real[], real, vector) -real normal_ccdf_log(real[], real, row_vector) -real normal_ccdf_log(real[], vector, real) -real normal_ccdf_log(real[], vector, vector) -real normal_ccdf_log(real[], vector, row_vector) -real normal_ccdf_log(real[], vector, real[]) -real normal_ccdf_log(real[], row_vector, real) -real normal_ccdf_log(real[], row_vector, vector) -real normal_ccdf_log(real[], row_vector, row_vector) -real normal_ccdf_log(real[], row_vector, real[]) -real normal_ccdf_log(real[], real[], vector) -real normal_ccdf_log(real[], real[], row_vector) -real normal_cdf(real, real, vector) -real normal_cdf(real, real, row_vector) -real normal_cdf(real, vector, real) -real normal_cdf(real, vector, vector) -real normal_cdf(real, vector, row_vector) -real normal_cdf(real, vector, real[]) -real normal_cdf(real, row_vector, real) -real normal_cdf(real, row_vector, vector) -real normal_cdf(real, row_vector, row_vector) -real normal_cdf(real, row_vector, real[]) -real normal_cdf(real, real[], vector) -real normal_cdf(real, real[], row_vector) -real normal_cdf(vector, real, real) -real normal_cdf(vector, real, vector) -real normal_cdf(vector, real, row_vector) -real normal_cdf(vector, real, real[]) -real normal_cdf(vector, vector, real) -real normal_cdf(vector, vector, vector) -real normal_cdf(vector, vector, row_vector) -real normal_cdf(vector, vector, real[]) -real normal_cdf(vector, row_vector, real) -real normal_cdf(vector, row_vector, vector) -real normal_cdf(vector, row_vector, row_vector) -real normal_cdf(vector, row_vector, real[]) -real normal_cdf(vector, real[], real) -real normal_cdf(vector, real[], vector) -real normal_cdf(vector, real[], row_vector) -real normal_cdf(vector, real[], real[]) -real normal_cdf(row_vector, real, real) -real normal_cdf(row_vector, real, vector) -real normal_cdf(row_vector, real, row_vector) -real normal_cdf(row_vector, real, real[]) -real normal_cdf(row_vector, vector, real) -real normal_cdf(row_vector, vector, vector) -real normal_cdf(row_vector, vector, row_vector) -real normal_cdf(row_vector, vector, real[]) -real normal_cdf(row_vector, row_vector, real) -real normal_cdf(row_vector, row_vector, vector) -real normal_cdf(row_vector, row_vector, row_vector) -real normal_cdf(row_vector, row_vector, real[]) -real normal_cdf(row_vector, real[], real) -real normal_cdf(row_vector, real[], vector) -real normal_cdf(row_vector, real[], row_vector) -real normal_cdf(row_vector, real[], real[]) -real normal_cdf(real[], real, vector) -real normal_cdf(real[], real, row_vector) -real normal_cdf(real[], vector, real) -real normal_cdf(real[], vector, vector) -real normal_cdf(real[], vector, row_vector) -real normal_cdf(real[], vector, real[]) -real normal_cdf(real[], row_vector, real) -real normal_cdf(real[], row_vector, vector) -real normal_cdf(real[], row_vector, row_vector) -real normal_cdf(real[], row_vector, real[]) -real normal_cdf(real[], real[], vector) -real normal_cdf(real[], real[], row_vector) -real normal_cdf_log(real, real, vector) -real normal_cdf_log(real, real, row_vector) -real normal_cdf_log(real, vector, real) -real normal_cdf_log(real, vector, vector) -real normal_cdf_log(real, vector, row_vector) -real normal_cdf_log(real, vector, real[]) -real normal_cdf_log(real, row_vector, real) -real normal_cdf_log(real, row_vector, vector) -real normal_cdf_log(real, row_vector, row_vector) -real normal_cdf_log(real, row_vector, real[]) -real normal_cdf_log(real, real[], vector) -real normal_cdf_log(real, real[], row_vector) -real normal_cdf_log(vector, real, real) -real normal_cdf_log(vector, real, vector) -real normal_cdf_log(vector, real, row_vector) -real normal_cdf_log(vector, real, real[]) -real normal_cdf_log(vector, vector, real) -real normal_cdf_log(vector, vector, vector) -real normal_cdf_log(vector, vector, row_vector) -real normal_cdf_log(vector, vector, real[]) -real normal_cdf_log(vector, row_vector, real) -real normal_cdf_log(vector, row_vector, vector) -real normal_cdf_log(vector, row_vector, row_vector) -real normal_cdf_log(vector, row_vector, real[]) -real normal_cdf_log(vector, real[], real) -real normal_cdf_log(vector, real[], vector) -real normal_cdf_log(vector, real[], row_vector) -real normal_cdf_log(vector, real[], real[]) -real normal_cdf_log(row_vector, real, real) -real normal_cdf_log(row_vector, real, vector) -real normal_cdf_log(row_vector, real, row_vector) -real normal_cdf_log(row_vector, real, real[]) -real normal_cdf_log(row_vector, vector, real) -real normal_cdf_log(row_vector, vector, vector) -real normal_cdf_log(row_vector, vector, row_vector) -real normal_cdf_log(row_vector, vector, real[]) -real normal_cdf_log(row_vector, row_vector, real) -real normal_cdf_log(row_vector, row_vector, vector) -real normal_cdf_log(row_vector, row_vector, row_vector) -real normal_cdf_log(row_vector, row_vector, real[]) -real normal_cdf_log(row_vector, real[], real) -real normal_cdf_log(row_vector, real[], vector) -real normal_cdf_log(row_vector, real[], row_vector) -real normal_cdf_log(row_vector, real[], real[]) -real normal_cdf_log(real[], real, vector) -real normal_cdf_log(real[], real, row_vector) -real normal_cdf_log(real[], vector, real) -real normal_cdf_log(real[], vector, vector) -real normal_cdf_log(real[], vector, row_vector) -real normal_cdf_log(real[], vector, real[]) -real normal_cdf_log(real[], row_vector, real) -real normal_cdf_log(real[], row_vector, vector) -real normal_cdf_log(real[], row_vector, row_vector) -real normal_cdf_log(real[], row_vector, real[]) -real normal_cdf_log(real[], real[], vector) -real normal_cdf_log(real[], real[], row_vector) -real normal_lccdf(real, real, vector) -real normal_lccdf(real, real, row_vector) -real normal_lccdf(real, vector, real) -real normal_lccdf(real, vector, vector) -real normal_lccdf(real, vector, row_vector) -real normal_lccdf(real, vector, real[]) -real normal_lccdf(real, row_vector, real) -real normal_lccdf(real, row_vector, vector) -real normal_lccdf(real, row_vector, row_vector) -real normal_lccdf(real, row_vector, real[]) -real normal_lccdf(real, real[], vector) -real normal_lccdf(real, real[], row_vector) -real normal_lccdf(vector, real, real) -real normal_lccdf(vector, real, vector) -real normal_lccdf(vector, real, row_vector) -real normal_lccdf(vector, real, real[]) -real normal_lccdf(vector, vector, real) -real normal_lccdf(vector, vector, vector) -real normal_lccdf(vector, vector, row_vector) -real normal_lccdf(vector, vector, real[]) -real normal_lccdf(vector, row_vector, real) -real normal_lccdf(vector, row_vector, vector) -real normal_lccdf(vector, row_vector, row_vector) -real normal_lccdf(vector, row_vector, real[]) -real normal_lccdf(vector, real[], real) -real normal_lccdf(vector, real[], vector) -real normal_lccdf(vector, real[], row_vector) -real normal_lccdf(vector, real[], real[]) -real normal_lccdf(row_vector, real, real) -real normal_lccdf(row_vector, real, vector) -real normal_lccdf(row_vector, real, row_vector) -real normal_lccdf(row_vector, real, real[]) -real normal_lccdf(row_vector, vector, real) -real normal_lccdf(row_vector, vector, vector) -real normal_lccdf(row_vector, vector, row_vector) -real normal_lccdf(row_vector, vector, real[]) -real normal_lccdf(row_vector, row_vector, real) -real normal_lccdf(row_vector, row_vector, vector) -real normal_lccdf(row_vector, row_vector, row_vector) -real normal_lccdf(row_vector, row_vector, real[]) -real normal_lccdf(row_vector, real[], real) -real normal_lccdf(row_vector, real[], vector) -real normal_lccdf(row_vector, real[], row_vector) -real normal_lccdf(row_vector, real[], real[]) -real normal_lccdf(real[], real, vector) -real normal_lccdf(real[], real, row_vector) -real normal_lccdf(real[], vector, real) -real normal_lccdf(real[], vector, vector) -real normal_lccdf(real[], vector, row_vector) -real normal_lccdf(real[], vector, real[]) -real normal_lccdf(real[], row_vector, real) -real normal_lccdf(real[], row_vector, vector) -real normal_lccdf(real[], row_vector, row_vector) -real normal_lccdf(real[], row_vector, real[]) -real normal_lccdf(real[], real[], vector) -real normal_lccdf(real[], real[], row_vector) -real normal_lcdf(real, real, vector) -real normal_lcdf(real, real, row_vector) -real normal_lcdf(real, vector, real) -real normal_lcdf(real, vector, vector) -real normal_lcdf(real, vector, row_vector) -real normal_lcdf(real, vector, real[]) -real normal_lcdf(real, row_vector, real) -real normal_lcdf(real, row_vector, vector) -real normal_lcdf(real, row_vector, row_vector) -real normal_lcdf(real, row_vector, real[]) -real normal_lcdf(real, real[], vector) -real normal_lcdf(real, real[], row_vector) -real normal_lcdf(vector, real, real) -real normal_lcdf(vector, real, vector) -real normal_lcdf(vector, real, row_vector) -real normal_lcdf(vector, real, real[]) -real normal_lcdf(vector, vector, real) -real normal_lcdf(vector, vector, vector) -real normal_lcdf(vector, vector, row_vector) -real normal_lcdf(vector, vector, real[]) -real normal_lcdf(vector, row_vector, real) -real normal_lcdf(vector, row_vector, vector) -real normal_lcdf(vector, row_vector, row_vector) -real normal_lcdf(vector, row_vector, real[]) -real normal_lcdf(vector, real[], real) -real normal_lcdf(vector, real[], vector) -real normal_lcdf(vector, real[], row_vector) -real normal_lcdf(vector, real[], real[]) -real normal_lcdf(row_vector, real, real) -real normal_lcdf(row_vector, real, vector) -real normal_lcdf(row_vector, real, row_vector) -real normal_lcdf(row_vector, real, real[]) -real normal_lcdf(row_vector, vector, real) -real normal_lcdf(row_vector, vector, vector) -real normal_lcdf(row_vector, vector, row_vector) -real normal_lcdf(row_vector, vector, real[]) -real normal_lcdf(row_vector, row_vector, real) -real normal_lcdf(row_vector, row_vector, vector) -real normal_lcdf(row_vector, row_vector, row_vector) -real normal_lcdf(row_vector, row_vector, real[]) -real normal_lcdf(row_vector, real[], real) -real normal_lcdf(row_vector, real[], vector) -real normal_lcdf(row_vector, real[], row_vector) -real normal_lcdf(row_vector, real[], real[]) -real normal_lcdf(real[], real, vector) -real normal_lcdf(real[], real, row_vector) -real normal_lcdf(real[], vector, real) -real normal_lcdf(real[], vector, vector) -real normal_lcdf(real[], vector, row_vector) -real normal_lcdf(real[], vector, real[]) -real normal_lcdf(real[], row_vector, real) -real normal_lcdf(real[], row_vector, vector) -real normal_lcdf(real[], row_vector, row_vector) -real normal_lcdf(real[], row_vector, real[]) -real normal_lcdf(real[], real[], vector) -real normal_lcdf(real[], real[], row_vector) -real normal_log(real, real, vector) -real normal_log(real, real, row_vector) -real normal_log(real, vector, real) -real normal_log(real, vector, vector) -real normal_log(real, vector, row_vector) -real normal_log(real, vector, real[]) -real normal_log(real, row_vector, real) -real normal_log(real, row_vector, vector) -real normal_log(real, row_vector, row_vector) -real normal_log(real, row_vector, real[]) -real normal_log(real, real[], vector) -real normal_log(real, real[], row_vector) -real normal_log(vector, real, real) -real normal_log(vector, real, vector) -real normal_log(vector, real, row_vector) -real normal_log(vector, real, real[]) -real normal_log(vector, vector, real) -real normal_log(vector, vector, vector) -real normal_log(vector, vector, row_vector) -real normal_log(vector, vector, real[]) -real normal_log(vector, row_vector, real) -real normal_log(vector, row_vector, vector) -real normal_log(vector, row_vector, row_vector) -real normal_log(vector, row_vector, real[]) -real normal_log(vector, real[], real) -real normal_log(vector, real[], vector) -real normal_log(vector, real[], row_vector) -real normal_log(vector, real[], real[]) -real normal_log(row_vector, real, real) -real normal_log(row_vector, real, vector) -real normal_log(row_vector, real, row_vector) -real normal_log(row_vector, real, real[]) -real normal_log(row_vector, vector, real) -real normal_log(row_vector, vector, vector) -real normal_log(row_vector, vector, row_vector) -real normal_log(row_vector, vector, real[]) -real normal_log(row_vector, row_vector, real) -real normal_log(row_vector, row_vector, vector) -real normal_log(row_vector, row_vector, row_vector) -real normal_log(row_vector, row_vector, real[]) -real normal_log(row_vector, real[], real) -real normal_log(row_vector, real[], vector) -real normal_log(row_vector, real[], row_vector) -real normal_log(row_vector, real[], real[]) -real normal_log(real[], real, vector) -real normal_log(real[], real, row_vector) -real normal_log(real[], vector, real) -real normal_log(real[], vector, vector) -real normal_log(real[], vector, row_vector) -real normal_log(real[], vector, real[]) -real normal_log(real[], row_vector, real) -real normal_log(real[], row_vector, vector) -real normal_log(real[], row_vector, row_vector) -real normal_log(real[], row_vector, real[]) -real normal_log(real[], real[], vector) -real normal_log(real[], real[], row_vector) -real normal_lpdf(real, real, vector) -real normal_lpdf(real, real, row_vector) -real normal_lpdf(real, vector, real) -real normal_lpdf(real, vector, vector) -real normal_lpdf(real, vector, row_vector) -real normal_lpdf(real, vector, real[]) -real normal_lpdf(real, row_vector, real) -real normal_lpdf(real, row_vector, vector) -real normal_lpdf(real, row_vector, row_vector) -real normal_lpdf(real, row_vector, real[]) -real normal_lpdf(real, real[], vector) -real normal_lpdf(real, real[], row_vector) -real normal_lpdf(vector, real, real) -real normal_lpdf(vector, real, vector) -real normal_lpdf(vector, real, row_vector) -real normal_lpdf(vector, real, real[]) -real normal_lpdf(vector, vector, real) -real normal_lpdf(vector, vector, vector) -real normal_lpdf(vector, vector, row_vector) -real normal_lpdf(vector, vector, real[]) -real normal_lpdf(vector, row_vector, real) -real normal_lpdf(vector, row_vector, vector) -real normal_lpdf(vector, row_vector, row_vector) -real normal_lpdf(vector, row_vector, real[]) -real normal_lpdf(vector, real[], real) -real normal_lpdf(vector, real[], vector) -real normal_lpdf(vector, real[], row_vector) -real normal_lpdf(vector, real[], real[]) -real normal_lpdf(row_vector, real, real) -real normal_lpdf(row_vector, real, vector) -real normal_lpdf(row_vector, real, row_vector) -real normal_lpdf(row_vector, real, real[]) -real normal_lpdf(row_vector, vector, real) -real normal_lpdf(row_vector, vector, vector) -real normal_lpdf(row_vector, vector, row_vector) -real normal_lpdf(row_vector, vector, real[]) -real normal_lpdf(row_vector, row_vector, real) -real normal_lpdf(row_vector, row_vector, vector) -real normal_lpdf(row_vector, row_vector, row_vector) -real normal_lpdf(row_vector, row_vector, real[]) -real normal_lpdf(row_vector, real[], real) -real normal_lpdf(row_vector, real[], vector) -real normal_lpdf(row_vector, real[], row_vector) -real normal_lpdf(row_vector, real[], real[]) -real normal_lpdf(real[], real, vector) -real normal_lpdf(real[], real, row_vector) -real normal_lpdf(real[], vector, real) -real normal_lpdf(real[], vector, vector) -real normal_lpdf(real[], vector, row_vector) -real normal_lpdf(real[], vector, real[]) -real normal_lpdf(real[], row_vector, real) -real normal_lpdf(real[], row_vector, vector) -real normal_lpdf(real[], row_vector, row_vector) -real normal_lpdf(real[], row_vector, real[]) -real normal_lpdf(real[], real[], vector) -real normal_lpdf(real[], real[], row_vector) -real[] normal_rng(int, vector) -real[] normal_rng(int, row_vector) -real[] normal_rng(real, vector) -real[] normal_rng(real, row_vector) -real[] normal_rng(vector, int) -real[] normal_rng(vector, real) -real[] normal_rng(vector, vector) -real[] normal_rng(vector, row_vector) -real[] normal_rng(vector, int[]) -real[] normal_rng(vector, real[]) -real[] normal_rng(row_vector, int) -real[] normal_rng(row_vector, real) -real[] normal_rng(row_vector, vector) -real[] normal_rng(row_vector, row_vector) -real[] normal_rng(row_vector, int[]) -real[] normal_rng(row_vector, real[]) -real[] normal_rng(int[], vector) -real[] normal_rng(int[], row_vector) -real[] normal_rng(real[], vector) -real[] normal_rng(real[], row_vector) real ordered_logistic_log(int, real, vector) real ordered_logistic_log(int[], vector, vector) real ordered_logistic_log(int[], vector, vector[]) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 4ef9795368b..b72d1d2712f 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -492,19 +492,18 @@ class AgradCcdfLogTestFixture : public ::testing::Test { } } - void test_multiple_gradient_values(const bool is_vec, - const double single_ccdf_log, - const vector& single_gradients, - size_t& pos_single, - const vector& multiple_gradients, - size_t& pos_multiple, - const size_t N_REPEAT) { + void test_multiple_gradient_values( + const bool is_vec, const double single_ccdf_log, + const vector& single_gradients, size_t& pos_single, + const vector& multiple_gradients, size_t& pos_multiple, + const size_t N_REPEAT, const int argument_number) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -512,7 +511,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } @@ -594,37 +594,37 @@ class AgradCcdfLogTestFixture : public ::testing::Test { && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients1, - pos_single, multiple_gradients1, pos_multiple, N_REPEAT); + pos_single, multiple_gradients1, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -633,37 +633,37 @@ class AgradCcdfLogTestFixture : public ::testing::Test { || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients2, - pos_single, multiple_gradients2, pos_multiple, N_REPEAT); + pos_single, multiple_gradients2, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -671,32 +671,32 @@ class AgradCcdfLogTestFixture : public ::testing::Test { && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_ccdf_log, single_gradients3, - pos_single, multiple_gradients3, pos_multiple, N_REPEAT); + pos_single, multiple_gradients3, pos_multiple, N_REPEAT, 5); } } diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 8f3f5556a45..28405582c66 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -487,13 +487,15 @@ class AgradCdfTestFixture : public ::testing::Test { size_t& pos_single, const vector& multiple_gradients, size_t& pos_multiple, - const size_t N_REPEAT) { + const size_t N_REPEAT, + const int argument_number) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single] / N_REPEAT, multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -501,7 +503,8 @@ class AgradCdfTestFixture : public ::testing::Test { EXPECT_NEAR(single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } @@ -587,37 +590,37 @@ class AgradCdfTestFixture : public ::testing::Test { && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -626,37 +629,37 @@ class AgradCdfTestFixture : public ::testing::Test { || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -664,32 +667,32 @@ class AgradCdfTestFixture : public ::testing::Test { && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 5); } } diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 93b205ec7f2..6496d5b7bd5 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -493,19 +493,18 @@ class AgradCdfLogTestFixture : public ::testing::Test { } } - void test_multiple_gradient_values(const bool is_vec, - const double single_cdf_log, - const vector& single_gradients, - size_t& pos_single, - const vector& multiple_gradients, - size_t& pos_multiple, - const size_t N_REPEAT) { + void test_multiple_gradient_values( + const bool is_vec, const double single_cdf_log, + const vector& single_gradients, size_t& pos_single, + const vector& multiple_gradients, size_t& pos_multiple, + const size_t N_REPEAT, const int argument_number) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -513,7 +512,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } @@ -595,37 +595,37 @@ class AgradCdfLogTestFixture : public ::testing::Test { && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients1, pos_single, - multiple_gradients1, pos_multiple, N_REPEAT); + multiple_gradients1, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -634,37 +634,37 @@ class AgradCdfLogTestFixture : public ::testing::Test { || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients2, pos_single, - multiple_gradients2, pos_multiple, N_REPEAT); + multiple_gradients2, pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -672,32 +672,32 @@ class AgradCdfLogTestFixture : public ::testing::Test { && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values( is_vector::value, single_cdf_log, single_gradients3, pos_single, - multiple_gradients3, pos_multiple, N_REPEAT); + multiple_gradients3, pos_multiple, N_REPEAT, 5); } } diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index 39d7e20cdda..3a716eb946f 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -555,18 +555,17 @@ class AgradDistributionTestFixture : public ::testing::Test { } } - void test_multiple_gradient_values(const bool is_vec, - const vector& single_gradients, - size_t& pos_single, - const vector& multiple_gradients, - size_t& pos_multiple, - const size_t N_REPEAT) { + void test_multiple_gradient_values( + const bool is_vec, const vector& single_gradients, + size_t& pos_single, const vector& multiple_gradients, + size_t& pos_multiple, const size_t N_REPEAT, const int argument_number) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -574,7 +573,8 @@ class AgradDistributionTestFixture : public ::testing::Test { EXPECT_NEAR(single_gradients[pos_single] * double(N_REPEAT), multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed"; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } @@ -660,37 +660,37 @@ class AgradDistributionTestFixture : public ::testing::Test { && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && !std::is_same>::value && !std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients1, pos_single, multiple_gradients1, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -699,37 +699,37 @@ class AgradDistributionTestFixture : public ::testing::Test { || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && (std::is_same>::value || std::is_same>>::value)) test_multiple_gradient_values(is_vector::value, single_gradients2, pos_single, multiple_gradients2, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 5); pos_single = 0; pos_multiple = 0; @@ -737,32 +737,32 @@ class AgradDistributionTestFixture : public ::testing::Test { && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 0); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 1); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 2); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 3); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 4); if (!is_constant_all::value && !is_empty::value && std::is_same>>::value) test_multiple_gradient_values(is_vector::value, single_gradients3, pos_single, multiple_gradients3, - pos_multiple, N_REPEAT); + pos_multiple, N_REPEAT, 5); } }