product_extra.cpp File Reference
#include "main.h"

Functions

template<typename MatrixType >
void product_extra (const MatrixType &m)
 
void mat_mat_scalar_scalar_product ()
 
template<typename MatrixType >
void zero_sized_objects (const MatrixType &m)
 
template<int >
void bug_127 ()
 
template<int >
void bug_817 ()
 
template<int >
void unaligned_objects ()
 
template<typename T >
EIGEN_DONT_INLINE Index test_compute_block_size (Index m, Index n, Index k)
 
template<typename T >
Index compute_block_size ()
 
template<typename >
void aliasing_with_resize ()
 
template<int >
void bug_1308 ()
 
 EIGEN_DECLARE_TEST (product_extra)
 

Function Documentation

◆ aliasing_with_resize()

template<typename >
void aliasing_with_resize ( )
266  {
267  Index m = internal::random<Index>(10, 50);
268  Index n = internal::random<Index>(10, 50);
269  MatrixXd A, B, C(m, n), D(m, m);
270  VectorXd a, b, c(n);
271  C.setRandom();
272  D.setRandom();
273  c.setRandom();
274  double s = internal::random<double>(1, 10);
275 
276  A = C;
277  B = A * A.transpose();
278  A = A * A.transpose();
279  VERIFY_IS_APPROX(A, B);
280 
281  A = C;
282  B = (A * A.transpose()) / s;
283  A = (A * A.transpose()) / s;
284  VERIFY_IS_APPROX(A, B);
285 
286  A = C;
287  B = (A * A.transpose()) + D;
288  A = (A * A.transpose()) + D;
289  VERIFY_IS_APPROX(A, B);
290 
291  A = C;
292  B = D + (A * A.transpose());
293  A = D + (A * A.transpose());
294  VERIFY_IS_APPROX(A, B);
295 
296  A = C;
297  B = s * (A * A.transpose());
298  A = s * (A * A.transpose());
299  VERIFY_IS_APPROX(A, B);
300 
301  A = C;
302  a = c;
303  b = (A * a) / s;
304  a = (A * a) / s;
305  VERIFY_IS_APPROX(a, b);
306 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
dominoes D
Definition: Domino.cpp:55
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Definition: matrices.h:74
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
RealScalar s
Definition: level1_cplx_impl.h:130
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
int c
Definition: calibrate.py:100

References a, b, calibrate::c, D, m, n, s, and VERIFY_IS_APPROX.

◆ bug_127()

template<int >
void bug_127 ( )
187  {
188  // Bug 127
189  //
190  // a product of the form lhs*rhs with
191  //
192  // lhs:
193  // rows = 1, cols = 4
194  // RowsAtCompileTime = 1, ColsAtCompileTime = -1
195  // MaxRowsAtCompileTime = 1, MaxColsAtCompileTime = 5
196  //
197  // rhs:
198  // rows = 4, cols = 0
199  // RowsAtCompileTime = -1, ColsAtCompileTime = -1
200  // MaxRowsAtCompileTime = 5, MaxColsAtCompileTime = 1
201  //
202  // was failing on a runtime assertion, because it had been mis-compiled as a dot product because Product.h was using
203  // the max-sizes to detect size 1 indicating vectors, and that didn't account for 0-sized object with max-size 1.
204 
207  a* b;
208 }

References a, and b.

◆ bug_1308()

template<int >
void bug_1308 ( )
309  {
310  int n = 10;
311  MatrixXd r(n, n);
312  VectorXd v = VectorXd::Random(n);
313  r = v * RowVectorXd::Ones(n);
314  VERIFY_IS_APPROX(r, v.rowwise().replicate(n));
315  r = VectorXd::Ones(n) * v.transpose();
316  VERIFY_IS_APPROX(r, v.rowwise().replicate(n).transpose());
317 
318  Matrix4d ones44 = Matrix4d::Ones();
319  Matrix4d m44 = Matrix4d::Ones() * Matrix4d::Ones();
320  VERIFY_IS_APPROX(m44, Matrix4d::Constant(4));
321  VERIFY_IS_APPROX(m44.noalias() = ones44 * Matrix4d::Ones(), Matrix4d::Constant(4));
322  VERIFY_IS_APPROX(m44.noalias() = ones44.transpose() * Matrix4d::Ones(), Matrix4d::Constant(4));
323  VERIFY_IS_APPROX(m44.noalias() = Matrix4d::Ones() * ones44, Matrix4d::Constant(4));
324  VERIFY_IS_APPROX(m44.noalias() = Matrix4d::Ones() * ones44.transpose(), Matrix4d::Constant(4));
325 
326  typedef Matrix<double, 4, 4, RowMajor> RMatrix4d;
327  RMatrix4d r44 = Matrix4d::Ones() * Matrix4d::Ones();
328  VERIFY_IS_APPROX(r44, Matrix4d::Constant(4));
329  VERIFY_IS_APPROX(r44.noalias() = ones44 * Matrix4d::Ones(), Matrix4d::Constant(4));
330  VERIFY_IS_APPROX(r44.noalias() = ones44.transpose() * Matrix4d::Ones(), Matrix4d::Constant(4));
331  VERIFY_IS_APPROX(r44.noalias() = Matrix4d::Ones() * ones44, Matrix4d::Constant(4));
332  VERIFY_IS_APPROX(r44.noalias() = Matrix4d::Ones() * ones44.transpose(), Matrix4d::Constant(4));
333  VERIFY_IS_APPROX(r44.noalias() = ones44 * RMatrix4d::Ones(), Matrix4d::Constant(4));
334  VERIFY_IS_APPROX(r44.noalias() = ones44.transpose() * RMatrix4d::Ones(), Matrix4d::Constant(4));
335  VERIFY_IS_APPROX(r44.noalias() = RMatrix4d::Ones() * ones44, Matrix4d::Constant(4));
336  VERIFY_IS_APPROX(r44.noalias() = RMatrix4d::Ones() * ones44.transpose(), Matrix4d::Constant(4));
337 
338  // RowVector4d r4;
339  m44.setOnes();
340  r44.setZero();
341  VERIFY_IS_APPROX(r44.noalias() += m44.row(0).transpose() * RowVector4d::Ones(), ones44);
342  r44.setZero();
343  VERIFY_IS_APPROX(r44.noalias() += m44.col(0) * RowVector4d::Ones(), ones44);
344  r44.setZero();
345  VERIFY_IS_APPROX(r44.noalias() += Vector4d::Ones() * m44.row(0), ones44);
346  r44.setZero();
347  VERIFY_IS_APPROX(r44.noalias() += Vector4d::Ones() * m44.col(0).transpose(), ones44);
348 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
r
Definition: UniformPSDSelfTest.py:20

References n, UniformPSDSelfTest::r, v, and VERIFY_IS_APPROX.

◆ bug_817()

template<int >
void bug_817 ( )
211  {
212  ArrayXXf B = ArrayXXf::Random(10, 10), C;
213  VectorXf x = VectorXf::Random(10);
214  C = (x.transpose() * B.matrix());
215  B = (x.transpose() * B.matrix());
216  VERIFY_IS_APPROX(B, C);
217 }
list x
Definition: plotDoE.py:28

References VERIFY_IS_APPROX, and plotDoE::x.

◆ compute_block_size()

template<typename T >
Index compute_block_size ( )
253  {
254  Index ret = 0;
255  ret += test_compute_block_size<T>(0, 1, 1);
256  ret += test_compute_block_size<T>(1, 0, 1);
257  ret += test_compute_block_size<T>(1, 1, 0);
258  ret += test_compute_block_size<T>(0, 0, 1);
259  ret += test_compute_block_size<T>(0, 1, 0);
260  ret += test_compute_block_size<T>(1, 0, 0);
261  ret += test_compute_block_size<T>(0, 0, 0);
262  return ret;
263 }
Eigen::DenseIndex ret
Definition: level1_cplx_impl.h:43

References ret.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( product_extra  )
350  {
351  for (int i = 0; i < g_repeat; i++) {
353  MatrixXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
355  MatrixXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
357  CALL_SUBTEST_3(product_extra(MatrixXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2),
358  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
359  CALL_SUBTEST_4(product_extra(MatrixXcd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2),
360  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
362  MatrixXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
363  }
364  CALL_SUBTEST_5(bug_127<0>());
365  CALL_SUBTEST_5(bug_817<0>());
366  CALL_SUBTEST_5(bug_1308<0>());
367  CALL_SUBTEST_6(unaligned_objects<0>());
368  CALL_SUBTEST_7(compute_block_size<float>());
369  CALL_SUBTEST_7(compute_block_size<double>());
370  CALL_SUBTEST_7(compute_block_size<std::complex<double> >());
371  CALL_SUBTEST_8(aliasing_with_resize<void>());
372 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
static int g_repeat
Definition: main.h:191
void product_extra(const MatrixType &m)
Definition: product_extra.cpp:13
void zero_sized_objects(const MatrixType &m)
Definition: product_extra.cpp:129
void mat_mat_scalar_scalar_product()
Definition: product_extra.cpp:121
Index compute_block_size()
Definition: product_extra.cpp:253
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, compute_block_size(), EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, mat_mat_scalar_scalar_product(), product_extra(), and zero_sized_objects().

◆ mat_mat_scalar_scalar_product()

void mat_mat_scalar_scalar_product ( )
121  {
122  Eigen::Matrix2Xd dNdxy(2, 3);
123  dNdxy << -0.5, 0.5, 0, -0.3, 0, 0.3;
124  double det = 6.0, wt = 0.5;
125  VERIFY_IS_APPROX(dNdxy.transpose() * dNdxy * det * wt, det * wt * dNdxy.transpose() * dNdxy);
126 }

References VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ product_extra()

template<typename MatrixType >
void product_extra ( const MatrixType m)
13  {
14  typedef typename MatrixType::Scalar Scalar;
15  typedef Matrix<Scalar, 1, Dynamic> RowVectorType;
16  typedef Matrix<Scalar, Dynamic, 1> ColVectorType;
18 
19  Index rows = m.rows();
20  Index cols = m.cols();
21 
22  MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols),
23  mzero = MatrixType::Zero(rows, cols), identity = MatrixType::Identity(rows, rows),
24  square = MatrixType::Random(rows, rows), res = MatrixType::Random(rows, rows),
25  square2 = MatrixType::Random(cols, cols), res2 = MatrixType::Random(cols, cols);
26  RowVectorType v1 = RowVectorType::Random(rows), vrres(rows);
27  ColVectorType vc2 = ColVectorType::Random(cols), vcres(cols);
28  OtherMajorMatrixType tm1 = m1;
29 
30  Scalar s1 = internal::random<Scalar>(), s2 = internal::random<Scalar>(), s3 = internal::random<Scalar>();
31 
32  VERIFY_IS_APPROX(m3.noalias() = m1 * m2.adjoint(), m1 * m2.adjoint().eval());
33  VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * square.adjoint(), m1.adjoint().eval() * square.adjoint().eval());
34  VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * m2, m1.adjoint().eval() * m2);
35  VERIFY_IS_APPROX(m3.noalias() = (s1 * m1.adjoint()) * m2, (s1 * m1.adjoint()).eval() * m2);
36  VERIFY_IS_APPROX(m3.noalias() = ((s1 * m1).adjoint()) * m2, (numext::conj(s1) * m1.adjoint()).eval() * m2);
37  VERIFY_IS_APPROX(m3.noalias() = (-m1.adjoint() * s1) * (s3 * m2), (-m1.adjoint() * s1).eval() * (s3 * m2).eval());
38  VERIFY_IS_APPROX(m3.noalias() = (s2 * m1.adjoint() * s1) * m2, (s2 * m1.adjoint() * s1).eval() * m2);
39  VERIFY_IS_APPROX(m3.noalias() = (-m1 * s2) * s1 * m2.adjoint(), (-m1 * s2).eval() * (s1 * m2.adjoint()).eval());
40 
41  // a very tricky case where a scale factor has to be automatically conjugated:
42  VERIFY_IS_APPROX(m1.adjoint() * (s1 * m2).conjugate(), (m1.adjoint()).eval() * ((s1 * m2).conjugate()).eval());
43 
44  // test all possible conjugate combinations for the four matrix-vector product cases:
45 
46  VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2), (-m1.conjugate() * s2).eval() * (s1 * vc2).eval());
47  VERIFY_IS_APPROX((-m1 * s2) * (s1 * vc2.conjugate()), (-m1 * s2).eval() * (s1 * vc2.conjugate()).eval());
48  VERIFY_IS_APPROX((-m1.conjugate() * s2) * (s1 * vc2.conjugate()),
49  (-m1.conjugate() * s2).eval() * (s1 * vc2.conjugate()).eval());
50 
51  VERIFY_IS_APPROX((s1 * vc2.transpose()) * (-m1.adjoint() * s2),
52  (s1 * vc2.transpose()).eval() * (-m1.adjoint() * s2).eval());
53  VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.transpose() * s2),
54  (s1 * vc2.adjoint()).eval() * (-m1.transpose() * s2).eval());
55  VERIFY_IS_APPROX((s1 * vc2.adjoint()) * (-m1.adjoint() * s2),
56  (s1 * vc2.adjoint()).eval() * (-m1.adjoint() * s2).eval());
57 
58  VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.transpose()),
59  (-m1.adjoint() * s2).eval() * (s1 * v1.transpose()).eval());
60  VERIFY_IS_APPROX((-m1.transpose() * s2) * (s1 * v1.adjoint()),
61  (-m1.transpose() * s2).eval() * (s1 * v1.adjoint()).eval());
62  VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.adjoint()),
63  (-m1.adjoint() * s2).eval() * (s1 * v1.adjoint()).eval());
64 
65  VERIFY_IS_APPROX((s1 * v1) * (-m1.conjugate() * s2), (s1 * v1).eval() * (-m1.conjugate() * s2).eval());
66  VERIFY_IS_APPROX((s1 * v1.conjugate()) * (-m1 * s2), (s1 * v1.conjugate()).eval() * (-m1 * s2).eval());
67  VERIFY_IS_APPROX((s1 * v1.conjugate()) * (-m1.conjugate() * s2),
68  (s1 * v1.conjugate()).eval() * (-m1.conjugate() * s2).eval());
69 
70  VERIFY_IS_APPROX((-m1.adjoint() * s2) * (s1 * v1.adjoint()),
71  (-m1.adjoint() * s2).eval() * (s1 * v1.adjoint()).eval());
72 
73  // test the vector-matrix product with non aligned starts
74  Index i = internal::random<Index>(0, m1.rows() - 2);
75  Index j = internal::random<Index>(0, m1.cols() - 2);
76  Index r = internal::random<Index>(1, m1.rows() - i);
77  Index c = internal::random<Index>(1, m1.cols() - j);
78  Index i2 = internal::random<Index>(0, m1.rows() - 1);
79  Index j2 = internal::random<Index>(0, m1.cols() - 1);
80 
81  VERIFY_IS_APPROX(m1.col(j2).adjoint() * m1.block(0, j, m1.rows(), c),
82  m1.col(j2).adjoint().eval() * m1.block(0, j, m1.rows(), c).eval());
83  VERIFY_IS_APPROX(m1.block(i, 0, r, m1.cols()) * m1.row(i2).adjoint(),
84  m1.block(i, 0, r, m1.cols()).eval() * m1.row(i2).adjoint().eval());
85 
86  // test negative strides
87  {
89  Stride<Dynamic, Dynamic>(-m1.outerStride(), -1));
91  Stride<Dynamic, Dynamic>(-m2.outerStride(), -1));
92  Map<RowVectorType, Unaligned, InnerStride<-1> > mapv1(&v1(v1.size() - 1), v1.size(), InnerStride<-1>(-1));
93  Map<ColVectorType, Unaligned, InnerStride<-1> > mapvc2(&vc2(vc2.size() - 1), vc2.size(), InnerStride<-1>(-1));
94  VERIFY_IS_APPROX(MatrixType(map1), m1.reverse());
95  VERIFY_IS_APPROX(MatrixType(map2), m2.reverse());
96  VERIFY_IS_APPROX(m3.noalias() = MatrixType(map1) * MatrixType(map2).adjoint(),
97  m1.reverse() * m2.reverse().adjoint());
98  VERIFY_IS_APPROX(m3.noalias() = map1 * map2.adjoint(), m1.reverse() * m2.reverse().adjoint());
99  VERIFY_IS_APPROX(map1 * vc2, m1.reverse() * vc2);
100  VERIFY_IS_APPROX(m1 * mapvc2, m1 * mapvc2);
101  VERIFY_IS_APPROX(map1.adjoint() * v1.transpose(), m1.adjoint().reverse() * v1.transpose());
102  VERIFY_IS_APPROX(m1.adjoint() * mapv1.transpose(), m1.adjoint() * v1.reverse().transpose());
103  }
104 
105  // regression test
106  MatrixType tmp = m1 * m1.adjoint() * s1;
107  VERIFY_IS_APPROX(tmp, m1 * m1.adjoint() * s1);
108 
109  // regression test for bug 1343, assignment to arrays
110  Array<Scalar, Dynamic, 1> a1 = m1 * vc2;
111  VERIFY_IS_APPROX(a1.matrix(), m1 * vc2);
112  Array<Scalar, Dynamic, 1> a2 = s1 * (m1 * vc2);
113  VERIFY_IS_APPROX(a2.matrix(), s1 * m1 * vc2);
115  VERIFY_IS_APPROX(a3.matrix(), v1 * m1);
116  Array<Scalar, Dynamic, Dynamic> a4 = m1 * m2.adjoint();
117  VERIFY_IS_APPROX(a4.matrix(), m1 * m2.adjoint());
118 }
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
Matrix3d m1
Definition: IOFormat.cpp:2
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
MatrixType m2(n_dims)
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:85
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:48
Convenience specialization of Stride to specify only an inner stride See class Map for some examples.
Definition: Stride.h:93
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
Holds strides information for Map.
Definition: Stride.h:55
@ Unaligned
Definition: Constants.h:235
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
squared absolute sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2 square(power 2)
double Zero
Definition: pseudosolid_node_update_elements.cc:35
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References adjoint(), calibrate::c, cols, conj(), i, j, m, m1, m2(), UniformPSDSelfTest::r, res, rows, Eigen::square(), tmp, Eigen::Unaligned, v1(), VERIFY_IS_APPROX, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().

