aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/stdvector.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-10 13:10:23 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-10 13:10:23 +0000
commit0c1ef2f4c67430e3c6605adfb1ddc3ac1d1e779f (patch)
tree15aad48552efe309e4d18c440cff5b1ac63b68d5 /test/stdvector.cpp
parent3efe6e4176dd76fc3a4e6981ec44ef9741c361d9 (diff)
make the std::vector fix work also with dynamic size Eigen objects, e.g.
std::vector<VectorXd> update unit test
Diffstat (limited to 'test/stdvector.cpp')
-rw-r--r--test/stdvector.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/test/stdvector.cpp b/test/stdvector.cpp
index 4e6aa9e3a..d14b85f95 100644
--- a/test/stdvector.cpp
+++ b/test/stdvector.cpp
@@ -26,10 +26,12 @@
#include <Eigen/StdVector>
template<typename MatrixType>
-void check_stdvector_fixedsize()
+void check_stdvector(const MatrixType& m)
{
- MatrixType x = MatrixType::Random(), y = MatrixType::Random();
- std::vector<MatrixType> v(10), w(20, y);
+ int rows = m.rows();
+ int cols = m.cols();
+ MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
+ std::vector<MatrixType> v(10, MatrixType(rows,cols)), w(20, y);
v[5] = x;
w[6] = v[5];
VERIFY_IS_APPROX(w[6], v[5]);
@@ -38,27 +40,33 @@ void check_stdvector_fixedsize()
{
VERIFY_IS_APPROX(w[i], v[i]);
}
+
v.resize(21);
- v[20] = x;
+ v[20].set(x);
VERIFY_IS_APPROX(v[20], x);
v.resize(22,y);
- VERIFY_IS_APPROX(v[21], y);
+ VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
+ VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType));
}
-
void test_stdvector()
{
// some non vectorizable fixed sizes
- CALL_SUBTEST(check_stdvector_fixedsize<Vector2f>());
- CALL_SUBTEST(check_stdvector_fixedsize<Matrix3f>());
- CALL_SUBTEST(check_stdvector_fixedsize<Matrix3d>());
+ CALL_SUBTEST(check_stdvector(Vector2f()));
+ CALL_SUBTEST(check_stdvector(Matrix3f()));
+ CALL_SUBTEST(check_stdvector(Matrix3d()));
// some vectorizable fixed sizes
- CALL_SUBTEST(check_stdvector_fixedsize<Vector2d>());
- CALL_SUBTEST(check_stdvector_fixedsize<Vector4f>());
- CALL_SUBTEST(check_stdvector_fixedsize<Matrix4f>());
- CALL_SUBTEST(check_stdvector_fixedsize<Matrix4d>());
-
+ CALL_SUBTEST(check_stdvector(Matrix2f()));
+ CALL_SUBTEST(check_stdvector(Vector4f()));
+ CALL_SUBTEST(check_stdvector(Matrix4f()));
+ CALL_SUBTEST(check_stdvector(Matrix4d()));
+
+ // some dynamic sizes
+ CALL_SUBTEST(check_stdvector(MatrixXd(1,1)));
+ CALL_SUBTEST(check_stdvector(VectorXd(20)));
+ CALL_SUBTEST(check_stdvector(RowVectorXf(20)));
+ CALL_SUBTEST(check_stdvector(MatrixXcf(10,10)));
}