Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 1 | // This file is part of Eigen, a lightweight C++ template library |
Benoit Jacob | 6347b1d | 2009-05-22 20:25:33 +0200 | [diff] [blame] | 2 | // for linear algebra. |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 3 | // |
Gael Guennebaud | 28e64b0 | 2010-06-24 23:21:58 +0200 | [diff] [blame] | 4 | // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 5 | // |
Benoit Jacob | 69124cf | 2012-07-13 14:42:47 -0400 | [diff] [blame] | 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/. |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 9 | |
| 10 | #include "main.h" |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 11 | |
| 12 | template<typename MatrixType> void replicate(const MatrixType& m) |
| 13 | { |
| 14 | /* this test covers the following files: |
| 15 | Replicate.cpp |
| 16 | */ |
Hauke Heibel | f1679c7 | 2010-06-20 17:37:56 +0200 | [diff] [blame] | 17 | typedef typename MatrixType::Index Index; |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 18 | typedef typename MatrixType::Scalar Scalar; |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 19 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 20 | typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX; |
| 21 | typedef Matrix<Scalar, Dynamic, 1> VectorX; |
| 22 | |
Hauke Heibel | f1679c7 | 2010-06-20 17:37:56 +0200 | [diff] [blame] | 23 | Index rows = m.rows(); |
| 24 | Index cols = m.cols(); |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 25 | |
| 26 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 27 | m2 = MatrixType::Random(rows, cols); |
Gael Guennebaud | 1443094 | 2009-10-13 09:23:09 +0200 | [diff] [blame] | 28 | |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 29 | VectorType v1 = VectorType::Random(rows); |
Gael Guennebaud | 1443094 | 2009-10-13 09:23:09 +0200 | [diff] [blame] | 30 | |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 31 | MatrixX x1, x2; |
| 32 | VectorX vx1; |
| 33 | |
Benoit Jacob | 4716040 | 2010-10-25 10:15:22 -0400 | [diff] [blame] | 34 | int f1 = internal::random<int>(1,10), |
| 35 | f2 = internal::random<int>(1,10); |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 36 | |
| 37 | x1.resize(rows*f1,cols*f2); |
| 38 | for(int j=0; j<f2; j++) |
| 39 | for(int i=0; i<f1; i++) |
| 40 | x1.block(i*rows,j*cols,rows,cols) = m1; |
| 41 | VERIFY_IS_APPROX(x1, m1.replicate(f1,f2)); |
Gael Guennebaud | 1443094 | 2009-10-13 09:23:09 +0200 | [diff] [blame] | 42 | |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 43 | x2.resize(2*rows,3*cols); |
| 44 | x2 << m2, m2, m2, |
| 45 | m2, m2, m2; |
| 46 | VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>())); |
Gael Guennebaud | 1443094 | 2009-10-13 09:23:09 +0200 | [diff] [blame] | 47 | |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 48 | x2.resize(rows,f1); |
| 49 | for (int j=0; j<f1; ++j) |
| 50 | x2.col(j) = v1; |
| 51 | VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1)); |
Gael Guennebaud | 1443094 | 2009-10-13 09:23:09 +0200 | [diff] [blame] | 52 | |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 53 | vx1.resize(rows*f2); |
| 54 | for (int j=0; j<f2; ++j) |
| 55 | vx1.segment(j*rows,rows) = v1; |
| 56 | VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2)); |
| 57 | } |
| 58 | |
| 59 | void test_array_replicate() |
| 60 | { |
| 61 | for(int i = 0; i < g_repeat; i++) { |
Benoit Jacob | 2840ac7 | 2009-10-28 18:19:29 -0400 | [diff] [blame] | 62 | CALL_SUBTEST_1( replicate(Matrix<float, 1, 1>()) ); |
| 63 | CALL_SUBTEST_2( replicate(Vector2f()) ); |
| 64 | CALL_SUBTEST_3( replicate(Vector3d()) ); |
| 65 | CALL_SUBTEST_4( replicate(Vector4f()) ); |
| 66 | CALL_SUBTEST_5( replicate(VectorXf(16)) ); |
| 67 | CALL_SUBTEST_6( replicate(VectorXcd(10)) ); |
Gael Guennebaud | 0be89a4 | 2009-03-05 10:25:22 +0000 | [diff] [blame] | 68 | } |
| 69 | } |