◆ test_compute_block_size()

template<typename T >
EIGEN_DONT_INLINE Index test_compute_block_size ( Index  m,
Index  n,
Index  k 
)
246  {
247  Index mc(m), nc(n), kc(k);
248  internal::computeProductBlockingSizes<T, T>(kc, mc, nc);
249  return kc + mc + nc;
250 }
char char char int int * k
Definition: level2_impl.h:374

References k, m, and n.

◆ unaligned_objects()

template<int >
void unaligned_objects ( )
220  {
221  // Regression test for the bug reported here:
222  // http://forum.kde.org/viewtopic.php?f=74&t=107541
223  // Recall the matrix*vector kernel avoid unaligned loads by loading two packets and then reassemble then.
224  // There was a mistake in the computation of the valid range for fully unaligned objects: in some rare cases,
225  // memory was read outside the allocated matrix memory. Though the values were not used, this might raise segfault.
226  for (int m = 450; m < 460; ++m) {
227  for (int n = 8; n < 12; ++n) {
228  MatrixXf M(m, n);
229  VectorXf v1(n), r1(500);
230  RowVectorXf v2(m), r2(16);
231 
232  M.setRandom();
233  v1.setRandom();
234  v2.setRandom();
235  for (int o = 0; o < 4; ++o) {
236  r1.segment(o, m).noalias() = M * v1;
237  VERIFY_IS_APPROX(r1.segment(o, m), M * MatrixXf(v1));
238  r2.segment(o, n).noalias() = v2 * M;
239  VERIFY_IS_APPROX(r2.segment(o, n), MatrixXf(v2) * M);
240  }
241  }
242  }
243 }
Map< RowVectorXf > v2(M2.data(), M2.size())
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:50
Derived & setRandom(Index size)
Definition: Random.h:147

