corners.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 
00027 #define COMPARE_CORNER(A,B) \
00028   VERIFY_IS_EQUAL(matrix.A, matrix.B); \
00029   VERIFY_IS_EQUAL(const_matrix.A, const_matrix.B);
00030 
00031 template<typename MatrixType> void corners(const MatrixType& m)
00032 {
00033   typedef typename MatrixType::Index Index;
00034   Index rows = m.rows();
00035   Index cols = m.cols();
00036 
00037   Index r = internal::random<Index>(1,rows);
00038   Index c = internal::random<Index>(1,cols);
00039 
00040   MatrixType matrix = MatrixType::Random(rows,cols);
00041   const MatrixType const_matrix = MatrixType::Random(rows,cols);
00042 
00043   COMPARE_CORNER(topLeftCorner(r,c), block(0,0,r,c));
00044   COMPARE_CORNER(topRightCorner(r,c), block(0,cols-c,r,c));
00045   COMPARE_CORNER(bottomLeftCorner(r,c), block(rows-r,0,r,c));
00046   COMPARE_CORNER(bottomRightCorner(r,c), block(rows-r,cols-c,r,c));
00047 
00048   Index sr = internal::random<Index>(1,rows) - 1;
00049   Index nr = internal::random<Index>(1,rows-sr);
00050   Index sc = internal::random<Index>(1,cols) - 1;
00051   Index nc = internal::random<Index>(1,cols-sc);
00052 
00053   COMPARE_CORNER(topRows(r), block(0,0,r,cols));
00054   COMPARE_CORNER(middleRows(sr,nr), block(sr,0,nr,cols));
00055   COMPARE_CORNER(bottomRows(r), block(rows-r,0,r,cols));
00056   COMPARE_CORNER(leftCols(c), block(0,0,rows,c));
00057   COMPARE_CORNER(middleCols(sc,nc), block(0,sc,rows,nc));
00058   COMPARE_CORNER(rightCols(c), block(0,cols-c,rows,c));
00059 }
00060 
00061 template<typename MatrixType, int CRows, int CCols, int SRows, int SCols> void corners_fixedsize()
00062 {
00063   MatrixType matrix = MatrixType::Random();
00064   const MatrixType const_matrix = MatrixType::Random();
00065 
00066   enum {
00067     rows = MatrixType::RowsAtCompileTime,
00068     cols = MatrixType::ColsAtCompileTime,
00069     r = CRows,
00070     c = CCols,
00071         sr = SRows,
00072         sc = SCols
00073   };
00074 
00075   VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template block<r,c>(0,0)));
00076   VERIFY_IS_EQUAL((matrix.template topRightCorner<r,c>()), (matrix.template block<r,c>(0,cols-c)));
00077   VERIFY_IS_EQUAL((matrix.template bottomLeftCorner<r,c>()), (matrix.template block<r,c>(rows-r,0)));
00078   VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template block<r,c>(rows-r,cols-c)));
00079 
00080   VERIFY_IS_EQUAL((matrix.template topRows<r>()), (matrix.template block<r,cols>(0,0)));
00081   VERIFY_IS_EQUAL((matrix.template middleRows<r>(sr)), (matrix.template block<r,cols>(sr,0)));
00082   VERIFY_IS_EQUAL((matrix.template bottomRows<r>()), (matrix.template block<r,cols>(rows-r,0)));
00083   VERIFY_IS_EQUAL((matrix.template leftCols<c>()), (matrix.template block<rows,c>(0,0)));
00084   VERIFY_IS_EQUAL((matrix.template middleCols<c>(sc)), (matrix.template block<rows,c>(0,sc)));
00085   VERIFY_IS_EQUAL((matrix.template rightCols<c>()), (matrix.template block<rows,c>(0,cols-c)));
00086 
00087   VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template block<r,c>(0,0)));
00088   VERIFY_IS_EQUAL((const_matrix.template topRightCorner<r,c>()), (const_matrix.template block<r,c>(0,cols-c)));
00089   VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,0)));
00090   VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,cols-c)));
00091 
00092   VERIFY_IS_EQUAL((const_matrix.template topRows<r>()), (const_matrix.template block<r,cols>(0,0)));
00093   VERIFY_IS_EQUAL((const_matrix.template middleRows<r>(sr)), (const_matrix.template block<r,cols>(sr,0)));
00094   VERIFY_IS_EQUAL((const_matrix.template bottomRows<r>()), (const_matrix.template block<r,cols>(rows-r,0)));
00095   VERIFY_IS_EQUAL((const_matrix.template leftCols<c>()), (const_matrix.template block<rows,c>(0,0)));
00096   VERIFY_IS_EQUAL((const_matrix.template middleCols<c>(sc)), (const_matrix.template block<rows,c>(0,sc)));
00097   VERIFY_IS_EQUAL((const_matrix.template rightCols<c>()), (const_matrix.template block<rows,c>(0,cols-c)));
00098 }
00099 
00100 void test_corners()
00101 {
00102   for(int i = 0; i < g_repeat; i++) {
00103     CALL_SUBTEST_1( corners(Matrix<float, 1, 1>()) );
00104     CALL_SUBTEST_2( corners(Matrix4d()) );
00105     CALL_SUBTEST_3( corners(Matrix<int,10,12>()) );
00106     CALL_SUBTEST_4( corners(MatrixXcf(5, 7)) );
00107     CALL_SUBTEST_5( corners(MatrixXf(21, 20)) );
00108 
00109     CALL_SUBTEST_1(( corners_fixedsize<Matrix<float, 1, 1>, 1, 1, 0, 0>() ));
00110     CALL_SUBTEST_2(( corners_fixedsize<Matrix4d,2,2,1,1>() ));
00111     CALL_SUBTEST_3(( corners_fixedsize<Matrix<int,10,12>,4,7,5,2>() ));
00112   }
00113 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:59