Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP] Update to Eigen 3.4 #2583

Merged
merged 32 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
db4e5f7
Update Eigen and fix Stan headers
andrjohns Jun 22, 2022
08d9fed
Merge branch 'develop' into feature/eigen_test
andrjohns Jun 22, 2022
438b0ba
Undo old changes
andrjohns Jun 22, 2022
7dfaad9
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 22, 2022
80f8230
Remove missed testing changes
andrjohns Jun 22, 2022
60cf7dc
Fix include errors
andrjohns Jun 22, 2022
c6e3f22
Add error check for inv_wishart_cholesky
andrjohns Jun 22, 2022
b41d20c
Prob test failures fix
andrjohns Jun 22, 2022
f55a619
Trigger CI
andrjohns Jun 23, 2022
eff6373
Prob test fix
andrjohns Jun 23, 2022
853f46d
Trigger CI
andrjohns Jun 23, 2022
d655ab9
Merge remote-tracking branch 'upstream/develop' into update/eigen-3.4
andrjohns Jul 1, 2022
64c6fb1
update docs
SteveBronder Jul 8, 2022
0991901
update to newest version of 3.4
SteveBronder Jul 9, 2022
bee5ad4
Merge remote-tracking branch 'upstream/develop' into HEAD
andrjohns Jul 11, 2022
7c7e178
Merge remote-tracking branch 'origin/develop' into update/eigen-3.4
SteveBronder Aug 16, 2022
2d7abef
Merge branch 'develop' into update/eigen-3.4
andrjohns Sep 12, 2022
444765d
Merge remote-tracking branch 'upstream/update/eigen-3.4' into update/…
andrjohns Sep 12, 2022
a8d62cd
Merge remote-tracking branch 'upstream/develop' into update/eigen-3.4
andrjohns Oct 25, 2022
935a52f
Run tests with suspected commit reverted
andrjohns Oct 26, 2022
eaf9d58
Merge branch 'develop' into update/eigen-3.4
andrjohns Oct 26, 2022
a6eb5c6
Trigger CI
andrjohns Oct 26, 2022
d36f958
Revert "Run tests with suspected commit reverted"
andrjohns Nov 7, 2022
6ef0290
Merge branch 'develop' into update/eigen-3.4
andrjohns Nov 7, 2022
bf93ef1
Merge remote-tracking branch 'upstream/develop' into update/eigen-3.4
andrjohns Dec 2, 2022
5cd2c21
Merge remote-tracking branch 'upstream/develop' into update/eigen-3.4
andrjohns Feb 6, 2023
661af5a
Merge branch 'develop' into update/eigen-3.4
WardBrian Mar 6, 2023
5ec8978
Merge branch 'develop' into update/eigen-3.4
WardBrian Mar 9, 2023
b2483c4
Split up eigenvectors_test file
WardBrian Mar 9, 2023
11fd3fa
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Mar 9, 2023
5f3920c
Split up eigendecompoe_identity_test file
WardBrian Mar 9, 2023
f06d5ca
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Mar 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split up eigenvectors_test file
  • Loading branch information
WardBrian committed Mar 9, 2023
commit b2483c4afee8143dd866a9dbae067823f68af935
60 changes: 60 additions & 0 deletions test/unit/math/mix/fun/eigendecompose_identity_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <test/unit/math/test_ad.hpp>


template <typename T>
void expect_identity_matrix(const T& x) {
EXPECT_EQ(x.rows(), x.cols());
for (int j = 0; j < x.cols(); ++j) {
for (int i = 0; i < x.rows(); ++i) {
EXPECT_NEAR(i == j ? 1 : 0, stan::math::value_of_rec(x(i, j)), 1e-6);
}
}
}

template <typename T>
void expectEigenvectorsId() {
for (const auto& m_d : stan::test::square_test_matrices(1, 2)) {
Eigen::Matrix<T, -1, -1> m(m_d);
auto vecs = eigenvectors(m).eval();
auto vals = eigenvalues(m).eval();
auto I = (vecs.inverse() * m * vecs * vals.asDiagonal().inverse()).real();
expect_identity_matrix(I);
}
}

