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.

62 lines
1.9 KiB

  1. // This file is triangularView of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
  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. // This file tests the basic selfadjointView API,
  11. // the related products and decompositions are tested in specific files.
  12. template<typename MatrixType> void selfadjoint(const MatrixType& m)
  13. {
  14. typedef typename MatrixType::Index Index;
  15. typedef typename MatrixType::Scalar Scalar;
  16. typedef typename NumTraits<Scalar>::Real RealScalar;
  17. Index rows = m.rows();
  18. Index cols = m.cols();
  19. MatrixType m1 = MatrixType::Random(rows, cols),
  20. m3(rows, cols);
  21. m1.diagonal() = m1.diagonal().real().template cast<Scalar>();
  22. // check selfadjoint to dense
  23. m3 = m1.template selfadjointView<Upper>();
  24. VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Upper>()), MatrixType(m1.template triangularView<Upper>()));
  25. VERIFY_IS_APPROX(m3, m3.adjoint());
  26. m3 = m1.template selfadjointView<Lower>();
  27. VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Lower>()), MatrixType(m1.template triangularView<Lower>()));
  28. VERIFY_IS_APPROX(m3, m3.adjoint());
  29. }
  30. void bug_159()
  31. {
  32. Matrix3d m = Matrix3d::Random().selfadjointView<Lower>();
  33. EIGEN_UNUSED_VARIABLE(m)
  34. }
  35. void test_selfadjoint()
  36. {
  37. for(int i = 0; i < g_repeat ; i++)
  38. {
  39. int s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE); EIGEN_UNUSED_VARIABLE(s);
  40. CALL_SUBTEST_1( selfadjoint(Matrix<float, 1, 1>()) );
  41. CALL_SUBTEST_2( selfadjoint(Matrix<float, 2, 2>()) );
  42. CALL_SUBTEST_3( selfadjoint(Matrix3cf()) );
  43. CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) );
  44. CALL_SUBTEST_5( selfadjoint(Matrix<float,Dynamic,Dynamic,RowMajor>(s, s)) );
  45. EIGEN_UNUSED_VARIABLE(s)
  46. }
  47. CALL_SUBTEST_1( bug_159() );
  48. }