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.

76 lines
3.1 KiB

  1. // This file is part 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. #define CHECK_MMTR(DEST, TRI, OP) { \
  11. ref2 = ref1 = DEST; \
  12. DEST.template triangularView<TRI>() OP; \
  13. ref1 OP; \
  14. ref2.template triangularView<TRI>() \
  15. = ref1.template triangularView<TRI>(); \
  16. VERIFY_IS_APPROX(DEST,ref2); \
  17. }
  18. template<typename Scalar> void mmtr(int size)
  19. {
  20. typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> MatrixColMaj;
  21. typedef Matrix<Scalar,Dynamic,Dynamic,RowMajor> MatrixRowMaj;
  22. DenseIndex othersize = internal::random<DenseIndex>(1,200);
  23. MatrixColMaj matc = MatrixColMaj::Zero(size, size);
  24. MatrixRowMaj matr = MatrixRowMaj::Zero(size, size);
  25. MatrixColMaj ref1(size, size), ref2(size, size);
  26. MatrixColMaj soc(size,othersize); soc.setRandom();
  27. MatrixColMaj osc(othersize,size); osc.setRandom();
  28. MatrixRowMaj sor(size,othersize); sor.setRandom();
  29. MatrixRowMaj osr(othersize,size); osr.setRandom();
  30. MatrixColMaj sqc(size,size); sqc.setRandom();
  31. MatrixRowMaj sqr(size,size); sqr.setRandom();
  32. Scalar s = internal::random<Scalar>();
  33. CHECK_MMTR(matc, Lower, = s*soc*sor.adjoint());
  34. CHECK_MMTR(matc, Upper, = s*(soc*soc.adjoint()));
  35. CHECK_MMTR(matr, Lower, = s*soc*soc.adjoint());
  36. CHECK_MMTR(matr, Upper, = soc*(s*sor.adjoint()));
  37. CHECK_MMTR(matc, Lower, += s*soc*soc.adjoint());
  38. CHECK_MMTR(matc, Upper, += s*(soc*sor.transpose()));
  39. CHECK_MMTR(matr, Lower, += s*sor*soc.adjoint());
  40. CHECK_MMTR(matr, Upper, += soc*(s*soc.adjoint()));
  41. CHECK_MMTR(matc, Lower, -= s*soc*soc.adjoint());
  42. CHECK_MMTR(matc, Upper, -= s*(osc.transpose()*osc.conjugate()));
  43. CHECK_MMTR(matr, Lower, -= s*soc*soc.adjoint());
  44. CHECK_MMTR(matr, Upper, -= soc*(s*soc.adjoint()));
  45. CHECK_MMTR(matc, Lower, -= s*sqr*sqc.template triangularView<Upper>());
  46. CHECK_MMTR(matc, Upper, = s*sqc*sqr.template triangularView<Upper>());
  47. CHECK_MMTR(matc, Lower, += s*sqr*sqc.template triangularView<Lower>());
  48. CHECK_MMTR(matc, Upper, = s*sqc*sqc.template triangularView<Lower>());
  49. CHECK_MMTR(matc, Lower, = (s*sqr).template triangularView<Upper>()*sqc);
  50. CHECK_MMTR(matc, Upper, -= (s*sqc).template triangularView<Upper>()*sqc);
  51. CHECK_MMTR(matc, Lower, = (s*sqr).template triangularView<Lower>()*sqc);
  52. CHECK_MMTR(matc, Upper, += (s*sqc).template triangularView<Lower>()*sqc);
  53. }
  54. void test_product_mmtr()
  55. {
  56. for(int i = 0; i < g_repeat ; i++)
  57. {
  58. CALL_SUBTEST_1((mmtr<float>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))));
  59. CALL_SUBTEST_2((mmtr<double>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))));
  60. CALL_SUBTEST_3((mmtr<std::complex<float> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))));
  61. CALL_SUBTEST_4((mmtr<std::complex<double> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))));
  62. }
  63. }