References m, n, Eigen::PlainObjectBase< Derived >::setRandom(), v1(), v2(), and VERIFY_IS_APPROX.

◆ zero_sized_objects()

template<typename MatrixType >
void zero_sized_objects ( const MatrixType m)
129  {
130  typedef typename MatrixType::Scalar Scalar;
131  const int PacketSize = internal::packet_traits<Scalar>::size;
132  const int PacketSize1 = PacketSize > 1 ? PacketSize - 1 : 1;
133  Index rows = m.rows();
134  Index cols = m.cols();
135 
136  {
137  MatrixType res, a(rows, 0), b(0, cols);
139  VERIFY_IS_APPROX((res = a * a.transpose()), MatrixType::Zero(rows, rows));
140  VERIFY_IS_APPROX((res = b.transpose() * b), MatrixType::Zero(cols, cols));
141  VERIFY_IS_APPROX((res = b.transpose() * a.transpose()), MatrixType::Zero(cols, rows));
142  }
143 
144  {
145  MatrixType res, a(rows, cols), b(cols, 0);
146  res = a * b;
147  VERIFY(res.rows() == rows && res.cols() == 0);
148  b.resize(0, rows);
149  res = b * a;
150  VERIFY(res.rows() == 0 && res.cols() == cols);
151  }
152 
153  {
157  VERIFY_IS_APPROX((res = a * b), MatrixType::Zero(PacketSize, 1));
158  VERIFY_IS_APPROX((res = a.lazyProduct(b)), MatrixType::Zero(PacketSize, 1));
159  }
160 
161  {
165  VERIFY_IS_APPROX((res = a * b), MatrixType::Zero(PacketSize1, 1));
166  VERIFY_IS_APPROX((res = a.lazyProduct(b)), MatrixType::Zero(PacketSize1, 1));
167  }
168 
169  {
170  Matrix<Scalar, PacketSize, Dynamic> a(PacketSize, 0);
173  VERIFY_IS_APPROX((res = a * b), MatrixType::Zero(PacketSize, 1));
174  VERIFY_IS_APPROX((res = a.lazyProduct(b)), MatrixType::Zero(PacketSize, 1));
175  }
176 
177  {
178  Matrix<Scalar, PacketSize1, Dynamic> a(PacketSize1, 0);
181  VERIFY_IS_APPROX((res = a * b), MatrixType::Zero(PacketSize1, 1));
182  VERIFY_IS_APPROX((res = a.lazyProduct(b)), MatrixType::Zero(PacketSize1, 1));
183  }
184 }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
#define VERIFY(a)
Definition: main.h:362

References a, b, cols, m, res, rows, size, VERIFY, VERIFY_IS_APPROX, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().