diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index 888729ee7..22d8bd8a7 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -40,7 +40,10 @@
* \param _Cols Number of columns, or \b Dynamic
*
* The remaining template parameters are optional -- in most cases you don't have to worry about them.
- * \param _StorageOrder Either \b RowMajor or \b ColMajor. The default is \b ColMajor.
+ * \param _Options A combination of either \b Matrix_RowMajor or \b Matrix_ColMajor, and of either
+ * \b Matrix_AutoAlign or \b Matrix_DontAlign.
+ * The former controls storage order, and defaults to column-major. The latter controls alignment, which is required
+ * for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size.
* \param _MaxRows Maximum number of rows. Defaults to \a _Rows (\ref maxrows "note").
* \param _MaxCols Maximum number of columns. Defaults to \a _Cols (\ref maxrows "note").
*
@@ -85,7 +88,7 @@
* to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time.
*
* Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime
- * variables, and the array of coefficients is allocated dynamically, typically on the heap (\ref alloca "note").
+ * variables, and the array of coefficients is allocated dynamically on the heap.
*
* Note that \em dense matrices, be they Fixed-size or Dynamic-size, do not expand dynamically in the sense of a std::map.
* If you want this behavior, see the Sparse module.
@@ -97,15 +100,10 @@
* exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols
* are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.
*
- *
\anchor alloca Usage of alloca():
- * On the Linux platform, for small enough arrays, Eigen will avoid heap allocation and instead will use alloca() to perform a dynamic
- * allocation on the stack.
- *
- *
* \see MatrixBase for the majority of the API methods for matrices
*/
-template
-struct ei_traits >
+template
+struct ei_traits >
{
typedef _Scalar Scalar;
enum {
@@ -113,27 +111,34 @@ struct ei_traits::ret,
+ Flags = ei_compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
CoeffReadCost = NumTraits::ReadCost,
SupportedAccessPatterns = RandomAccessPattern
};
};
-template
+template
+struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {};
+
+template
+struct ei_matrix_with_aligned_operator_new {};
+
+template
class Matrix
- : public MatrixBase >
- , public ei_with_aligned_operator_new<_Scalar,ei_size_at_compile_time<_Rows,_Cols>::ret>
+ : public MatrixBase >
+ , public ei_matrix_with_aligned_operator_new<_Options>
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
- enum { StorageOrder = _StorageOrder };
+ enum { Options = _Options };
friend class Eigen::Map;
typedef class Eigen::Map UnalignedMapType;
friend class Eigen::Map;
typedef class Eigen::Map AlignedMapType;
protected:
- ei_matrix_storage m_storage;
+ ei_matrix_storage m_storage;
public:
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
index 9027acee7..7d869579b 100644
--- a/Eigen/src/Core/MatrixStorage.h
+++ b/Eigen/src/Core/MatrixStorage.h
@@ -26,6 +26,27 @@
#ifndef EIGEN_MATRIXSTORAGE_H
#define EIGEN_MATRIXSTORAGE_H
+/** \internal
+ * Static array automatically aligned if the total byte size is a multiple of 16 and the matrix options require auto alignment
+ */
+template struct ei_matrix_array
+{
+ EIGEN_ALIGN_128 T array[Size];
+
+ ei_matrix_array()
+ {
+ ei_assert((reinterpret_cast(array) & 0xf) == 0
+ && "this assertion is explained here: http://eigen.tuxfamily.org/api/UnalignedArrayAssert.html **** READ THIS WEB PAGE !!! ****");
+ }
+};
+
+template struct ei_matrix_array
+{
+ T array[Size];
+};
+
/** \internal
*
* \class ei_matrix_storage
@@ -37,12 +58,12 @@
*
* \sa Matrix
*/
-template class ei_matrix_storage;
+template class ei_matrix_storage;
// purely fixed-size matrix
-template class ei_matrix_storage
+template class ei_matrix_storage
{
- ei_aligned_array m_data;
+ ei_matrix_array m_data;
public:
inline explicit ei_matrix_storage() {}
inline ei_matrix_storage(int,int,int) {}
@@ -55,9 +76,9 @@ template class ei_matrix_storage
};
// dynamic-size matrix with fixed-size storage
-template class ei_matrix_storage
+template class ei_matrix_storage
{
- ei_aligned_array m_data;
+ ei_matrix_array m_data;
int m_rows;
int m_cols;
public:
@@ -78,9 +99,9 @@ template class ei_matrix_storage class ei_matrix_storage
+template class ei_matrix_storage
{
- ei_aligned_array m_data;
+ ei_matrix_array m_data;
int m_rows;
public:
inline explicit ei_matrix_storage() : m_rows(0) {}
@@ -98,9 +119,9 @@ template class ei_matrix_storage class ei_matrix_storage
+template class ei_matrix_storage
{
- ei_aligned_array m_data;
+ ei_matrix_array m_data;
int m_cols;
public:
inline explicit ei_matrix_storage() : m_cols(0) {}
@@ -118,7 +139,7 @@ template class ei_matrix_storage class ei_matrix_storage
+template class ei_matrix_storage
{
T *m_data;
int m_rows;
@@ -147,7 +168,7 @@ template class ei_matrix_storage
};
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
-template class ei_matrix_storage
+template class ei_matrix_storage
{
T *m_data;
int m_cols;
@@ -172,7 +193,7 @@ template class ei_matrix_storage class ei_matrix_storage
+template class ei_matrix_storage
{
T *m_data;
int m_rows;
diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h
index 203f3b294..a535e2417 100644
--- a/Eigen/src/Core/util/Constants.h
+++ b/Eigen/src/Core/util/Constants.h
@@ -223,8 +223,15 @@ enum {
};
enum {
- ColMajor = 0,
- RowMajor = RowMajorBit
+ Matrix_ColMajor = 0,
+ Matrix_RowMajor = 0x1, // it is only a coincidence that this is equal to RowMajorBit -- don't rely on that
+ /** \internal Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated, may still be
+ requested to be aligned) */
+ ColMajor = Matrix_ColMajor, // deprecated
+ RowMajor = Matrix_RowMajor, // deprecated
+ Matrix_DontAlign = 0,
+ /** \internal Align the matrix itself */
+ Matrix_AutoAlign = 0x2
};
enum {
diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h
index b61316dfc..bb4567ad0 100644
--- a/Eigen/src/Core/util/ForwardDeclarations.h
+++ b/Eigen/src/Core/util/ForwardDeclarations.h
@@ -28,7 +28,8 @@
template struct ei_traits;
template struct NumTraits;
-template class Matrix;
template class Flagged;
diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h
index 422bc7bd1..3160ce7f6 100644
--- a/Eigen/src/Core/util/Macros.h
+++ b/Eigen/src/Core/util/Macros.h
@@ -28,6 +28,12 @@
#undef minor
+#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
+#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Matrix_RowMajor
+#else
+#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Matrix_ColMajor
+#endif
+
/** \internal Defines the maximal loop size to enable meta unrolling of loops.
* Note that the value here is expressed in Eigen's own notion of "number of FLOPS",
* it does not correspond to the number of iterations or the number of instructions
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h
index 35b6b4ab9..0e49ffeae 100644
--- a/Eigen/src/Core/util/Memory.h
+++ b/Eigen/src/Core/util/Memory.h
@@ -31,25 +31,6 @@
extern "C" int posix_memalign (void **, size_t, size_t) throw ();
#endif
-/** \internal
- * Static array automatically aligned if the total byte size is a multiple of 16
- */
-template struct ei_aligned_array
-{
- EIGEN_ALIGN_128 T array[Size];
-
- ei_aligned_array()
- {
- ei_assert((reinterpret_cast(array) & 0xf) == 0
- && "this assertion is explained here: http://eigen.tuxfamily.org/api/UnalignedArrayAssert.html **** READ THIS WEB PAGE !!! ****");
- }
-};
-
-template struct ei_aligned_array
-{
- T array[Size];
-};
-
struct ei_byte_forcing_aligned_malloc
{
unsigned char c; // sizeof must be 1.
diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h
index ae8703958..739eb1108 100644
--- a/Eigen/src/Core/util/XprHelper.h
+++ b/Eigen/src/Core/util/XprHelper.h
@@ -85,22 +85,16 @@ template struct ei_unpacket_traits
enum {size=1};
};
-
-template
+template
class ei_compute_matrix_flags
{
enum {
- row_major_bit = (Rows != 1 && Cols != 1) // if this is not a vector,
- // then the storage order really matters,
- // so let us strictly honor the user's choice.
- ? StorageOrder
- : Cols > 1 ? RowMajorBit : 0,
+ row_major_bit = Options&Matrix_RowMajor ? RowMajorBit : 0,
inner_max_size = row_major_bit ? MaxCols : MaxRows,
is_big = inner_max_size == Dynamic,
- is_packet_size_multiple = (Cols * Rows)%ei_packet_traits::size==0,
- packet_access_bit = ei_packet_traits::size > 1
- && (is_big || is_packet_size_multiple) ? PacketAccessBit : 0,
- aligned_bit = packet_access_bit && (is_big || is_packet_size_multiple) ? AlignedBit : 0
+ is_packet_size_multiple = (Cols*Rows) % ei_packet_traits::size == 0,
+ aligned_bit = ((Options&Matrix_AutoAlign) && (is_big || is_packet_size_multiple)) ? AlignedBit : 0,
+ packet_access_bit = ei_packet_traits::size > 1 && aligned_bit ? PacketAccessBit : 0
};
public:
@@ -123,7 +117,7 @@ template struct ei_eval
typedef Matrix::Scalar,
ei_traits::RowsAtCompileTime,
ei_traits::ColsAtCompileTime,
- ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor,
+ Matrix_AutoAlign | (ei_traits::Flags&RowMajorBit ? Matrix_RowMajor : Matrix_ColMajor),
ei_traits::MaxRowsAtCompileTime,
ei_traits::MaxColsAtCompileTime
> type;
@@ -144,7 +138,7 @@ template struct ei_plain_matrix_type
typedef Matrix::Scalar,
ei_traits::RowsAtCompileTime,
ei_traits::ColsAtCompileTime,
- ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor,
+ Matrix_AutoAlign | (ei_traits::Flags&RowMajorBit ? Matrix_RowMajor : Matrix_ColMajor),
ei_traits::MaxRowsAtCompileTime,
ei_traits::MaxColsAtCompileTime
> type;
@@ -157,7 +151,7 @@ template struct ei_plain_matrix_type_column_major
typedef Matrix::Scalar,
ei_traits::RowsAtCompileTime,
ei_traits::ColsAtCompileTime,
- ColMajor,
+ Matrix_AutoAlign | Matrix_ColMajor,
ei_traits::MaxRowsAtCompileTime,
ei_traits::MaxColsAtCompileTime
> type;
diff --git a/Eigen/src/LU/LU.h b/Eigen/src/LU/LU.h
index 1ac14034f..82b408d3c 100644
--- a/Eigen/src/LU/LU.h
+++ b/Eigen/src/LU/LU.h
@@ -76,7 +76,7 @@ template class LU
MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix" is the number of cols of the original matrix
// so that the product "matrix * kernel = zero" makes sense
Dynamic, // we don't know at compile-time the dimension of the kernel
- MatrixType::StorageOrder,
+ MatrixType::Options,
MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, whose dimension is the number
// of columns of the original matrix
@@ -86,7 +86,7 @@ template class LU
MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose dimension is the number
// of rows of the original matrix
Dynamic, // we don't know at compile time the dimension of the image (the rank)
- MatrixType::StorageOrder,
+ MatrixType::Options,
MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix,
MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns.
> ImageResultType;
@@ -436,7 +436,7 @@ void LU::computeKernel(KernelMatrixType *result) const
* independent vectors in Ker U.
*/
- Matrix
y(-m_lu.corner(TopRight, m_rank, dimker));
@@ -504,7 +504,7 @@ bool LU::solve(
// Step 2
Matrix l(rows, rows);
l.setZero();
@@ -523,7 +523,7 @@ bool LU::solve(
return false;
}
Matrix
d(c.corner(TopLeft, m_rank, c.cols()));
m_lu.corner(TopLeft, m_rank, m_rank)
diff --git a/bench/btl/cmake/FindEigen2.cmake b/bench/btl/cmake/FindEigen2.cmake
index 49dfd1e6d..2579a6c9c 100644
--- a/bench/btl/cmake/FindEigen2.cmake
+++ b/bench/btl/cmake/FindEigen2.cmake
@@ -1,11 +1,9 @@
-# - Try to find eigen2 headers
+# - Try to find Eigen2 lib
# Once done this will define
#
-# EIGEN2_FOUND - system has eigen2 lib
-# EIGEN2_INCLUDE_DIR - the eigen2 include directory
-#
-# Copyright (C) 2008 Gael Guennebaud
-# Adapted from FindEigen.cmake:
+# EIGEN2_FOUND - system has eigen lib
+# EIGEN2_INCLUDE_DIR - the eigen include directory
+
# Copyright (c) 2006, 2007 Montel Laurent,
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -19,12 +17,14 @@ else (EIGEN2_INCLUDE_DIR)
find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core
PATHS
- ${Eigen_SOURCE_DIR}/
${INCLUDE_INSTALL_DIR}
+ ${KDE4_INCLUDE_DIR}
+ PATH_SUFFIXES eigen2
)
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR)
+find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR )
+
mark_as_advanced(EIGEN2_INCLUDE_DIR)
diff --git a/test/determinant.cpp b/test/determinant.cpp
index 68e91e4c1..bc647d25d 100644
--- a/test/determinant.cpp
+++ b/test/determinant.cpp
@@ -38,8 +38,8 @@ template void determinant(const MatrixType& m)
m2.setRandom();
typedef typename MatrixType::Scalar Scalar;
Scalar x = ei_random();
- VERIFY(ei_isApprox(MatrixType::Identity(size, size).determinant(), Scalar(1)));
- VERIFY(ei_isApprox((m1*m2).determinant(), m1.determinant() * m2.determinant()));
+ VERIFY_IS_APPROX(MatrixType::Identity(size, size).determinant(), Scalar(1));
+ VERIFY_IS_APPROX((m1*m2).determinant(), m1.determinant() * m2.determinant());
if(size==1) return;
int i = ei_random(0, size-1);
int j;
@@ -48,18 +48,18 @@ template void determinant(const MatrixType& m)
} while(j==i);
m2 = m1;
m2.row(i).swap(m2.row(j));
- VERIFY(ei_isApprox(m2.determinant(), -m1.determinant()));
+ VERIFY_IS_APPROX(m2.determinant(), -m1.determinant());
m2 = m1;
m2.col(i).swap(m2.col(j));
- VERIFY(ei_isApprox(m2.determinant(), -m1.determinant()));
- VERIFY(ei_isApprox(m2.determinant(), m2.transpose().determinant()));
- VERIFY(ei_isApprox(ei_conj(m2.determinant()), m2.adjoint().determinant()));
+ VERIFY_IS_APPROX(m2.determinant(), -m1.determinant());
+ VERIFY_IS_APPROX(m2.determinant(), m2.transpose().determinant());
+ VERIFY_IS_APPROX(ei_conj(m2.determinant()), m2.adjoint().determinant());
m2 = m1;
m2.row(i) += x*m2.row(j);
- VERIFY(ei_isApprox(m2.determinant(), m1.determinant()));
+ VERIFY_IS_APPROX(m2.determinant(), m1.determinant());
m2 = m1;
m2.row(i) *= x;
- VERIFY(ei_isApprox(m2.determinant(), m1.determinant() * x));
+ VERIFY_IS_APPROX(m2.determinant(), m1.determinant() * x);
}
void test_determinant()
@@ -72,4 +72,5 @@ void test_determinant()
CALL_SUBTEST( determinant(Matrix, 10, 10>()) );
CALL_SUBTEST( determinant(MatrixXd(20, 20)) );
}
+ CALL_SUBTEST( determinant(MatrixXd(200, 200)) );
}
diff --git a/test/unalignedassert.cpp b/test/unalignedassert.cpp
index 4f9495a51..0b5bf0c77 100644
--- a/test/unalignedassert.cpp
+++ b/test/unalignedassert.cpp
@@ -67,6 +67,12 @@ struct Good8 : Eigen::WithAlignedOperatorNew
Matrix4f m;
};
+struct Good9
+{
+ Matrix m; // good: no alignment requested
+ float f;
+};
+
template
void check_unalignedassert_good()
{
@@ -80,7 +86,7 @@ void check_unalignedassert_good()
template
void check_unalignedassert_bad()
{
- float buf[1000];
+ float buf[sizeof(T)+16];
float *unaligned = buf;
while((reinterpret_cast(unaligned)&0xf)==0) ++unaligned; // make sure unaligned is really unaligned
T *x = new(static_cast(unaligned)) T;
@@ -97,6 +103,7 @@ void unalignedassert()
VERIFY_RAISES_ASSERT(check_unalignedassert_bad());
check_unalignedassert_good();
check_unalignedassert_good();
+ check_unalignedassert_good();
}
void test_unalignedassert()