Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +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 | // |
| 4 | // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> |
| 5 | // |
| 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. |
| 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 |
| 18 | // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the |
| 19 | // GNU General Public License for more details. |
| 20 | // |
| 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/>. |
| 24 | |
| 25 | #include "main.h" |
| 26 | #include <Eigen/StdVector> |
| 27 | |
| 28 | template<typename MatrixType> |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 29 | void check_stdvector(const MatrixType& m) |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 30 | { |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 31 | int rows = m.rows(); |
| 32 | int cols = m.cols(); |
| 33 | MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols); |
| 34 | std::vector<MatrixType> v(10, MatrixType(rows,cols)), w(20, y); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 35 | v[5] = x; |
| 36 | w[6] = v[5]; |
| 37 | VERIFY_IS_APPROX(w[6], v[5]); |
| 38 | v = w; |
| 39 | for(int i = 0; i < 20; i++) |
| 40 | { |
| 41 | VERIFY_IS_APPROX(w[i], v[i]); |
| 42 | } |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 43 | |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 44 | v.resize(21); |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 45 | v[20].set(x); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 46 | VERIFY_IS_APPROX(v[20], x); |
| 47 | v.resize(22,y); |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 48 | VERIFY_IS_APPROX(v[21], y); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 49 | v.push_back(x); |
| 50 | VERIFY_IS_APPROX(v[22], x); |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 51 | VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType)); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 54 | void test_stdvector() |
| 55 | { |
| 56 | // some non vectorizable fixed sizes |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 57 | CALL_SUBTEST(check_stdvector(Vector2f())); |
| 58 | CALL_SUBTEST(check_stdvector(Matrix3f())); |
| 59 | CALL_SUBTEST(check_stdvector(Matrix3d())); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 60 | |
| 61 | // some vectorizable fixed sizes |
Benoit Jacob | 0c1ef2f | 2009-01-10 13:10:23 +0000 | [diff] [blame^] | 62 | CALL_SUBTEST(check_stdvector(Matrix2f())); |
| 63 | CALL_SUBTEST(check_stdvector(Vector4f())); |
| 64 | CALL_SUBTEST(check_stdvector(Matrix4f())); |
| 65 | CALL_SUBTEST(check_stdvector(Matrix4d())); |
| 66 | |
| 67 | // some dynamic sizes |
| 68 | CALL_SUBTEST(check_stdvector(MatrixXd(1,1))); |
| 69 | CALL_SUBTEST(check_stdvector(VectorXd(20))); |
| 70 | CALL_SUBTEST(check_stdvector(RowVectorXf(20))); |
| 71 | CALL_SUBTEST(check_stdvector(MatrixXcf(10,10))); |
Benoit Jacob | 335d3bc | 2009-01-09 23:26:45 +0000 | [diff] [blame] | 72 | } |