array_replicate.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) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
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 template<typename MatrixType> void replicate(const MatrixType& m)
00028 {
00029   /* this test covers the following files:
00030      Replicate.cpp
00031   */
00032   typedef typename MatrixType::Index Index;
00033   typedef typename MatrixType::Scalar Scalar;
00034   typedef typename NumTraits<Scalar>::Real RealScalar;
00035   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00036   typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
00037   typedef Matrix<Scalar, Dynamic, 1> VectorX;
00038 
00039   Index rows = m.rows();
00040   Index cols = m.cols();
00041 
00042   MatrixType m1 = MatrixType::Random(rows, cols),
00043              m2 = MatrixType::Random(rows, cols);
00044 
00045   VectorType v1 = VectorType::Random(rows);
00046 
00047   MatrixX x1, x2;
00048   VectorX vx1;
00049 
00050   int  f1 = internal::random<int>(1,10),
00051        f2 = internal::random<int>(1,10);
00052 
00053   x1.resize(rows*f1,cols*f2);
00054   for(int j=0; j<f2; j++)
00055   for(int i=0; i<f1; i++)
00056     x1.block(i*rows,j*cols,rows,cols) = m1;
00057   VERIFY_IS_APPROX(x1, m1.replicate(f1,f2));
00058 
00059   x2.resize(2*rows,3*cols);
00060   x2 << m2, m2, m2,
00061         m2, m2, m2;
00062   VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>()));
00063 
00064   x2.resize(rows,f1);
00065   for (int j=0; j<f1; ++j)
00066     x2.col(j) = v1;
00067   VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1));
00068 
00069   vx1.resize(rows*f2);
00070   for (int j=0; j<f2; ++j)
00071     vx1.segment(j*rows,rows) = v1;
00072   VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2));
00073 }
00074 
00075 void test_array_replicate()
00076 {
00077   for(int i = 0; i < g_repeat; i++) {
00078     CALL_SUBTEST_1( replicate(Matrix<float, 1, 1>()) );
00079     CALL_SUBTEST_2( replicate(Vector2f()) );
00080     CALL_SUBTEST_3( replicate(Vector3d()) );
00081     CALL_SUBTEST_4( replicate(Vector4f()) );
00082     CALL_SUBTEST_5( replicate(VectorXf(16)) );
00083     CALL_SUBTEST_6( replicate(VectorXcd(10)) );
00084   }
00085 }


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