| 10 | #include "main.h" |
| 11 | |
| 12 | template<typename MatrixType> void miscMatrices(const MatrixType& m) |
| 13 | { |
| 14 | /* this test covers the following files: |
| 15 | DiagonalMatrix.h Ones.h |
| 16 | */ |
| 17 | typedef typename MatrixType::Index Index; |
| 18 | typedef typename MatrixType::Scalar Scalar; |
| 19 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 20 | Index rows = m.rows(); |
| 21 | Index cols = m.cols(); |
| 22 | |
| 23 | Index r = internal::random<Index>(0, rows-1), r2 = internal::random<Index>(0, rows-1), c = internal::random<Index>(0, cols-1); |
| 24 | VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1)); |
| 25 | MatrixType m1 = MatrixType::Ones(rows,cols); |
| 26 | VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1)); |
| 27 | VectorType v1 = VectorType::Random(rows); |
| 28 | v1[0]; |
| 29 | Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> |
| 30 | square(v1.asDiagonal()); |
| 31 | if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]); |
| 32 | else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1)); |
| 33 | square = MatrixType::Zero(rows, rows); |
| 34 | square.diagonal() = VectorType::Ones(rows); |
| 35 | VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows)); |
| 36 | } |
| 37 | |
| 38 | void test_miscmatrices() |
| 39 | { |