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.

61 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. Index rows = m.rows();
  17. Index cols = m.cols();
  18. MatrixType m1 = MatrixType::Random(rows, cols),
  19. m3(rows, cols);
  20. m1.diagonal() = m1.diagonal().real().template cast<Scalar>();
  21. // check selfadjoint to dense
  22. m3 = m1.template selfadjointView<Upper>();
  23. VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Upper>()), MatrixType(m1.template triangularView<Upper>()));
  24. VERIFY_IS_APPROX(m3, m3.adjoint());
  25. m3 = m1.template selfadjointView<Lower>();
  26. VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Lower>()), MatrixType(m1.template triangularView<Lower>()));
  27. VERIFY_IS_APPROX(m3, m3.adjoint());
  28. }
  29. void bug_159()
  30. {
  31. Matrix3d m = Matrix3d::Random().selfadjointView<Lower>();
  32. EIGEN_UNUSED_VARIABLE(m)
  33. }
  34. void test_selfadjoint()
  35. {
  36. for(int i = 0; i < g_repeat ; i++)
  37. {
  38. int s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE);
  39. CALL_SUBTEST_1( selfadjoint(Matrix<float, 1, 1>()) );
  40. CALL_SUBTEST_2( selfadjoint(Matrix<float, 2, 2>()) );
  41. CALL_SUBTEST_3( selfadjoint(Matrix3cf()) );
  42. CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) );
  43. CALL_SUBTEST_5( selfadjoint(Matrix<float,Dynamic,Dynamic,RowMajor>(s, s)) );
  44. TEST_SET_BUT_UNUSED_VARIABLE(s)
  45. }
  46. CALL_SUBTEST_1( bug_159() );
  47. }