corners.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-2010 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 "main.h"
11 
12 #define COMPARE_CORNER(A,B) \
13  VERIFY_IS_EQUAL(matrix.A, matrix.B); \
14  VERIFY_IS_EQUAL(const_matrix.A, const_matrix.B);
15 
16 template<typename MatrixType> void corners(const MatrixType& m)
17 {
18  Index rows = m.rows();
19  Index cols = m.cols();
20 
21  Index r = internal::random<Index>(1,rows);
22  Index c = internal::random<Index>(1,cols);
23 
24  MatrixType matrix = MatrixType::Random(rows,cols);
25  const MatrixType const_matrix = MatrixType::Random(rows,cols);
26 
27  COMPARE_CORNER(topLeftCorner(r,c), block(0,0,r,c));
31 
32  Index sr = internal::random<Index>(1,rows) - 1;
33  Index nr = internal::random<Index>(1,rows-sr);
34  Index sc = internal::random<Index>(1,cols) - 1;
35  Index nc = internal::random<Index>(1,cols-sc);
36 
37  COMPARE_CORNER(topRows(r), block(0,0,r,cols));
38  COMPARE_CORNER(middleRows(sr,nr), block(sr,0,nr,cols));
43 }
44 
45 template<typename MatrixType, int CRows, int CCols, int SRows, int SCols> void corners_fixedsize()
46 {
47  MatrixType matrix = MatrixType::Random();
48  const MatrixType const_matrix = MatrixType::Random();
49 
50  enum {
51  rows = MatrixType::RowsAtCompileTime,
52  cols = MatrixType::ColsAtCompileTime,
53  r = CRows,
54  c = CCols,
55  sr = SRows,
56  sc = SCols
57  };
58 
59  VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template block<r,c>(0,0)));
60  VERIFY_IS_EQUAL((matrix.template topRightCorner<r,c>()), (matrix.template block<r,c>(0,cols-c)));
61  VERIFY_IS_EQUAL((matrix.template bottomLeftCorner<r,c>()), (matrix.template block<r,c>(rows-r,0)));
62  VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template block<r,c>(rows-r,cols-c)));
63 
64  VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template topLeftCorner<r,Dynamic>(r,c)));
65  VERIFY_IS_EQUAL((matrix.template topRightCorner<r,c>()), (matrix.template topRightCorner<r,Dynamic>(r,c)));
66  VERIFY_IS_EQUAL((matrix.template bottomLeftCorner<r,c>()), (matrix.template bottomLeftCorner<r,Dynamic>(r,c)));
67  VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template bottomRightCorner<r,Dynamic>(r,c)));
68 
69  VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template topLeftCorner<Dynamic,c>(r,c)));
70  VERIFY_IS_EQUAL((matrix.template topRightCorner<r,c>()), (matrix.template topRightCorner<Dynamic,c>(r,c)));
71  VERIFY_IS_EQUAL((matrix.template bottomLeftCorner<r,c>()), (matrix.template bottomLeftCorner<Dynamic,c>(r,c)));
72  VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template bottomRightCorner<Dynamic,c>(r,c)));
73 
74  VERIFY_IS_EQUAL((matrix.template topRows<r>()), (matrix.template block<r,cols>(0,0)));
75  VERIFY_IS_EQUAL((matrix.template middleRows<r>(sr)), (matrix.template block<r,cols>(sr,0)));
76  VERIFY_IS_EQUAL((matrix.template bottomRows<r>()), (matrix.template block<r,cols>(rows-r,0)));
77  VERIFY_IS_EQUAL((matrix.template leftCols<c>()), (matrix.template block<rows,c>(0,0)));
78  VERIFY_IS_EQUAL((matrix.template middleCols<c>(sc)), (matrix.template block<rows,c>(0,sc)));
79  VERIFY_IS_EQUAL((matrix.template rightCols<c>()), (matrix.template block<rows,c>(0,cols-c)));
80 
81  VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template block<r,c>(0,0)));
82  VERIFY_IS_EQUAL((const_matrix.template topRightCorner<r,c>()), (const_matrix.template block<r,c>(0,cols-c)));
83  VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,0)));
84  VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,cols-c)));
85 
86  VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template topLeftCorner<r,Dynamic>(r,c)));
87  VERIFY_IS_EQUAL((const_matrix.template topRightCorner<r,c>()), (const_matrix.template topRightCorner<r,Dynamic>(r,c)));
88  VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner<r,c>()), (const_matrix.template bottomLeftCorner<r,Dynamic>(r,c)));
89  VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template bottomRightCorner<r,Dynamic>(r,c)));
90 
91  VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template topLeftCorner<Dynamic,c>(r,c)));
92  VERIFY_IS_EQUAL((const_matrix.template topRightCorner<r,c>()), (const_matrix.template topRightCorner<Dynamic,c>(r,c)));
93  VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner<r,c>()), (const_matrix.template bottomLeftCorner<Dynamic,c>(r,c)));
94  VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template bottomRightCorner<Dynamic,c>(r,c)));
95 
96  VERIFY_IS_EQUAL((const_matrix.template topRows<r>()), (const_matrix.template block<r,cols>(0,0)));
97  VERIFY_IS_EQUAL((const_matrix.template middleRows<r>(sr)), (const_matrix.template block<r,cols>(sr,0)));
98  VERIFY_IS_EQUAL((const_matrix.template bottomRows<r>()), (const_matrix.template block<r,cols>(rows-r,0)));
99  VERIFY_IS_EQUAL((const_matrix.template leftCols<c>()), (const_matrix.template block<rows,c>(0,0)));
100  VERIFY_IS_EQUAL((const_matrix.template middleCols<c>(sc)), (const_matrix.template block<rows,c>(0,sc)));
101  VERIFY_IS_EQUAL((const_matrix.template rightCols<c>()), (const_matrix.template block<rows,c>(0,cols-c)));
102 }
103 
105 {
106  for(int i = 0; i < g_repeat; i++) {
108  CALL_SUBTEST_2( corners(Matrix4d()) );
110  CALL_SUBTEST_4( corners(MatrixXcf(5, 7)) );
111  CALL_SUBTEST_5( corners(MatrixXf(21, 20)) );
112 
114  CALL_SUBTEST_2(( corners_fixedsize<Matrix4d,2,2,1,1>() ));
116  }
117 }
rightCols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NColsBlockXpr< internal::get_fixed_value< NColsType >::value >::Type rightCols(NColsType n)
Definition: BlockMethods.h:872
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(corners)
Definition: corners.cpp:104
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
corners
void corners(const MatrixType &m)
Definition: corners.cpp:16
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
topRightCorner
mat1 topRightCorner(size/2, size/2)
middleCols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NColsBlockXpr< internal::get_fixed_value< NColsType >::value >::Type middleCols(Index startCol, NColsType numCols)
Definition: BlockMethods.h:948
block
m m block(1, 0, 2, 2)<< 4
leftCols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NColsBlockXpr< internal::get_fixed_value< NColsType >::value >::Type leftCols(NColsType n)
Definition: BlockMethods.h:797
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
topRows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NRowsBlockXpr< internal::get_fixed_value< NRowsType >::value >::Type topRows(NRowsType n)
Definition: BlockMethods.h:570
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
bottomRightCorner
mat1 bottomRightCorner(size/2, size/2)
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
topLeftCorner
Eigen::Block< Derived > topLeftCorner(MatrixBase< Derived > &m, int rows, int cols)
Definition: class_Block.cpp:8
COMPARE_CORNER
#define COMPARE_CORNER(A, B)
Definition: corners.cpp:12
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
bottomRows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NRowsBlockXpr< internal::get_fixed_value< NRowsType >::value >::Type bottomRows(NRowsType n)
Definition: BlockMethods.h:645
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
corners_fixedsize
void corners_fixedsize()
Definition: corners.cpp:45
bottomLeftCorner
mat1 bottomLeftCorner(size/2, size/2)
main.h
middleRows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NRowsBlockXpr< internal::get_fixed_value< NRowsType >::value >::Type middleRows(Index startRow, NRowsType n)
Definition: BlockMethods.h:721
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
test_virtual_functions.nc
nc
Definition: test_virtual_functions.py:207


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:07