array_replicate.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) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
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 "main.h"
11 
12 template<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;
19  typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
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 }
70 
71 EIGEN_DECLARE_TEST(array_replicate)
72 {
73  for(int i = 0; i < g_repeat; i++) {
75  CALL_SUBTEST_2( replicate(Vector2f()) );
76  CALL_SUBTEST_3( replicate(Vector3d()) );
77  CALL_SUBTEST_4( replicate(Vector4f()) );
78  CALL_SUBTEST_5( replicate(VectorXf(16)) );
79  CALL_SUBTEST_6( replicate(VectorXcd(10)) );
80  }
81 }
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(array_replicate)
Definition: array_replicate.cpp:71
test_constructor::f1
auto f1
Definition: testHybridNonlinearFactor.cpp:56
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
m1
Matrix3d m1
Definition: IOFormat.cpp:2
f2
double f2(const Vector2 &x)
Definition: testNumericalDerivative.cpp:56
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
replicate
void replicate(const MatrixType &m)
Definition: array_replicate.cpp:12
m2
MatrixType m2(n_dims)
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
x1
Pose3 x1
Definition: testPose3.cpp:663
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
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
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
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
main.h
VectorX
Matrix< Scalar, Dynamic, 1 > VectorX
Definition: sparse_lu.cpp:41
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
VectorType
Definition: FFTW.cpp:65
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
x2
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
v1
Vector v1
Definition: testSerializationBase.cpp:38
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:31:53