diff --git a/test/unit/math/opencl/pinned_matrix_test.cpp b/test/unit/math/opencl/pinned_matrix_test.cpp index eb266809655..6ff90df7af4 100644 --- a/test/unit/math/opencl/pinned_matrix_test.cpp +++ b/test/unit/math/opencl/pinned_matrix_test.cpp @@ -1,10 +1,11 @@ #ifdef STAN_OPENCL #include #include +#include #include #include -TEST(AgradRev, pinned_matrix_matrix_test) { +TEST_F(AgradRev, pinned_matrix_matrix_test) { using Eigen::MatrixXd; using stan::math::pinned_matrix; @@ -45,7 +46,7 @@ TEST(AgradRev, pinned_matrix_matrix_test) { stan::math::recover_memory(); } -TEST(AgradRev, pinned_matrix_vector_test) { +TEST_F(AgradRev, pinned_matrix_vector_test) { using Eigen::VectorXd; using stan::math::pinned_matrix; @@ -86,7 +87,7 @@ TEST(AgradRev, pinned_matrix_vector_test) { stan::math::recover_memory(); } -TEST(AgradRev, pinned_matrix_row_vector_test) { +TEST_F(AgradRev, pinned_matrix_row_vector_test) { using Eigen::RowVectorXd; using stan::math::pinned_matrix; diff --git a/test/unit/math/opencl/rev/arena_matrix_cl_test.cpp b/test/unit/math/opencl/rev/arena_matrix_cl_test.cpp index 7176cfd947d..bb067482643 100644 --- a/test/unit/math/opencl/rev/arena_matrix_cl_test.cpp +++ b/test/unit/math/opencl/rev/arena_matrix_cl_test.cpp @@ -1,9 +1,10 @@ #ifdef STAN_OPENCL #include +#include #include #include -TEST(AgradRev, arena_matrix_cl_shallow_copies) { +TEST_F(AgradRev, arena_matrix_cl_shallow_copies) { stan::math::arena_matrix_cl a(3, 2); stan::math::arena_matrix_cl b(a); stan::math::arena_matrix_cl c; @@ -12,13 +13,13 @@ TEST(AgradRev, arena_matrix_cl_shallow_copies) { EXPECT_EQ(a.buffer()(), c.buffer()()); } -TEST(AgradRev, arena_matrix_cl_to_matrix_cl_conversion) { +TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_conversion) { stan::math::arena_matrix_cl a(3, 2); const stan::math::matrix_cl& b(a); EXPECT_EQ(a.buffer()(), b.buffer()()); } -TEST(AgradRev, arena_matrix_cl_to_matrix_cl_move_construction) { +TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_move_construction) { stan::math::arena_matrix_cl a(3, 2); cl::Buffer a_buf = a.buffer(); stan::math::matrix_cl b(std::move(a)); @@ -26,7 +27,7 @@ TEST(AgradRev, arena_matrix_cl_to_matrix_cl_move_construction) { EXPECT_EQ(a_buf(), b.buffer()()); } -TEST(AgradRev, arena_matrix_cl_to_matrix_cl_move_assignment) { +TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_move_assignment) { stan::math::arena_matrix_cl a(3, 2); cl::Buffer a_buf = a.buffer(); stan::math::matrix_cl b; diff --git a/test/unit/math/opencl/rev/to_arena_test.cpp b/test/unit/math/opencl/rev/to_arena_test.cpp index 33b6a2853ed..caa5620df60 100644 --- a/test/unit/math/opencl/rev/to_arena_test.cpp +++ b/test/unit/math/opencl/rev/to_arena_test.cpp @@ -1,9 +1,10 @@ #ifdef STAN_OPENCL #include +#include #include #include -TEST(AgradRev, to_arena_matrix_cl_test) { +TEST_F(AgradRev, to_arena_matrix_cl_test) { Eigen::MatrixXd m(3, 2); m << 1, 2, 3, 4, 5, 6; stan::math::matrix_cl a(m); @@ -22,7 +23,7 @@ TEST(AgradRev, to_arena_matrix_cl_test) { stan::math::recover_memory(); } -TEST(AgradRev, to_arena_kg_expression_test) { +TEST_F(AgradRev, to_arena_kg_expression_test) { Eigen::MatrixXd m(3, 2); m << 1, 2, 3, 4, 5, 6; stan::math::matrix_cl a(m); @@ -40,7 +41,7 @@ TEST(AgradRev, to_arena_kg_expression_test) { stan::math::recover_memory(); } -TEST(AgradRev, to_arena_var_value_matrix_cl_test) { +TEST_F(AgradRev, to_arena_var_value_matrix_cl_test) { Eigen::MatrixXd val(3, 2); val << 1, 2, 3, 4, 5, 6; Eigen::MatrixXd adj(3, 2); diff --git a/test/unit/math/opencl/rev/vari_test.cpp b/test/unit/math/opencl/rev/vari_test.cpp index 5800f8875da..24233040f95 100644 --- a/test/unit/math/opencl/rev/vari_test.cpp +++ b/test/unit/math/opencl/rev/vari_test.cpp @@ -1,26 +1,28 @@ #ifdef STAN_OPENCL #include #include +#include #include #include -TEST(AgradRev, matrix_cl_vari_block) { +TEST_F(AgradRev, matrix_cl_vari_block) { using stan::math::vari_value; Eigen::MatrixXd a = Eigen::MatrixXd::Random(3, 3); Eigen::MatrixXd b = Eigen::MatrixXd::Random(3, 3); stan::math::matrix_cl a_cl(a); stan::math::matrix_cl b_cl(b); - vari_value> A(a); + stan::math::nested_rev_autodiff nested; + auto& A = *new vari_value>(a); EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2), stan::math::from_matrix_cl(A.block(0, 1, 2, 2).val_)); - vari_value> B(a_cl); + auto& B = *new vari_value>(a_cl); B.adj_ = b_cl; EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2), stan::math::from_matrix_cl(B.block(0, 1, 2, 2).val_)); EXPECT_MATRIX_EQ(b.block(0, 1, 2, 2), stan::math::from_matrix_cl(B.block(0, 1, 2, 2).adj_)); - vari_value> C(a_cl, a_cl); + auto& C = *new vari_value>(a_cl, a_cl); EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2), stan::math::from_matrix_cl(C.block(0, 1, 2, 2).val_)); EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2), diff --git a/test/unit/math/prim/functor/reduce_sum_util.hpp b/test/unit/math/prim/functor/reduce_sum_util.hpp index 18172224e22..bd028713e37 100644 --- a/test/unit/math/prim/functor/reduce_sum_util.hpp +++ b/test/unit/math/prim/functor/reduce_sum_util.hpp @@ -160,22 +160,22 @@ inline void test_slices(T1 result, T2&& vec_value, Args&&... args) { << "Failed for reduce_sum"; } -auto reduce_sum_static_int_sum_lpdf = [](auto&&... args) { +inline auto reduce_sum_static_int_sum_lpdf = [](auto&&... args) { return stan::math::reduce_sum_static(std::vector(2, 10.0), 1, get_new_msg(), args...); }; -auto reduce_sum_static_sum_lpdf = [](auto&& data, auto&&... args) { +inline auto reduce_sum_static_sum_lpdf = [](auto&& data, auto&&... args) { return stan::math::reduce_sum_static(data, 1, get_new_msg(), args...); }; -auto reduce_sum_int_sum_lpdf = [](auto&&... args) { +inline auto reduce_sum_int_sum_lpdf = [](auto&&... args) { return stan::math::reduce_sum(std::vector(2, 10.0), 1, get_new_msg(), args...); }; -auto reduce_sum_sum_lpdf = [](auto&& data, auto&&... args) { +inline auto reduce_sum_sum_lpdf = [](auto&& data, auto&&... args) { return stan::math::reduce_sum(data, 1, get_new_msg(), args...); }; diff --git a/test/unit/math/rev/core/gradable.hpp b/test/unit/math/rev/core/gradable.hpp index a4c198d1ed6..c7185ae988c 100644 --- a/test/unit/math/rev/core/gradable.hpp +++ b/test/unit/math/rev/core/gradable.hpp @@ -25,7 +25,7 @@ struct gradable { double adj() { return f_.adj(); } }; -gradable setup_quad_form() { +inline gradable setup_quad_form() { using Eigen::Dynamic; using Eigen::Matrix; using stan::math::quad_form; @@ -52,7 +52,7 @@ gradable setup_quad_form() { return gradable(x, f, g_expected); } -gradable setup_simple() { +inline gradable setup_simple() { stan::math::var a = 3; stan::math::var b = 7; std::vector x; diff --git a/test/unit/math/rev/fun/util.hpp b/test/unit/math/rev/fun/util.hpp index 7fdca697ef7..22d51a4aaf3 100644 --- a/test/unit/math/rev/fun/util.hpp +++ b/test/unit/math/rev/fun/util.hpp @@ -26,7 +26,7 @@ struct third_order_mixed { } }; -Eigen::Matrix third_order_mixed_hess( +inline Eigen::Matrix third_order_mixed_hess( const Eigen::Matrix& inp_vec) { Eigen::Matrix hess; @@ -46,7 +46,7 @@ Eigen::Matrix third_order_mixed_hess( return hess; } -Eigen::Matrix norm_hess( +inline Eigen::Matrix norm_hess( const Eigen::Matrix& inp_vec) { using Eigen::Dynamic; using Eigen::Matrix; @@ -62,7 +62,7 @@ Eigen::Matrix norm_hess( return hess; } -std::vector> +inline std::vector> third_order_mixed_grad_hess( const Eigen::Matrix& inp_vec) { using Eigen::Dynamic; @@ -91,7 +91,7 @@ third_order_mixed_grad_hess( return grad_hess_ret; } -std::vector> +inline std::vector> norm_grad_hess(const Eigen::Matrix& inp_vec) { using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/rev/functor/map_rect_mpi_prim_test.cpp b/test/unit/math/rev/functor/map_rect_mpi_prim_test.cpp index 0296aa087c2..492da69eaa8 100644 --- a/test/unit/math/rev/functor/map_rect_mpi_prim_test.cpp +++ b/test/unit/math/rev/functor/map_rect_mpi_prim_test.cpp @@ -13,12 +13,13 @@ #include #include -STAN_REGISTER_MAP_RECT(0, hard_work) -STAN_REGISTER_MAP_RECT(1, hard_work) -STAN_REGISTER_MAP_RECT(2, faulty_functor) -STAN_REGISTER_MAP_RECT(3, faulty_functor) +// Keep call IDs unique across the grouped functor executable. +STAN_REGISTER_MAP_RECT(10, hard_work) +STAN_REGISTER_MAP_RECT(11, hard_work) +STAN_REGISTER_MAP_RECT(12, faulty_functor) +STAN_REGISTER_MAP_RECT(13, faulty_functor) -struct MpiJob : public ::testing::Test { +struct MpiPrimJob : public ::testing::Test { Eigen::VectorXd shared_params_d; std::vector job_params_d; const std::size_t N = 10; @@ -64,11 +65,11 @@ struct MpiJobSmallWorld : public ::testing::Test { } }; -TEST_F(MpiJob, hard_work_dd) { - Eigen::VectorXd result_mpi = stan::math::map_rect<0, hard_work>( +TEST_F(MpiPrimJob, hard_work_dd) { + Eigen::VectorXd result_mpi = stan::math::map_rect<10, hard_work>( shared_params_d, job_params_d, x_r, x_i); Eigen::VectorXd result_concurrent - = stan::math::internal::map_rect_concurrent<0, hard_work>( + = stan::math::internal::map_rect_concurrent<10, hard_work>( shared_params_d, job_params_d, x_r, x_i); EXPECT_EQ(result_mpi.rows(), result_concurrent.rows()); @@ -80,10 +81,10 @@ TEST_F(MpiJob, hard_work_dd) { // execute fewer jobs than the cluster size TEST_F(MpiJobSmallWorld, hard_work_dd) { - Eigen::VectorXd result_mpi = stan::math::map_rect<1, hard_work>( + Eigen::VectorXd result_mpi = stan::math::map_rect<11, hard_work>( shared_params_d, job_params_d, x_r, x_i); Eigen::VectorXd result_concurrent - = stan::math::internal::map_rect_concurrent<1, hard_work>( + = stan::math::internal::map_rect_concurrent<11, hard_work>( shared_params_d, job_params_d, x_r, x_i); EXPECT_EQ(result_mpi.rows(), result_concurrent.rows()); @@ -93,10 +94,10 @@ TEST_F(MpiJobSmallWorld, hard_work_dd) { } } -TEST_F(MpiJob, always_faulty_functor) { +TEST_F(MpiPrimJob, always_faulty_functor) { Eigen::VectorXd result; - EXPECT_NO_THROW((result = stan::math::map_rect<2, faulty_functor>( + EXPECT_NO_THROW((result = stan::math::map_rect<12, faulty_functor>( shared_params_d, job_params_d, x_r, x_i))); // faulty functor throws on theta(0) being -1.0 @@ -106,16 +107,16 @@ TEST_F(MpiJob, always_faulty_functor) { // upon the second evaluation throwing is handled internally // different - EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<12, faulty_functor>( shared_params_d, job_params_d, x_r, x_i)), std::domain_error, "Error during MPI evaluation."); // throwing on the very first evaluation - EXPECT_THROW_MSG((result = stan::math::map_rect<3, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<13, faulty_functor>( shared_params_d, job_params_d, x_r, x_i)), std::domain_error, "MPI error on first evaluation."); // things don't get better if we repeat - EXPECT_THROW_MSG((result = stan::math::map_rect<3, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<13, faulty_functor>( shared_params_d, job_params_d, x_r, x_i)), std::domain_error, "MPI error on first evaluation."); } diff --git a/test/unit/math/rev/functor/map_rect_mpi_test.cpp b/test/unit/math/rev/functor/map_rect_mpi_test.cpp index 40a2851ef51..facba63c504 100644 --- a/test/unit/math/rev/functor/map_rect_mpi_test.cpp +++ b/test/unit/math/rev/functor/map_rect_mpi_test.cpp @@ -13,9 +13,10 @@ #include #include -STAN_REGISTER_MAP_RECT(0, hard_work) -STAN_REGISTER_MAP_RECT(1, faulty_functor) -STAN_REGISTER_MAP_RECT(2, faulty_functor) +// Keep call IDs unique across the grouped functor executable. +STAN_REGISTER_MAP_RECT(20, hard_work) +STAN_REGISTER_MAP_RECT(21, faulty_functor) +STAN_REGISTER_MAP_RECT(22, faulty_functor) struct MpiJob : public ::testing::Test { stan::math::vector_d shared_params_d; @@ -67,11 +68,11 @@ TEST_F(MpiJob, hard_work_vv) { job_params_v2_vec.push_back(stan::math::to_array_1d(job_params_v2[i])); } - stan::math::vector_v result_mpi = stan::math::map_rect<0, hard_work>( + stan::math::vector_v result_mpi = stan::math::map_rect<20, hard_work>( shared_params_v, job_params_v, x_r, x_i, 0); stan::math::vector_v result_concurrent - = stan::math::internal::map_rect_concurrent<0, hard_work>( + = stan::math::internal::map_rect_concurrent<20, hard_work>( shared_params_v2, job_params_v2, x_r, x_i, 0); std::vector z_grad1; @@ -111,7 +112,7 @@ TEST_F(MpiJob, hard_work_vv) { TEST_F(MpiJob, always_faulty_functor_vv) { stan::math::vector_v result; - EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>( shared_params_v, job_params_v, x_r, x_i))); // faulty functor throws on theta(0) being -1.0 @@ -120,12 +121,12 @@ TEST_F(MpiJob, always_faulty_functor_vv) { job_params_v[0](0) = -1; // upon the second evaluation throwing is handled internally different - EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>( shared_params_v, job_params_v, x_r, x_i)), std::domain_error, "Error during MPI evaluation."); // throwing on the very first evaluation - EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>( shared_params_v, job_params_v, x_r, x_i)), std::domain_error, "MPI error on first evaluation."); } @@ -133,7 +134,7 @@ TEST_F(MpiJob, always_faulty_functor_vv) { TEST_F(MpiJob, always_faulty_functor_vd) { stan::math::vector_v result; - EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>( shared_params_v, job_params_d, x_r, x_i))); // faulty functor throws on theta(0) being -1.0 @@ -142,12 +143,12 @@ TEST_F(MpiJob, always_faulty_functor_vd) { job_params_d[0](0) = -1; // upon the second evaluation throwing is handled internally different - EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>( shared_params_v, job_params_d, x_r, x_i)), std::domain_error, "Error during MPI evaluation."); // throwing on the very first evaluation - EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>( shared_params_v, job_params_d, x_r, x_i)), std::domain_error, "MPI error on first evaluation."); } @@ -155,7 +156,7 @@ TEST_F(MpiJob, always_faulty_functor_vd) { TEST_F(MpiJob, always_faulty_functor_dv) { stan::math::vector_v result; - EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>( shared_params_d, job_params_v, x_r, x_i))); // faulty functor throws on theta(0) being -1.0 @@ -164,12 +165,12 @@ TEST_F(MpiJob, always_faulty_functor_dv) { job_params_v[0](0) = -1; // upon the second evaluation throwing is handled internally different - EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>( shared_params_d, job_params_v, x_r, x_i)), std::domain_error, "Error during MPI evaluation."); // throwing on the very first evaluation - EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>( + EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>( shared_params_d, job_params_v, x_r, x_i)), std::domain_error, "MPI error on first evaluation."); } diff --git a/test/unit/math/rev/functor/map_rect_prim_test.cpp b/test/unit/math/rev/functor/map_rect_prim_test.cpp index fbdd38ae275..6b935c5a1b3 100644 --- a/test/unit/math/rev/functor/map_rect_prim_test.cpp +++ b/test/unit/math/rev/functor/map_rect_prim_test.cpp @@ -10,12 +10,13 @@ // the tests here check that map_rect refuses mal-formatted input as // such it does not matter if STAN_MPI is defined or not -STAN_REGISTER_MAP_RECT(0, hard_work) -STAN_REGISTER_MAP_RECT(1, hard_work) -STAN_REGISTER_MAP_RECT(2, hard_work) -STAN_REGISTER_MAP_RECT(3, hard_work) -STAN_REGISTER_MAP_RECT(4, hard_work) -STAN_REGISTER_MAP_RECT(5, hard_work) +// Keep call IDs unique across the grouped functor executable. +STAN_REGISTER_MAP_RECT(30, hard_work) +STAN_REGISTER_MAP_RECT(31, hard_work) +STAN_REGISTER_MAP_RECT(32, hard_work) +STAN_REGISTER_MAP_RECT(33, hard_work) +STAN_REGISTER_MAP_RECT(34, hard_work) +STAN_REGISTER_MAP_RECT(35, hard_work) struct map_rect_prim : public ::testing::Test { Eigen::VectorXd shared_params_d; @@ -44,54 +45,54 @@ TEST_F(map_rect_prim, no_job_input_ok_dd) { x_i.resize(0); x_r.resize(0); - EXPECT_NO_THROW((stan::math::map_rect<0, hard_work>(shared_params_d, - job_params_d, x_r, x_i))); + EXPECT_NO_THROW((stan::math::map_rect<30, hard_work>( + shared_params_d, job_params_d, x_r, x_i))); } TEST_F(map_rect_prim, size_mismatch_job_params_dd) { job_params_d.pop_back(); - EXPECT_THROW((stan::math::map_rect<1, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<31, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } TEST_F(map_rect_prim, size_mismatch_real_data_dd) { x_r.pop_back(); - EXPECT_THROW((stan::math::map_rect<2, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<32, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } TEST_F(map_rect_prim, size_mismatch_int_data_dd) { x_i.pop_back(); - EXPECT_THROW((stan::math::map_rect<3, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<33, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } TEST_F(map_rect_prim, wrong_size_job_params_dd) { job_params_d[1].resize(5); - EXPECT_THROW((stan::math::map_rect<1, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<31, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } TEST_F(map_rect_prim, wrong_size_real_data_dd) { x_r[1] = std::vector(5, 1); - EXPECT_THROW((stan::math::map_rect<4, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<34, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } TEST_F(map_rect_prim, wrong_size_int_data_dd) { x_i[1] = std::vector(5, 1); - EXPECT_THROW((stan::math::map_rect<5, hard_work>(shared_params_d, - job_params_d, x_r, x_i)), + EXPECT_THROW((stan::math::map_rect<35, hard_work>(shared_params_d, + job_params_d, x_r, x_i)), std::invalid_argument); } diff --git a/test/unit/math/rev/functor/util_algebra_solver.hpp b/test/unit/math/rev/functor/util_algebra_solver.hpp index 6035ca4d0d7..0ac3865dc77 100644 --- a/test/unit/math/rev/functor/util_algebra_solver.hpp +++ b/test/unit/math/rev/functor/util_algebra_solver.hpp @@ -518,7 +518,7 @@ inline void max_num_steps_test(Eigen::Matrix& y, std::domain_error); } -Eigen::Matrix variadic_eq_impl_test( +inline Eigen::Matrix variadic_eq_impl_test( const Eigen::Matrix A, const stan::math::var& y_1, const stan::math::var& y_2, const stan::math::var& y_3, const int i, bool is_newton = false, diff --git a/test/unit/math/rev/prob/bernoulli_logit_glm_lpmf_test.cpp b/test/unit/math/rev/prob/bernoulli_logit_glm_lpmf_test.cpp index cb8c2a16395..9a89fc2e1ed 100644 --- a/test/unit/math/rev/prob/bernoulli_logit_glm_lpmf_test.cpp +++ b/test/unit/math/rev/prob/bernoulli_logit_glm_lpmf_test.cpp @@ -573,6 +573,8 @@ TYPED_TEST(ProbDistributionsBernoulliLogitGLM, for (int n = 0; n < N; n++) { yw2[n] = -(Eigen::Matrix::Random(1, 1)[0] % 2); } + // Random draws can all be zero, so guarantee an out-of-domain label. + yw2[N - 1] = -1; Eigen::Matrix yw3(N, 1); for (int n = 0; n < N; n++) { yw3[n] = 42 + (Eigen::Matrix::Random(1, 1)[0] % 2); @@ -600,7 +602,8 @@ TYPED_TEST(ProbDistributionsBernoulliLogitGLM, EXPECT_THROW(stan::math::bernoulli_logit_glm_lpmf(yw1, x, alpha, beta), std::invalid_argument); EXPECT_THROW(stan::math::bernoulli_logit_glm_lpmf(yw2, x, alpha, beta), - std::domain_error); + std::domain_error) + << "Negative-label fixture: " << yw2.transpose(); EXPECT_THROW(stan::math::bernoulli_logit_glm_lpmf(yw3, x, alpha, beta), std::domain_error); EXPECT_THROW(stan::math::bernoulli_logit_glm_lpmf(y, xw1, alpha, beta), diff --git a/test/unit/math/test_ad.hpp b/test/unit/math/test_ad.hpp index 6336f1b03d0..78c8aecf15a 100644 --- a/test/unit/math/test_ad.hpp +++ b/test/unit/math/test_ad.hpp @@ -59,7 +59,7 @@ auto eval(const std::complex& x) { * @param[in] x value * @return value */ -auto eval(const stan::math::var& x) { return x; } +inline auto eval(const stan::math::var& x) { return x; } /** * Evaluates all matrix expression templates, which is a no-op for @@ -974,7 +974,7 @@ inline void expect_ad_vvv(const ad_tolerances& tols, const F& f, int x1, int x2, * * @return non-zero arguments */ -const std::vector& common_nonzero_args() { +inline const std::vector& common_nonzero_args() { static const std::vector common_nz_args{ -1.3, 0.49, diff --git a/test/unit/util.hpp b/test/unit/util.hpp index 6d13989d579..a0343c1a111 100644 --- a/test/unit/util.hpp +++ b/test/unit/util.hpp @@ -167,7 +167,7 @@ * @param s string to match count occurrences * @return number of found occurrences of target in s */ -int count_matches(const std::string& target, const std::string& s) { +inline int count_matches(const std::string& target, const std::string& s) { if (target.size() == 0) return -1; // error int count = 0; @@ -212,7 +212,7 @@ int count_matches(const std::string& target, const std::string& s) { namespace stan { namespace test { -auto make_sparse_matrix_random(int rows, int cols) { +inline auto make_sparse_matrix_random(int rows, int cols) { using eigen_triplet = Eigen::Triplet; boost::mt19937 gen; boost::random::uniform_real_distribution dist(0.0, 1.0);