3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 05:43:40 +01:00

Clean the eigenelements tests.

- Clean the output of the test.
- Separate from previous commit to be able to retest previous test
  with same lib code.
This commit is contained in:
Olivier Parcollet 2014-09-04 11:58:20 +02:00
parent 9265c2db7f
commit dcbdd5bc54
2 changed files with 16 additions and 72 deletions

View File

@ -34,7 +34,8 @@ template <typename T> void check_eig(matrix<T> M, matrix<T> vectors, array<doubl
std::cerr << "check " << i << std::endl;
std::cerr << (M - values(i)) * vectors(i, _) << std::endl;
assert_all_close(M * vectors(i, _), values(i) * vectors(i, _), 1.e-14);
}}
}
}
template <typename M> void test(M A) {
auto w = eigenelements(make_clone(A));
@ -54,18 +55,8 @@ int main(int argc, char **argv) {
A(i, j) = (i > j ? i + 2 * j : i - j);
A(j, i) = A(i, j);
}
std::cerr << "A = " << A << std::endl;
test(A);
auto B = A;
auto w = eigenelements(B);
std::cout << "A = " << B << std::endl;
std::cout << " vectors = " << w.first << std::endl;
std::cout << " values = " << w.second << std::endl;
check_eig (A, w.second, w.first);
}
{
matrix<double> A(3, 3);
A() = 0;
A(0, 1) = 1;
A(1, 0) = 1;
@ -73,31 +64,15 @@ int main(int argc, char **argv) {
A(0, 2) = 2;
A(2, 0) = 2;
auto B = A;
std::cout << "A = " << A << std::endl;
auto w = eigenelements(B);
std::cout << " values = " <<w.first << std::endl;
std::cout << " vectors = " << w.second << std::endl;
check_eig (A, w.second, w.first);
}
{
matrix<double> A(3, 3);
test(A);
A() = 0;
A(0, 1) = 1;
A(1, 0) = 1;
A(2, 2) = 8;
auto B = A;
std::cout << "A = " << A << std::endl;
auto w = eigenelements(B);
std::cout << " vectors = " << w.second << std::endl;
std::cout << " values = " <<w.first << std::endl;
std::cout << "A = " << A << std::endl;
check_eig (A, w.second, w.first);
test(A);
}
{ // the complex case
matrix<dcomplex> M(2, 2);

View File

@ -1,31 +0,0 @@
A =
[[-0.193187,-0.65727,0.728474]
[-0.896252,0.420344,0.141577]
[-0.399264,-0.625545,-0.670284]]
vectors = [-4.13941,-0.784934,4.92434]
values =
[[-0.193187,-0.65727,0.728474]
[-0.896252,0.420344,0.141577]
[-0.399264,-0.625545,-0.670284]]
A =
[[0,1,2]
[1,0,0]
[2,0,8]]
values = [-1.23962,0.761178,8.47844]
vectors =
[[-0.767503,0.619144,0.166133]
[-0.597371,-0.784798,0.165046]
[0.232568,0.0274306,0.972193]]
A =
[[0,1,0]
[1,0,0]
[0,0,8]]
vectors =
[[-0.707107,0.707107,0]
[0.707107,0.707107,0]
[0,0,1]]
values = [-1,1,8]
A =
[[0,1,0]
[1,0,0]
[0,0,8]]