aboutsummaryrefslogtreecommitdiffhomepage
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
parent3efe6e4176dd76fc3a4e6981ec44ef9741c361d9 (diff)
make the std::vector fix work also with dynamic size Eigen objects, e.g.
std::vector<VectorXd> update unit test
-rw-r--r--Eigen/StdVector5
-rw-r--r--Eigen/src/Core/Matrix.h5
-rw-r--r--Eigen/src/Core/MatrixStorage.h33
-rw-r--r--test/stdvector.cpp36
4 files changed, 42 insertions, 37 deletions
diff --git a/Eigen/StdVector b/Eigen/StdVector
index 6d5366468..19be257db 100644
--- a/Eigen/StdVector
+++ b/Eigen/StdVector
@@ -29,7 +29,7 @@
#include "Core"
#include <vector>
-namespace Eigen{
+namespace Eigen {
template<typename aligned_type> class ei_unaligned_type;
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
@@ -38,9 +38,10 @@ class ei_unaligned_type<Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> >
{
public:
typedef Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> aligned_base;
- ei_unaligned_type() : aligned_base(ei_select_matrix_constructor_doing_absolutely_nothing()) {}
+ ei_unaligned_type() : aligned_base(ei_constructor_without_unaligned_array_assert()) {}
ei_unaligned_type(const aligned_base& other)
{
+ resize(other.rows(), other.cols());
ei_assign_impl<ei_unaligned_type,aligned_base,NoVectorization>::run(*this, other);
}
};
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index a95da9995..5349029bf 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -25,7 +25,6 @@
#ifndef EIGEN_MATRIX_H
#define EIGEN_MATRIX_H
-struct ei_select_matrix_constructor_doing_absolutely_nothing {};
/** \class Matrix
*
@@ -133,8 +132,8 @@ class Matrix
protected:
ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime, Options> m_storage;
- Matrix(ei_select_matrix_constructor_doing_absolutely_nothing) // this ctor does not even do an assertion
- : m_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing()) {}
+ Matrix(ei_constructor_without_unaligned_array_assert)
+ : m_storage(ei_constructor_without_unaligned_array_assert()) {}
public:
enum { NeedsToAlign = (Options&AutoAlign) == AutoAlign
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
index a1a10ead5..972ea558a 100644
--- a/Eigen/src/Core/MatrixStorage.h
+++ b/Eigen/src/Core/MatrixStorage.h
@@ -26,8 +26,7 @@
#ifndef EIGEN_MATRIXSTORAGE_H
#define EIGEN_MATRIXSTORAGE_H
-struct ei_select_matrix_storage_constructor_doing_absolutely_nothing {};
-struct ei_select_matrix_array_constructor_doing_absolutely_nothing {};
+struct ei_constructor_without_unaligned_array_assert {};
/** \internal
* Static array automatically aligned if the total byte size is a multiple of 16 and the matrix options require auto alignment
@@ -46,14 +45,14 @@ template <typename T, int Size, int MatrixOptions,
#endif
}
- ei_matrix_array(ei_select_matrix_array_constructor_doing_absolutely_nothing) {}
+ ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
};
template <typename T, int Size, int MatrixOptions> struct ei_matrix_array<T,Size,MatrixOptions,false>
{
T array[Size];
ei_matrix_array() {}
- ei_matrix_array(ei_select_matrix_array_constructor_doing_absolutely_nothing) {}
+ ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
};
/** \internal
@@ -75,8 +74,8 @@ template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matr
ei_matrix_array<T,Size,_Options> m_data;
public:
inline explicit ei_matrix_storage() {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(ei_constructor_without_unaligned_array_assert()) {}
inline ei_matrix_storage(int,int,int) {}
inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); }
inline static int rows(void) {return _Rows;}
@@ -94,8 +93,8 @@ template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dy
int m_cols;
public:
inline explicit ei_matrix_storage() : m_rows(0), m_cols(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
inline ei_matrix_storage(int, int rows, int cols) : m_rows(rows), m_cols(cols) {}
inline ~ei_matrix_storage() {}
inline void swap(ei_matrix_storage& other)
@@ -118,8 +117,8 @@ template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<
int m_rows;
public:
inline explicit ei_matrix_storage() : m_rows(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0) {}
inline ei_matrix_storage(int, int rows, int) : m_rows(rows) {}
inline ~ei_matrix_storage() {}
inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
@@ -140,8 +139,8 @@ template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<
int m_cols;
public:
inline explicit ei_matrix_storage() : m_cols(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(ei_constructor_without_unaligned_array_assert()), m_cols(0) {}
inline ei_matrix_storage(int, int, int cols) : m_cols(cols) {}
inline ~ei_matrix_storage() {}
inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
@@ -163,8 +162,8 @@ template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic,
int m_cols;
public:
inline explicit ei_matrix_storage() : m_data(0), m_rows(0), m_cols(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(0), m_rows(0), m_cols(0) {}
inline ei_matrix_storage(int size, int rows, int cols)
: m_data(ei_aligned_new<T>(size)), m_rows(rows), m_cols(cols) {}
inline ~ei_matrix_storage() { ei_aligned_delete(m_data, m_rows*m_cols); }
@@ -193,8 +192,7 @@ template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic
int m_cols;
public:
inline explicit ei_matrix_storage() : m_data(0), m_cols(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
inline ei_matrix_storage(int size, int, int cols) : m_data(ei_aligned_new<T>(size)), m_cols(cols) {}
inline ~ei_matrix_storage() { ei_aligned_delete(m_data, _Rows*m_cols); }
inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
@@ -220,8 +218,7 @@ template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic
int m_rows;
public:
inline explicit ei_matrix_storage() : m_data(0), m_rows(0) {}
- inline ei_matrix_storage(ei_select_matrix_storage_constructor_doing_absolutely_nothing)
- : m_data(ei_select_matrix_array_constructor_doing_absolutely_nothing()) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
inline ei_matrix_storage(int size, int rows, int) : m_data(ei_aligned_new<T>(size)), m_rows(rows) {}
inline ~ei_matrix_storage() { ei_aligned_delete(m_data, _Cols*m_rows); }
inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
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)));
}