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.

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