| 12 | #include "main.h" |
| 13 | |
| 14 | template<typename MatrixType> void basicStuff(const MatrixType& m) |
| 15 | { |
| 16 | typedef typename MatrixType::Index Index; |
| 17 | typedef typename MatrixType::Scalar Scalar; |
| 18 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 19 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType; |
| 20 | |
| 21 | Index rows = m.rows(); |
| 22 | Index cols = m.cols(); |
| 23 | |
| 24 | // this test relies a lot on Random.h, and there's not much more that we can do |
| 25 | // to test it, hence I consider that we will have tested Random.h |
| 26 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 27 | m2 = MatrixType::Random(rows, cols), |
| 28 | m3(rows, cols), |
| 29 | mzero = MatrixType::Zero(rows, cols), |
| 30 | square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows); |
| 31 | VectorType v1 = VectorType::Random(rows), |
| 32 | vzero = VectorType::Zero(rows); |
| 33 | SquareMatrixType sm1 = SquareMatrixType::Random(rows,rows), sm2(rows,rows); |
| 34 | |
| 35 | Scalar x = 0; |
| 36 | while(x == Scalar(0)) x = internal::random<Scalar>(); |
| 37 | |
| 38 | Index r = internal::random<Index>(0, rows-1), |
| 39 | c = internal::random<Index>(0, cols-1); |
| 40 | |
| 41 | m1.coeffRef(r,c) = x; |
| 42 | VERIFY_IS_APPROX(x, m1.coeff(r,c)); |
| 43 | m1(r,c) = x; |
| 44 | VERIFY_IS_APPROX(x, m1(r,c)); |
| 45 | v1.coeffRef(r) = x; |
| 46 | VERIFY_IS_APPROX(x, v1.coeff(r)); |
| 47 | v1(r) = x; |
| 48 | VERIFY_IS_APPROX(x, v1(r)); |
| 49 | v1[r] = x; |
| 50 | VERIFY_IS_APPROX(x, v1[r]); |
| 51 | |
| 52 | VERIFY_IS_APPROX( v1, v1); |
| 53 | VERIFY_IS_NOT_APPROX( v1, 2*v1); |
| 54 | VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1); |
| 55 | VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1.squaredNorm()); |
| 56 | VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1, v1); |
| 57 | VERIFY_IS_APPROX( vzero, v1-v1); |
| 58 | VERIFY_IS_APPROX( m1, m1); |
| 59 | VERIFY_IS_NOT_APPROX( m1, 2*m1); |
| 60 | VERIFY_IS_MUCH_SMALLER_THAN( mzero, m1); |
| 61 | VERIFY_IS_NOT_MUCH_SMALLER_THAN(m1, m1); |
| 62 | VERIFY_IS_APPROX( mzero, m1-m1); |
| 63 | |
| 64 | // always test operator() on each read-only expression class, |
| 65 | // in order to check const-qualifiers. |
| 66 | // indeed, if an expression class (here Zero) is meant to be read-only, |
| 67 | // hence has no _write() method, the corresponding MatrixBase method (here zero()) |
| 68 | // should return a const-qualified object so that it is the const-qualified |
| 69 | // operator() that gets called, which in turn calls _read(). |
| 70 | VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows,cols)(r,c), static_cast<Scalar>(1)); |
| 71 | |