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.

65 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 typename NumTraits<Scalar>::Real RealScalar;
  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(size, size);
  24. MatrixRowMaj matr(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. Scalar s = internal::random<Scalar>();
  31. CHECK_MMTR(matc, Lower, = s*soc*sor.adjoint());
  32. CHECK_MMTR(matc, Upper, = s*(soc*soc.adjoint()));
  33. CHECK_MMTR(matr, Lower, = s*soc*soc.adjoint());
  34. CHECK_MMTR(matr, Upper, = soc*(s*sor.adjoint()));
  35. CHECK_MMTR(matc, Lower, += s*soc*soc.adjoint());
  36. CHECK_MMTR(matc, Upper, += s*(soc*sor.transpose()));
  37. CHECK_MMTR(matr, Lower, += s*sor*soc.adjoint());
  38. CHECK_MMTR(matr, Upper, += soc*(s*soc.adjoint()));
  39. CHECK_MMTR(matc, Lower, -= s*soc*soc.adjoint());
  40. CHECK_MMTR(matc, Upper, -= s*(osc.transpose()*osc.conjugate()));
  41. CHECK_MMTR(matr, Lower, -= s*soc*soc.adjoint());
  42. CHECK_MMTR(matr, Upper, -= soc*(s*soc.adjoint()));
  43. }
  44. void test_product_mmtr()
  45. {
  46. for(int i = 0; i < g_repeat ; i++)
  47. {
  48. CALL_SUBTEST_1((mmtr<float>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))));
  49. CALL_SUBTEST_2((mmtr<double>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))));
  50. CALL_SUBTEST_3((mmtr<std::complex<float> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))));
  51. CALL_SUBTEST_4((mmtr<std::complex<double> >(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))));
  52. }
  53. }