| 10 | #include "main.h" |
| 11 | |
| 12 | template<typename MatrixType> void replicate(const MatrixType& m) |
| 13 | { |
| 14 | /* this test covers the following files: |
| 15 | Replicate.cpp |
| 16 | */ |
| 17 | typedef typename MatrixType::Index Index; |
| 18 | typedef typename MatrixType::Scalar Scalar; |
| 19 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 20 | typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX; |
| 21 | typedef Matrix<Scalar, Dynamic, 1> VectorX; |
| 22 | |
| 23 | Index rows = m.rows(); |
| 24 | Index cols = m.cols(); |
| 25 | |
| 26 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 27 | m2 = MatrixType::Random(rows, cols); |
| 28 | |
| 29 | VectorType v1 = VectorType::Random(rows); |
| 30 | |
| 31 | MatrixX x1, x2; |
| 32 | VectorX vx1; |
| 33 | |
| 34 | int f1 = internal::random<int>(1,10), |
| 35 | f2 = internal::random<int>(1,10); |
| 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)); |
| 42 | |
| 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>())); |
| 47 | |
| 48 | x2.resize(rows,3*cols); |
| 49 | x2 << m2, m2, m2; |
| 50 | VERIFY_IS_APPROX(x2, (m2.template replicate<1,3>())); |
| 51 | |
| 52 | vx1.resize(3*rows,cols); |
| 53 | vx1 << m2, m2, m2; |
| 54 | VERIFY_IS_APPROX(vx1+vx1, vx1+(m2.template replicate<3,1>())); |
| 55 | |
| 56 | vx1=m2+(m2.colwise().replicate(1)); |
| 57 | |
| 58 | if(m2.cols()==1) |
| 59 | VERIFY_IS_APPROX(m2.coeff(0), (m2.template replicate<3,1>().coeff(m2.rows()))); |
| 60 | |
| 61 | x2.resize(rows,f1); |
| 62 | for (int j=0; j<f1; ++j) |
| 63 | x2.col(j) = v1; |
| 64 | VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1)); |
| 65 | |
| 66 | vx1.resize(rows*f2); |
| 67 | for (int j=0; j<f2; ++j) |
| 68 | vx1.segment(j*rows,rows) = v1; |
| 69 | VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2)); |