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.

84 lines
3.4 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
  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 "product.h"
  10. void test_product_large()
  11. {
  12. for(int i = 0; i < g_repeat; i++) {
  13. CALL_SUBTEST_1( product(MatrixXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
  14. CALL_SUBTEST_2( product(MatrixXd(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
  15. CALL_SUBTEST_3( product(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
  16. CALL_SUBTEST_4( product(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2), internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))) );
  17. CALL_SUBTEST_5( product(Matrix<float,Dynamic,Dynamic,RowMajor>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
  18. }
  19. #if defined EIGEN_TEST_PART_6
  20. {
  21. // test a specific issue in DiagonalProduct
  22. int N = 1000000;
  23. VectorXf v = VectorXf::Ones(N);
  24. MatrixXf m = MatrixXf::Ones(N,3);
  25. m = (v+v).asDiagonal() * m;
  26. VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
  27. }
  28. {
  29. // test deferred resizing in Matrix::operator=
  30. MatrixXf a = MatrixXf::Random(10,4), b = MatrixXf::Random(4,10), c = a;
  31. VERIFY_IS_APPROX((a = a * b), (c * b).eval());
  32. }
  33. {
  34. // check the functions to setup blocking sizes compile and do not segfault
  35. // FIXME check they do what they are supposed to do !!
  36. std::ptrdiff_t l1 = internal::random<int>(10000,20000);
  37. std::ptrdiff_t l2 = internal::random<int>(100000,200000);
  38. std::ptrdiff_t l3 = internal::random<int>(1000000,2000000);
  39. setCpuCacheSizes(l1,l2,l3);
  40. VERIFY(l1==l1CacheSize());
  41. VERIFY(l2==l2CacheSize());
  42. std::ptrdiff_t k1 = internal::random<int>(10,100)*16;
  43. std::ptrdiff_t m1 = internal::random<int>(10,100)*16;
  44. std::ptrdiff_t n1 = internal::random<int>(10,100)*16;
  45. // only makes sure it compiles fine
  46. internal::computeProductBlockingSizes<float,float>(k1,m1,n1,1);
  47. }
  48. {
  49. // test regression in row-vector by matrix (bad Map type)
  50. MatrixXf mat1(10,32); mat1.setRandom();
  51. MatrixXf mat2(32,32); mat2.setRandom();
  52. MatrixXf r1 = mat1.row(2)*mat2.transpose();
  53. VERIFY_IS_APPROX(r1, (mat1.row(2)*mat2.transpose()).eval());
  54. MatrixXf r2 = mat1.row(2)*mat2;
  55. VERIFY_IS_APPROX(r2, (mat1.row(2)*mat2).eval());
  56. }
  57. {
  58. Eigen::MatrixXd A(10,10), B, C;
  59. A.setRandom();
  60. C = A;
  61. for(int k=0; k<79; ++k)
  62. C = C * A;
  63. B.noalias() = (((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A)) * ((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A)))
  64. * (((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A)) * ((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A))*((A*A)*(A*A)));
  65. VERIFY_IS_APPROX(B,C);
  66. }
  67. #endif
  68. // Regression test for bug 714:
  69. #if defined EIGEN_HAS_OPENMP
  70. omp_set_dynamic(1);
  71. for(int i = 0; i < g_repeat; i++) {
  72. CALL_SUBTEST_6( product(Matrix<float,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
  73. }
  74. #endif
  75. }