Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 1 | // This file is part of Eigen, a lightweight C++ template library |
| 2 | // for linear algebra. Eigen itself is part of the KDE project. |
| 3 | // |
Benoit Jacob | 8ba3055 | 2008-01-07 09:34:21 +0000 | [diff] [blame] | 4 | // Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 5 | // |
Benoit Jacob | 3698d8c | 2008-02-28 15:44:45 +0000 | [diff] [blame] | 6 | // Eigen is free software; you can redistribute it and/or |
| 7 | // modify it under the terms of the GNU Lesser General Public |
| 8 | // License as published by the Free Software Foundation; either |
| 9 | // version 3 of the License, or (at your option) any later version. |
| 10 | // |
| 11 | // Alternatively, you can redistribute it and/or |
| 12 | // modify it under the terms of the GNU General Public License as |
| 13 | // published by the Free Software Foundation; either version 2 of |
| 14 | // the License, or (at your option) any later version. |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 15 | // |
| 16 | // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY |
| 17 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
Benoit Jacob | 3698d8c | 2008-02-28 15:44:45 +0000 | [diff] [blame] | 18 | // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the |
| 19 | // GNU General Public License for more details. |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 20 | // |
Benoit Jacob | 3698d8c | 2008-02-28 15:44:45 +0000 | [diff] [blame] | 21 | // You should have received a copy of the GNU Lesser General Public |
| 22 | // License and a copy of the GNU General Public License along with |
| 23 | // Eigen. If not, see <http://www.gnu.org/licenses/>. |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 24 | |
| 25 | #include "main.h" |
| 26 | |
| 27 | namespace Eigen { |
| 28 | |
| 29 | template<typename MatrixType> void miscMatrices(const MatrixType& m) |
| 30 | { |
| 31 | /* this test covers the following files: |
| 32 | DiagonalMatrix.h Ones.h |
| 33 | */ |
| 34 | |
| 35 | typedef typename MatrixType::Scalar Scalar; |
Benoit Jacob | 84934ea | 2008-01-06 16:35:21 +0000 | [diff] [blame] | 36 | typedef Matrix<Scalar, MatrixType::Traits::RowsAtCompileTime, 1> VectorType; |
| 37 | typedef Matrix<Scalar, 1, MatrixType::Traits::ColsAtCompileTime> RowVectorType; |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 38 | int rows = m.rows(); |
| 39 | int cols = m.cols(); |
| 40 | |
Benoit Jacob | 6907886 | 2008-02-28 12:38:12 +0000 | [diff] [blame] | 41 | int r = ei_random<int>(0, rows-1), r2 = ei_random<int>(0, rows-1), c = ei_random<int>(0, cols-1); |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 42 | VERIFY_IS_APPROX(MatrixType::ones(rows,cols)(r,c), static_cast<Scalar>(1)); |
| 43 | MatrixType m1 = MatrixType::ones(rows,cols); |
| 44 | VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1)); |
| 45 | VectorType v1 = VectorType::random(rows); |
| 46 | v1[0]; |
Benoit Jacob | 84934ea | 2008-01-06 16:35:21 +0000 | [diff] [blame] | 47 | Matrix<Scalar, MatrixType::Traits::RowsAtCompileTime, MatrixType::Traits::RowsAtCompileTime> |
Benoit Jacob | d1d55e6 | 2008-01-05 10:57:14 +0000 | [diff] [blame] | 48 | square = v1.asDiagonal(); |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 49 | if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]); |
| 50 | else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1)); |
| 51 | square = MatrixType::zero(rows, rows); |
| 52 | square.diagonal() = VectorType::ones(rows); |
Benoit Jacob | bcf7b29 | 2008-01-11 15:56:21 +0000 | [diff] [blame] | 53 | VERIFY_IS_APPROX(square, MatrixType::identity(rows, rows)); |
Benoit Jacob | 7c38475 | 2007-12-15 18:16:30 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void EigenTest::testMiscMatrices() |
| 57 | { |
| 58 | for(int i = 0; i < m_repeat; i++) { |
| 59 | miscMatrices(Matrix<float, 1, 1>()); |
| 60 | miscMatrices(Matrix4d()); |
| 61 | miscMatrices(MatrixXcf(3, 3)); |
| 62 | miscMatrices(MatrixXi(8, 12)); |
| 63 | miscMatrices(MatrixXcd(20, 20)); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | } // namespace Eigen |