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.

43 lines
1.7 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
  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 <Eigen/SVD>
  11. template<typename MatrixType> void upperbidiag(const MatrixType& m)
  12. {
  13. const typename MatrixType::Index rows = m.rows();
  14. const typename MatrixType::Index cols = m.cols();
  15. typedef Matrix<typename MatrixType::RealScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime> RealMatrixType;
  16. typedef Matrix<typename MatrixType::Scalar, MatrixType::ColsAtCompileTime, MatrixType::RowsAtCompileTime> TransposeMatrixType;
  17. MatrixType a = MatrixType::Random(rows,cols);
  18. internal::UpperBidiagonalization<MatrixType> ubd(a);
  19. RealMatrixType b(rows, cols);
  20. b.setZero();
  21. b.block(0,0,cols,cols) = ubd.bidiagonal();
  22. MatrixType c = ubd.householderU() * b * ubd.householderV().adjoint();
  23. VERIFY_IS_APPROX(a,c);
  24. TransposeMatrixType d = ubd.householderV() * b.adjoint() * ubd.householderU().adjoint();
  25. VERIFY_IS_APPROX(a.adjoint(),d);
  26. }
  27. void test_upperbidiagonalization()
  28. {
  29. for(int i = 0; i < g_repeat; i++) {
  30. CALL_SUBTEST_1( upperbidiag(MatrixXf(3,3)) );
  31. CALL_SUBTEST_2( upperbidiag(MatrixXd(17,12)) );
  32. CALL_SUBTEST_3( upperbidiag(MatrixXcf(20,20)) );
  33. CALL_SUBTEST_4( upperbidiag(Matrix<std::complex<double>,Dynamic,Dynamic,RowMajor>(16,15)) );
  34. CALL_SUBTEST_5( upperbidiag(Matrix<float,6,4>()) );
  35. CALL_SUBTEST_6( upperbidiag(Matrix<float,5,5>()) );
  36. CALL_SUBTEST_7( upperbidiag(Matrix<double,4,3>()) );
  37. }
  38. }