You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.6 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. #include <limits>
  11. #include <Eigen/Eigenvalues>
  12. template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTime)
  13. {
  14. typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar;
  15. typedef typename ComplexSchur<MatrixType>::ComplexMatrixType ComplexMatrixType;
  16. // Test basic functionality: T is triangular and A = U T U*
  17. for(int counter = 0; counter < g_repeat; ++counter) {
  18. MatrixType A = MatrixType::Random(size, size);
  19. ComplexSchur<MatrixType> schurOfA(A);
  20. VERIFY_IS_EQUAL(schurOfA.info(), Success);
  21. ComplexMatrixType U = schurOfA.matrixU();
  22. ComplexMatrixType T = schurOfA.matrixT();
  23. for(int row = 1; row < size; ++row) {
  24. for(int col = 0; col < row; ++col) {
  25. VERIFY(T(row,col) == (typename MatrixType::Scalar)0);
  26. }
  27. }
  28. VERIFY_IS_APPROX(A.template cast<ComplexScalar>(), U * T * U.adjoint());
  29. }
  30. // Test asserts when not initialized
  31. ComplexSchur<MatrixType> csUninitialized;
  32. VERIFY_RAISES_ASSERT(csUninitialized.matrixT());
  33. VERIFY_RAISES_ASSERT(csUninitialized.matrixU());
  34. VERIFY_RAISES_ASSERT(csUninitialized.info());
  35. // Test whether compute() and constructor returns same result
  36. MatrixType A = MatrixType::Random(size, size);
  37. ComplexSchur<MatrixType> cs1;
  38. cs1.compute(A);
  39. ComplexSchur<MatrixType> cs2(A);
  40. VERIFY_IS_EQUAL(cs1.info(), Success);
  41. VERIFY_IS_EQUAL(cs2.info(), Success);
  42. VERIFY_IS_EQUAL(cs1.matrixT(), cs2.matrixT());
  43. VERIFY_IS_EQUAL(cs1.matrixU(), cs2.matrixU());
  44. // Test computation of only T, not U
  45. ComplexSchur<MatrixType> csOnlyT(A, false);
  46. VERIFY_IS_EQUAL(csOnlyT.info(), Success);
  47. VERIFY_IS_EQUAL(cs1.matrixT(), csOnlyT.matrixT());
  48. VERIFY_RAISES_ASSERT(csOnlyT.matrixU());
  49. if (size > 1)
  50. {
  51. // Test matrix with NaN
  52. A(0,0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN();
  53. ComplexSchur<MatrixType> csNaN(A);
  54. VERIFY_IS_EQUAL(csNaN.info(), NoConvergence);
  55. }
  56. }
  57. void test_schur_complex()
  58. {
  59. CALL_SUBTEST_1(( schur<Matrix4cd>() ));
  60. CALL_SUBTEST_2(( schur<MatrixXcf>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4)) ));
  61. CALL_SUBTEST_3(( schur<Matrix<std::complex<float>, 1, 1> >() ));
  62. CALL_SUBTEST_4(( schur<Matrix<float, 3, 3, Eigen::RowMajor> >() ));
  63. // Test problem size constructors
  64. CALL_SUBTEST_5(ComplexSchur<MatrixXf>(10));
  65. }