diff --git a/Eigen/CMakeLists.txt b/Eigen/CMakeLists.txt index e3aa67927..7eeb595dd 100644 --- a/Eigen/CMakeLists.txt +++ b/Eigen/CMakeLists.txt @@ -1,4 +1,4 @@ -set(Eigen_HEADERS Core LU Cholesky QR Geometry Sparse Array SVD Regression LeastSquares) +set(Eigen_HEADERS Core LU Cholesky QR Geometry Sparse Array SVD Regression LeastSquares StdVector) if(EIGEN_BUILD_LIB) set(Eigen_SRCS diff --git a/Eigen/StdVector b/Eigen/StdVector new file mode 100644 index 000000000..6d5366468 --- /dev/null +++ b/Eigen/StdVector @@ -0,0 +1,75 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2009 Alex Stapleton +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN_STDVECTOR_MODULE_H +#define EIGEN_STDVECTOR_MODULE_H + +#include "Core" +#include + +namespace Eigen{ +template class ei_unaligned_type; + +template +class ei_unaligned_type > + : public 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(const aligned_base& other) + { + ei_assign_impl::run(*this, other); + } +}; +} // namespace Eigen + +namespace std { + + template + class vector, _Alloc> + : public vector >, + Eigen::aligned_allocator > > > + { + public: + typedef Eigen::ei_unaligned_type > value_type; + typedef Eigen::aligned_allocator allocator_type; + typedef vector unaligned_base; + typedef typename unaligned_base::size_type size_type; + typedef typename unaligned_base::iterator iterator; + + explicit vector(const allocator_type& __a = allocator_type()) : unaligned_base(__a) {} + vector(const vector& c) : unaligned_base(c) {} + vector(size_type num, const value_type& val = value_type()) : unaligned_base(num, val) {} + vector(iterator start, iterator end) : unaligned_base(start, end) {} + vector& operator=(const vector& __x) { + unaligned_base::operator=(__x); + return *this; + } + }; + +} // namespace std + +#endif // EIGEN_STDVECTOR_MODULE_H diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h index ceee90e1a..a1a10ead5 100644 --- a/Eigen/src/Core/MatrixStorage.h +++ b/Eigen/src/Core/MatrixStorage.h @@ -52,6 +52,8 @@ template struct ei_matrix_array { T array[Size]; + ei_matrix_array() {} + ei_matrix_array(ei_select_matrix_array_constructor_doing_absolutely_nothing) {} }; /** \internal diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 377193289..68f7f08d7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -186,6 +186,7 @@ ei_add_test(hyperplane) ei_add_test(parametrizedline) ei_add_test(alignedbox) ei_add_test(regression) +ei_add_test(stdvector) ei_add_test(sparse_basic " " "${SPARSE_LIBS}") ei_add_test(sparse_vector " " "${SPARSE_LIBS}") ei_add_test(sparse_solvers " " "${SPARSE_LIBS}") diff --git a/test/stdvector.cpp b/test/stdvector.cpp new file mode 100644 index 000000000..4e6aa9e3a --- /dev/null +++ b/test/stdvector.cpp @@ -0,0 +1,64 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#include "main.h" +#include + +template +void check_stdvector_fixedsize() +{ + MatrixType x = MatrixType::Random(), y = MatrixType::Random(); + std::vector v(10), w(20, y); + v[5] = x; + w[6] = v[5]; + VERIFY_IS_APPROX(w[6], v[5]); + v = w; + for(int i = 0; i < 20; i++) + { + VERIFY_IS_APPROX(w[i], v[i]); + } + v.resize(21); + v[20] = x; + VERIFY_IS_APPROX(v[20], x); + v.resize(22,y); + VERIFY_IS_APPROX(v[21], y); + v.push_back(x); + VERIFY_IS_APPROX(v[22], x); +} + + +void test_stdvector() +{ + // some non vectorizable fixed sizes + CALL_SUBTEST(check_stdvector_fixedsize()); + CALL_SUBTEST(check_stdvector_fixedsize()); + CALL_SUBTEST(check_stdvector_fixedsize()); + + // some vectorizable fixed sizes + CALL_SUBTEST(check_stdvector_fixedsize()); + CALL_SUBTEST(check_stdvector_fixedsize()); + CALL_SUBTEST(check_stdvector_fixedsize()); + CALL_SUBTEST(check_stdvector_fixedsize()); + +}