stddeque.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) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #include "main.h"
00027 #include <Eigen/StdDeque>
00028 #include <Eigen/Geometry>
00029 
00030 template<typename MatrixType>
00031 void check_stddeque_matrix(const MatrixType& m)
00032 {
00033   typedef typename MatrixType::Index Index;
00034   
00035   Index rows = m.rows();
00036   Index cols = m.cols();
00037   MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
00038   std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> > v(10, MatrixType(rows,cols)), w(20, y);
00039   v.front() = x;
00040   w.front() = w.back();
00041   VERIFY_IS_APPROX(w.front(), w.back());
00042   v = w;
00043 
00044   typename std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator vi = v.begin();
00045   typename std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator wi = w.begin();
00046   for(int i = 0; i < 20; i++)
00047   {
00048     VERIFY_IS_APPROX(*vi, *wi);
00049     ++vi;
00050     ++wi;
00051   }
00052 
00053   v.resize(21);  
00054   v.back() = x;
00055   VERIFY_IS_APPROX(v.back(), x);
00056   v.resize(22,y);
00057   VERIFY_IS_APPROX(v.back(), y);
00058   v.push_back(x);
00059   VERIFY_IS_APPROX(v.back(), x);
00060 }
00061 
00062 template<typename TransformType>
00063 void check_stddeque_transform(const TransformType&)
00064 {
00065   typedef typename TransformType::MatrixType MatrixType;
00066   TransformType x(MatrixType::Random()), y(MatrixType::Random());
00067   std::deque<TransformType,Eigen::aligned_allocator<TransformType> > v(10), w(20, y);
00068   v.front() = x;
00069   w.front() = w.back();
00070   VERIFY_IS_APPROX(w.front(), w.back());
00071   v = w;
00072 
00073   typename std::deque<TransformType,Eigen::aligned_allocator<TransformType> >::iterator vi = v.begin();
00074   typename std::deque<TransformType,Eigen::aligned_allocator<TransformType> >::iterator wi = w.begin();
00075   for(int i = 0; i < 20; i++)
00076   {
00077     VERIFY_IS_APPROX(*vi, *wi);
00078     ++vi;
00079     ++wi;
00080   }
00081 
00082   v.resize(21);
00083   v.back() = x;
00084   VERIFY_IS_APPROX(v.back(), x);
00085   v.resize(22,y);
00086   VERIFY_IS_APPROX(v.back(), y);
00087   v.push_back(x);
00088   VERIFY_IS_APPROX(v.back(), x);
00089 }
00090 
00091 template<typename QuaternionType>
00092 void check_stddeque_quaternion(const QuaternionType&)
00093 {
00094   typedef typename QuaternionType::Coefficients Coefficients;
00095   QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
00096   std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> > v(10), w(20, y);
00097   v.front() = x;
00098   w.front() = w.back();
00099   VERIFY_IS_APPROX(w.front(), w.back());
00100   v = w;
00101 
00102   typename std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator vi = v.begin();
00103   typename std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator wi = w.begin();
00104   for(int i = 0; i < 20; i++)
00105   {
00106     VERIFY_IS_APPROX(*vi, *wi);
00107     ++vi;
00108     ++wi;
00109   }
00110 
00111   v.resize(21);
00112   v.back() = x;
00113   VERIFY_IS_APPROX(v.back(), x);
00114   v.resize(22,y);
00115   VERIFY_IS_APPROX(v.back(), y);
00116   v.push_back(x);
00117   VERIFY_IS_APPROX(v.back(), x);
00118 }
00119 
00120 void test_stddeque()
00121 {
00122   // some non vectorizable fixed sizes
00123   CALL_SUBTEST_1(check_stddeque_matrix(Vector2f()));
00124   CALL_SUBTEST_1(check_stddeque_matrix(Matrix3f()));
00125   CALL_SUBTEST_2(check_stddeque_matrix(Matrix3d()));
00126 
00127   // some vectorizable fixed sizes
00128   CALL_SUBTEST_1(check_stddeque_matrix(Matrix2f()));
00129   CALL_SUBTEST_1(check_stddeque_matrix(Vector4f()));
00130   CALL_SUBTEST_1(check_stddeque_matrix(Matrix4f()));
00131   CALL_SUBTEST_2(check_stddeque_matrix(Matrix4d()));
00132 
00133   // some dynamic sizes
00134   CALL_SUBTEST_3(check_stddeque_matrix(MatrixXd(1,1)));
00135   CALL_SUBTEST_3(check_stddeque_matrix(VectorXd(20)));
00136   CALL_SUBTEST_3(check_stddeque_matrix(RowVectorXf(20)));
00137   CALL_SUBTEST_3(check_stddeque_matrix(MatrixXcf(10,10)));
00138 
00139   // some Transform
00140   CALL_SUBTEST_4(check_stddeque_transform(Affine2f()));
00141   CALL_SUBTEST_4(check_stddeque_transform(Affine3f()));
00142   CALL_SUBTEST_4(check_stddeque_transform(Affine3d()));
00143 
00144   // some Quaternion
00145   CALL_SUBTEST_5(check_stddeque_quaternion(Quaternionf()));
00146   CALL_SUBTEST_5(check_stddeque_quaternion(Quaterniond()));
00147 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:40