MCPcopy Create free account
hub / github.com/avaxman/Directional / replicate

Function replicate

external/eigen/test/array_replicate.cpp:12–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "main.h"
11
12template<typename MatrixType> void replicate(const MatrixType& m)
13{
14 /* this test covers the following files:
15 Replicate.cpp
16 */
17 typedef typename MatrixType::Scalar Scalar;
18 typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
19 typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
20 typedef Matrix<Scalar, Dynamic, 1> VectorX;
21
22 Index rows = m.rows();
23 Index cols = m.cols();
24
25 MatrixType m1 = MatrixType::Random(rows, cols),
26 m2 = MatrixType::Random(rows, cols);
27
28 VectorType v1 = VectorType::Random(rows);
29
30 MatrixX x1, x2;
31 VectorX vx1;
32
33 int f1 = internal::random<int>(1,10),
34 f2 = internal::random<int>(1,10);
35
36 x1.resize(rows*f1,cols*f2);
37 for(int j=0; j<f2; j++)
38 for(int i=0; i<f1; i++)
39 x1.block(i*rows,j*cols,rows,cols) = m1;
40 VERIFY_IS_APPROX(x1, m1.replicate(f1,f2));
41
42 x2.resize(2*rows,3*cols);
43 x2 << m2, m2, m2,
44 m2, m2, m2;
45 VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>()));
46
47 x2.resize(rows,3*cols);
48 x2 << m2, m2, m2;
49 VERIFY_IS_APPROX(x2, (m2.template replicate<1,3>()));
50
51 vx1.resize(3*rows,cols);
52 vx1 << m2, m2, m2;
53 VERIFY_IS_APPROX(vx1+vx1, vx1+(m2.template replicate<3,1>()));
54
55 vx1=m2+(m2.colwise().replicate(1));
56
57 if(m2.cols()==1)
58 VERIFY_IS_APPROX(m2.coeff(0), (m2.template replicate<3,1>().coeff(m2.rows())));
59
60 x2.resize(rows,f1);
61 for (int j=0; j<f1; ++j)
62 x2.col(j) = v1;
63 VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1));
64
65 vx1.resize(rows*f2);
66 for (int j=0; j<f2; ++j)
67 vx1.segment(j*rows,rows) = v1;
68 VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2));
69}

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 9

replicateMethod · 0.80
colwiseMethod · 0.80
rowwiseMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
resizeMethod · 0.45
blockMethod · 0.45
coeffMethod · 0.45
colMethod · 0.45

Tested by

no test coverage detected