product_large.cpp
Go to the documentation of this file.
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 
10 #include "product.h"
11 #include <Eigen/LU>
12 
13 template<typename T>
15 {
16  int rows = internal::random<int>(1,12);
17  int cols = internal::random<int>(1,12);
20  VectorType x(cols); x.setRandom();
21  VectorType z(x);
22  VectorType y(rows); y.setZero();
23  MatrixType A(rows,cols); A.setRandom();
24  // CwiseBinaryOp
25  VERIFY_IS_APPROX(x = y + A*x, A*z); // OK because "y + A*x" is marked as "assume-aliasing"
26  x = z;
27  // CwiseUnaryOp
28  VERIFY_IS_APPROX(x = T(1.)*(A*x), A*z); // OK because 1*(A*x) is replaced by (1*A*x) which is a Product<> expression
29  x = z;
30  // VERIFY_IS_APPROX(x = y-A*x, -A*z); // Not OK in 3.3 because x is resized before A*x gets evaluated
31  x = z;
32 }
33 
34 template<int>
36 {
37  {
38  // test a specific issue in DiagonalProduct
39  int N = 1000000;
40  VectorXf v = VectorXf::Ones(N);
41  MatrixXf m = MatrixXf::Ones(N,3);
42  m = (v+v).asDiagonal() * m;
43  VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
44  }
45 
46  {
47  // test deferred resizing in Matrix::operator=
48  MatrixXf a = MatrixXf::Random(10,4), b = MatrixXf::Random(4,10), c = a;
49  VERIFY_IS_APPROX((a = a * b), (c * b).eval());
50  }
51 
52  {
53  // check the functions to setup blocking sizes compile and do not segfault
54  // FIXME check they do what they are supposed to do !!
55  std::ptrdiff_t l1 = internal::random<int>(10000,20000);
56  std::ptrdiff_t l2 = internal::random<int>(100000,200000);
57  std::ptrdiff_t l3 = internal::random<int>(1000000,2000000);
59  VERIFY(l1==l1CacheSize());
60  VERIFY(l2==l2CacheSize());
61  std::ptrdiff_t k1 = internal::random<int>(10,100)*16;
62  std::ptrdiff_t m1 = internal::random<int>(10,100)*16;
63  std::ptrdiff_t n1 = internal::random<int>(10,100)*16;
64  // only makes sure it compiles fine
65  internal::computeProductBlockingSizes<float,float,std::ptrdiff_t>(k1,m1,n1,1);
66  }
67 
68  {
69  // test regression in row-vector by matrix (bad Map type)
70  MatrixXf mat1(10,32); mat1.setRandom();
71  MatrixXf mat2(32,32); mat2.setRandom();
72  MatrixXf r1 = mat1.row(2)*mat2.transpose();
73  VERIFY_IS_APPROX(r1, (mat1.row(2)*mat2.transpose()).eval());
74 
75  MatrixXf r2 = mat1.row(2)*mat2;
76  VERIFY_IS_APPROX(r2, (mat1.row(2)*mat2).eval());
77  }
78 
79  {
80  Eigen::MatrixXd A(10,10), B, C;
81  A.setRandom();
82  C = A;
83  for(int k=0; k<79; ++k)
84  C = C * A;
85  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)))
86  * (((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)));
88  }
89 }
90 
91 template<int>
92 void bug_1622() {
93  typedef Matrix<double, 2, -1, 0, 2, -1> Mat2X;
94  Mat2X x(2,2); x.setRandom();
95  MatrixXd y(2,2); y.setRandom();
96  const Mat2X K1 = x * y.inverse();
97  const Matrix2d K2 = x * y.inverse();
99 }
100 
101 EIGEN_DECLARE_TEST(product_large)
102 {
103  for(int i = 0; i < g_repeat; i++) {
104  CALL_SUBTEST_1( product(MatrixXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
105  CALL_SUBTEST_2( product(MatrixXd(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
106  CALL_SUBTEST_2( product(MatrixXd(internal::random<int>(1,10), internal::random<int>(1,10))) );
107 
108  CALL_SUBTEST_3( product(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
109  CALL_SUBTEST_4( product(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2), internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))) );
110  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))) );
111 
112  CALL_SUBTEST_1( test_aliasing<float>() );
113 
114  CALL_SUBTEST_6( bug_1622<1>() );
115 
116  CALL_SUBTEST_7( product(MatrixXcd(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2), internal::random<int>(1,EIGEN_TEST_MAX_SIZE/2))) );
117  CALL_SUBTEST_8( product(Matrix<double,Dynamic,Dynamic,RowMajor>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
118  CALL_SUBTEST_9( product(Matrix<std::complex<float>,Dynamic,Dynamic,RowMajor>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
119  CALL_SUBTEST_10( product(Matrix<std::complex<double>,Dynamic,Dynamic,RowMajor>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
120  }
121 
122  CALL_SUBTEST_6( product_large_regressions<0>() );
123 
124  // Regression test for bug 714:
125 #if defined EIGEN_HAS_OPENMP
126  omp_set_dynamic(1);
127  for(int i = 0; i < g_repeat; i++) {
128  CALL_SUBTEST_6( product(Matrix<float,Dynamic,Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
129  }
130 #endif
131 }
l3
Point3 l3(2, 2, 0)
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
benchmark.n1
n1
Definition: benchmark.py:79
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
l2
gtsam::Key l2
Definition: testLinearContainerFactor.cpp:24
mat1
MatrixXd mat1(size, size)
r2
static const double r2
Definition: testSmartRangeFactor.cpp:32
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
m1
Matrix3d m1
Definition: IOFormat.cpp:2
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
Eigen::setCpuCacheSizes
void setCpuCacheSizes(std::ptrdiff_t l1, std::ptrdiff_t l2, std::ptrdiff_t l3)
Definition: products/GeneralBlockPanelKernel.h:2638
K2
static const Cal3Bundler K2(625, 1e-3, 1e-3)
r1
static const double r1
Definition: testSmartRangeFactor.cpp:32
CALL_SUBTEST_9
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(product_large)
Definition: product_large.cpp:101
bug_1622
void bug_1622()
Definition: product_large.cpp:92
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
product.h
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
test_aliasing
void test_aliasing()
Definition: product_large.cpp:14
k1
double k1(double x)
Definition: k1.c:133
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
CALL_SUBTEST_10
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58
product_large_regressions
void product_large_regressions()
Definition: product_large.cpp:35
CALL_SUBTEST_5
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
K1
static Cal3_S2::shared_ptr K1(new Cal3_S2(fov, w, h))
CALL_SUBTEST_6
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
y
Scalar * y
Definition: level1_cplx_impl.h:124
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
l1
gtsam::Key l1
Definition: testLinearContainerFactor.cpp:24
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
product
void product(const MatrixType &m)
Definition: product.h:20
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
omp_set_dynamic
void omp_set_dynamic(int num_threads)
N
#define N
Definition: igam.h:9
VectorType
Definition: FFTW.cpp:65
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
CALL_SUBTEST_7
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
Eigen::l1CacheSize
std::ptrdiff_t l1CacheSize()
Definition: products/GeneralBlockPanelKernel.h:2607
CALL_SUBTEST_8
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
eval
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:38
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::l2CacheSize
std::ptrdiff_t l2CacheSize()
Definition: products/GeneralBlockPanelKernel.h:2616
VERIFY
#define VERIFY(a)
Definition: main.h:380


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:42