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.

65 lines
2.1 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
  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 real_qz(const MatrixType& m)
  13. {
  14. /* this test covers the following files:
  15. RealQZ.h
  16. */
  17. using std::abs;
  18. typedef typename MatrixType::Index Index;
  19. typedef typename MatrixType::Scalar Scalar;
  20. Index dim = m.cols();
  21. MatrixType A = MatrixType::Random(dim,dim),
  22. B = MatrixType::Random(dim,dim);
  23. RealQZ<MatrixType> qz(A,B);
  24. VERIFY_IS_EQUAL(qz.info(), Success);
  25. // check for zeros
  26. bool all_zeros = true;
  27. for (Index i=0; i<A.cols(); i++)
  28. for (Index j=0; j<i; j++) {
  29. if (abs(qz.matrixT()(i,j))!=Scalar(0.0))
  30. all_zeros = false;
  31. if (j<i-1 && abs(qz.matrixS()(i,j))!=Scalar(0.0))
  32. all_zeros = false;
  33. if (j==i-1 && j>0 && abs(qz.matrixS()(i,j))!=Scalar(0.0) && abs(qz.matrixS()(i-1,j-1))!=Scalar(0.0))
  34. all_zeros = false;
  35. }
  36. VERIFY_IS_EQUAL(all_zeros, true);
  37. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixS()*qz.matrixZ(), A);
  38. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixT()*qz.matrixZ(), B);
  39. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixQ().adjoint(), MatrixType::Identity(dim,dim));
  40. VERIFY_IS_APPROX(qz.matrixZ()*qz.matrixZ().adjoint(), MatrixType::Identity(dim,dim));
  41. }
  42. void test_real_qz()
  43. {
  44. int s = 0;
  45. for(int i = 0; i < g_repeat; i++) {
  46. CALL_SUBTEST_1( real_qz(Matrix4f()) );
  47. s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
  48. CALL_SUBTEST_2( real_qz(MatrixXd(s,s)) );
  49. // some trivial but implementation-wise tricky cases
  50. CALL_SUBTEST_2( real_qz(MatrixXd(1,1)) );
  51. CALL_SUBTEST_2( real_qz(MatrixXd(2,2)) );
  52. CALL_SUBTEST_3( real_qz(Matrix<double,1,1>()) );
  53. CALL_SUBTEST_4( real_qz(Matrix2d()) );
  54. }
  55. TEST_SET_BUT_UNUSED_VARIABLE(s)
  56. }