1 // This file is part of Eigen, a lightweight C++ template library
4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
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/.
15 int rows
= internal::random
<int>(1,12);
16 int cols
= internal::random
<int>(1,12);
17 typedef Matrix
<T
,Dynamic
,Dynamic
> MatrixType
;
18 typedef Matrix
<T
,Dynamic
,1> VectorType
;
19 VectorType
x(cols
); x
.setRandom();
21 VectorType
y(rows
); y
.setZero();
22 MatrixType
A(rows
,cols
); A
.setRandom();
24 VERIFY_IS_APPROX(x
= y
+ A
*x
, A
*z
); // OK because "y + A*x" is marked as "assume-aliasing"
27 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 // VERIFY_IS_APPROX(x = y-A*x, -A*z); // Not OK in 3.3 because x is resized before A*x gets evaluated
33 void test_product_large()
35 for(int i
= 0; i
< g_repeat
; i
++) {
36 CALL_SUBTEST_1( product(MatrixXf(internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
), internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
))) );
37 CALL_SUBTEST_2( product(MatrixXd(internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
), internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
))) );
38 CALL_SUBTEST_3( product(MatrixXi(internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
), internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
))) );
39 CALL_SUBTEST_4( product(MatrixXcf(internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
/2), internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
/2))) );
40 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
))) );
42 CALL_SUBTEST_1( test_aliasing
<float>() );
45 #if defined EIGEN_TEST_PART_6
47 // test a specific issue in DiagonalProduct
49 VectorXf v
= VectorXf::Ones(N
);
50 MatrixXf m
= MatrixXf::Ones(N
,3);
51 m
= (v
+v
).asDiagonal() * m
;
52 VERIFY_IS_APPROX(m
, MatrixXf::Constant(N
,3,2));
56 // test deferred resizing in Matrix::operator=
57 MatrixXf a
= MatrixXf::Random(10,4), b
= MatrixXf::Random(4,10), c
= a
;
58 VERIFY_IS_APPROX((a
= a
* b
), (c
* b
).eval());
62 // check the functions to setup blocking sizes compile and do not segfault
63 // FIXME check they do what they are supposed to do !!
64 std::ptrdiff_t l1
= internal::random
<int>(10000,20000);
65 std::ptrdiff_t l2
= internal::random
<int>(100000,200000);
66 std::ptrdiff_t l3
= internal::random
<int>(1000000,2000000);
67 setCpuCacheSizes(l1
,l2
,l3
);
68 VERIFY(l1
==l1CacheSize());
69 VERIFY(l2
==l2CacheSize());
70 std::ptrdiff_t k1
= internal::random
<int>(10,100)*16;
71 std::ptrdiff_t m1
= internal::random
<int>(10,100)*16;
72 std::ptrdiff_t n1
= internal::random
<int>(10,100)*16;
73 // only makes sure it compiles fine
74 internal::computeProductBlockingSizes
<float,float,std::ptrdiff_t>(k1
,m1
,n1
,1);
78 // test regression in row-vector by matrix (bad Map type)
79 MatrixXf
mat1(10,32); mat1
.setRandom();
80 MatrixXf
mat2(32,32); mat2
.setRandom();
81 MatrixXf r1
= mat1
.row(2)*mat2
.transpose();
82 VERIFY_IS_APPROX(r1
, (mat1
.row(2)*mat2
.transpose()).eval());
84 MatrixXf r2
= mat1
.row(2)*mat2
;
85 VERIFY_IS_APPROX(r2
, (mat1
.row(2)*mat2
).eval());
89 Eigen::MatrixXd
A(10,10), B
, C
;
92 for(int k
=0; k
<79; ++k
)
94 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
)))
95 * (((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
)));
96 VERIFY_IS_APPROX(B
,C
);
100 // Regression test for bug 714:
101 #if defined EIGEN_HAS_OPENMP
103 for(int i
= 0; i
< g_repeat
; i
++) {
104 CALL_SUBTEST_6( product(Matrix
<float,Dynamic
,Dynamic
>(internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
), internal::random
<int>(1,EIGEN_TEST_MAX_SIZE
))) );