@@ -31,17 +31,17 @@ TEST(mathMixFun, eigenvectorsComplex) {
3131
3232template <typename T>
3333void expect_identity_matrix (const T& x) {
34- EXPECT_EQUAL (x.rows (), x.cols ());
34+ EXPECT_EQ (x.rows (), x.cols ());
3535 for (int j = 0 ; j < x.cols (); ++j) {
3636 for (int i = 0 ; i < x.rows (); ++i) {
37- EXPECT_NEAR (i == j ? 1 : 0 , x (i, j), 1e-6 );
37+ EXPECT_NEAR (i == j ? 1 : 0 , stan::math::value_of_rec ( x (i, j) ), 1e-6 );
3838 }
3939 }
4040}
4141
4242template <typename T>
4343void expectEigenvectorsId () {
44- for (const auto & m_d : stan::test::square_test_matrices (0 , 2 )) {
44+ for (const auto & m_d : stan::test::square_test_matrices (1 , 2 )) {
4545 Eigen::Matrix<T, -1 , -1 > m (m_d);
4646 auto vecs = eigenvectors (m).eval ();
4747 auto vals = eigenvalues (m).eval ();
@@ -50,7 +50,21 @@ void expectEigenvectorsId() {
5050 }
5151}
5252
53- // THESE TESTS USED TO WORK STANDALONE
53+ template <typename T>
54+ void expectComplexEigenvectorsId () {
55+ Eigen::Matrix<std::complex <T>, -1 , -1 > c22 (2 , 2 );
56+ c22 << stan::math::to_complex (T (0 ), T (-1 )),
57+ stan::math::to_complex (T (0 ), T (0 )), stan::math::to_complex (T (2 ), T (0 )),
58+ stan::math::to_complex (T (4 ), T (0 ));
59+ auto eigenvalues = stan::math::eigenvalues (c22);
60+ auto eigenvectors = stan::math::eigenvectors (c22);
61+
62+ auto I = (eigenvectors.inverse () * c22 * eigenvectors
63+ * eigenvalues.asDiagonal ().inverse ())
64+ .real ();
65+
66+ expect_identity_matrix (I);
67+ }
5468
5569TEST (mathMixFun, eigenvectorsId) {
5670 using d_t = double ;
@@ -60,9 +74,15 @@ TEST(mathMixFun, eigenvectorsId) {
6074 using fv_t = stan::math::fvar<stan::math::var>;
6175 using ffv_t = stan::math::fvar<fv_t >;
6276
63- // expectEigenvectorsId<v_t>();
64- // expectEigenvectorsId<fd_t>();
65- // expectEigenvectorsId<ffd_t>();
66- // expectEigenvectorsId<fv_t>();
67- // expectEigenvectorsId<ffv_t>();
77+ expectEigenvectorsId<v_t >();
78+ expectEigenvectorsId<fd_t >();
79+ expectEigenvectorsId<ffd_t >();
80+ expectEigenvectorsId<fv_t >();
81+ expectEigenvectorsId<ffv_t >();
82+
83+ expectComplexEigenvectorsId<v_t >();
84+ expectComplexEigenvectorsId<fd_t >();
85+ expectComplexEigenvectorsId<ffd_t >();
86+ expectComplexEigenvectorsId<fv_t >();
87+ expectComplexEigenvectorsId<ffv_t >();
6888}
0 commit comments