From 461ed404458c6dde54be4abee3cd9af382104b74 Mon Sep 17 00:00:00 2001 From: tadej Date: Fri, 10 Jul 2020 10:32:32 +0200 Subject: [PATCH 1/9] generalized normal --- stan/math/prim/prob/normal_cdf.hpp | 22 +-- stan/math/prim/prob/normal_lccdf.hpp | 22 +-- stan/math/prim/prob/normal_lcdf.hpp | 22 +-- stan/math/prim/prob/normal_lpdf.hpp | 91 +++++++------ stan/math/prim/prob/normal_rng.hpp | 12 +- .../math/prim/prob/normal_sufficient_lpdf.hpp | 128 ++++++++++-------- 6 files changed, 168 insertions(+), 129 deletions(-) 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..e3c76801d20 100644 --- a/stan/math/prim/prob/normal_lpdf.hpp +++ b/stan/math/prim/prob/normal_lpdf.hpp @@ -39,13 +39,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 +72,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..75d03c1b662 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -50,23 +51,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,56 +104,42 @@ 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); - - 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); - - if (include_summand::value) { - logp += NEG_LOG_SQRT_TWO_PI * n_obs_dbl; - } - - if (include_summand::value) { - logp -= n_obs_dbl * log(sigma_dbl); - } + 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); - 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); + 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); + } - // 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) { - ops_partials.edge2_.partials_[i] -= 0.5 / sigma_squared; + 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_obs_val / sigma_squared * diff); + if (!is_constant_all::value) { + ops_partials.edge3_.partials_ = -common_derivative; } - 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.edge1_.partials_ = std::move(common_derivative); } } + if (!is_constant_all::value) { + ops_partials.edge2_.partials_ = -0.5 / sigma_squared; + } + if (!is_constant_all::value) { + ops_partials.edge4_.partials_ + = (cons_expr / sigma_squared - n_obs_val) / sigma_val; + } return ops_partials.build(logp); } From e5836680407200b5ee05b976229a493242ca37d5 Mon Sep 17 00:00:00 2001 From: tadej Date: Fri, 11 Sep 2020 13:07:16 +0200 Subject: [PATCH 2/9] enabled testing --- .../stan_math_sigs_exceptions.expected | 412 ------------------ 1 file changed, 412 deletions(-) diff --git a/test/expressions/stan_math_sigs_exceptions.expected b/test/expressions/stan_math_sigs_exceptions.expected index d5e75f75bfb..4809c3f6625 100644 --- a/test/expressions/stan_math_sigs_exceptions.expected +++ b/test/expressions/stan_math_sigs_exceptions.expected @@ -1785,418 +1785,6 @@ int[] neg_binomial_rng(int[], vector) int[] neg_binomial_rng(int[], row_vector) int[] neg_binomial_rng(real[], vector) int[] neg_binomial_rng(real[], row_vector) -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[]) From e5972e8a65957d8ee151fda2f8edd24b44f27b0d Mon Sep 17 00:00:00 2001 From: tadej Date: Fri, 11 Sep 2020 13:23:18 +0200 Subject: [PATCH 3/9] added missing includes --- stan/math/prim/prob/normal_lpdf.hpp | 1 + stan/math/prim/prob/normal_sufficient_lpdf.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/stan/math/prim/prob/normal_lpdf.hpp b/stan/math/prim/prob/normal_lpdf.hpp index e3c76801d20..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 diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 75d03c1b662..4c7af9e1320 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include From d995b22af90aa8d597df9ad1808690cc9de4c450 Mon Sep 17 00:00:00 2001 From: tadej Date: Mon, 14 Sep 2020 09:48:39 +0200 Subject: [PATCH 4/9] bugfix sufficient --- stan/math/prim/prob/normal_sufficient_lpdf.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 4c7af9e1320..5cf743217d9 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -135,7 +135,21 @@ return_type_t normal_sufficient_lpdf( } } if (!is_constant_all::value) { - ops_partials.edge2_.partials_ = -0.5 / sigma_squared; + 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( + size(sigma), + -0.5 / forward_as(sigma_squared)); + } else { + ops_partials.edge2_.partials_ = -0.5 / sigma_squared; + } + } } if (!is_constant_all::value) { ops_partials.edge4_.partials_ From b88668b1e1df7152fa5f367e21e93d9aa3eed561 Mon Sep 17 00:00:00 2001 From: tadej Date: Mon, 14 Sep 2020 13:12:48 +0200 Subject: [PATCH 5/9] another bugfix for sufficient --- stan/math/prim/prob/normal_sufficient_lpdf.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 5cf743217d9..06d2b788a07 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -147,7 +147,9 @@ return_type_t normal_sufficient_lpdf( size(sigma), -0.5 / forward_as(sigma_squared)); } else { - ops_partials.edge2_.partials_ = -0.5 / sigma_squared; + forward_as>( + ops_partials.edge2_.partials_) + = -0.5 / sigma_squared; } } } From be59f6d798be0a8777d61d5a2ada3df7393330d9 Mon Sep 17 00:00:00 2001 From: tadej Date: Tue, 15 Sep 2020 13:25:01 +0200 Subject: [PATCH 6/9] yet another bugfix --- stan/math/prim/prob/normal_sufficient_lpdf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 06d2b788a07..52900f7f28f 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -144,7 +144,7 @@ return_type_t normal_sufficient_lpdf( } else { if (is_vector::value) { ops_partials.edge2_.partials_ = T_sigma_value_vector::Constant( - size(sigma), + size(s_squared), -0.5 / forward_as(sigma_squared)); } else { forward_as>( From bd96d05edec358d3b16a405dc6a80b0acc60f7dc Mon Sep 17 00:00:00 2001 From: tadej Date: Fri, 18 Sep 2020 10:37:24 +0200 Subject: [PATCH 7/9] improved test_repeat_as_vector to print which argument's derivative is wrong --- test/prob/test_fixture_ccdf_log.hpp | 43 +++++++++++++++-------------- test/prob/test_fixture_cdf.hpp | 43 +++++++++++++++-------------- test/prob/test_fixture_cdf_log.hpp | 43 +++++++++++++++-------------- test/prob/test_fixture_distr.hpp | 43 +++++++++++++++-------------- 4 files changed, 88 insertions(+), 84 deletions(-) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 4ef9795368b..a563e2afb87 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -498,13 +498,14 @@ class AgradCcdfLogTestFixture : 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], 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 +513,7 @@ 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 +595,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 +634,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 +672,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..f4b34b5cdea 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -487,13 +487,14 @@ 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 +502,7 @@ 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 +588,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 +627,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 +665,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..a5c933aaf00 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -499,13 +499,14 @@ class AgradCdfLogTestFixture : 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], 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 +514,7 @@ 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 +596,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 +635,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 +673,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..a3ed4fb89df 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -560,13 +560,14 @@ class AgradDistributionTestFixture : 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], 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 +575,7 @@ 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 +661,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 +700,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 +738,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); } } From 4783cdbdd3af836c191144c33cff1fb11df3ae2b Mon Sep 17 00:00:00 2001 From: tadej Date: Fri, 18 Sep 2020 10:39:05 +0200 Subject: [PATCH 8/9] one more bugfix --- stan/math/prim/prob/normal_sufficient_lpdf.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index 52900f7f28f..c24e7ab51e9 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -126,7 +126,7 @@ return_type_t normal_sufficient_lpdf( if (!is_constant_all::value) { const auto& common_derivative = to_ref_if<( !is_constant_all::value && !is_constant_all::value)>( - n_obs_val / sigma_squared * diff); + 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; } @@ -144,12 +144,11 @@ return_type_t normal_sufficient_lpdf( } else { if (is_vector::value) { ops_partials.edge2_.partials_ = T_sigma_value_vector::Constant( - size(s_squared), - -0.5 / forward_as(sigma_squared)); + N, -0.5 / forward_as(sigma_squared)); } else { forward_as>( ops_partials.edge2_.partials_) - = -0.5 / sigma_squared; + = -0.5 / sigma_squared * N / size(sigma); } } } From f7de7169f96e22e0d2d99e59fc9e0df7ea3b8cda Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Fri, 18 Sep 2020 04:39:34 -0400 Subject: [PATCH 9/9] [Jenkins] auto-formatting by clang-format version 6.0.1-14 (tags/RELEASE_601/final) --- .../math/prim/prob/normal_sufficient_lpdf.hpp | 3 ++- test/prob/test_fixture_ccdf_log.hpp | 19 +++++++++---------- test/prob/test_fixture_cdf.hpp | 6 ++++-- test/prob/test_fixture_cdf_log.hpp | 19 +++++++++---------- test/prob/test_fixture_distr.hpp | 17 ++++++++--------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/stan/math/prim/prob/normal_sufficient_lpdf.hpp b/stan/math/prim/prob/normal_sufficient_lpdf.hpp index c24e7ab51e9..c3a3aa12904 100644 --- a/stan/math/prim/prob/normal_sufficient_lpdf.hpp +++ b/stan/math/prim/prob/normal_sufficient_lpdf.hpp @@ -126,7 +126,8 @@ return_type_t normal_sufficient_lpdf( 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); + 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; } diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index a563e2afb87..b72d1d2712f 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -492,20 +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, - const int argument_number) { + 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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -513,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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index f4b34b5cdea..28405582c66 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -494,7 +494,8 @@ class AgradCdfTestFixture : public ::testing::Test { EXPECT_NEAR(single_gradients[pos_single] / N_REPEAT, multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " - "failed for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -502,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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index a5c933aaf00..6496d5b7bd5 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -493,20 +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, - const int argument_number) { + 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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -514,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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; } diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index a3ed4fb89df..3a716eb946f 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -555,19 +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, - const int argument_number) { + 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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_multiple++; } pos_single++; @@ -575,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 for argument number " << argument_number; + "failed for argument number " + << argument_number; pos_single++; pos_multiple++; }