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> |
| 29 | void check_stdvector_fixedsize() |
| 30 | { |
| 31 | MatrixType x = MatrixType::Random(), y = MatrixType::Random(); |
| 32 | std::vector<MatrixType> v(10), w(20, y); |
| 33 | v[5] = x; |
| 34 | w[6] = v[5]; |
| 35 | VERIFY_IS_APPROX(w[6], v[5]); |
| 36 | v = w; |
| 37 | for(int i = 0; i < 20; i++) |
| 38 | { |
| 39 | VERIFY_IS_APPROX(w[i], v[i]); |
| 40 | } |
| 41 | v.resize(21); |
| 42 | v[20] = x; |
| 43 | VERIFY_IS_APPROX(v[20], x); |
| 44 | v.resize(22,y); |
| 45 | VERIFY_IS_APPROX(v[21], y); |
| 46 | v.push_back(x); |
| 47 | VERIFY_IS_APPROX(v[22], x); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void test_stdvector() |
| 52 | { |
| 53 | // some non vectorizable fixed sizes |
| 54 | CALL_SUBTEST(check_stdvector_fixedsize<Vector2f>()); |
| 55 | CALL_SUBTEST(check_stdvector_fixedsize<Matrix3f>()); |
| 56 | CALL_SUBTEST(check_stdvector_fixedsize<Matrix3d>()); |
| 57 | |
| 58 | // some vectorizable fixed sizes |
| 59 | CALL_SUBTEST(check_stdvector_fixedsize<Vector2d>()); |
| 60 | CALL_SUBTEST(check_stdvector_fixedsize<Vector4f>()); |
| 61 | CALL_SUBTEST(check_stdvector_fixedsize<Matrix4f>()); |
| 62 | CALL_SUBTEST(check_stdvector_fixedsize<Matrix4d>()); |
| 63 | |
| 64 | } |