diff --git a/stan/math/prim/eigen_plugins.h b/stan/math/prim/eigen_plugins.h index 00be6a4c855..37e16fc768b 100644 --- a/stan/math/prim/eigen_plugins.h +++ b/stan/math/prim/eigen_plugins.h @@ -53,14 +53,14 @@ struct val_Op{ //Returns value from a vari* template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - std::enable_if_t::value, reverse_return_t> + std::enable_if_t::value, const double&> operator()(T &v) const { return v->val_; } //Returns value from a var template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::enable_if_t<(!std::is_pointer::value && !is_fvar::value - && !std::is_arithmetic::value), reverse_return_t> + && !std::is_arithmetic::value), const double&> operator()(T &v) const { return v.vi_->val_; } //Returns value from an fvar diff --git a/test/unit/math/fwd/eigen_plugins_test.cpp b/test/unit/math/fwd/eigen_plugins_test.cpp index 7b5018451ef..1e5ef8b0a76 100644 --- a/test/unit/math/fwd/eigen_plugins_test.cpp +++ b/test/unit/math/fwd/eigen_plugins_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(AgradFwdMatrixAddons, fvar_double_matrix) { @@ -18,11 +18,11 @@ TEST(AgradFwdMatrixAddons, fvar_double_matrix) { } } - expect_matrix_eq(vals, mat_in.val()); - expect_matrix_eq(vals.array().exp(), mat_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), mat_in.val().array().exp()); - expect_matrix_eq(derivs, mat_in.d()); - expect_matrix_eq(derivs.array().exp(), mat_in.d().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_in.d()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), mat_in.d().array().exp()); EXPECT_EQ(mat_in.val().rows(), vals.rows()); EXPECT_EQ(mat_in.val().cols(), vals.cols()); @@ -47,11 +47,11 @@ TEST(AgradFwdMatrixAddons, fvarfvar_double_matrix) { } } - expect_matrix_eq(vals, mat_in.val().val()); - expect_matrix_eq(vals.array().exp(), mat_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), mat_in.val().val().array().exp()); - expect_matrix_eq(derivs, mat_in.d().val()); - expect_matrix_eq(derivs.array().exp(), mat_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), mat_in.d().val().array().exp()); EXPECT_EQ(mat_in.val().rows(), vals.rows()); EXPECT_EQ(mat_in.val().cols(), vals.cols()); @@ -74,11 +74,11 @@ TEST(AgradFwdMatrixAddons, fvar_double_vector) { vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, vec_in.val()); - expect_matrix_eq(vals.array().exp(), vec_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), vec_in.val().array().exp()); - expect_matrix_eq(derivs, vec_in.d()); - expect_matrix_eq(derivs.array().exp(), vec_in.d().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_in.d()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), vec_in.d().array().exp()); EXPECT_EQ(vec_in.val().rows(), vals.rows()); EXPECT_EQ(vec_in.val().cols(), vals.cols()); @@ -101,11 +101,11 @@ TEST(AgradFwdMatrixAddons, fvarfvar_double_vector) { vec_in(i).d_.val_ = derivs(i); } - expect_matrix_eq(vals, vec_in.val().val()); - expect_matrix_eq(vals.array().exp(), vec_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), vec_in.val().val().array().exp()); - expect_matrix_eq(derivs, vec_in.d().val()); - expect_matrix_eq(derivs.array().exp(), vec_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), vec_in.d().val().array().exp()); EXPECT_EQ(vec_in.val().rows(), vals.rows()); EXPECT_EQ(vec_in.val().cols(), vals.cols()); @@ -128,11 +128,11 @@ TEST(AgradFwdMatrixAddons, fvar_double_rowvector) { row_vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, row_vec_in.val()); - expect_matrix_eq(vals.array().exp(), row_vec_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), row_vec_in.val().array().exp()); - expect_matrix_eq(derivs, row_vec_in.d()); - expect_matrix_eq(derivs.array().exp(), row_vec_in.d().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_in.d()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), row_vec_in.d().array().exp()); EXPECT_EQ(row_vec_in.val().rows(), vals.rows()); EXPECT_EQ(row_vec_in.val().cols(), vals.cols()); @@ -155,11 +155,13 @@ TEST(AgradFwdMatrixAddons, fvarfvar_double_rowvector) { row_vec_in(i).d_.val_ = derivs(i); } - expect_matrix_eq(vals, row_vec_in.val().val()); - expect_matrix_eq(vals.array().exp(), row_vec_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), + row_vec_in.val().val().array().exp()); - expect_matrix_eq(derivs, row_vec_in.d().val()); - expect_matrix_eq(derivs.array().exp(), row_vec_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), + row_vec_in.d().val().array().exp()); EXPECT_EQ(row_vec_in.val().rows(), vals.rows()); EXPECT_EQ(row_vec_in.val().cols(), vals.cols()); diff --git a/test/unit/math/fwd/fun/read_fvar_test.cpp b/test/unit/math/fwd/fun/read_fvar_test.cpp index 6ad7873c8d4..2ee53fb04fc 100644 --- a/test/unit/math/fwd/fun/read_fvar_test.cpp +++ b/test/unit/math/fwd/fun/read_fvar_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(AgradFwdMatrix, read_fvar_mat_fd) { @@ -13,8 +13,8 @@ TEST(AgradFwdMatrix, read_fvar_mat_fd) { matrix_fvar.d() = MatrixXd::Random(100, 100); read_fvar(matrix_fvar, matrix_val, matrix_deriv); - expect_matrix_eq(matrix_fvar.val(), matrix_val); - expect_matrix_eq(matrix_fvar.d(), matrix_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar.val(), matrix_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar.d(), matrix_deriv); } TEST(AgradFwdMatrix, read_fvar_vec_fd) { @@ -28,8 +28,8 @@ TEST(AgradFwdMatrix, read_fvar_vec_fd) { vector_fvar.d() = VectorXd::Random(100); read_fvar(vector_fvar, vector_val, vector_deriv); - expect_matrix_eq(vector_fvar.val(), vector_val); - expect_matrix_eq(vector_fvar.d(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(vector_fvar.val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(vector_fvar.d(), vector_deriv); } TEST(AgradFwdMatrix, read_fvar_rowvec_fd) { @@ -43,8 +43,8 @@ TEST(AgradFwdMatrix, read_fvar_rowvec_fd) { row_vector_fvar.d() = RowVectorXd::Random(100); read_fvar(row_vector_fvar, row_vector_val, row_vector_deriv); - expect_matrix_eq(row_vector_fvar.val(), row_vector_val); - expect_matrix_eq(row_vector_fvar.d(), row_vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(row_vector_fvar.val(), row_vector_val); + EXPECT_MATRIX_FLOAT_EQ(row_vector_fvar.d(), row_vector_deriv); } TEST(AgradFwdMatrix, read_fvar_expr_fd) { @@ -58,8 +58,8 @@ TEST(AgradFwdMatrix, read_fvar_expr_fd) { matrix_fvar.d() = MatrixXd::Random(100, 100); read_fvar(matrix_fvar.diagonal(), matrix_diag_val, matrix_diag_deriv); - expect_matrix_eq(matrix_fvar.diagonal().val(), matrix_diag_val); - expect_matrix_eq(matrix_fvar.diagonal().d(), matrix_diag_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar.diagonal().val(), matrix_diag_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar.diagonal().d(), matrix_diag_deriv); } TEST(AgradFwdMatrix, read_fvar_mat_ffd) { @@ -74,8 +74,8 @@ TEST(AgradFwdMatrix, read_fvar_mat_ffd) { matrix_fvar_fvar.d().val() = MatrixXd::Random(100, 100); read_fvar(matrix_fvar_fvar, matrix_val, matrix_deriv); - expect_matrix_eq(matrix_fvar_fvar.val().val(), matrix_val.val()); - expect_matrix_eq(matrix_fvar_fvar.d().val(), matrix_deriv.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar_fvar.val().val(), matrix_val.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar_fvar.d().val(), matrix_deriv.val()); } TEST(AgradFwdMatrix, read_fvar_vec_ffd) { @@ -90,8 +90,8 @@ TEST(AgradFwdMatrix, read_fvar_vec_ffd) { vector_fvar_fvar.d().val() = VectorXd::Random(100); read_fvar(vector_fvar_fvar, vector_val, vector_deriv); - expect_matrix_eq(vector_fvar_fvar.val().val(), vector_val.val()); - expect_matrix_eq(vector_fvar_fvar.d().val(), vector_deriv.val()); + EXPECT_MATRIX_FLOAT_EQ(vector_fvar_fvar.val().val(), vector_val.val()); + EXPECT_MATRIX_FLOAT_EQ(vector_fvar_fvar.d().val(), vector_deriv.val()); } TEST(AgradFwdMatrix, read_fvar_rowvec_ffd) { @@ -106,8 +106,10 @@ TEST(AgradFwdMatrix, read_fvar_rowvec_ffd) { row_vector_fvar_fvar.d().val() = RowVectorXd::Random(100); read_fvar(row_vector_fvar_fvar, row_vector_val, row_vector_deriv); - expect_matrix_eq(row_vector_fvar_fvar.val().val(), row_vector_val.val()); - expect_matrix_eq(row_vector_fvar_fvar.d().val(), row_vector_deriv.val()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_fvar_fvar.val().val(), + row_vector_val.val()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_fvar_fvar.d().val(), + row_vector_deriv.val()); } TEST(AgradFwdMatrix, read_fvar_expr_ffd) { @@ -122,8 +124,8 @@ TEST(AgradFwdMatrix, read_fvar_expr_ffd) { matrix_fvar_fvar.d().val() = MatrixXd::Random(100, 100); read_fvar(matrix_fvar_fvar.diagonal(), matrix_diag_val, matrix_diag_deriv); - expect_matrix_eq(matrix_fvar_fvar.diagonal().val().val(), - matrix_diag_val.val()); - expect_matrix_eq(matrix_fvar_fvar.diagonal().d().val(), - matrix_diag_deriv.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar_fvar.diagonal().val().val(), + matrix_diag_val.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_fvar_fvar.diagonal().d().val(), + matrix_diag_deriv.val()); } diff --git a/test/unit/math/mix/eigen_plugins_test.cpp b/test/unit/math/mix/eigen_plugins_test.cpp index 271265ae59c..3956f5cd06f 100644 --- a/test/unit/math/mix/eigen_plugins_test.cpp +++ b/test/unit/math/mix/eigen_plugins_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(AgradMixMatrixAddons, matrix_fv) { @@ -17,11 +17,11 @@ TEST(AgradMixMatrixAddons, matrix_fv) { } } - expect_matrix_eq(vals, mat_in.val().val()); - expect_matrix_eq(vals.array().exp(), mat_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), mat_in.val().val().array().exp()); - expect_matrix_eq(derivs, mat_in.d().val()); - expect_matrix_eq(derivs.array().exp(), mat_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), mat_in.d().val().array().exp()); EXPECT_EQ(mat_in.val().val().rows(), vals.rows()); EXPECT_EQ(mat_in.val().val().cols(), vals.cols()); @@ -45,11 +45,13 @@ TEST(AgradMixMatrixAddons, matrix_ffv) { } } - expect_matrix_eq(vals, mat_in.val().val().val()); - expect_matrix_eq(vals.array().exp(), mat_in.val().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_in.val().val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), + mat_in.val().val().val().array().exp()); - expect_matrix_eq(derivs, mat_in.d().val().val()); - expect_matrix_eq(derivs.array().exp(), mat_in.d().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_in.d().val().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), + mat_in.d().val().val().array().exp()); EXPECT_EQ(mat_in.val().val().val().rows(), vals.rows()); EXPECT_EQ(mat_in.val().val().val().cols(), vals.cols()); @@ -71,11 +73,11 @@ TEST(AgradMixMatrixAddons, vector_fv) { vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, vec_in.val().val()); - expect_matrix_eq(vals.array().exp(), vec_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), vec_in.val().val().array().exp()); - expect_matrix_eq(derivs, vec_in.d().val()); - expect_matrix_eq(derivs.array().exp(), vec_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), vec_in.d().val().array().exp()); EXPECT_EQ(vec_in.val().val().rows(), vals.rows()); EXPECT_EQ(vec_in.val().val().cols(), vals.cols()); @@ -97,11 +99,13 @@ TEST(AgradMixMatrixAddons, vector_ffv) { vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, vec_in.val().val().val()); - expect_matrix_eq(vals.array().exp(), vec_in.val().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_in.val().val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), + vec_in.val().val().val().array().exp()); - expect_matrix_eq(derivs, vec_in.d().val().val()); - expect_matrix_eq(derivs.array().exp(), vec_in.d().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_in.d().val().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), + vec_in.d().val().val().array().exp()); EXPECT_EQ(vec_in.val().val().val().rows(), vals.rows()); EXPECT_EQ(vec_in.val().val().val().cols(), vals.cols()); @@ -123,11 +127,13 @@ TEST(AgradMixMatrixAddons, row_vector_fv) { row_vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, row_vec_in.val().val()); - expect_matrix_eq(vals.array().exp(), row_vec_in.val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_in.val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), + row_vec_in.val().val().array().exp()); - expect_matrix_eq(derivs, row_vec_in.d().val()); - expect_matrix_eq(derivs.array().exp(), row_vec_in.d().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_in.d().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), + row_vec_in.d().val().array().exp()); EXPECT_EQ(row_vec_in.val().val().rows(), vals.rows()); EXPECT_EQ(row_vec_in.val().val().cols(), vals.cols()); @@ -149,13 +155,13 @@ TEST(AgradMixMatrixAddons, row_vector_ffv) { row_vec_in(i).d_ = derivs(i); } - expect_matrix_eq(vals, row_vec_in.val().val().val()); - expect_matrix_eq(vals.array().exp(), - row_vec_in.val().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_in.val().val().val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), + row_vec_in.val().val().val().array().exp()); - expect_matrix_eq(derivs, row_vec_in.d().val().val()); - expect_matrix_eq(derivs.array().exp(), - row_vec_in.d().val().val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_in.d().val().val()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), + row_vec_in.d().val().val().array().exp()); EXPECT_EQ(row_vec_in.val().val().val().rows(), vals.rows()); EXPECT_EQ(row_vec_in.val().val().val().cols(), vals.cols()); diff --git a/test/unit/math/opencl/async_test.cpp b/test/unit/math/opencl/async_test.cpp index 544a9899485..88c8ac3f2df 100644 --- a/test/unit/math/opencl/async_test.cpp +++ b/test/unit/math/opencl/async_test.cpp @@ -2,12 +2,9 @@ #include #include +#include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - // Test we can handle a semi-complicated but normal queue TEST(async_opencl, thrash_opencl) { auto size = 100; diff --git a/test/unit/math/opencl/cholesky_decompose_test.cpp b/test/unit/math/opencl/cholesky_decompose_test.cpp index e6c7303643a..94d11184651 100644 --- a/test/unit/math/opencl/cholesky_decompose_test.cpp +++ b/test/unit/math/opencl/cholesky_decompose_test.cpp @@ -1,14 +1,11 @@ #ifdef STAN_OPENCL #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixOpenCL, cholesky_decompose_cpu_vs_cl_small) { stan::math::matrix_d m0(3, 3); m0 << 25, 15, -5, 15, 18, 0, -5, 0, 11; diff --git a/test/unit/math/opencl/kernel_cl_test.cpp b/test/unit/math/opencl/kernel_cl_test.cpp index dfafc117e9b..3d3899ea4a5 100644 --- a/test/unit/math/opencl/kernel_cl_test.cpp +++ b/test/unit/math/opencl/kernel_cl_test.cpp @@ -2,13 +2,10 @@ #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathGpu, make_kernel) { stan::math::matrix_d m(3, 3); diff --git a/test/unit/math/opencl/kernel_generator/append_test.cpp b/test/unit/math/opencl/kernel_generator/append_test.cpp index 08629d3fe28..7f208a1d807 100644 --- a/test/unit/math/opencl/kernel_generator/append_test.cpp +++ b/test/unit/math/opencl/kernel_generator/append_test.cpp @@ -4,13 +4,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, append_row_errors) { using Eigen::MatrixXd; using stan::math::append_row; diff --git a/test/unit/math/opencl/kernel_generator/binary_operation_test.cpp b/test/unit/math/opencl/kernel_generator/binary_operation_test.cpp index 087c843139a..028c51fcf8c 100644 --- a/test/unit/math/opencl/kernel_generator/binary_operation_test.cpp +++ b/test/unit/math/opencl/kernel_generator/binary_operation_test.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,10 +16,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, addition_test) { std::string kernel_filename = "binary_operation_addition.cl"; MatrixXd m1(3, 3); @@ -61,7 +58,7 @@ TEST(KernelGenerator, addition_test) { \ Matrix correct \ = m1.array() operation m2.cast().array(); \ - EXPECT_MATRIX_NEAR(res, correct, 1e-9); \ + EXPECT_TYPED_MATRIX_NEAR(res, correct, 1e-9, res_type); \ } BINARY_OPERATION_TEST(subtraction_test, -, double); @@ -121,7 +118,7 @@ TEST(KernelGenerator, logical_or_test) { Matrix res = stan::math::from_matrix_cl(res_cl); Matrix correct = m1 || m2; - EXPECT_MATRIX_NEAR(res, correct, 1e-9); + EXPECT_TYPED_MATRIX_EQ(res, correct, bool); } TEST(KernelGenerator, logical_and_test) { @@ -138,7 +135,7 @@ TEST(KernelGenerator, logical_and_test) { Matrix res = stan::math::from_matrix_cl(res_cl); Matrix correct = m1 && m2; - EXPECT_MATRIX_NEAR(res, correct, 1e-9); + EXPECT_TYPED_MATRIX_EQ(res, correct, bool); } TEST(KernelGenerator, binary_operation_multiple_operations) { diff --git a/test/unit/math/opencl/kernel_generator/block_test.cpp b/test/unit/math/opencl/kernel_generator/block_test.cpp index 09c85107cbf..2e6615faeb8 100644 --- a/test/unit/math/opencl/kernel_generator/block_test.cpp +++ b/test/unit/math/opencl/kernel_generator/block_test.cpp @@ -1,9 +1,10 @@ #ifdef STAN_OPENCL #include -#include #include #include +#include +#include #include #include #include @@ -13,12 +14,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - EXPECT_EQ(A.rows(), B.rows()); \ - EXPECT_EQ(A.cols(), B.cols()); \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, block_errors) { using stan::math::block; diff --git a/test/unit/math/opencl/kernel_generator/broadcast_test.cpp b/test/unit/math/opencl/kernel_generator/broadcast_test.cpp index 50a688a14f8..97c929ebfd3 100644 --- a/test/unit/math/opencl/kernel_generator/broadcast_test.cpp +++ b/test/unit/math/opencl/kernel_generator/broadcast_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, broadcast_errors) { using Eigen::MatrixXd; using stan::math::matrix_cl; diff --git a/test/unit/math/opencl/kernel_generator/calc_if_test.cpp b/test/unit/math/opencl/kernel_generator/calc_if_test.cpp index 3cff22dc4f2..0343ae0a350 100644 --- a/test/unit/math/opencl/kernel_generator/calc_if_test.cpp +++ b/test/unit/math/opencl/kernel_generator/calc_if_test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -11,12 +12,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - EXPECT_EQ(A.rows(), B.rows()); \ - EXPECT_EQ(A.cols(), B.cols()); \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, is_without_output_test) { EXPECT_TRUE((stan::math::is_without_output< stan::math::calc_if_>>::value)); diff --git a/test/unit/math/opencl/kernel_generator/colwise_reduction_test.cpp b/test/unit/math/opencl/kernel_generator/colwise_reduction_test.cpp index 383973e0f1a..b5754a1b5d0 100644 --- a/test/unit/math/opencl/kernel_generator/colwise_reduction_test.cpp +++ b/test/unit/math/opencl/kernel_generator/colwise_reduction_test.cpp @@ -1,11 +1,12 @@ #ifdef STAN_OPENCL +#include #include #include #include #include -#include #include +#include #include #include @@ -14,10 +15,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, colwise_sum_test) { std::string kernel_filename = "colwise_sum.cl"; MatrixXd m(3, 2); diff --git a/test/unit/math/opencl/kernel_generator/diagonal_test.cpp b/test/unit/math/opencl/kernel_generator/diagonal_test.cpp index c8298a35825..10bed702b88 100644 --- a/test/unit/math/opencl/kernel_generator/diagonal_test.cpp +++ b/test/unit/math/opencl/kernel_generator/diagonal_test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13,12 +14,6 @@ using Eigen::VectorXd; using stan::math::diagonal; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - EXPECT_EQ(A.rows(), B.rows()); \ - EXPECT_EQ(A.cols(), B.cols()); \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, diagonal_test) { MatrixXd m = MatrixXd::Random(3, 4); diff --git a/test/unit/math/opencl/kernel_generator/holder_cl_test.cpp b/test/unit/math/opencl/kernel_generator/holder_cl_test.cpp index 89d611ef233..160ccc6a881 100644 --- a/test/unit/math/opencl/kernel_generator/holder_cl_test.cpp +++ b/test/unit/math/opencl/kernel_generator/holder_cl_test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -10,10 +11,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - template auto f(T&& a) { auto* a_heap = new std::remove_reference_t(std::forward(a)); diff --git a/test/unit/math/opencl/kernel_generator/multi_result_kernel_test.cpp b/test/unit/math/opencl/kernel_generator/multi_result_kernel_test.cpp index 668d8711bf8..fd672b250d7 100644 --- a/test/unit/math/opencl/kernel_generator/multi_result_kernel_test.cpp +++ b/test/unit/math/opencl/kernel_generator/multi_result_kernel_test.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -12,10 +13,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, multi_result_kernel_errors) { matrix_cl m1_cl(3, 3); matrix_cl m2_cl(3, 3); diff --git a/test/unit/math/opencl/kernel_generator/operation_test.cpp b/test/unit/math/opencl/kernel_generator/operation_test.cpp index 1c6d26b1929..97a06939092 100644 --- a/test/unit/math/opencl/kernel_generator/operation_test.cpp +++ b/test/unit/math/opencl/kernel_generator/operation_test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13,10 +14,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, operation_cl_errors) { EXPECT_THROW(matrix_cl a = stan::math::as_operation_cl(3.5), std::domain_error); diff --git a/test/unit/math/opencl/kernel_generator/optional_broadcast_test.cpp b/test/unit/math/opencl/kernel_generator/optional_broadcast_test.cpp index 3cc33c9c933..d43a02786e6 100644 --- a/test/unit/math/opencl/kernel_generator/optional_broadcast_test.cpp +++ b/test/unit/math/opencl/kernel_generator/optional_broadcast_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, optional_broadcast_errors) { using Eigen::MatrixXd; using Eigen::MatrixXi; diff --git a/test/unit/math/opencl/kernel_generator/rowwise_reduction_test.cpp b/test/unit/math/opencl/kernel_generator/rowwise_reduction_test.cpp index 8004c006d9b..854cd21284c 100644 --- a/test/unit/math/opencl/kernel_generator/rowwise_reduction_test.cpp +++ b/test/unit/math/opencl/kernel_generator/rowwise_reduction_test.cpp @@ -1,19 +1,16 @@ #ifdef STAN_OPENCL +#include #include #include #include #include -#include +#include #include using Eigen::MatrixXd; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, rowwise_sum_test) { MatrixXd m(3, 2); m << 1.1, 1.2, 1.3, 1.4, 1.5, 1.6; diff --git a/test/unit/math/opencl/kernel_generator/select_test.cpp b/test/unit/math/opencl/kernel_generator/select_test.cpp index 36eef34efe8..a5d8e11815f 100644 --- a/test/unit/math/opencl/kernel_generator/select_test.cpp +++ b/test/unit/math/opencl/kernel_generator/select_test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13,10 +14,6 @@ using Eigen::MatrixXd; using Eigen::MatrixXi; using stan::math::matrix_cl; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, select_errors) { using stan::math::select; diff --git a/test/unit/math/opencl/kernel_generator/transpose_test.cpp b/test/unit/math/opencl/kernel_generator/transpose_test.cpp index a03efc57986..c92d03cfc57 100644 --- a/test/unit/math/opencl/kernel_generator/transpose_test.cpp +++ b/test/unit/math/opencl/kernel_generator/transpose_test.cpp @@ -5,13 +5,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, transpose_rvalue_test) { using Eigen::MatrixXd; using stan::math::matrix_cl; diff --git a/test/unit/math/opencl/kernel_generator/unary_function_cl_test.cpp b/test/unit/math/opencl/kernel_generator/unary_function_cl_test.cpp index eaa7557d650..7041ddb37d4 100644 --- a/test/unit/math/opencl/kernel_generator/unary_function_cl_test.cpp +++ b/test/unit/math/opencl/kernel_generator/unary_function_cl_test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -22,10 +23,6 @@ MatrixXd rsqrt(const MatrixXd& a) { return stan::math::inv_sqrt(a); } } // namespace math } // namespace stan -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - #define TEST_FUNCTION(fun) \ TEST(KernelGenerator, fun##_test) { \ using stan::math::fun; \ @@ -127,7 +124,7 @@ TEST(KernelGenerator, log1m_exp_test) { \ Eigen::Matrix res = stan::math::from_matrix_cl(res_cl); \ Eigen::Matrix correct = fun(m1.array()); \ - EXPECT_MATRIX_NEAR(correct, res, 1e-9); \ + EXPECT_TYPED_MATRIX_EQ(correct, res, bool); \ } TEST_CLASSIFICATION_FUNCTION(isfinite) diff --git a/test/unit/math/opencl/kernel_generator/unary_operation_cl_test.cpp b/test/unit/math/opencl/kernel_generator/unary_operation_cl_test.cpp index 49898d095f2..dc191a46866 100644 --- a/test/unit/math/opencl/kernel_generator/unary_operation_cl_test.cpp +++ b/test/unit/math/opencl/kernel_generator/unary_operation_cl_test.cpp @@ -6,13 +6,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(KernelGenerator, logical_negation_test) { using stan::math::matrix_cl; Eigen::Matrix m1(3, 3); @@ -24,7 +21,7 @@ TEST(KernelGenerator, logical_negation_test) { Eigen::Matrix res = stan::math::from_matrix_cl(res_cl); Eigen::Matrix correct = !m1.array(); - EXPECT_MATRIX_NEAR(correct, res, 1e-9); + EXPECT_TYPED_MATRIX_EQ(correct, res, bool); } TEST(KernelGenerator, unary_minus_test) { diff --git a/test/unit/math/opencl/multiply_transpose_test.cpp b/test/unit/math/opencl/multiply_transpose_test.cpp index 6a8967b295d..5f193aaacc1 100644 --- a/test/unit/math/opencl/multiply_transpose_test.cpp +++ b/test/unit/math/opencl/multiply_transpose_test.cpp @@ -3,15 +3,12 @@ #include #include #include +#include #include #include #include boost::random::mt19937 rng; -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixOpenCL, multiply_transpose_exception_fail_zero) { stan::math::row_vector_d rv(0); stan::math::matrix_d m(0, 3); diff --git a/test/unit/math/opencl/prim/add_test.cpp b/test/unit/math/opencl/prim/add_test.cpp index 82088191f2c..1c3a53cf6ce 100644 --- a/test/unit/math/opencl/prim/add_test.cpp +++ b/test/unit/math/opencl/prim/add_test.cpp @@ -1,13 +1,10 @@ #ifdef STAN_OPENCL #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, add_v_exception_pass) { stan::math::vector_d d1, d2; @@ -216,7 +213,7 @@ TEST(MathMatrixCL, add_value_check) { EXPECT_MATRIX_NEAR((v1 + v2), v3, 1E-8); rv3 = stan::math::from_matrix_cl(rv33fun); - EXPECT_MATRIX_NEAR((rv1 + rv2), v3, 1E-8); + EXPECT_MATRIX_NEAR((rv1 + rv2), rv3, 1E-8); m3 = stan::math::from_matrix_cl(m33fun); EXPECT_MATRIX_NEAR((m1 + m2), m3, 1E-8); diff --git a/test/unit/math/opencl/prim/cholesky_decompose_test.cpp b/test/unit/math/opencl/prim/cholesky_decompose_test.cpp index 38db720eea7..a2a2ce95cf0 100644 --- a/test/unit/math/opencl/prim/cholesky_decompose_test.cpp +++ b/test/unit/math/opencl/prim/cholesky_decompose_test.cpp @@ -1,14 +1,11 @@ #ifdef STAN_OPENCL #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixOpenCLPrim, cholesky_decompose_cl_exceptions) { using stan::math::matrix_cl; matrix_cl m0; diff --git a/test/unit/math/opencl/prim/divide_test.cpp b/test/unit/math/opencl/prim/divide_test.cpp index 3519db8d647..22d80b97b7a 100644 --- a/test/unit/math/opencl/prim/divide_test.cpp +++ b/test/unit/math/opencl/prim/divide_test.cpp @@ -1,13 +1,10 @@ #ifdef STAN_OPENCL #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, divide_exception_pass) { stan::math::matrix_cl m; EXPECT_NO_THROW(stan::math::divide(m, 2)); diff --git a/test/unit/math/opencl/prim/inv_cloglog_test.cpp b/test/unit/math/opencl/prim/inv_cloglog_test.cpp index be37f257ac7..95344fbcad8 100644 --- a/test/unit/math/opencl/prim/inv_cloglog_test.cpp +++ b/test/unit/math/opencl/prim/inv_cloglog_test.cpp @@ -4,13 +4,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inv_cloglog) { stan::math::matrix_d y(1, 4); y << 3.7, 0.0, -2.93, std::numeric_limits::quiet_NaN(); diff --git a/test/unit/math/opencl/prim/inv_logit_test.cpp b/test/unit/math/opencl/prim/inv_logit_test.cpp index bd686adc8e7..ec7906f4c6d 100644 --- a/test/unit/math/opencl/prim/inv_logit_test.cpp +++ b/test/unit/math/opencl/prim/inv_logit_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inv_logit) { stan::math::matrix_d y(1, 3); y << 0.0, 5.0, std::numeric_limits::quiet_NaN(); diff --git a/test/unit/math/opencl/prim/inv_sqrt_test.cpp b/test/unit/math/opencl/prim/inv_sqrt_test.cpp index 955f72b0632..721be87dc20 100644 --- a/test/unit/math/opencl/prim/inv_sqrt_test.cpp +++ b/test/unit/math/opencl/prim/inv_sqrt_test.cpp @@ -3,14 +3,11 @@ #include #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inv_sqrt) { stan::math::matrix_d y(1, 4); y << 4.0, 25.0, 0.0, -50.0; diff --git a/test/unit/math/opencl/prim/inv_square_test.cpp b/test/unit/math/opencl/prim/inv_square_test.cpp index 74009a5cc52..a52ee01c5ff 100644 --- a/test/unit/math/opencl/prim/inv_square_test.cpp +++ b/test/unit/math/opencl/prim/inv_square_test.cpp @@ -3,12 +3,9 @@ #include #include #include +#include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inv_square) { stan::math::matrix_d y(1, 4); y << 2.0, 22.0, 0.0, -22.0; diff --git a/test/unit/math/opencl/prim/inv_test.cpp b/test/unit/math/opencl/prim/inv_test.cpp index a0766f351cb..817c1124f65 100644 --- a/test/unit/math/opencl/prim/inv_test.cpp +++ b/test/unit/math/opencl/prim/inv_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inv_nan) { stan::math::matrix_d y(1, 4); y << 2.0, 0.0, -32.7, std::numeric_limits::quiet_NaN(); diff --git a/test/unit/math/opencl/prim/log1m_inv_logit_test.cpp b/test/unit/math/opencl/prim/log1m_inv_logit_test.cpp index c758579224a..029dcfa6f8e 100644 --- a/test/unit/math/opencl/prim/log1m_inv_logit_test.cpp +++ b/test/unit/math/opencl/prim/log1m_inv_logit_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, log1m_inv_logit) { stan::math::matrix_d a(5, 1); a << -7.2, 0.0, 1.9, -5.0, 0.1; diff --git a/test/unit/math/opencl/prim/logit_test.cpp b/test/unit/math/opencl/prim/logit_test.cpp index 6c4c4af7330..f146835372c 100644 --- a/test/unit/math/opencl/prim/logit_test.cpp +++ b/test/unit/math/opencl/prim/logit_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, logit) { stan::math::matrix_d a(5, 1); a << 0.5, 0.4, 0.3, 0.2, 0.1; diff --git a/test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp b/test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp index ddc371aeb2f..79c478ab954 100644 --- a/test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp +++ b/test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp @@ -2,14 +2,11 @@ #include #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, mdivide_left_tri_low_cl_exception) { stan::math::matrix_d m1(2, 3); m1 << 1, 2, 3, 4, 5, 6; diff --git a/test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp b/test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp index 615634a152e..f58e9d45235 100644 --- a/test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp +++ b/test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp @@ -2,14 +2,11 @@ #include #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, mdivide_right_tri_low_cl_exception) { stan::math::matrix_d m1(2, 3); m1 << 1, 2, 3, 4, 5, 6; diff --git a/test/unit/math/opencl/prim/multiply_test.cpp b/test/unit/math/opencl/prim/multiply_test.cpp index d74f8078698..c3b736442af 100644 --- a/test/unit/math/opencl/prim/multiply_test.cpp +++ b/test/unit/math/opencl/prim/multiply_test.cpp @@ -1,13 +1,10 @@ #ifdef STAN_OPENCL #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixOpenCLPrim, vector_row_vector) { stan::math::vector_d v(3); stan::math::row_vector_d rv(3); diff --git a/test/unit/math/opencl/prim/rep_matrix_test.cpp b/test/unit/math/opencl/prim/rep_matrix_test.cpp index 2840855eb19..bd068c064c0 100644 --- a/test/unit/math/opencl/prim/rep_matrix_test.cpp +++ b/test/unit/math/opencl/prim/rep_matrix_test.cpp @@ -2,13 +2,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_EQ(A, B) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_EQ(A(i), B(i)); - TEST(MathMatrixCL, rep_matrix_size_one_exception_pass) { stan::math::matrix_cl a(2, 2); EXPECT_THROW(stan::math::rep_matrix(a, 5, 5), std::invalid_argument); @@ -90,7 +87,7 @@ TEST(MathMatrixCL, rep_matrix_v_value_check) { stan::math::matrix_d m1_cl_res = stan::math::from_matrix_cl(m1_cl); EXPECT_EQ(m1.rows(), m1_cl_res.rows()); EXPECT_EQ(m1.cols(), m1_cl_res.cols()); - EXPECT_MATRIX_EQ(m1, m1_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m1, m1_cl_res); } TEST(MathMatrixCL, rep_matrix_rv_value_check) { @@ -103,6 +100,6 @@ TEST(MathMatrixCL, rep_matrix_rv_value_check) { stan::math::matrix_d m1_cl_res = stan::math::from_matrix_cl(m1_cl); EXPECT_EQ(m1.rows(), m1_cl_res.rows()); EXPECT_EQ(m1.cols(), m1_cl_res.cols()); - EXPECT_MATRIX_EQ(m1, m1_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m1, m1_cl_res); } #endif diff --git a/test/unit/math/opencl/prim/rep_row_vector_test.cpp b/test/unit/math/opencl/prim/rep_row_vector_test.cpp index a55e040e02c..e1b1f744d55 100644 --- a/test/unit/math/opencl/prim/rep_row_vector_test.cpp +++ b/test/unit/math/opencl/prim/rep_row_vector_test.cpp @@ -2,13 +2,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_EQ(A, B) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_EQ(A(i), B(i)); - TEST(MathMatrixCL, rep_rv_exception_pass) { stan::math::matrix_cl a(2, 2); EXPECT_THROW(stan::math::rep_row_vector(a, 5), std::invalid_argument); @@ -33,7 +30,7 @@ TEST(MathMatrixCL, rep_rv_value_check) { stan::math::matrix_d m1_cl_res = stan::math::from_matrix_cl(m1_cl); EXPECT_EQ(m1.rows(), m1_cl_res.rows()); EXPECT_EQ(m1.cols(), m1_cl_res.cols()); - EXPECT_MATRIX_EQ(m1, m1_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m1, m1_cl_res); double val00 = -7.0; stan::math::matrix_cl m00_cl(val00); @@ -43,10 +40,16 @@ TEST(MathMatrixCL, rep_rv_value_check) { stan::math::matrix_d m2_cl_res = stan::math::from_matrix_cl(m2_cl); EXPECT_EQ(m2.rows(), m2_cl_res.rows()); EXPECT_EQ(m2.cols(), m2_cl_res.cols()); - EXPECT_MATRIX_EQ(m2, m2_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m2, m2_cl_res); stan::math::vector_d a(1); a << 6.0; + stan::math::matrix_cl m33_cl(a); stan::math::matrix_d b = stan::math::rep_matrix(a, 5); + stan::math::matrix_cl m3_cl = stan::math::rep_matrix(m33_cl, 1, 5); + stan::math::matrix_d m3_cl_res = stan::math::from_matrix_cl(m3_cl); + EXPECT_EQ(b.rows(), m3_cl_res.rows()); + EXPECT_EQ(b.cols(), m3_cl_res.cols()); + EXPECT_MATRIX_FLOAT_EQ(b, m3_cl_res); } #endif diff --git a/test/unit/math/opencl/prim/rep_vector_test.cpp b/test/unit/math/opencl/prim/rep_vector_test.cpp index f2ed34cf373..6feb5410bf5 100644 --- a/test/unit/math/opencl/prim/rep_vector_test.cpp +++ b/test/unit/math/opencl/prim/rep_vector_test.cpp @@ -3,13 +3,10 @@ #include #include #include +#include #include #include -#define EXPECT_MATRIX_EQ(A, B) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_EQ(A(i), B(i)); - TEST(MathMatrixCL, rep_v_exception_pass) { stan::math::matrix_cl a(2, 2); EXPECT_THROW(stan::math::rep_vector(a, 5), std::invalid_argument); @@ -32,9 +29,7 @@ TEST(MathMatrixCL, rep_v_value_check) { stan::math::matrix_d m1 = stan::math::rep_vector(val, 1); stan::math::matrix_cl m1_cl = stan::math::rep_vector(m0_cl, 1); stan::math::matrix_d m1_cl_res = stan::math::from_matrix_cl(m1_cl); - EXPECT_EQ(m1.rows(), m1_cl_res.rows()); - EXPECT_EQ(m1.cols(), m1_cl_res.cols()); - EXPECT_MATRIX_EQ(m1, m1_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m1, m1_cl_res); double val00 = -7.0; stan::math::matrix_cl m00_cl(val00); @@ -42,8 +37,6 @@ TEST(MathMatrixCL, rep_v_value_check) { stan::math::matrix_d m2 = stan::math::rep_vector(val00, 7); stan::math::matrix_cl m2_cl = stan::math::rep_vector(m00_cl, 7); stan::math::matrix_d m2_cl_res = stan::math::from_matrix_cl(m2_cl); - EXPECT_EQ(m2.rows(), m2_cl_res.rows()); - EXPECT_EQ(m2.cols(), m2_cl_res.cols()); - EXPECT_MATRIX_EQ(m2, m2_cl_res); + EXPECT_MATRIX_FLOAT_EQ(m2, m2_cl_res); } #endif diff --git a/test/unit/math/opencl/tri_inverse_test.cpp b/test/unit/math/opencl/tri_inverse_test.cpp index 32ef758d956..6bd312e2129 100644 --- a/test/unit/math/opencl/tri_inverse_test.cpp +++ b/test/unit/math/opencl/tri_inverse_test.cpp @@ -1,14 +1,11 @@ #ifdef STAN_OPENCL #include #include +#include #include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixCL, inverse_cl_exception) { stan::math::matrix_d m1(2, 3); m1 << 1, 2, 3, 4, 5, 6; diff --git a/test/unit/math/prim/fun/append_col_test.cpp b/test/unit/math/prim/fun/append_col_test.cpp index e8375cef286..0060c1b4c1d 100644 --- a/test/unit/math/prim/fun/append_col_test.cpp +++ b/test/unit/math/prim/fun/append_col_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include using stan::math::append_col; diff --git a/test/unit/math/prim/fun/append_row_test.cpp b/test/unit/math/prim/fun/append_row_test.cpp index 380a5e42937..f9bb2d794a7 100644 --- a/test/unit/math/prim/fun/append_row_test.cpp +++ b/test/unit/math/prim/fun/append_row_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include using stan::math::append_row; diff --git a/test/unit/math/prim/fun/containers_conversion_test.cpp b/test/unit/math/prim/fun/containers_conversion_test.cpp index b329902956a..db6b6bb1402 100644 --- a/test/unit/math/prim/fun/containers_conversion_test.cpp +++ b/test/unit/math/prim/fun/containers_conversion_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -122,7 +122,7 @@ TEST(MathMatrixPrimMat, conversions_1) { // matrix to_matrix(vector) a2 = to_matrix(a1); - expect_matrix_eq(a1, a2); + EXPECT_MATRIX_FLOAT_EQ(a1, a2); // matrix to_matrix(vector) a2 = to_matrix(c1); @@ -172,7 +172,7 @@ TEST(MathMatrixPrimMat, conversions_1) { // vector to_vector(vector) c2 = to_vector(c1); - expect_matrix_eq(c1, c2); + EXPECT_MATRIX_FLOAT_EQ(c1, c2); // vector to_vector(real[]) c2 = to_vector(e1); @@ -204,7 +204,7 @@ TEST(MathMatrixPrimMat, conversions_1) { // row_vector to_row_vector(row_vector) d2 = to_row_vector(d1); - expect_matrix_eq(d1, d2); + EXPECT_MATRIX_FLOAT_EQ(d1, d2); // row_vector to_row_vector(real[]) d2 = to_row_vector(e1); @@ -253,13 +253,13 @@ TEST(MathMatrixPrimMat, conversions_1) { EXPECT_EQ(c1(2), e2[2]); // Now we play with some lossless operations - expect_matrix_eq(a1, to_matrix(to_array_2d(a1))); - expect_matrix_eq(c1, to_vector(to_array_1d(c1))); - expect_matrix_eq(c1, to_vector(to_matrix(c1))); - expect_matrix_eq(c1, to_vector(to_row_vector(c1))); - expect_matrix_eq(d1, to_row_vector(to_array_1d(d1))); - expect_matrix_eq(d1, to_row_vector(to_matrix(d1))); - expect_matrix_eq(d1, to_row_vector(to_vector(d1))); + EXPECT_MATRIX_FLOAT_EQ(a1, to_matrix(to_array_2d(a1))); + EXPECT_MATRIX_FLOAT_EQ(c1, to_vector(to_array_1d(c1))); + EXPECT_MATRIX_FLOAT_EQ(c1, to_vector(to_matrix(c1))); + EXPECT_MATRIX_FLOAT_EQ(c1, to_vector(to_row_vector(c1))); + EXPECT_MATRIX_FLOAT_EQ(d1, to_row_vector(to_array_1d(d1))); + EXPECT_MATRIX_FLOAT_EQ(d1, to_row_vector(to_matrix(d1))); + EXPECT_MATRIX_FLOAT_EQ(d1, to_row_vector(to_vector(d1))); } TEST(MathMatrixPrimMat, conversions_2) { vector > > a1( diff --git a/test/unit/math/prim/fun/corr_matrix_transform_test.cpp b/test/unit/math/prim/fun/corr_matrix_transform_test.cpp index 4c47999e8df..1483e07aee7 100644 --- a/test/unit/math/prim/fun/corr_matrix_transform_test.cpp +++ b/test/unit/math/prim/fun/corr_matrix_transform_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(prob_transform, corr_matrix_j) { @@ -10,7 +10,7 @@ TEST(prob_transform, corr_matrix_j) { double lp = -12.9; Eigen::MatrixXd y = stan::math::corr_matrix_constrain(x, K, lp); Eigen::VectorXd xrt = stan::math::corr_matrix_free(y); - expect_matrix_eq(x, xrt); + EXPECT_MATRIX_FLOAT_EQ(x, xrt); } TEST(prob_transform, corr_matrix_j2x2) { @@ -22,7 +22,7 @@ TEST(prob_transform, corr_matrix_j2x2) { double lp = -12.9; Eigen::MatrixXd y = stan::math::corr_matrix_constrain(x, K, lp); Eigen::VectorXd xrt = stan::math::corr_matrix_free(y); - expect_matrix_eq(x, xrt); + EXPECT_MATRIX_FLOAT_EQ(x, xrt); } TEST(prob_transform, corr_matrix_j1x1) { @@ -33,7 +33,7 @@ TEST(prob_transform, corr_matrix_j1x1) { double lp = -12.9; Eigen::MatrixXd y = stan::math::corr_matrix_constrain(x, K, lp); Eigen::VectorXd xrt = stan::math::corr_matrix_free(y); - expect_matrix_eq(x, xrt); + EXPECT_MATRIX_FLOAT_EQ(x, xrt); } TEST(prob_transform, corr_matrix_constrain_exception) { diff --git a/test/unit/math/prim/fun/diag_post_multiply_test.cpp b/test/unit/math/prim/fun/diag_post_multiply_test.cpp index b4059ac280c..02f3007dd78 100644 --- a/test/unit/math/prim/fun/diag_post_multiply_test.cpp +++ b/test/unit/math/prim/fun/diag_post_multiply_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include using Eigen::Dynamic; @@ -16,7 +16,7 @@ TEST(MathMatrixPrimMat, diagPostMultiply) { Matrix v_m(1, 1); v_m << 9; - expect_matrix_eq(m * v_m, diag_post_multiply(m, v)); + EXPECT_MATRIX_FLOAT_EQ(m * v_m, diag_post_multiply(m, v)); } TEST(MathMatrixPrimMat, diagPostMultiply2) { @@ -29,11 +29,11 @@ TEST(MathMatrixPrimMat, diagPostMultiply2) { Matrix v_m(2, 2); v_m << 10, 0, 0, 100; - expect_matrix_eq(m * v_m, diag_post_multiply(m, v)); + EXPECT_MATRIX_FLOAT_EQ(m * v_m, diag_post_multiply(m, v)); Matrix rv(2); rv << 10, 100; - expect_matrix_eq(m * v_m, diag_post_multiply(m, rv)); + EXPECT_MATRIX_FLOAT_EQ(m * v_m, diag_post_multiply(m, rv)); } TEST(MathMatrixPrimMat, diagPostMultiplyException) { diff --git a/test/unit/math/prim/fun/diag_pre_multiply_test.cpp b/test/unit/math/prim/fun/diag_pre_multiply_test.cpp index 0a55add55ef..1080f7d5c9b 100644 --- a/test/unit/math/prim/fun/diag_pre_multiply_test.cpp +++ b/test/unit/math/prim/fun/diag_pre_multiply_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include using Eigen::Dynamic; @@ -16,7 +16,7 @@ TEST(MathMatrixPrimMat, diagPreMultiply) { Matrix v_m(1, 1); v_m << 9; - expect_matrix_eq(v_m * m, diag_pre_multiply(v, m)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m, diag_pre_multiply(v, m)); } TEST(MathMatrixPrimMat, diagPreMultiply2) { @@ -29,11 +29,11 @@ TEST(MathMatrixPrimMat, diagPreMultiply2) { Matrix v_m(3, 3); v_m << 1, 0, 0, 0, 2, 0, 0, 0, 3; - expect_matrix_eq(v_m * m, diag_pre_multiply(v, m)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m, diag_pre_multiply(v, m)); Matrix rv(3); rv << 1, 2, 3; - expect_matrix_eq(v_m * m, diag_pre_multiply(rv, m)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m, diag_pre_multiply(rv, m)); } TEST(MathMatrixPrimMat, diagPreMultiplyException) { diff --git a/test/unit/math/prim/fun/divide_test.cpp b/test/unit/math/prim/fun/divide_test.cpp index cd5a57ecc4b..0b5c0b1dd58 100644 --- a/test/unit/math/prim/fun/divide_test.cpp +++ b/test/unit/math/prim/fun/divide_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -72,9 +72,9 @@ TEST(MathMatrixPrimMat, divide) { rv0_over_2 << 0.5, 1.0, 1.5; m0_over_2 << 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5; - expect_matrix_eq(v0_over_2, divide(v0, 2.0)); - expect_matrix_eq(rv0_over_2, divide(rv0, 2.0)); - expect_matrix_eq(m0_over_2, divide(m0, 2.0)); + EXPECT_MATRIX_FLOAT_EQ(v0_over_2, divide(v0, 2.0)); + EXPECT_MATRIX_FLOAT_EQ(rv0_over_2, divide(rv0, 2.0)); + EXPECT_MATRIX_FLOAT_EQ(m0_over_2, divide(m0, 2.0)); double inf = std::numeric_limits::infinity(); double nan = std::numeric_limits::quiet_NaN(); diff --git a/test/unit/math/prim/fun/expect_matrix_eq.hpp b/test/unit/math/prim/fun/expect_matrix_eq.hpp deleted file mode 100644 index 676d6f0b479..00000000000 --- a/test/unit/math/prim/fun/expect_matrix_eq.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef TEST_UNIT_MATH_PRIM_FUN_EXPECT_MATRIX_EQ_HPP -#define TEST_UNIT_MATH_PRIM_FUN_EXPECT_MATRIX_EQ_HPP - -#include -#include -#include - -void expect_matrix_eq( - const Eigen::Matrix& a, - const Eigen::Matrix& b) { - EXPECT_EQ(a.rows(), b.rows()); - EXPECT_EQ(a.cols(), b.cols()); - for (int i = 0; i < a.rows(); ++i) - for (int j = 0; j < a.cols(); ++j) - EXPECT_FLOAT_EQ(a(i, j), b(i, j)); -} - -template > -void expect_std_vector_eq(const std::vector& a, const std::vector& b) { - EXPECT_EQ(a.size(), b.size()); - for (int i = 0; i < a.size(); ++i) - EXPECT_FLOAT_EQ(a[i], b[i]); -} - -#endif diff --git a/test/unit/math/prim/fun/identity_matrix_test.cpp b/test/unit/math/prim/fun/identity_matrix_test.cpp index 9874d78bc0e..184ad3ff693 100644 --- a/test/unit/math/prim/fun/identity_matrix_test.cpp +++ b/test/unit/math/prim/fun/identity_matrix_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathFunctions, identity_matrix) { @@ -12,7 +12,7 @@ TEST(MathFunctions, identity_matrix) { for (int K = 1; K < 5; K++) { MatrixXd m = Eigen::MatrixXd::Identity(K, K); - expect_matrix_eq(m, identity_matrix(K)); + EXPECT_MATRIX_FLOAT_EQ(m, identity_matrix(K)); } } diff --git a/test/unit/math/prim/fun/linspaced_array_test.cpp b/test/unit/math/prim/fun/linspaced_array_test.cpp index 063208e3fad..4eec77c3bf6 100644 --- a/test/unit/math/prim/fun/linspaced_array_test.cpp +++ b/test/unit/math/prim/fun/linspaced_array_test.cpp @@ -1,20 +1,17 @@ #include -#include +#include #include #include #include -void expect_linspaced_array(int K, double low, double high, - const std::vector& expected) { - std::vector found = stan::math::linspaced_array(K, low, high); - expect_std_vector_eq(expected, found); -} - TEST(MathFunctions, linspaced_array) { - expect_linspaced_array(0, 1, 5, {}); - expect_linspaced_array(1, 1, 5, {5}); - expect_linspaced_array(5, 1, 5, {1, 2, 3, 4, 5}); - expect_linspaced_array(5, -2, 2, {-2, -1, 0, 1, 2}); + using stan::math::linspaced_array; + EXPECT_STD_VECTOR_FLOAT_EQ(linspaced_array(0, 1, 5), std::vector({})); + EXPECT_STD_VECTOR_FLOAT_EQ(linspaced_array(1, 1, 5), std::vector({5})); + EXPECT_STD_VECTOR_FLOAT_EQ(linspaced_array(5, 1, 5), + std::vector({1, 2, 3, 4, 5})); + EXPECT_STD_VECTOR_FLOAT_EQ(linspaced_array(5, -2, 2), + std::vector({-2, -1, 0, 1, 2})); } TEST(MathFunctions, linspaced_array_throw) { diff --git a/test/unit/math/prim/fun/linspaced_row_vector_test.cpp b/test/unit/math/prim/fun/linspaced_row_vector_test.cpp index 9a77d358a3d..a5d08ba3305 100644 --- a/test/unit/math/prim/fun/linspaced_row_vector_test.cpp +++ b/test/unit/math/prim/fun/linspaced_row_vector_test.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include void expect_linspaced_row_vector(int K, double low, double high, const Eigen::RowVectorXd& expected) { Eigen::RowVectorXd found = stan::math::linspaced_row_vector(K, low, high); - expect_matrix_eq(expected, found); + EXPECT_MATRIX_FLOAT_EQ(expected, found); } TEST(MathFunctions, linspaced_row_vector) { diff --git a/test/unit/math/prim/fun/linspaced_vector_test.cpp b/test/unit/math/prim/fun/linspaced_vector_test.cpp index aa69acf9d82..26ec8524347 100644 --- a/test/unit/math/prim/fun/linspaced_vector_test.cpp +++ b/test/unit/math/prim/fun/linspaced_vector_test.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include void expect_linspaced_vector(int K, double low, double high, const Eigen::VectorXd& expected) { Eigen::VectorXd found = stan::math::linspaced_vector(K, low, high); - expect_matrix_eq(expected, found); + EXPECT_MATRIX_FLOAT_EQ(expected, found); } TEST(MathFunctions, linspaced_vector) { diff --git a/test/unit/math/prim/fun/matrix_exp_2x2_test.cpp b/test/unit/math/prim/fun/matrix_exp_2x2_test.cpp index 93f7a9b649d..d34c674a597 100644 --- a/test/unit/math/prim/fun/matrix_exp_2x2_test.cpp +++ b/test/unit/math/prim/fun/matrix_exp_2x2_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathMatrixPrimMat, matrix_exp_2x2_2x2_1) { @@ -8,7 +8,7 @@ TEST(MathMatrixPrimMat, matrix_exp_2x2_2x2_1) { m1 << 3, 0, 0, 4; m2 << exp(3), 0, 0, exp(4); - expect_matrix_eq(m2, stan::math::matrix_exp_2x2(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_2x2(m1)); } TEST(MathMatrixPrimMat, matrix_exp_2x2_2x2_2) { @@ -18,5 +18,5 @@ TEST(MathMatrixPrimMat, matrix_exp_2x2_2x2_2) { m1 << -49, 24, -64, 31; m2 << -.735759, .551819, -1.471518, 1.103638; - expect_matrix_eq(m2, stan::math::matrix_exp_2x2(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_2x2(m1)); } diff --git a/test/unit/math/prim/fun/matrix_exp_pade_test.cpp b/test/unit/math/prim/fun/matrix_exp_pade_test.cpp index dc6e4306dce..eab4301fbfe 100644 --- a/test/unit/math/prim/fun/matrix_exp_pade_test.cpp +++ b/test/unit/math/prim/fun/matrix_exp_pade_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -7,7 +7,7 @@ TEST(MathMatrixPrimMat, matrix_exp_pade_0x0) { Eigen::Matrix m1(0, 0); - expect_matrix_eq(m1, stan::math::matrix_exp_pade(m1)); + EXPECT_MATRIX_FLOAT_EQ(m1, stan::math::matrix_exp_pade(m1)); } TEST(MathMatrixPrimMat, matrix_exp_pade_1x1) { @@ -15,7 +15,7 @@ TEST(MathMatrixPrimMat, matrix_exp_pade_1x1) { m1 << 0; m2 << 1; - expect_matrix_eq(m2, stan::math::matrix_exp_pade(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_pade(m1)); } TEST(MathMatrixPrimMat, matrix_exp_pade_2x2) { @@ -25,7 +25,7 @@ TEST(MathMatrixPrimMat, matrix_exp_pade_2x2) { m1 << -49, 24, -64, 31; m2 << -.735759, .551819, -1.471518, 1.103638; - expect_matrix_eq(m2, stan::math::matrix_exp_pade(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_pade(m1)); } TEST(MathMatrixPrimMat, matrix_exp_pade_3x3) { @@ -34,7 +34,7 @@ TEST(MathMatrixPrimMat, matrix_exp_pade_3x3) { m1 << 0, 1, 2, 0, 0, -1, 0, 0, 0; m2 << 1, 1, 1.5, 0, 1, -1, 0, 0, 1; - expect_matrix_eq(m2, stan::math::matrix_exp_pade(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_pade(m1)); } TEST(MathMatrixPrimMat, matrix_exp_pade_3x3_2) { @@ -43,7 +43,7 @@ TEST(MathMatrixPrimMat, matrix_exp_pade_3x3_2) { m2 << 245.95891, -182.43047, -49.11821, 93.41549, -67.3433, -18.68310, 842.54120, -631.90590, -168.14036; - expect_matrix_eq(m2, stan::math::matrix_exp_pade(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp_pade(m1)); } TEST(MathMatrixPrimMat, matrix_exp_pade_100x100) { diff --git a/test/unit/math/prim/fun/matrix_exp_test.cpp b/test/unit/math/prim/fun/matrix_exp_test.cpp index e8a04a3e8ea..e345f36ea9e 100644 --- a/test/unit/math/prim/fun/matrix_exp_test.cpp +++ b/test/unit/math/prim/fun/matrix_exp_test.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -9,7 +9,7 @@ TEST(MathMatrixPrimMat, matrix_exp_0x0) { Eigen::Matrix m1(0, 0); - expect_matrix_eq(m1, stan::math::matrix_exp(m1)); + EXPECT_MATRIX_FLOAT_EQ(m1, stan::math::matrix_exp(m1)); } TEST(MathMatrixPrimMat, matrix_exp_1x1) { @@ -17,7 +17,7 @@ TEST(MathMatrixPrimMat, matrix_exp_1x1) { m1 << 0; m2 << 1; - expect_matrix_eq(m2, stan::math::matrix_exp(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp(m1)); } TEST(MathMatrixPrimMat, matrix_exp_2x2) { @@ -26,7 +26,7 @@ TEST(MathMatrixPrimMat, matrix_exp_2x2) { m1 << -49, 24, -64, 31; m2 << -.735759, .551819, -1.471518, 1.103638; - expect_matrix_eq(m2, stan::math::matrix_exp(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp(m1)); } TEST(MathMatrixPrimMat, matrix_exp_2x2_2) { @@ -39,7 +39,7 @@ TEST(MathMatrixPrimMat, matrix_exp_2x2_2) { exp_m << 0.2746483852, 0.2893267425, -0.4170720513, 0.7937977746; - expect_matrix_eq(exp_m, stan::math::matrix_exp(m)); + EXPECT_MATRIX_FLOAT_EQ(exp_m, stan::math::matrix_exp(m)); } TEST(MathMatrixPrimMat, matrix_exp_3x3) { @@ -48,7 +48,7 @@ TEST(MathMatrixPrimMat, matrix_exp_3x3) { m1 << 0, 1, 2, 0, 0, -1, 0, 0, 0; m2 << 1, 1, 1.5, 0, 1, -1, 0, 0, 1; - expect_matrix_eq(m2, stan::math::matrix_exp(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp(m1)); } TEST(MathMatrixPrimMat, matrix_exp_3x3_2) { @@ -57,7 +57,7 @@ TEST(MathMatrixPrimMat, matrix_exp_3x3_2) { m2 << 245.95891, -182.43047, -49.11821, 93.41549, -67.3433, -18.68310, 842.54120, -631.90590, -168.14036; - expect_matrix_eq(m2, stan::math::matrix_exp(m1)); + EXPECT_MATRIX_FLOAT_EQ(m2, stan::math::matrix_exp(m1)); } TEST(MathMatrixPrimMat, matrix_exp_100x100) { diff --git a/test/unit/math/prim/fun/matrix_power_test.cpp b/test/unit/math/prim/fun/matrix_power_test.cpp index 61b006bc256..574971dcdb6 100644 --- a/test/unit/math/prim/fun/matrix_power_test.cpp +++ b/test/unit/math/prim/fun/matrix_power_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -16,11 +16,11 @@ TEST(MathMatrixPower, two_by_two) { Eigen::MatrixXd M9(2, 2); M9 << 890461.0, 1297782.0, 1946673.0, 2837134.0; - expect_matrix_eq(I, matrix_power(M, 0)); - expect_matrix_eq(M, matrix_power(M, 1)); - expect_matrix_eq(M2, matrix_power(M, 2)); - expect_matrix_eq(M3, matrix_power(M, 3)); - expect_matrix_eq(M9, matrix_power(M, 9)); + EXPECT_MATRIX_FLOAT_EQ(I, matrix_power(M, 0)); + EXPECT_MATRIX_FLOAT_EQ(M, matrix_power(M, 1)); + EXPECT_MATRIX_FLOAT_EQ(M2, matrix_power(M, 2)); + EXPECT_MATRIX_FLOAT_EQ(M3, matrix_power(M, 3)); + EXPECT_MATRIX_FLOAT_EQ(M9, matrix_power(M, 9)); } TEST(MathMatrixPower, one_by_one) { @@ -37,11 +37,11 @@ TEST(MathMatrixPower, one_by_one) { Eigen::MatrixXd M9(1, 1); M9 << 19683.0; - expect_matrix_eq(I, matrix_power(M, 0)); - expect_matrix_eq(M, matrix_power(M, 1)); - expect_matrix_eq(M2, matrix_power(M, 2)); - expect_matrix_eq(M3, matrix_power(M, 3)); - expect_matrix_eq(M9, matrix_power(M, 9)); + EXPECT_MATRIX_FLOAT_EQ(I, matrix_power(M, 0)); + EXPECT_MATRIX_FLOAT_EQ(M, matrix_power(M, 1)); + EXPECT_MATRIX_FLOAT_EQ(M2, matrix_power(M, 2)); + EXPECT_MATRIX_FLOAT_EQ(M3, matrix_power(M, 3)); + EXPECT_MATRIX_FLOAT_EQ(M9, matrix_power(M, 9)); } TEST(MathMatrixPower, compare_to_simple_impl) { @@ -54,7 +54,7 @@ TEST(MathMatrixPower, compare_to_simple_impl) { for (int i = 0; i < exponent; i++) expected *= M; - expect_matrix_eq(expected, matrix_power(M, exponent)); + EXPECT_MATRIX_FLOAT_EQ(expected, matrix_power(M, exponent)); } TEST(MathMatrixPower, zero_size) { @@ -113,7 +113,7 @@ TEST(MathMatrixPower, matrix_power_operator) { Eigen::MatrixXd M2(2, 2); M2 << 7.0, 10.0, 15.0, 22.0; - expect_matrix_eq(M2, M ^ 2); + EXPECT_MATRIX_FLOAT_EQ(M2, (M ^ 2)); } TEST(MathMatrixPower, large) { @@ -165,5 +165,5 @@ TEST(MathMatrixPower, large) { 109278.842978772, 190220.314850057, 156078.552041347, 185519.091744448, 174246.126849153, 143954.733727807, 157071.213262326, 135683.920871181; - expect_matrix_eq(M9, matrix_power(M, 9)); + EXPECT_MATRIX_FLOAT_EQ(M9, matrix_power(M, 9)); } diff --git a/test/unit/math/prim/fun/mdivide_left_test.cpp b/test/unit/math/prim/fun/mdivide_left_test.cpp index 548ef3c3d19..96ed82d7add 100644 --- a/test/unit/math/prim/fun/mdivide_left_test.cpp +++ b/test/unit/math/prim/fun/mdivide_left_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathMatrixPrim, mdivide_left_val) { @@ -7,7 +7,7 @@ TEST(MathMatrixPrim, mdivide_left_val) { Ad << 2.0, 3.0, 5.0, 7.0; stan::math::matrix_d I = Eigen::MatrixXd::Identity(2, 2); - expect_matrix_eq(I, stan::math::mdivide_left(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, stan::math::mdivide_left(Ad, Ad)); } TEST(MathMatrixPrim, mdivide_left_val2) { @@ -20,7 +20,7 @@ TEST(MathMatrixPrim, mdivide_left_val2) { b << 19, 150, -170, 140, 31; expected << -1204, -1154, -915, 295, 31; - expect_matrix_eq(expected, stan::math::mdivide_left(A, b)); + EXPECT_MATRIX_FLOAT_EQ(expected, stan::math::mdivide_left(A, b)); } TEST(MathMatrixPrim, mdivide_left_size_zero) { diff --git a/test/unit/math/prim/fun/mdivide_left_tri_low_test.cpp b/test/unit/math/prim/fun/mdivide_left_tri_low_test.cpp index 4240a977f66..758173f50b2 100644 --- a/test/unit/math/prim/fun/mdivide_left_tri_low_test.cpp +++ b/test/unit/math/prim/fun/mdivide_left_tri_low_test.cpp @@ -1,18 +1,14 @@ #include -#include +#include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixPrim, mdivide_left_tri_low_val) { using stan::math::mdivide_left_tri_low; stan::math::matrix_d I = Eigen::MatrixXd::Identity(2, 2); stan::math::matrix_d Ad(2, 2); Ad << 2.0, 0.0, 5.0, 7.0; - expect_matrix_eq(I, mdivide_left_tri_low(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_left_tri_low(Ad, Ad)); stan::math::matrix_d A_Ainv = Ad * mdivide_left_tri_low(Ad); EXPECT_MATRIX_NEAR(I, A_Ainv, 1e-15); @@ -20,7 +16,7 @@ TEST(MathMatrixPrim, mdivide_left_tri_low_val) { I = Eigen::MatrixXd::Identity(1, 1); Ad.resize(1, 1); Ad << 2; - expect_matrix_eq(I, mdivide_left_tri_low(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_left_tri_low(Ad, Ad)); A_Ainv = Ad * mdivide_left_tri_low(Ad); EXPECT_MATRIX_NEAR(I, A_Ainv, 1e-15); diff --git a/test/unit/math/prim/fun/mdivide_left_tri_test.cpp b/test/unit/math/prim/fun/mdivide_left_tri_test.cpp index f48dfba5dc6..81268f207b1 100644 --- a/test/unit/math/prim/fun/mdivide_left_tri_test.cpp +++ b/test/unit/math/prim/fun/mdivide_left_tri_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #ifdef STAN_OPENCL @@ -7,23 +7,19 @@ #include #endif -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixPrim, mdivide_left_tri_val) { using stan::math::mdivide_left_tri; stan::math::matrix_d I = Eigen::MatrixXd::Identity(2, 2); stan::math::matrix_d Ad(2, 2); Ad << 2.0, 0.0, 5.0, 7.0; - expect_matrix_eq(I, mdivide_left_tri(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_left_tri(Ad, Ad)); stan::math::matrix_d A_Ainv = Ad * mdivide_left_tri(Ad); EXPECT_MATRIX_NEAR(I, A_Ainv, 1e-15); Ad << 2.0, 3.0, 0.0, 7.0; - expect_matrix_eq(I, mdivide_left_tri(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_left_tri(Ad, Ad)); } TEST(MathMatrixPrim, mdivide_left_tri_size_zero) { diff --git a/test/unit/math/prim/fun/mdivide_right_test.cpp b/test/unit/math/prim/fun/mdivide_right_test.cpp index 028e4f6789a..ae29981cd60 100644 --- a/test/unit/math/prim/fun/mdivide_right_test.cpp +++ b/test/unit/math/prim/fun/mdivide_right_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathMatrixPrim, mdivide_right_val) { @@ -7,7 +7,7 @@ TEST(MathMatrixPrim, mdivide_right_val) { Ad << 2.0, 3.0, 5.0, 7.0; stan::math::matrix_d I = Eigen::MatrixXd::Identity(2, 2); - expect_matrix_eq(I, stan::math::mdivide_left(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, stan::math::mdivide_left(Ad, Ad)); } TEST(MathMatrixPrim, mdivide_right_val2) { @@ -20,7 +20,7 @@ TEST(MathMatrixPrim, mdivide_right_val2) { 1; expected << 19, -2, 1, 13, 4; - expect_matrix_eq(expected, stan::math::mdivide_right(b, A)); + EXPECT_MATRIX_FLOAT_EQ(expected, stan::math::mdivide_right(b, A)); } TEST(MathMatrixPrim, mdivide_right_size_zero) { diff --git a/test/unit/math/prim/fun/mdivide_right_tri_test.cpp b/test/unit/math/prim/fun/mdivide_right_tri_test.cpp index bec2a951133..e63ec3f11e9 100644 --- a/test/unit/math/prim/fun/mdivide_right_tri_test.cpp +++ b/test/unit/math/prim/fun/mdivide_right_tri_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #ifdef STAN_OPENCL @@ -7,20 +7,16 @@ #include #endif -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(MathMatrixPrim, mdivide_right_tri_val) { using stan::math::mdivide_right_tri; stan::math::matrix_d I = Eigen::MatrixXd::Identity(2, 2); stan::math::matrix_d Ad(2, 2); Ad << 2.0, 0.0, 5.0, 7.0; - expect_matrix_eq(I, mdivide_right_tri(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_right_tri(Ad, Ad)); Ad << 2.0, 3.0, 0.0, 7.0; - expect_matrix_eq(I, mdivide_right_tri(Ad, Ad)); + EXPECT_MATRIX_FLOAT_EQ(I, mdivide_right_tri(Ad, Ad)); } TEST(MathMatrixPrim, mdivide_right_tri_size_zero) { diff --git a/test/unit/math/prim/fun/multiply_test.cpp b/test/unit/math/prim/fun/multiply_test.cpp index 1d8d64f94d1..f6aede69f0e 100644 --- a/test/unit/math/prim/fun/multiply_test.cpp +++ b/test/unit/math/prim/fun/multiply_test.cpp @@ -1,4 +1,5 @@ #include +#include #include TEST(MathMatrixPrim, multiply_c_v) { @@ -157,9 +158,6 @@ TEST(MathMatrixPrim, multiply_vector_int) { } #ifdef STAN_OPENCL -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); TEST(MathMatrixPrim, multiply_opencl) { int multiply_dim_prod_worth_transfer diff --git a/test/unit/math/prim/fun/one_hot_array_test.cpp b/test/unit/math/prim/fun/one_hot_array_test.cpp index 50165866ffb..6405a6b660c 100644 --- a/test/unit/math/prim/fun/one_hot_array_test.cpp +++ b/test/unit/math/prim/fun/one_hot_array_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -8,7 +8,7 @@ TEST(MathFunctions, one_hot_array) { for (int k = 1; k <= K; k++) { std::vector v(K); v[k - 1] = 1; - expect_std_vector_eq(v, stan::math::one_hot_array(K, k)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::one_hot_array(K, k)); } } } diff --git a/test/unit/math/prim/fun/one_hot_int_array_test.cpp b/test/unit/math/prim/fun/one_hot_int_array_test.cpp index 1ace98afdbe..b1b2bf4939e 100644 --- a/test/unit/math/prim/fun/one_hot_int_array_test.cpp +++ b/test/unit/math/prim/fun/one_hot_int_array_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -8,7 +8,7 @@ TEST(MathFunctions, one_hot_int_array) { for (int k = 1; k <= K; k++) { std::vector v(K); v[k - 1] = 1; - expect_std_vector_eq(v, stan::math::one_hot_int_array(K, k)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::one_hot_int_array(K, k)); } } } diff --git a/test/unit/math/prim/fun/one_hot_row_vector_test.cpp b/test/unit/math/prim/fun/one_hot_row_vector_test.cpp index 8f3aacf19f7..27e15b97685 100644 --- a/test/unit/math/prim/fun/one_hot_row_vector_test.cpp +++ b/test/unit/math/prim/fun/one_hot_row_vector_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathFunctions, one_hot_row_vector) { @@ -7,7 +7,7 @@ TEST(MathFunctions, one_hot_row_vector) { for (int k = 1; k <= K; k++) { Eigen::RowVectorXd y = Eigen::RowVectorXd::Zero(K); y[k - 1] = 1; - expect_matrix_eq(y, stan::math::one_hot_row_vector(K, k)); + EXPECT_MATRIX_FLOAT_EQ(y, stan::math::one_hot_row_vector(K, k)); } } } diff --git a/test/unit/math/prim/fun/one_hot_vector_test.cpp b/test/unit/math/prim/fun/one_hot_vector_test.cpp index 835f907e60a..b5042d071a2 100644 --- a/test/unit/math/prim/fun/one_hot_vector_test.cpp +++ b/test/unit/math/prim/fun/one_hot_vector_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathFunctions, one_hot_vector) { @@ -7,7 +7,7 @@ TEST(MathFunctions, one_hot_vector) { for (int k = 1; k <= K; k++) { Eigen::VectorXd y = Eigen::VectorXd::Zero(K); y[k - 1] = 1; - expect_matrix_eq(y, stan::math::one_hot_vector(K, k)); + EXPECT_MATRIX_FLOAT_EQ(y, stan::math::one_hot_vector(K, k)); } } } diff --git a/test/unit/math/prim/fun/ones_array_test.cpp b/test/unit/math/prim/fun/ones_array_test.cpp index 3e05ffcb01e..d87508b6638 100644 --- a/test/unit/math/prim/fun/ones_array_test.cpp +++ b/test/unit/math/prim/fun/ones_array_test.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include TEST(MathFunctions, ones_array) { for (int K = 0; K < 5; K++) { std::vector v(K, 1); - expect_std_vector_eq(v, stan::math::ones_array(K)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::ones_array(K)); } } diff --git a/test/unit/math/prim/fun/ones_int_array_test.cpp b/test/unit/math/prim/fun/ones_int_array_test.cpp index 2f53d9d8cb3..678d5741c81 100644 --- a/test/unit/math/prim/fun/ones_int_array_test.cpp +++ b/test/unit/math/prim/fun/ones_int_array_test.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include TEST(MathFunctions, ones_int_array) { for (int K = 0; K < 5; K++) { std::vector v(K, 1); - expect_std_vector_eq(v, stan::math::ones_int_array(K)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::ones_int_array(K)); } } diff --git a/test/unit/math/prim/fun/ones_row_vector_test.cpp b/test/unit/math/prim/fun/ones_row_vector_test.cpp index a1d216b3050..ade2306bc9a 100644 --- a/test/unit/math/prim/fun/ones_row_vector_test.cpp +++ b/test/unit/math/prim/fun/ones_row_vector_test.cpp @@ -1,11 +1,11 @@ #include -#include +#include #include TEST(MathFunctions, ones_row_vector) { for (int K = 0; K < 5; K++) { Eigen::RowVectorXd y = Eigen::RowVectorXd::Constant(K, 1); - expect_matrix_eq(y, stan::math::ones_row_vector(K)); + EXPECT_MATRIX_FLOAT_EQ(y, stan::math::ones_row_vector(K)); } } diff --git a/test/unit/math/prim/fun/ones_vector_test.cpp b/test/unit/math/prim/fun/ones_vector_test.cpp index 57ae056aeb1..cb3c828eb5a 100644 --- a/test/unit/math/prim/fun/ones_vector_test.cpp +++ b/test/unit/math/prim/fun/ones_vector_test.cpp @@ -1,11 +1,11 @@ #include -#include +#include #include TEST(MathFunctions, ones_vector) { for (int K = 0; K < 5; K++) { Eigen::VectorXd y = Eigen::VectorXd::Constant(K, 1); - expect_matrix_eq(y, stan::math::ones_vector(K)); + EXPECT_MATRIX_FLOAT_EQ(y, stan::math::ones_vector(K)); } } diff --git a/test/unit/math/prim/fun/quad_form_diag_test.cpp b/test/unit/math/prim/fun/quad_form_diag_test.cpp index 791f63da681..aa658f4fba2 100644 --- a/test/unit/math/prim/fun/quad_form_diag_test.cpp +++ b/test/unit/math/prim/fun/quad_form_diag_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include using stan::math::quad_form_diag; @@ -13,7 +13,7 @@ TEST(MathMatrixPrim, quadFormDiag) { Eigen::MatrixXd v_m = v.asDiagonal(); - expect_matrix_eq(v_m * m * v_m, quad_form_diag(m, v)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m * v_m, quad_form_diag(m, v)); } TEST(MathMatrixPrim, quadFormDiag2) { @@ -25,11 +25,11 @@ TEST(MathMatrixPrim, quadFormDiag2) { Eigen::MatrixXd v_m = v.asDiagonal(); - expect_matrix_eq(v_m * m * v_m, quad_form_diag(m, v)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m * v_m, quad_form_diag(m, v)); Eigen::RowVectorXd rv(3); rv << 1, 2, 3; - expect_matrix_eq(v_m * m * v_m, quad_form_diag(m, rv)); + EXPECT_MATRIX_FLOAT_EQ(v_m * m * v_m, quad_form_diag(m, rv)); } TEST(MathMatrixPrim, quadFormDiagException) { diff --git a/test/unit/math/prim/fun/reverse_test.cpp b/test/unit/math/prim/fun/reverse_test.cpp index 9b4d973c4cb..6c854dd15a5 100644 --- a/test/unit/math/prim/fun/reverse_test.cpp +++ b/test/unit/math/prim/fun/reverse_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -37,19 +37,19 @@ TEST(MathFunctions, reverse_vector) { EXPECT_EQ(0, reverse(x0).size()); Eigen::VectorXd x1 = Eigen::VectorXd::Constant(1, 5); - expect_matrix_eq(x1, reverse(x1)); + EXPECT_MATRIX_FLOAT_EQ(x1, reverse(x1)); Eigen::VectorXd x(4); x << 7, -1.2, 4, -3; Eigen::VectorXd rev(4); rev << -3, 4, -1.2, 7; - expect_matrix_eq(rev, reverse(x)); + EXPECT_MATRIX_FLOAT_EQ(rev, reverse(x)); std::vector cont_x{x0, x1, x}; std::vector cont_rev{x, x1, x0}; std::vector cont_y = stan::math::reverse(cont_x); for (int i = 0; i < cont_x.size(); i++) { - expect_matrix_eq(cont_y[i], cont_rev[i]); + EXPECT_MATRIX_FLOAT_EQ(cont_y[i], cont_rev[i]); } } @@ -60,18 +60,18 @@ TEST(MathFunctions, reverse_row_vector) { EXPECT_EQ(0, reverse(x0).size()); Eigen::RowVectorXd x1 = Eigen::RowVectorXd::Constant(1, 5); - expect_matrix_eq(x1, reverse(x1)); + EXPECT_MATRIX_FLOAT_EQ(x1, reverse(x1)); Eigen::RowVectorXd x(4); x << 7, -1.2, 4, -3; Eigen::RowVectorXd rev(4); rev << -3, 4, -1.2, 7; - expect_matrix_eq(rev, reverse(x)); + EXPECT_MATRIX_FLOAT_EQ(rev, reverse(x)); std::vector cont_x{x0, x1, x}; std::vector cont_rev{x, x1, x0}; std::vector cont_y = stan::math::reverse(cont_x); for (int i = 0; i < cont_x.size(); i++) { - expect_matrix_eq(cont_y[i], cont_rev[i]); + EXPECT_MATRIX_FLOAT_EQ(cont_y[i], cont_rev[i]); } } diff --git a/test/unit/math/prim/fun/to_array1d_test.cpp b/test/unit/math/prim/fun/to_array1d_test.cpp index 15864bddc42..e771b673b7f 100644 --- a/test/unit/math/prim/fun/to_array1d_test.cpp +++ b/test/unit/math/prim/fun/to_array1d_test.cpp @@ -1,23 +1,23 @@ #include -#include +#include #include #include #include -using stan::math::to_array_1d; - TEST(MathMatrix, to_array_1d_matrix) { + using stan::math::to_array_1d; Eigen::MatrixXd a(3, 3); a << 1, 2, 3, 4, 5, 6, 7, 8, 9; std::vector a_correct{1, 4, 7, 2, 5, 8, 3, 6, 9}; std::vector a_res = to_array_1d(a); - expect_std_vector_eq(a_res, a_correct); + EXPECT_STD_VECTOR_FLOAT_EQ(a_res, a_correct); } TEST(MathMatrix, to_array_1d_matrix_block) { + using stan::math::to_array_1d; Eigen::MatrixXd a(3, 3); a << 1, 2, 3, 4, 5, 6, 7, 8, 9; std::vector a_correct{2, 5, 3, 6}; std::vector a_res = to_array_1d(a.block(0, 1, 2, 2)); - expect_std_vector_eq(a_res, a_correct); + EXPECT_STD_VECTOR_FLOAT_EQ(a_res, a_correct); } diff --git a/test/unit/math/prim/fun/to_matrix_test.cpp b/test/unit/math/prim/fun/to_matrix_test.cpp index c6e9b62f99d..9b71577b96b 100644 --- a/test/unit/math/prim/fun/to_matrix_test.cpp +++ b/test/unit/math/prim/fun/to_matrix_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -29,14 +29,15 @@ void test_to_matrix_array_answers(int m, int n) { Eigen::MatrixXd a(m, n); for (int i = 0; i < m * n; ++i) a(i) = i; - expect_matrix_eq(a, to_matrix(vec, m, n)); - expect_matrix_eq(a, to_matrix(vec, m, n, 1)); - expect_matrix_eq(a, to_matrix(vec, m, n, -1)); - expect_matrix_eq(a, to_matrix(vec, m, n, 2)); - expect_matrix_eq(a, row_major_to_column_major(to_matrix(vec, m, n, 0))); - expect_matrix_eq(a, to_matrix(vec_int, m, n)); - expect_matrix_eq(a, to_matrix(vec_int, m, n, 1)); - expect_matrix_eq(a, row_major_to_column_major(to_matrix(vec_int, m, n, 0))); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec, m, n)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec, m, n, 1)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec, m, n, -1)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec, m, n, 2)); + EXPECT_MATRIX_FLOAT_EQ(a, row_major_to_column_major(to_matrix(vec, m, n, 0))); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec_int, m, n)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec_int, m, n, 1)); + EXPECT_MATRIX_FLOAT_EQ( + a, row_major_to_column_major(to_matrix(vec_int, m, n, 0))); } TEST(ToMatrixArray, answers) { @@ -58,7 +59,7 @@ void test_to_matrix_matrix_answers(int m, int n) { Eigen::MatrixXd a(m, n); for (int i = 0; i < m * n; ++i) a(i) = i; - expect_matrix_eq(a, to_matrix(a)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(a)); } TEST(ToMatrixMatrix, answers) { @@ -76,15 +77,15 @@ void test_to_matrix_matrix_reshape_answers(int m1, int n1, int m2, int n2) { a(i) = static_cast(i) / 1.26; b(i) = static_cast(i) / 1.26; } - expect_matrix_eq(a, to_matrix(b, m1, n1)); - expect_matrix_eq(a, to_matrix(b, m1, n1, 1)); - expect_matrix_eq(a, to_matrix(b, m1, n1, -1)); - expect_matrix_eq(a, to_matrix(b, m1, n1, 2)); - expect_matrix_eq(a, row_major_to_column_major(to_matrix(b, m1, n1, 0))); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(b, m1, n1)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(b, m1, n1, 1)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(b, m1, n1, -1)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(b, m1, n1, 2)); + EXPECT_MATRIX_FLOAT_EQ(a, row_major_to_column_major(to_matrix(b, m1, n1, 0))); - expect_matrix_eq(b, to_matrix(a, m2, n2)); - expect_matrix_eq(b, to_matrix(a, m2, n2, 1)); - expect_matrix_eq(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, 1)); + EXPECT_MATRIX_FLOAT_EQ(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); if (n1 != 0) { EXPECT_THROW(to_matrix(a, m1 + 1, n1), std::invalid_argument); @@ -127,14 +128,14 @@ void test_to_vector_matrix_answers(int m, int m2, int n2) { c(i) = static_cast(i) / 1.26; } // without reshape - expect_matrix_eq(c, to_matrix(a)); + EXPECT_MATRIX_FLOAT_EQ(c, to_matrix(a)); // with reshape - expect_matrix_eq(b, to_matrix(a, m2, n2)); - expect_matrix_eq(b, to_matrix(a, m2, n2, 1)); - expect_matrix_eq(b, to_matrix(a, m2, n2, -1)); - expect_matrix_eq(b, to_matrix(a, m2, n2, 2)); - expect_matrix_eq(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, 1)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, -1)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, 2)); + EXPECT_MATRIX_FLOAT_EQ(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); if (n2 != 0) { EXPECT_THROW(to_matrix(a, m2 + 1, n2), std::invalid_argument); @@ -167,14 +168,14 @@ void test_to_row_vector_matrix_answers(int n, int m2, int n2) { c(i) = static_cast(i) / 1.26; } // without reshape - expect_matrix_eq(c, to_matrix(a)); + EXPECT_MATRIX_FLOAT_EQ(c, to_matrix(a)); // with reshape - expect_matrix_eq(b, to_matrix(a, m2, n2)); - expect_matrix_eq(b, to_matrix(a, m2, n2, 1)); - expect_matrix_eq(b, to_matrix(a, m2, n2, -1)); - expect_matrix_eq(b, to_matrix(a, m2, n2, 2)); - expect_matrix_eq(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, 1)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, -1)); + EXPECT_MATRIX_FLOAT_EQ(b, to_matrix(a, m2, n2, 2)); + EXPECT_MATRIX_FLOAT_EQ(b, row_major_to_column_major(to_matrix(a, m2, n2, 0))); if (n2 != 0) { EXPECT_THROW(to_matrix(a, m2 + 1, n2), std::invalid_argument); @@ -212,8 +213,8 @@ void test_to_matrix_2darray_answers(int m, int n) { a(i, j) = i * j; } } - expect_matrix_eq(a, to_matrix(vec)); - expect_matrix_eq(a, to_matrix(vec_int)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec)); + EXPECT_MATRIX_FLOAT_EQ(a, to_matrix(vec_int)); } TEST(ToMatrix2dArray, answers) { diff --git a/test/unit/math/prim/fun/uniform_simplex_test.cpp b/test/unit/math/prim/fun/uniform_simplex_test.cpp index e0290b4e7d2..fa86ec18ce6 100644 --- a/test/unit/math/prim/fun/uniform_simplex_test.cpp +++ b/test/unit/math/prim/fun/uniform_simplex_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(MathFunctions, uniform_simplex) { @@ -8,7 +8,7 @@ TEST(MathFunctions, uniform_simplex) { for (int K = 1; K < 5; K++) { Eigen::VectorXd v = Eigen::VectorXd::Constant(K, 1.0 / K); - expect_matrix_eq(v, uniform_simplex(K)); + EXPECT_MATRIX_FLOAT_EQ(v, uniform_simplex(K)); } } diff --git a/test/unit/math/prim/fun/value_of_rec_test.cpp b/test/unit/math/prim/fun/value_of_rec_test.cpp index 59867a6dd12..1e075bbdb8d 100644 --- a/test/unit/math/prim/fun/value_of_rec_test.cpp +++ b/test/unit/math/prim/fun/value_of_rec_test.cpp @@ -1,11 +1,8 @@ #include +#include #include #include -#define EXPECT_MATRIX_EQ(A, B) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_EQ(A(i), B(i)); - TEST(MathFunctions, value_of_rec) { using stan::math::value_of_rec; double x = 5.0; @@ -28,11 +25,8 @@ TEST(MathMatrixPrimArr, value_of_rec) { vector d_a = value_of_rec(a); vector d_b = value_of_rec(b); - for (int i = 0; i < 5; ++i) - EXPECT_FLOAT_EQ(b[i], d_b[i]); - - for (int i = 0; i < 10; ++i) - EXPECT_FLOAT_EQ(a[i], d_a[i]); + EXPECT_STD_VECTOR_FLOAT_EQ(a, d_a); + EXPECT_STD_VECTOR_FLOAT_EQ(b, d_b); } TEST(MathMatrixPrimMat, value_of_rec) { @@ -50,12 +44,8 @@ TEST(MathMatrixPrimMat, value_of_rec) { Eigen::MatrixXd d_a = value_of_rec(a); Eigen::VectorXd d_b = value_of_rec(b); - for (int i = 0; i < 5; ++i) - EXPECT_FLOAT_EQ(b(i), d_b(i)); - - for (int i = 0; i < 2; ++i) - for (int j = 0; j < 5; ++j) - EXPECT_FLOAT_EQ(a(i, j), d_a(i, j)); + EXPECT_MATRIX_FLOAT_EQ(a, d_a); + EXPECT_MATRIX_FLOAT_EQ(b, d_b); } TEST(MathMatrixPrimMat, value_of_rec_expression) { @@ -69,12 +59,13 @@ TEST(MathMatrixPrimMat, value_of_rec_expression) { Eigen::VectorXi b = Eigen::VectorXi::Random(7); Eigen::VectorXd res_b = value_of_rec(2 * b); Eigen::VectorXd correct_b = (2 * b).cast(); - EXPECT_MATRIX_EQ(res_b, correct_b); + EXPECT_MATRIX_EQ(correct_b, res_b); Eigen::ArrayXXd c = a.array(); Eigen::ArrayXXd res_c = value_of_rec(2 * c); Eigen::ArrayXXd correct_c = 2 * c; - EXPECT_MATRIX_EQ(res_c, correct_c); + for (int i = 0; i < res_c.size(); i++) + EXPECT_EQ(correct_c(i), res_c(i)); } TEST(MathFunctions, value_of_rec_return_type_short_circuit_std_vector) { diff --git a/test/unit/math/prim/fun/value_of_test.cpp b/test/unit/math/prim/fun/value_of_test.cpp index 822a113ad75..a9881261d4a 100644 --- a/test/unit/math/prim/fun/value_of_test.cpp +++ b/test/unit/math/prim/fun/value_of_test.cpp @@ -1,14 +1,11 @@ #include +#include #include #include #include #include #include -#define EXPECT_MATRIX_EQ(A, B) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_EQ(A(i), B(i)); - TEST(MathFunctions, value_of) { using stan::math::value_of; double x = 5.0; @@ -37,11 +34,8 @@ TEST(MathMatrixPrimArr, value_of) { vector d_a = value_of(a); vector d_b = value_of(b); - for (int i = 0; i < 5; ++i) - EXPECT_FLOAT_EQ(b[i], d_b[i]); - - for (int i = 0; i < 10; ++i) - EXPECT_FLOAT_EQ(a[i], d_a[i]); + EXPECT_STD_VECTOR_FLOAT_EQ(a, d_a); + EXPECT_STD_VECTOR_FLOAT_EQ(b, d_b); } TEST(MathFunctions, value_of_int_return_type_short_circuit) { @@ -77,12 +71,8 @@ TEST(MathMatrixPrimMat, value_of) { Eigen::MatrixXd d_a = value_of(a); Eigen::VectorXd d_b = value_of(b); - for (int i = 0; i < 5; ++i) - EXPECT_FLOAT_EQ(b(i), d_b(i)); - - for (int i = 0; i < 2; ++i) - for (int j = 0; j < 5; ++j) - EXPECT_FLOAT_EQ(a(i, j), d_a(i, j)); + EXPECT_MATRIX_FLOAT_EQ(a, d_a); + EXPECT_MATRIX_FLOAT_EQ(b, d_b); } TEST(MathMatrixPrimMat, value_of_expression) { @@ -91,17 +81,18 @@ TEST(MathMatrixPrimMat, value_of_expression) { Eigen::MatrixXd a = Eigen::MatrixXd::Random(5, 4); Eigen::MatrixXd res_a = value_of(2 * a); Eigen::MatrixXd correct_a = 2 * a; - EXPECT_MATRIX_EQ(res_a, correct_a); + EXPECT_MATRIX_EQ(correct_a, res_a); Eigen::VectorXi b = Eigen::VectorXi::Random(7); Eigen::VectorXi res_b = value_of(2 * b); Eigen::VectorXi correct_b = 2 * b; - EXPECT_MATRIX_EQ(res_b, correct_b); + EXPECT_TYPED_MATRIX_EQ(correct_b, res_b, int); Eigen::ArrayXXd c = a.array(); Eigen::ArrayXXd res_c = value_of(2 * c); Eigen::ArrayXXd correct_c = 2 * c; - EXPECT_MATRIX_EQ(res_c, correct_c); + for (int i = 0; i < res_c.size(); i++) + EXPECT_EQ(correct_c(i), res_c(i)); } TEST(MathFunctions, value_of_return_type_short_circuit_std_vector) { diff --git a/test/unit/math/prim/fun/zeros_array_test.cpp b/test/unit/math/prim/fun/zeros_array_test.cpp index 21d75b1a0d0..6166e184594 100644 --- a/test/unit/math/prim/fun/zeros_array_test.cpp +++ b/test/unit/math/prim/fun/zeros_array_test.cpp @@ -1,15 +1,15 @@ #include -#include +#include #include #include TEST(MathFunctions, zeros_array) { for (int K = 0; K < 5; K++) { std::vector v(K, 0); - expect_std_vector_eq(v, stan::math::zeros_array(K)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::zeros_array(K)); } } TEST(MathFunctions, zeros_array_throw) { - EXPECT_THROW(stan::math::zeros_array(-1), std::domain_error); + EXPECT_THROW(stan::math::zeros_int_array(-1), std::domain_error); } diff --git a/test/unit/math/prim/fun/zeros_int_array_test.cpp b/test/unit/math/prim/fun/zeros_int_array_test.cpp index 95282f7baf6..9ed62fd73a5 100644 --- a/test/unit/math/prim/fun/zeros_int_array_test.cpp +++ b/test/unit/math/prim/fun/zeros_int_array_test.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include #include TEST(MathFunctions, zeros_int_array) { for (int K = 0; K < 5; K++) { std::vector v(K, 0); - expect_std_vector_eq(v, stan::math::zeros_int_array(K)); + EXPECT_STD_VECTOR_FLOAT_EQ(v, stan::math::zeros_int_array(K)); } } diff --git a/test/unit/math/prim/fun/zeros_row_vector_test.cpp b/test/unit/math/prim/fun/zeros_row_vector_test.cpp index 88c74a9a8cf..68fc64e162a 100644 --- a/test/unit/math/prim/fun/zeros_row_vector_test.cpp +++ b/test/unit/math/prim/fun/zeros_row_vector_test.cpp @@ -1,11 +1,11 @@ #include -#include +#include #include TEST(MathFunctions, zeros_row_vector) { for (int K = 0; K < 5; K++) { Eigen::RowVectorXd v = Eigen::RowVectorXd::Zero(K); - expect_matrix_eq(v, stan::math::zeros_row_vector(K)); + EXPECT_MATRIX_FLOAT_EQ(v, stan::math::zeros_row_vector(K)); } } diff --git a/test/unit/math/prim/fun/zeros_vector_test.cpp b/test/unit/math/prim/fun/zeros_vector_test.cpp index 540f102564b..3e625221f88 100644 --- a/test/unit/math/prim/fun/zeros_vector_test.cpp +++ b/test/unit/math/prim/fun/zeros_vector_test.cpp @@ -1,11 +1,11 @@ #include -#include +#include #include TEST(MathFunctions, zeros_vector) { for (int K = 0; K < 5; K++) { Eigen::VectorXd v = Eigen::VectorXd::Zero(K); - expect_matrix_eq(v, stan::math::zeros_vector(K)); + EXPECT_MATRIX_FLOAT_EQ(v, stan::math::zeros_vector(K)); } } diff --git a/test/unit/math/rev/eigen_plugins_test.cpp b/test/unit/math/rev/eigen_plugins_test.cpp index 414efc8fb38..b7c67917fd7 100644 --- a/test/unit/math/rev/eigen_plugins_test.cpp +++ b/test/unit/math/rev/eigen_plugins_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(AgradRevMatrixAddons, var_matrix) { @@ -16,12 +16,12 @@ TEST(AgradRevMatrixAddons, var_matrix) { for (int j = 0; j < 100; j++) mat_in(i, j).vi_->adj_ = derivs(i, j); - expect_matrix_eq(vals, mat_in.val()); - expect_matrix_eq(vals.val(), mat_in.val()); - expect_matrix_eq(vals.array().exp(), mat_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.val(), mat_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), mat_in.val().array().exp()); - expect_matrix_eq(derivs, mat_in.adj()); - expect_matrix_eq(derivs.array().exp(), mat_in.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_in.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), mat_in.adj().array().exp()); EXPECT_EQ(mat_in.val().rows(), vals.rows()); EXPECT_EQ(mat_in.val().cols(), vals.cols()); @@ -36,11 +36,11 @@ TEST(AgradRevMatrixAddons, var_matrix) { matrix_vi mat_vi = mat_in.vi(); - expect_matrix_eq(vals, mat_vi.val()); - expect_matrix_eq(vals.array().exp(), mat_vi.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, mat_vi.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), mat_vi.val().array().exp()); - expect_matrix_eq(derivs, mat_vi.adj()); - expect_matrix_eq(derivs.array().exp(), mat_vi.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, mat_vi.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), mat_vi.adj().array().exp()); EXPECT_EQ(mat_vi.val().rows(), vals.rows()); EXPECT_EQ(mat_vi.val().cols(), vals.cols()); @@ -62,11 +62,11 @@ TEST(AgradRevMatrixAddons, var_vector) { for (int i = 0; i < 100; i++) vec_in(i).vi_->adj_ = derivs(i); - expect_matrix_eq(vals, vec_in.val()); - expect_matrix_eq(vals.array().exp(), vec_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), vec_in.val().array().exp()); - expect_matrix_eq(derivs, vec_in.adj()); - expect_matrix_eq(derivs.array().exp(), vec_in.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_in.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), vec_in.adj().array().exp()); EXPECT_EQ(vec_in.val().rows(), vals.rows()); EXPECT_EQ(vec_in.val().cols(), vals.cols()); @@ -76,11 +76,11 @@ TEST(AgradRevMatrixAddons, var_vector) { vector_vi vec_vi = vec_in.vi(); - expect_matrix_eq(vals, vec_vi.val()); - expect_matrix_eq(vals.array().exp(), vec_vi.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, vec_vi.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), vec_vi.val().array().exp()); - expect_matrix_eq(derivs, vec_vi.adj()); - expect_matrix_eq(derivs.array().exp(), vec_vi.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, vec_vi.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), vec_vi.adj().array().exp()); EXPECT_EQ(vec_vi.val().rows(), vals.rows()); EXPECT_EQ(vec_vi.val().cols(), vals.cols()); @@ -102,11 +102,11 @@ TEST(AgradRevMatrixAddons, var_row_vector) { for (int i = 0; i < 100; i++) row_vec_in(i).vi_->adj_ = derivs(i); - expect_matrix_eq(vals, row_vec_in.val()); - expect_matrix_eq(vals.array().exp(), row_vec_in.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_in.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), row_vec_in.val().array().exp()); - expect_matrix_eq(derivs, row_vec_in.adj()); - expect_matrix_eq(derivs.array().exp(), row_vec_in.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_in.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), row_vec_in.adj().array().exp()); EXPECT_EQ(row_vec_in.val().rows(), vals.rows()); EXPECT_EQ(row_vec_in.val().cols(), vals.cols()); @@ -116,11 +116,11 @@ TEST(AgradRevMatrixAddons, var_row_vector) { row_vector_vi row_vec_vi = row_vec_in.vi(); - expect_matrix_eq(vals, row_vec_vi.val()); - expect_matrix_eq(vals.array().exp(), row_vec_vi.val().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(vals, row_vec_vi.val()); + EXPECT_MATRIX_FLOAT_EQ(vals.array().exp(), row_vec_vi.val().array().exp()); - expect_matrix_eq(derivs, row_vec_vi.adj()); - expect_matrix_eq(derivs.array().exp(), row_vec_vi.adj().array().exp()); + EXPECT_MATRIX_FLOAT_EQ(derivs, row_vec_vi.adj()); + EXPECT_MATRIX_FLOAT_EQ(derivs.array().exp(), row_vec_vi.adj().array().exp()); EXPECT_EQ(row_vec_vi.val().rows(), vals.rows()); EXPECT_EQ(row_vec_vi.val().cols(), vals.cols()); diff --git a/test/unit/math/rev/fun/expect_matrix_eq.hpp b/test/unit/math/rev/fun/expect_matrix_eq.hpp deleted file mode 100644 index efedebe626b..00000000000 --- a/test/unit/math/rev/fun/expect_matrix_eq.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TEST_UNIT_MATH_REV_EXPECT_MATRIX_EQ_HPP -#define TEST_UNIT_MATH_REV_EXPECT_MATRIX_EQ_HPP - -#include -#include - -template -void expect_matrix_eq( - const Eigen::Matrix& a, - const Eigen::Matrix& b) { - EXPECT_EQ(a.rows(), b.rows()); - EXPECT_EQ(a.cols(), b.cols()); - for (int i = 0; i < a.rows(); ++i) - for (int j = 0; j < a.cols(); ++j) - EXPECT_FLOAT_EQ(value_of(a(i, j)), value_of(b(i, j))); -} - -#endif diff --git a/test/unit/math/rev/fun/mdivide_left_tri_test.cpp b/test/unit/math/rev/fun/mdivide_left_tri_test.cpp index 9a92d67ebb7..42ff29f0fdb 100644 --- a/test/unit/math/rev/fun/mdivide_left_tri_test.cpp +++ b/test/unit/math/rev/fun/mdivide_left_tri_test.cpp @@ -2,6 +2,7 @@ #include #include #include +#include // TODO(carpenter): move this to test framework; should be able to put // all this GPU config into the functor @@ -10,10 +11,6 @@ #ifdef STAN_OPENCL #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(stan::math::value_of(A(i)), stan::math::value_of(B(i)), DELTA); - boost::random::mt19937 rng; #define MDIVIDE_OPENCL_OVERRIDE 0 #define MDIVIDE_CPU_OVERRIDE INT_MAX @@ -45,7 +42,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Av, Av); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_OPENCL_OVERRIDE; @@ -53,7 +50,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Av, Ad); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_OPENCL_OVERRIDE; @@ -61,7 +58,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Ad, Av); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_OPENCL_OVERRIDE; @@ -71,7 +68,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { = MDIVIDE_CPU_OVERRIDE; matrix_v Av_inv = mdivide_left_tri(Av); I = Av * Av_inv; - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); for (int i = 0; i < mat_size; i++) { for (int j = 0; j < i; j++) { @@ -92,7 +89,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Av, Av); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_OPENCL_OVERRIDE; @@ -100,7 +97,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Av, Ad); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_OPENCL_OVERRIDE; @@ -108,7 +105,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_val_cl) { stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer = MDIVIDE_CPU_OVERRIDE; I = mdivide_left_tri(Ad, Av); - EXPECT_MATRIX_NEAR(I, I_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(I.val(), I_cl.val(), 1.0E-12); // restore default value stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -149,7 +146,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_lower_grad_vv_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Av, Bv); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -190,7 +187,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_lower_grad_dv_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Ad, Bv); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -231,7 +228,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_lower_grad_vd_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Av, Bd); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -272,7 +269,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_upper_grad_vv_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Av, Bv); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -313,7 +310,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_upper_grad_dv_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Ad, Bv); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer @@ -354,7 +351,7 @@ TEST(AgradRevMatrix, mdivide_left_tri_upper_grad_vd_cl) { = MDIVIDE_CPU_OVERRIDE; Cv = mdivide_left_tri(Av, Bd); Cv(0, 0).grad(); - EXPECT_MATRIX_NEAR(Cv, Cv_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(Cv.val(), Cv_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(Cv.adj(), Cv_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().tri_inverse_size_worth_transfer diff --git a/test/unit/math/rev/fun/multiply_test.cpp b/test/unit/math/rev/fun/multiply_test.cpp index 0d9bbb8b59f..71e6bc346e8 100644 --- a/test/unit/math/rev/fun/multiply_test.cpp +++ b/test/unit/math/rev/fun/multiply_test.cpp @@ -2,12 +2,10 @@ #include #include #include +#include #ifdef STAN_OPENCL #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(stan::math::value_of(A(i)), stan::math::value_of(B(i)), DELTA); boost::random::mt19937 rng; #define MULTIPLY_OPENCL_OVERRIDE 0 @@ -36,7 +34,7 @@ TEST(AgradRevMatrix, multiply_val_vv_cl) { = MULTIPLY_CPU_OVERRIDE; C = multiply(Av, Bv); C(0, 0).grad(); - EXPECT_MATRIX_NEAR(C, C_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(C.val(), C_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(C.adj(), C_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().multiply_dim_prod_worth_transfer @@ -68,7 +66,7 @@ TEST(AgradRevMatrix, multiply_val_vd_cl) { = MULTIPLY_CPU_OVERRIDE; C = multiply(Av, Bd); C(0, 0).grad(); - EXPECT_MATRIX_NEAR(C, C_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(C.val(), C_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(C.adj(), C_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().multiply_dim_prod_worth_transfer @@ -99,7 +97,7 @@ TEST(AgradRevMatrix, multiply_val_dv_cl) { = MULTIPLY_CPU_OVERRIDE; C = multiply(Ad, Bv); C(0, 0).grad(); - EXPECT_MATRIX_NEAR(C, C_cl, 1.0E-12); + EXPECT_MATRIX_NEAR(C.val(), C_cl.val(), 1.0E-12); EXPECT_MATRIX_NEAR(C.adj(), C_cl.adj(), 1.0E-12); stan::math::recover_memory(); stan::math::opencl_context.tuning_opts().multiply_dim_prod_worth_transfer diff --git a/test/unit/math/rev/fun/read_var_test.cpp b/test/unit/math/rev/fun/read_var_test.cpp index 59229ebebfb..2d8e89861c7 100644 --- a/test/unit/math/rev/fun/read_var_test.cpp +++ b/test/unit/math/rev/fun/read_var_test.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include TEST(AgradRevMatrix, read_var_mat) { @@ -18,34 +18,34 @@ TEST(AgradRevMatrix, read_var_mat) { matrix_var.adj() = MatrixXd::Random(100, 100); read_vi_val_adj(matrix_var, matrix_vari, matrix_val, matrix_deriv); - expect_matrix_eq(matrix_var.val(), matrix_val); - expect_matrix_eq(matrix_var.adj(), matrix_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.val(), matrix_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.adj(), matrix_deriv); matrix_val.setZero(); matrix_deriv.setZero(); read_val_adj(matrix_var, matrix_val, matrix_deriv); - expect_matrix_eq(matrix_var.val(), matrix_val); - expect_matrix_eq(matrix_var.adj(), matrix_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.val(), matrix_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.adj(), matrix_deriv); matrix_val.setZero(); matrix_deriv.setZero(); read_val_adj(matrix_vari, matrix_val, matrix_deriv); - expect_matrix_eq(matrix_vari.val(), matrix_val); - expect_matrix_eq(matrix_vari.adj(), matrix_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_vari.val(), matrix_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_vari.adj(), matrix_deriv); matrix_val.setZero(); matrix_vi matrix_vi2(100, 100); read_vi_val(matrix_var, matrix_vi2, matrix_val); - expect_matrix_eq(matrix_var.val(), matrix_val); - expect_matrix_eq(matrix_var.val(), matrix_vi2.val()); - expect_matrix_eq(matrix_var.adj(), matrix_vi2.adj()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.val(), matrix_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.val(), matrix_vi2.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.adj(), matrix_vi2.adj()); matrix_deriv.setZero(); matrix_vi matrix_vi3(100, 100); read_vi_adj(matrix_var, matrix_vi3, matrix_deriv); - expect_matrix_eq(matrix_var.adj(), matrix_deriv); - expect_matrix_eq(matrix_var.val(), matrix_vi3.val()); - expect_matrix_eq(matrix_var.adj(), matrix_vi3.adj()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.adj(), matrix_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.val(), matrix_vi3.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.adj(), matrix_vi3.adj()); } TEST(AgradRevMatrix, read_var_vec) { @@ -64,28 +64,28 @@ TEST(AgradRevMatrix, read_var_vec) { vector_var.adj() = VectorXd::Random(100); read_vi_val_adj(vector_var, vector_vari, vector_val, vector_deriv); - expect_matrix_eq(vector_var.val(), vector_val); - expect_matrix_eq(vector_var.adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(vector_var.val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(vector_var.adj(), vector_deriv); vector_val.setZero(); vector_deriv.setZero(); read_val_adj(vector_vari, vector_val, vector_deriv); - expect_matrix_eq(vector_vari.val(), vector_val); - expect_matrix_eq(vector_vari.adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(vector_vari.val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(vector_vari.adj(), vector_deriv); vector_val.setZero(); vector_vi vector_vi2(100); read_vi_val(vector_var, vector_vi2, vector_val); - expect_matrix_eq(vector_var.val(), vector_val); - expect_matrix_eq(vector_var.val(), vector_vi2.val()); - expect_matrix_eq(vector_var.adj(), vector_vi2.adj()); + EXPECT_MATRIX_FLOAT_EQ(vector_var.val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(vector_var.val(), vector_vi2.val()); + EXPECT_MATRIX_FLOAT_EQ(vector_var.adj(), vector_vi2.adj()); vector_deriv.setZero(); vector_vi vector_vi3(100); read_vi_adj(vector_var, vector_vi3, vector_deriv); - expect_matrix_eq(vector_var.adj(), vector_deriv); - expect_matrix_eq(vector_var.val(), vector_vi3.val()); - expect_matrix_eq(vector_var.adj(), vector_vi3.adj()); + EXPECT_MATRIX_FLOAT_EQ(vector_var.adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(vector_var.val(), vector_vi3.val()); + EXPECT_MATRIX_FLOAT_EQ(vector_var.adj(), vector_vi3.adj()); } TEST(AgradRevMatrix, read_var_rowvec) { @@ -105,28 +105,28 @@ TEST(AgradRevMatrix, read_var_rowvec) { read_vi_val_adj(row_vector_var, row_vector_vari, row_vector_val, row_vector_deriv); - expect_matrix_eq(row_vector_var.val(), row_vector_val); - expect_matrix_eq(row_vector_var.adj(), row_vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.val(), row_vector_val); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.adj(), row_vector_deriv); row_vector_val.setZero(); row_vector_deriv.setZero(); read_val_adj(row_vector_vari, row_vector_val, row_vector_deriv); - expect_matrix_eq(row_vector_vari.val(), row_vector_val); - expect_matrix_eq(row_vector_vari.adj(), row_vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(row_vector_vari.val(), row_vector_val); + EXPECT_MATRIX_FLOAT_EQ(row_vector_vari.adj(), row_vector_deriv); row_vector_val.setZero(); row_vector_vi row_vector_vi2(100); read_vi_val(row_vector_var, row_vector_vi2, row_vector_val); - expect_matrix_eq(row_vector_var.val(), row_vector_val); - expect_matrix_eq(row_vector_var.val(), row_vector_vi2.val()); - expect_matrix_eq(row_vector_var.adj(), row_vector_vi2.adj()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.val(), row_vector_val); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.val(), row_vector_vi2.val()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.adj(), row_vector_vi2.adj()); row_vector_deriv.setZero(); row_vector_vi row_vector_vi3(100); read_vi_adj(row_vector_var, row_vector_vi3, row_vector_deriv); - expect_matrix_eq(row_vector_var.adj(), row_vector_deriv); - expect_matrix_eq(row_vector_var.val(), row_vector_vi3.val()); - expect_matrix_eq(row_vector_var.adj(), row_vector_vi3.adj()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.adj(), row_vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.val(), row_vector_vi3.val()); + EXPECT_MATRIX_FLOAT_EQ(row_vector_var.adj(), row_vector_vi3.adj()); } TEST(AgradRevMatrix, read_var_expr) { @@ -149,32 +149,32 @@ TEST(AgradRevMatrix, read_var_expr) { matrix_vari = matrix_var.vi(); read_vi_val_adj(matrix_var.diagonal(), vector_vari, vector_val, vector_deriv); - expect_matrix_eq(matrix_var.diagonal().val(), vector_val); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_deriv); vector_val.setZero(); vector_deriv.setZero(); read_val_adj(matrix_var.diagonal(), vector_val, vector_deriv); - expect_matrix_eq(matrix_var.diagonal().val(), vector_val); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_deriv); vector_val.setZero(); vector_deriv.setZero(); read_val_adj(matrix_vari.diagonal(), vector_val, vector_deriv); - expect_matrix_eq(matrix_var.diagonal().val(), vector_val); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_deriv); vector_val.setZero(); vector_vi vector_vari2(100); read_vi_val(matrix_var.diagonal(), vector_vari2, vector_val); - expect_matrix_eq(matrix_var.diagonal().val(), vector_val); - expect_matrix_eq(matrix_var.diagonal().val(), vector_vari2.val()); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_vari2.adj()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_val); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_vari2.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_vari2.adj()); vector_deriv.setZero(); vector_vi vector_vari3(100); read_vi_adj(matrix_var.diagonal(), vector_vari3, vector_deriv); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_deriv); - expect_matrix_eq(matrix_var.diagonal().val(), vector_vari3.val()); - expect_matrix_eq(matrix_var.diagonal().adj(), vector_vari3.adj()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_deriv); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().val(), vector_vari3.val()); + EXPECT_MATRIX_FLOAT_EQ(matrix_var.diagonal().adj(), vector_vari3.adj()); } diff --git a/test/unit/math/rev/fun/value_of_rec_test.cpp b/test/unit/math/rev/fun/value_of_rec_test.cpp index f4956f43246..4b8fcdcb51e 100644 --- a/test/unit/math/rev/fun/value_of_rec_test.cpp +++ b/test/unit/math/rev/fun/value_of_rec_test.cpp @@ -1,12 +1,9 @@ #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(AgradRev, value_of_rec) { using stan::math::value_of_rec; using stan::math::var; diff --git a/test/unit/math/rev/fun/value_of_test.cpp b/test/unit/math/rev/fun/value_of_test.cpp index 0c951811eff..2f1f51951ae 100644 --- a/test/unit/math/rev/fun/value_of_test.cpp +++ b/test/unit/math/rev/fun/value_of_test.cpp @@ -1,12 +1,9 @@ #include #include +#include #include #include -#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ - for (int i = 0; i < A.size(); i++) \ - EXPECT_NEAR(A(i), B(i), DELTA); - TEST(AgradRev, value_of) { using stan::math::value_of; using stan::math::var; diff --git a/test/unit/util.hpp b/test/unit/util.hpp index 197a8db08d7..f266056690d 100644 --- a/test/unit/util.hpp +++ b/test/unit/util.hpp @@ -1,11 +1,128 @@ -#ifndef TEST__UNIT__UTIL_HPP -#define TEST__UNIT__UTIL_HPP +#ifndef TEST_UNIT_UTIL_HPP +#define TEST_UNIT_UTIL_HPP #include #include #include #include +/** + * Tests for exact elementwise equality of input matrices of + * the supplied type with he EXPECT_EQ macro from GTest. + * This EXPECT test should be used when the elements + * of the supplied matrices are not doubles. + * + * @param A first input matrix to compare + * @param B second input matrix to compare + * @param type types of elements in matrices A and B + */ +#define EXPECT_TYPED_MATRIX_EQ(A, B, type) \ + { \ + const Eigen::Matrix& A_eval = A; \ + const Eigen::Matrix& B_eval = B; \ + EXPECT_EQ(A_eval.rows(), B_eval.rows()); \ + EXPECT_EQ(A_eval.cols(), B_eval.cols()); \ + for (int i = 0; i < A_eval.size(); i++) \ + EXPECT_EQ(A_eval(i), B_eval(i)); \ + } + +/** + * Tests for exact elementwise equality of the input matrices + * of doubles with he EXPECT_EQ macro from GTest. + * + * @param A first input matrix to compare + * @param B second input matrix to compare + */ +#define EXPECT_MATRIX_EQ(A, B) \ + { \ + const Eigen::MatrixXd& A_eval = A; \ + const Eigen::MatrixXd& B_eval = B; \ + EXPECT_EQ(A_eval.rows(), B_eval.rows()); \ + EXPECT_EQ(A_eval.cols(), B_eval.cols()); \ + for (int i = 0; i < A_eval.size(); i++) \ + EXPECT_EQ(A_eval(i), B_eval(i)); \ + } + +/** + * Tests for elementwise equality of the input matrices + * of doubles with the EXPECT_FLOAT_EQ macro from + * GTest. + * + * @param A first input matrix to compare + * @param B second input matrix to compare + */ +#define EXPECT_MATRIX_FLOAT_EQ(A, B) \ + { \ + const Eigen::MatrixXd& A_eval = A; \ + const Eigen::MatrixXd& B_eval = B; \ + EXPECT_EQ(A_eval.rows(), B_eval.rows()); \ + EXPECT_EQ(A_eval.cols(), B_eval.cols()); \ + for (int i = 0; i < A_eval.size(); i++) \ + EXPECT_FLOAT_EQ(A_eval(i), B_eval(i)); \ + } + +/** + * Tests for elementwise equality of the input std::vectors + * of any type with the EXPECT_FLOAT_EQ macro from GTest. + * + * @param A first input vector to compare + * @param B second input vector to compare + */ +#define EXPECT_STD_VECTOR_FLOAT_EQ(A, B) \ + EXPECT_EQ(A.size(), B.size()); \ + for (int i = 0; i < A.size(); ++i) \ + EXPECT_FLOAT_EQ(A[i], B[i]); + +/** + * Tests if any elementwise difference of the input matrices + * of doubles is greater than DELTA. This uses the + * EXPECT_NEAR macro from GTest. + * + * @param A first input matrix to compare + * @param B second input matrix to compare + * @param DELTA the maximum allowed difference + */ +#define EXPECT_MATRIX_NEAR(A, B, DELTA) \ + { \ + const Eigen::MatrixXd& A_eval = A; \ + const Eigen::MatrixXd& B_eval = B; \ + EXPECT_EQ(A_eval.rows(), B_eval.rows()); \ + EXPECT_EQ(A_eval.cols(), B_eval.cols()); \ + for (int i = 0; i < A_eval.size(); i++) \ + EXPECT_NEAR(A_eval(i), B_eval(i), DELTA); \ + } + +/** + * Tests if any elementwise difference of the input matrices + * of the specified type is greater than DELTA. This uses the + * EXPECT_NEAR macro from GTest. + * + * @param A first input matrix to compare + * @param B second input matrix to compare + * @param DELTA the maximum allowed difference + * @param type of elements in the input matrices + */ +#define EXPECT_TYPED_MATRIX_NEAR(A, B, DELTA, type) \ + { \ + const Eigen::Matrix& A_eval = A; \ + const Eigen::Matrix& B_eval = B; \ + EXPECT_EQ(A_eval.rows(), B_eval.rows()); \ + EXPECT_EQ(A_eval.cols(), B_eval.cols()); \ + for (int i = 0; i < A_eval.size(); i++) \ + EXPECT_NEAR(A_eval(i), B_eval(i), DELTA); \ + } + +/** + * Tests if the expression throws the expected + * exception with a specific number of occurrences of + * the expected message in the throw message. + * + * @param expr expression to test + * @param T_e type of exception + * @param msg expected message + * @param count the expected number of occurrences of msg + * in the message of the exception + */ #define EXPECT_THROW_MSG_WITH_COUNT(expr, T_e, msg, count) \ EXPECT_THROW(expr, T_e); \ try { \ @@ -16,9 +133,25 @@ << "found message: " << e.what(); \ } +/** + * Tests if the expression throws the expected + * exception with the expected message. + * + * @param expr expression to test + * @param T_e type of exception + * @param msg expected message + */ #define EXPECT_THROW_MSG(expr, T_e, msg) \ EXPECT_THROW_MSG_WITH_COUNT(expr, T_e, msg, 1) +/** + * Count the number of times a substring is found in + * a supplied string. + * + * @param target substring to match in s + * @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) { if (target.size() == 0) return -1; // error @@ -28,6 +161,13 @@ int count_matches(const std::string& target, const std::string& s) { ++count; return count; } + +/** + * Test for equality of the supplied types + * + * @tparam T1 first tpye + * @tparam T2 second type + */ namespace test { template void expect_same_type() {