template <typename T>
void expectComplexEigenvectorsId() {
Eigen::Matrix<std::complex<T>, -1, -1> c22(2, 2);
c22 << stan::math::to_complex(T(0), T(-1)),
stan::math::to_complex(T(0), T(0)), stan::math::to_complex(T(2), T(0)),
stan::math::to_complex(T(4), T(0));
auto eigenvalues = stan::math::eigenvalues(c22);
auto eigenvectors = stan::math::eigenvectors(c22);

auto I = (eigenvectors.inverse() * c22 * eigenvectors
* eigenvalues.asDiagonal().inverse())
.real();

expect_identity_matrix(I);
}

TEST(mathMixFun, eigenvectorsId) {
using d_t = double;
using v_t = stan::math::var;
using fd_t = stan::math::fvar<double>;
using ffd_t = stan::math::fvar<fd_t>;
using fv_t = stan::math::fvar<stan::math::var>;
using ffv_t = stan::math::fvar<fv_t>;

expectEigenvectorsId<v_t>();
expectEigenvectorsId<fd_t>();
expectEigenvectorsId<ffd_t>();
expectEigenvectorsId<fv_t>();
expectEigenvectorsId<ffv_t>();

expectComplexEigenvectorsId<v_t>();
expectComplexEigenvectorsId<fd_t>();
expectComplexEigenvectorsId<ffd_t>();
expectComplexEigenvectorsId<fv_t>();
expectComplexEigenvectorsId<ffv_t>();
}
57 changes: 0 additions & 57 deletions test/unit/math/mix/fun/eigenvectors_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,3 @@ TEST(mathMixFun, eigenvectorsComplex) {
EXPECT_THROW(f(a32), std::invalid_argument);
}

template <typename T>
void expect_identity_matrix(const T& x) {
EXPECT_EQ(x.rows(), x.cols());
for (int j = 0; j < x.cols(); ++j) {
for (int i = 0; i < x.rows(); ++i) {
EXPECT_NEAR(i == j ? 1 : 0, stan::math::value_of_rec(x(i, j)), 1e-6);
}
}
}

template <typename T>
void expectEigenvectorsId() {
for (const auto& m_d : stan::test::square_test_matrices(1, 2)) {
Eigen::Matrix<T, -1, -1> m(m_d);
auto vecs = eigenvectors(m).eval();
auto vals = eigenvalues(m).eval();
auto I = (vecs.inverse() * m * vecs * vals.asDiagonal().inverse()).real();
expect_identity_matrix(I);
}
}

template <typename T>
void expectComplexEigenvectorsId() {
Eigen::Matrix<std::complex<T>, -1, -1> c22(2, 2);
c22 << stan::math::to_complex(T(0), T(-1)),
stan::math::to_complex(T(0), T(0)), stan::math::to_complex(T(2), T(0)),
stan::math::to_complex(T(4), T(0));
auto eigenvalues = stan::math::eigenvalues(c22);
auto eigenvectors = stan::math::eigenvectors(c22);

auto I = (eigenvectors.inverse() * c22 * eigenvectors
* eigenvalues.asDiagonal().inverse())
.real();

expect_identity_matrix(I);
}

TEST(mathMixFun, eigenvectorsId) {
using d_t = double;
using v_t = stan::math::var;
using fd_t = stan::math::fvar<double>;
using ffd_t = stan::math::fvar<fd_t>;
using fv_t = stan::math::fvar<stan::math::var>;
using ffv_t = stan::math::fvar<fv_t>;

expectEigenvectorsId<v_t>();
expectEigenvectorsId<fd_t>();
expectEigenvectorsId<ffd_t>();
expectEigenvectorsId<fv_t>();
expectEigenvectorsId<ffv_t>();

expectComplexEigenvectorsId<v_t>();
expectComplexEigenvectorsId<fd_t>();
expectComplexEigenvectorsId<ffd_t>();
expectComplexEigenvectorsId<fv_t>();
expectComplexEigenvectorsId<ffv_t>();
}