Skip to content

Commit

Permalink
Merge pull request #2991 from stan-dev/fix/2989-fabs-adl
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian authored Dec 22, 2023
2 parents 013bb8b + 2acfdd5 commit ae90c3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions stan/math/prim/err/check_symmetric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ template <typename EigMat, require_matrix_t<EigMat>* = nullptr>
inline void check_symmetric(const char* function, const char* name,
const EigMat& y) {
check_square(function, name, y);
using stan::math::fabs;
using std::fabs;

Eigen::Index k = y.rows();
Expand Down
11 changes: 11 additions & 0 deletions test/unit/math/prim/err/check_symmetric_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ TEST(ErrorHandlingMatrix, checkSymmetric_non_square) {
EXPECT_THROW(stan::math::check_symmetric("checkSymmetric", "y", y),
std::invalid_argument);
}

TEST(ErrorHandlingMatrix, checkSymmetric_complex) {
Eigen::MatrixXcd y(2, 2);
y << std::complex<double>(1, 1), std::complex<double>(2, 2),
std::complex<double>(2, 2), std::complex<double>(1, 1);

EXPECT_NO_THROW(stan::math::check_symmetric("checkSymmetric", "y", y));
y(0, 1) = std::complex<double>(2, 3);
EXPECT_THROW(stan::math::check_symmetric("checkSymmetric", "y", y),
std::domain_error);
}
6 changes: 6 additions & 0 deletions test/unit/math/prim/fun/fabs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ TEST(primScalFun, fabs) {
stan::test::expect_common_prim([](auto x) { return std::fabs(x); },
[](auto x) { return stan::math::fabs(x); });
}

TEST(primScalFun, fabs_complex) {
using stan::math::fabs;
std::complex<double> z(1.0, 2.0);
EXPECT_FLOAT_EQ(fabs(z), 2.236068);
}

0 comments on commit ae90c3e

Please sign in to comment.