Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for var_value<Matrix> for univariate distributions #2304

Merged
merged 33 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e99e1f8
adds tests for var_value<Matrix> to distributions
SteveBronder Jan 11, 2021
3a92428
fix tests makefile
SteveBronder Jan 11, 2021
e625777
checks value_of() for error handling in distributions
SteveBronder Jan 11, 2021
d0c2d4b
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 11, 2021
5eae85c
Added `value_of` to beta proportion lcdf and lccdf (Issue #2101)
bbbales2 Jan 12, 2021
e7dc4b3
Updated VectorBuilder to work with varmat (Issue #2101)
bbbales2 Jan 12, 2021
259bc73
Fixed `is_vector` check in `VectorBuilder` (Issue #2101)
bbbales2 Jan 12, 2021
cd86fc5
Removed unusual `promote_scalar` from `beta_proportion` (Issue #2101)
bbbales2 Jan 12, 2021
17b6b6d
Merge commit '0e419e94ad682521ed113c1947adc0452af76340' into HEAD
yashikno Jan 12, 2021
1058731
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 12, 2021
c77799b
Removed direction reverse checks (Issue #2101)
bbbales2 Jan 12, 2021
d488d68
Merge branch 'feature/varmat-dist-tests' of github.com:stan-dev/math …
bbbales2 Jan 12, 2021
d02ad05
Worked around bug in bernoulli and fixed expression thing in von mise…
bbbales2 Jan 12, 2021
e7668fc
Merge commit '7085ef69bdb399db7d918240659f56305885a2fd' into HEAD
yashikno Jan 12, 2021
e64bdc3
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 12, 2021
d3da2bc
Update gamma tests to work with new autodiff initializations (Issue #…
bbbales2 Jan 13, 2021
38874d1
Made normal cdf test work with new autodiff initializations (Issue #2…
bbbales2 Jan 13, 2021
2933d92
Merge branch 'feature/varmat-dist-tests' of github.com:stan-dev/math …
bbbales2 Jan 13, 2021
05ed31c
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 13, 2021
85b52bd
Removing extra difficult autodiff initialization (Issue #2101)
bbbales2 Jan 13, 2021
d2eec67
Fixed `scalar_seq_view` `operator[]` for varmat (Issue #2101)
bbbales2 Jan 13, 2021
daff60a
Merge commit 'ce84d1903b479c016b51b9255e05d36f6f3e1741' into HEAD
yashikno Jan 13, 2021
dd3f0f8
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 13, 2021
034d009
Merge remote-tracking branch 'origin/develop' into feature/varmat-dis…
SteveBronder Jan 26, 2021
9482b54
Merge remote-tracking branch 'origin/develop' into feature/varmat-dis…
SteveBronder Jan 31, 2021
0dd58c2
fix division for fvar to cast to double
SteveBronder Jan 31, 2021
4114b9a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jan 31, 2021
7c2c8dd
Reverting new test stuff, remove unnecessary value_ofs (Issue #2101)
bbbales2 Feb 1, 2021
86611b7
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Feb 1, 2021
ac312e2
Merge remote-tracking branch 'origin/develop' into feature/varmat-dis…
bbbales2 Feb 1, 2021
5dfbb26
Updated skew_double_exponential to support varmat (Issue #2101)
bbbales2 Feb 1, 2021
46e49f8
Merge branch 'feature/varmat-dist-tests' of github.com:stan-dev/math …
bbbales2 Feb 1, 2021
57d4438
Merge remote-tracking branch 'origin/develop' into feature/varmat-dis…
bbbales2 Feb 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ test/prob/generate_tests$(EXE) : test/prob/generate_tests.cpp


## FIXME: think about how to do this generally using test_types
# test_types := v fd fv ffd ffv
# test_types := v fd fv ffd ffv vv

test_name = $(shell echo $(1) | sed 's,_[0-9]\{5\},_test.hpp,g')

.SECONDEXPANSION:
test/prob/%_generated_v_test.cpp test/prob/%_generated_fd_test.cpp test/prob/%_generated_fv_test.cpp test/prob/%_generated_ffd_test.cpp test/prob/%_generated_ffv_test.cpp: test/prob/$$(call test_name,$$*) test/prob/generate_tests$(EXE)
test/prob/%_generated_v_test.cpp test/prob/%_generated_fd_test.cpp test/prob/%_generated_fv_test.cpp test/prob/%_generated_ffd_test.cpp test/prob/%_generated_ffv_test.cpp test/prob/%_generated_vv_test.cpp: test/prob/$$(call test_name,$$*) test/prob/generate_tests$(EXE)
$(WINE) test/prob/generate_tests$(EXE) $< $(N_TESTS)

LIST_OF_GENERATED_TESTS := $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_v_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_fd_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_fv_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_ffd_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_ffv_test.cpp,g')
LIST_OF_GENERATED_TESTS := $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_v_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_fd_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_fv_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_ffd_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_ffv_test.cpp,g') $(shell find test/prob -type f -name '*_test.hpp' | sed 's,_test.hpp,_00000_generated_vv_test.cpp,g')

.PHONY: generate-tests
generate-tests: $(LIST_OF_GENERATED_TESTS)
Expand Down
6 changes: 4 additions & 2 deletions stan/math/fwd/core/operator_division.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ inline fvar<T> operator/(const fvar<T>& x1, const fvar<T>& x2) {
*/
template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
inline fvar<T> operator/(const fvar<T>& x1, U x2) {
return fvar<T>(x1.val_ / x2, x1.d_ / x2);
return fvar<T>(x1.val_ / static_cast<double>(x2),
x1.d_ / static_cast<double>(x2));
}

/**
Expand All @@ -46,7 +47,8 @@ inline fvar<T> operator/(const fvar<T>& x1, U x2) {
*/
template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
inline fvar<T> operator/(U x1, const fvar<T>& x2) {
return fvar<T>(x1 / x2.val_, -x1 * x2.d_ / (x2.val_ * x2.val_));
return fvar<T>(static_cast<double>(x1) / x2.val_,
-static_cast<double>(x1) * x2.d_ / (x2.val_ * x2.val_));
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/fun/scalar_seq_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ class scalar_seq_view<C, require_var_matrix_t<C>> {
* @param i index
* @return the element at the specified position in the container
*/
inline auto operator[](size_t i) const { return c_.val().coeffRef(i); }
inline auto operator[](size_t i) const { return c_.coeff(i); }
inline const auto* data() const noexcept { return c_.vi_; }
inline auto* data() noexcept { return c_.vi_; }

inline auto size() const noexcept { return c_.size(); }

template <typename T = C, require_st_autodiff<T>* = nullptr>
inline auto val(size_t i) const {
return c_.val().coeffRef(i);
return c_.val().coeff(i);
}

template <typename T = C, require_st_autodiff<T>* = nullptr>
Expand Down
1 change: 0 additions & 1 deletion stan/math/prim/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
#include <stan/math/prim/meta/compiler_attributes.hpp>
#include <stan/math/prim/meta/contains_fvar.hpp>
#include <stan/math/prim/meta/contains_std_vector.hpp>
#include <stan/math/prim/meta/contains_vector.hpp>
#include <stan/math/prim/meta/error_index.hpp>
#include <stan/math/prim/meta/forward_as.hpp>
#include <stan/math/prim/meta/holder.hpp>
Expand Down
7 changes: 5 additions & 2 deletions stan/math/prim/meta/VectorBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define STAN_MATH_PRIM_META_VECTORBUILDER_HPP

#include <stan/math/prim/meta/VectorBuilderHelper.hpp>
#include <stan/math/prim/meta/contains_vector.hpp>
#include <stan/math/prim/meta/disjunction.hpp>
#include <stan/math/prim/meta/is_vector.hpp>

namespace stan {

Expand All @@ -25,7 +26,9 @@ namespace stan {
template <bool used, typename T1, typename... Args>
class VectorBuilder {
private:
using helper = VectorBuilderHelper<T1, used, contains_vector<Args...>::value>;
using helper
= VectorBuilderHelper<T1, used,
math::disjunction<is_vector<Args>...>::value>;

public:
using type = typename helper::type;
Expand Down
19 changes: 0 additions & 19 deletions stan/math/prim/meta/contains_vector.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion stan/math/prim/prob/bernoulli_cdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ return_type_t<T_prob> bernoulli_cdf(const T_n& n, const T_prob& theta) {
check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
T_theta_ref theta_ref = theta;
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, theta)) {
return 1.0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/bernoulli_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ return_type_t<T_prob> bernoulli_lccdf(const T_n& n, const T_prob& theta) {
check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
T_theta_ref theta_ref = theta;
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, theta)) {
return 0.0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/bernoulli_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ return_type_t<T_prob> bernoulli_lcdf(const T_n& n, const T_prob& theta) {
check_consistent_sizes(function, "Random variable", n,
"Probability parameter", theta);
T_theta_ref theta_ref = theta;
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, theta)) {
return 0.0;
Expand Down
7 changes: 4 additions & 3 deletions stan/math/prim/prob/bernoulli_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ return_type_t<T_prob> bernoulli_lpmf(const T_n& n, const T_prob& theta) {
const T_n_ref n_ref = to_ref(n);
const T_theta_ref theta_ref = to_ref(theta);
check_bounded(function, "n", n_ref, 0, 1);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, theta)) {
return 0.0;
Expand Down Expand Up @@ -83,8 +84,8 @@ return_type_t<T_prob> bernoulli_lpmf(const T_n& n, const T_prob& theta) {
logp += (N - sum) * log1m_theta;

if (!is_constant_all<T_prob>::value) {
ops_partials.edge1_.partials_[0] += sum / theta_dbl;
ops_partials.edge1_.partials_[0] += (N - sum) / (theta_dbl - 1);
ops_partials.edge1_.partials_[0] += sum * inv(theta_dbl);
ops_partials.edge1_.partials_[0] += (N - sum) * inv(theta_dbl - 1);
}
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/bernoulli_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ inline typename VectorBuilder<true, int, T_theta>::type bernoulli_rng(
using boost::variate_generator;
static const char* function = "bernoulli_rng";
ref_type_t<T_theta> theta_ref = theta;
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

scalar_seq_view<T_theta> theta_vec(theta_ref);
size_t N = stan::math::size(theta);
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/beta_cdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return_type_t<T_y, T_scale_succ, T_scale_fail> beta_cdf(
T_beta_ref beta_ref = beta;
check_positive_finite(function, "First shape parameter", alpha_ref);
check_positive_finite(function, "Second shape parameter", beta_ref);
check_bounded(function, "Random variable", y_ref, 0, 1);
check_bounded(function, "Random variable", value_of(y_ref), 0, 1);

T_partials_return P(1.0);
operands_and_partials<T_y_ref, T_alpha_ref, T_beta_ref> ops_partials(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/beta_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ return_type_t<T_y, T_scale_succ, T_scale_fail> beta_lccdf(
T_beta_ref beta_ref = beta_param;
check_positive_finite(function, "First shape parameter", alpha_ref);
check_positive_finite(function, "Second shape parameter", beta_ref);
check_bounded(function, "Random variable", y_ref, 0, 1);
check_bounded(function, "Random variable", value_of(y_ref), 0, 1);

T_partials_return ccdf_log(0.0);
operands_and_partials<T_y_ref, T_alpha_ref, T_beta_ref> ops_partials(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/beta_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ return_type_t<T_y, T_scale_succ, T_scale_fail> beta_lcdf(
T_beta_ref beta_ref = beta_param;
check_positive_finite(function, "First shape parameter", alpha_ref);
check_positive_finite(function, "Second shape parameter", beta_ref);
check_bounded(function, "Random variable", y_ref, 0, 1);
check_bounded(function, "Random variable", value_of(y_ref), 0, 1);

T_partials_return cdf_log(0.0);
operands_and_partials<T_y_ref, T_alpha_ref, T_beta_ref> ops_partials(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/beta_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ return_type_t<T_y, T_scale_succ, T_scale_fail> beta_lpdf(

check_positive_finite(function, "First shape parameter", alpha_val);
check_positive_finite(function, "Second shape parameter", beta_val);
check_bounded(function, "Random variable", y_val, 0, 1);
check_bounded(function, "Random variable", value_of(y_val), 0, 1);
if (!include_summand<propto, T_y, T_scale_succ, T_scale_fail>::value) {
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions stan/math/prim/prob/beta_proportion_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ return_type_t<T_y, T_loc, T_prec> beta_proportion_lccdf(const T_y& y,
T_y_ref y_ref = y;
T_mu_ref mu_ref = mu;
T_kappa_ref kappa_ref = kappa;
check_positive(function, "Location parameter", mu_ref);
check_less(function, "Location parameter", mu_ref, 1.0);
check_positive_finite(function, "Precision parameter", kappa_ref);
check_bounded(function, "Random variable", y_ref, 0.0, 1.0);
check_positive(function, "Location parameter", value_of(mu_ref));
check_less(function, "Location parameter", value_of(mu_ref), 1.0);
check_positive_finite(function, "Precision parameter", value_of(kappa_ref));
check_bounded(function, "Random variable", value_of(y_ref), 0.0, 1.0);

T_partials_return ccdf_log(0.0);
operands_and_partials<T_y_ref, T_mu_ref, T_kappa_ref> ops_partials(
Expand Down
8 changes: 4 additions & 4 deletions stan/math/prim/prob/beta_proportion_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ return_type_t<T_y, T_loc, T_prec> beta_proportion_lcdf(const T_y& y,
T_y_ref y_ref = y;
T_mu_ref mu_ref = mu;
T_kappa_ref kappa_ref = kappa;
check_positive(function, "Location parameter", mu_ref);
check_less(function, "Location parameter", mu_ref, 1.0);
check_positive_finite(function, "Precision parameter", kappa_ref);
check_bounded(function, "Random variable", y_ref, 0.0, 1.0);
check_positive(function, "Location parameter", value_of(mu_ref));
check_less(function, "Location parameter", value_of(mu_ref), 1.0);
check_positive_finite(function, "Precision parameter", value_of(kappa_ref));
check_bounded(function, "Random variable", value_of(y_ref), 0.0, 1.0);

T_partials_return cdf_log(0.0);
operands_and_partials<T_y_ref, T_mu_ref, T_kappa_ref> ops_partials(
Expand Down
5 changes: 2 additions & 3 deletions stan/math/prim/prob/beta_proportion_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ return_type_t<T_y, T_loc, T_prec> beta_proportion_lpdf(const T_y& y,

const auto& y_arr = as_array_or_scalar(y_col);
const auto& mu_arr = as_array_or_scalar(mu_col);
const auto& kappa_arr
= promote_scalar<T_partials_return_kappa>(as_array_or_scalar(kappa_col));
const auto& kappa_arr = as_array_or_scalar(kappa_col);

ref_type_t<decltype(value_of(y_arr))> y_val = value_of(y_arr);
ref_type_t<decltype(value_of(mu_arr))> mu_val = value_of(mu_arr);
Expand All @@ -84,7 +83,7 @@ return_type_t<T_y, T_loc, T_prec> beta_proportion_lpdf(const T_y& y,
check_positive(function, "Location parameter", mu_val);
check_less(function, "Location parameter", mu_val, 1.0);
check_positive_finite(function, "Precision parameter", kappa_val);
check_bounded(function, "Random variable", y_val, 0, 1);
check_bounded(function, "Random variable", value_of(y_val), 0, 1);

if (!include_summand<propto, T_y, T_loc, T_prec>::value) {
return 0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/binomial_cdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ return_type_t<T_prob> binomial_cdf(const T_n& n, const T_N& N,
T_theta_ref theta_ref = theta;

check_nonnegative(function, "Population size parameter", N_ref);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, N, theta)) {
return 1.0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/binomial_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ return_type_t<T_prob> binomial_lccdf(const T_n& n, const T_N& N,
T_theta_ref theta_ref = theta;

check_nonnegative(function, "Population size parameter", N_ref);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, N, theta)) {
return 0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/binomial_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ return_type_t<T_prob> binomial_lcdf(const T_n& n, const T_N& N,
T_theta_ref theta_ref = theta;

check_nonnegative(function, "Population size parameter", N_ref);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, N, theta)) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/binomial_logit_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return_type_t<T_prob> binomial_logit_lpmf(const T_n& n, const T_N& N,
ref_type_t<decltype(value_of(N_arr))> N_val = value_of(N_arr);
ref_type_t<decltype(value_of(alpha_arr))> alpha_val = value_of(alpha_arr);

check_bounded(function, "Successes variable", n_val, 0, N_val);
check_bounded(function, "Successes variable", value_of(n_val), 0, N_val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer

check_nonnegative(function, "Population size parameter", N_val);
check_finite(function, "Probability parameter", alpha_val);

Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/prob/binomial_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ return_type_t<T_prob> binomial_lpmf(const T_n& n, const T_N& N,
T_N_ref N_ref = N;
T_theta_ref theta_ref = theta;

check_bounded(function, "Successes variable", n_ref, 0, N_ref);
check_bounded(function, "Successes variable", value_of(n_ref), 0, N_ref);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer

check_nonnegative(function, "Population size parameter", N_ref);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

if (size_zero(n, N, theta)) {
return 0.0;
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/prob/binomial_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ inline typename VectorBuilder<true, int, T_N, T_theta>::type binomial_rng(
T_N_ref N_ref = N;
T_theta_ref theta_ref = theta;
check_nonnegative(function, "Population size parameter", N_ref);
check_bounded(function, "Probability parameter", theta_ref, 0.0, 1.0);
check_bounded(function, "Probability parameter", value_of(theta_ref), 0.0,
1.0);

scalar_seq_view<T_N_ref> N_vec(N_ref);
scalar_seq_view<T_theta_ref> theta_vec(theta_ref);
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/prob/categorical_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return_type_t<T_prob> categorical_lpmf(int n, const T_prob& theta) {

check_bounded(function, "Number of categories", n, 1, theta.size());
ref_type_t<T_prob> theta_ref = theta;
check_simplex(function, "Probabilities parameter", theta_ref);
check_simplex(function, "Probabilities parameter", value_of(theta_ref));

if (include_summand<propto, T_prob>::value) {
return log(theta_ref.coeff(n - 1));
Expand All @@ -36,7 +36,7 @@ return_type_t<T_prob> categorical_lpmf(const std::vector<int>& ns,

check_bounded(function, "element of outcome array", ns, 1, theta.size());
ref_type_t<T_prob> theta_ref = theta;
check_simplex(function, "Probabilities parameter", theta_ref);
check_simplex(function, "Probabilities parameter", value_of(theta_ref));

if (!include_summand<propto, T_prob>::value) {
return 0.0;
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/hypergeometric_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template <bool propto, typename T_n, typename T_N, typename T_a, typename T_b>
double hypergeometric_lpmf(const T_n& n, const T_N& N, const T_a& a,
const T_b& b) {
static const char* function = "hypergeometric_lpmf";
check_bounded(function, "Successes variable", n, 0, a);
check_bounded(function, "Successes variable", value_of(n), 0, a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer

check_consistent_sizes(function, "Successes variable", n, "Draws parameter",
N, "Successes in population parameter", a,
"Failures in population parameter", b);
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/hypergeometric_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inline int hypergeometric_rng(int N, int a, int b, RNG& rng) {
using boost::variate_generator;
using boost::math::hypergeometric_distribution;
static const char* function = "hypergeometric_rng";
check_bounded(function, "Draws parameter", N, 0, a + b);
check_bounded(function, "Draws parameter", value_of(N), 0, a + b);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer

check_positive(function, "Draws parameter", N);
check_positive(function, "Successes in population parameter", a);
check_positive(function, "Failures in population parameter", b);
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/prob/poisson_binomial_lccdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ return_type_t<T_theta> poisson_binomial_lccdf(const T_y& y,
for (size_t i = 0; i < max_sz; ++i) {
check_bounded(function, "Successes variable", y_vec[i], 0,
theta_vec[i].size());
check_finite(function, "Probability parameters", theta_vec[i]);
check_bounded(function, "Probability parameters", theta_vec[i], 0.0, 1.0);
check_finite(function, "Probability parameters", theta_vec.val(i));
check_bounded(function, "Probability parameters", theta_vec.val(i), 0.0,
1.0);
}

return sum(log1m_exp(log_sum_exp(poisson_binomial_log_probs(y, theta))));
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/prob/poisson_binomial_lcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ return_type_t<T_theta> poisson_binomial_lcdf(const T_y& y,
for (size_t i = 0; i < max_sz; ++i) {
check_bounded(function, "Successes variable", y_vec[i], 0,
theta_vec[i].size());
check_finite(function, "Probability parameters", theta_vec[i]);
check_bounded(function, "Probability parameters", theta_vec[i], 0.0, 1.0);
check_finite(function, "Probability parameters", theta_vec.val(i));
check_bounded(function, "Probability parameters", theta_vec.val(i), 0.0,
1.0);
}

return sum(log_sum_exp(poisson_binomial_log_probs(y, theta)));
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/prob/poisson_binomial_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ return_type_t<T_theta> poisson_binomial_lpmf(const T_y& y,
for (size_t i = 0; i < max_sz; ++i) {
check_bounded(function, "Successes variable", y_vec[i], 0,
theta_vec[i].size());
check_finite(function, "Probability parameters", theta_vec[i]);
check_bounded(function, "Probability parameters", theta_vec[i], 0.0, 1.0);
check_finite(function, "Probability parameters", theta_vec.val(i));
check_bounded(function, "Probability parameters", theta_vec.val(i), 0.0,
1.0);
}

return_type_t<T_theta> log_prob = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/prob/poisson_binomial_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline int poisson_binomial_rng(
const Eigen::Matrix<T_theta, Eigen::Dynamic, 1>& theta, RNG& rng) {
static const char* function = "poisson_binomial_rng";
check_finite(function, "Probability parameters", theta);
check_bounded(function, "Probability parameters", theta, 0.0, 1.0);
check_bounded(function, "Probability parameters", value_of(theta), 0.0, 1.0);

int y = 0;
for (size_t i = 0; i < theta.size(); ++i) {
Expand Down
Loading