From be193258f34e77fbba19b3af7670a1356dc3a8bd Mon Sep 17 00:00:00 2001 From: Taylor Erwin <1065262+terwin@users.noreply.github.com> Date: Fri, 19 Feb 2021 18:11:52 -0500 Subject: [PATCH 1/2] Re-enable eigendecomp test This reverts commit 08caf6ff39be6c1cbc0dc48298f1055652d3e455. --- unit_test/tstBatchedLinearAlgebra.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/unit_test/tstBatchedLinearAlgebra.hpp b/unit_test/tstBatchedLinearAlgebra.hpp index ca1a5c2..4d230bd 100644 --- a/unit_test/tstBatchedLinearAlgebra.hpp +++ b/unit_test/tstBatchedLinearAlgebra.hpp @@ -711,7 +711,6 @@ void kernelTest() } //---------------------------------------------------------------------------// -/* void eigendecompositionTest() { LinearAlgebra::Matrix A = { @@ -822,7 +821,6 @@ void eigendecompositionTest() for ( int j = 0; j < 4; ++j ) EXPECT_FLOAT_EQ( A( i, j ), l_op_ident( i, j ) ); } -*/ //---------------------------------------------------------------------------// // RUN TESTS @@ -867,8 +865,7 @@ TEST( TEST_CATEGORY, kernelTest ) kernelTest<20>(); } -// FIXME_KOKKOSKERNELS -// TEST( TEST_CATEGORY, eigendecomposition_test ) { eigendecompositionTest(); } +TEST( TEST_CATEGORY, eigendecomposition_test ) { eigendecompositionTest(); } //---------------------------------------------------------------------------// From 278ac1b5d0c9b831b792b09d273511be69f6d495 Mon Sep 17 00:00:00 2001 From: Taylor Erwin <1065262+terwin@users.noreply.github.com> Date: Fri, 19 Feb 2021 11:24:29 -0500 Subject: [PATCH 2/2] Add test exposing KokkosKernels eigendecomp bug --- unit_test/tstBatchedLinearAlgebra.hpp | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/unit_test/tstBatchedLinearAlgebra.hpp b/unit_test/tstBatchedLinearAlgebra.hpp index 4d230bd..0446957 100644 --- a/unit_test/tstBatchedLinearAlgebra.hpp +++ b/unit_test/tstBatchedLinearAlgebra.hpp @@ -16,6 +16,8 @@ #include +#include +#include #include using namespace Picasso; @@ -822,6 +824,43 @@ void eigendecompositionTest() EXPECT_FLOAT_EQ( A( i, j ), l_op_ident( i, j ) ); } +//---------------------------------------------------------------------------// +// Test a matrix for which the KokkosKernels eigendecomposition gives the wrong +// answer. +//---------------------------------------------------------------------------// +void eigendecompositionTestBad() +{ + LinearAlgebra::Matrix A = { { 0.5, 0.0, 2.5, 0.0, 0.0 }, + { 0.0, 0.5, 0.0, 0.0, 0.0 }, + { 0.0, 0.0, 0.5, 0.0, 0.4 }, + { 0.0, 0.0, 0.0, 0.5, 0.0 }, + { 0.0, 0.0, 1.05, 0.0, 0.5 } }; + + LinearAlgebra::Vector e_real; + LinearAlgebra::Vector e_imag; + LinearAlgebra::Matrix u_left; + LinearAlgebra::Matrix u_right; + + LinearAlgebra::eigendecomposition( A, e_real, e_imag, u_left, u_right ); + + // All eigenvalues should be real + for ( int i = 0; i < 5; ++i ) + EXPECT_EQ( 0.0, e_imag( i ) ) << "i = " << i; + + // Sort eigenvalues + std::array sorted_e_real; + for ( int i = 0; i < 5; ++i ) + sorted_e_real[i] = e_real( i ); + std::sort( sorted_e_real.begin(), sorted_e_real.end() ); + + // Test sorted eigenvalues + EXPECT_DOUBLE_EQ( -0.14807406984078597, sorted_e_real[0] ); + EXPECT_DOUBLE_EQ( 0.5, sorted_e_real[1] ); + EXPECT_DOUBLE_EQ( 0.5, sorted_e_real[2] ); + EXPECT_DOUBLE_EQ( 0.5, sorted_e_real[3] ); + EXPECT_DOUBLE_EQ( 1.148074069840786, sorted_e_real[4] ); +} + //---------------------------------------------------------------------------// // RUN TESTS //---------------------------------------------------------------------------// @@ -867,6 +906,11 @@ TEST( TEST_CATEGORY, kernelTest ) TEST( TEST_CATEGORY, eigendecomposition_test ) { eigendecompositionTest(); } +TEST( TEST_CATEGORY, eigendecomposition_test_bad ) +{ + eigendecompositionTestBad(); +} + //---------------------------------------------------------------------------// } // end namespace Test