blob: d14b85f951916638dcf5049a797879a797ba4649 [file] [log] [blame]
Benoit Jacob335d3bc2009-01-09 23:26:45 +00001// 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
28template<typename MatrixType>
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000029void check_stdvector(const MatrixType& m)
Benoit Jacob335d3bc2009-01-09 23:26:45 +000030{
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000031 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 Jacob335d3bc2009-01-09 23:26:45 +000035 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 Jacob0c1ef2f2009-01-10 13:10:23 +000043
Benoit Jacob335d3bc2009-01-09 23:26:45 +000044 v.resize(21);
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000045 v[20].set(x);
Benoit Jacob335d3bc2009-01-09 23:26:45 +000046 VERIFY_IS_APPROX(v[20], x);
47 v.resize(22,y);
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000048 VERIFY_IS_APPROX(v[21], y);
Benoit Jacob335d3bc2009-01-09 23:26:45 +000049 v.push_back(x);
50 VERIFY_IS_APPROX(v[22], x);
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000051 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType));
Benoit Jacob335d3bc2009-01-09 23:26:45 +000052}
53
Benoit Jacob335d3bc2009-01-09 23:26:45 +000054void test_stdvector()
55{
56 // some non vectorizable fixed sizes
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000057 CALL_SUBTEST(check_stdvector(Vector2f()));
58 CALL_SUBTEST(check_stdvector(Matrix3f()));
59 CALL_SUBTEST(check_stdvector(Matrix3d()));
Benoit Jacob335d3bc2009-01-09 23:26:45 +000060
61 // some vectorizable fixed sizes
Benoit Jacob0c1ef2f2009-01-10 13:10:23 +000062 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 Jacob335d3bc2009-01-09 23:26:45 +000072}