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.

69 lines
2.4 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. typedef typename MatrixType::Index Index;
  18. typedef typename MatrixType::Scalar Scalar;
  19. typedef typename NumTraits<Scalar>::Real RealScalar;
  20. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  21. typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, 1> RealVectorType;
  22. typedef typename std::complex<typename NumTraits<typename MatrixType::Scalar>::Real> Complex;
  23. Index dim = m.cols();
  24. MatrixType A = MatrixType::Random(dim,dim),
  25. B = MatrixType::Random(dim,dim);
  26. RealQZ<MatrixType> qz(A,B);
  27. VERIFY_IS_EQUAL(qz.info(), Success);
  28. // check for zeros
  29. bool all_zeros = true;
  30. for (Index i=0; i<A.cols(); i++)
  31. for (Index j=0; j<i; j++) {
  32. if (internal::abs(qz.matrixT()(i,j))!=Scalar(0.0))
  33. all_zeros = false;
  34. if (j<i-1 && internal::abs(qz.matrixS()(i,j))!=Scalar(0.0))
  35. all_zeros = false;
  36. if (j==i-1 && j>0 && internal::abs(qz.matrixS()(i,j))!=Scalar(0.0) && internal::abs(qz.matrixS()(i-1,j-1))!=Scalar(0.0))
  37. all_zeros = false;
  38. }
  39. VERIFY_IS_EQUAL(all_zeros, true);
  40. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixS()*qz.matrixZ(), A);
  41. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixT()*qz.matrixZ(), B);
  42. VERIFY_IS_APPROX(qz.matrixQ()*qz.matrixQ().adjoint(), MatrixType::Identity(dim,dim));
  43. VERIFY_IS_APPROX(qz.matrixZ()*qz.matrixZ().adjoint(), MatrixType::Identity(dim,dim));
  44. }
  45. void test_real_qz()
  46. {
  47. int s;
  48. for(int i = 0; i < g_repeat; i++) {
  49. CALL_SUBTEST_1( real_qz(Matrix4f()) );
  50. s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4);
  51. CALL_SUBTEST_2( real_qz(MatrixXd(s,s)) );
  52. // some trivial but implementation-wise tricky cases
  53. CALL_SUBTEST_2( real_qz(MatrixXd(1,1)) );
  54. CALL_SUBTEST_2( real_qz(MatrixXd(2,2)) );
  55. CALL_SUBTEST_3( real_qz(Matrix<double,1,1>()) );
  56. CALL_SUBTEST_4( real_qz(Matrix2d()) );
  57. }
  58. EIGEN_UNUSED_VARIABLE(s)
  59. }