mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
* the 4th template param of Matrix is now Options. One bit for storage
order, one bit for enabling/disabling auto-alignment. If you want to disable, do: Matrix<float,4,1,Matrix_DontAlign> The Matrix_ prefix is the only way I can see to avoid ambiguity/pollution. The old RowMajor, ColMajor constants are deprecated, remain for now. * this prompted several improvements in matrix_storage. ei_aligned_array renamed to ei_matrix_array and moved there. The %16==0 tests are now much more centralized in 1 place there. * unalignedassert test: updated * update FindEigen2.cmake from KDElibs * determinant test: use VERIFY_IS_APPROX to fix false positives; add testing of 1 big matrix
This commit is contained in:
parent
d9e5fd393a
commit
15ca6659ac
@ -40,7 +40,10 @@
|
|||||||
* \param _Cols Number of columns, or \b Dynamic
|
* \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.
|
* 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 _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").
|
* \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.
|
* 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
|
* 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, <em>do not</em> expand dynamically in the sense of a std::map.
|
* Note that \em dense matrices, be they Fixed-size or Dynamic-size, <em>do not</em> expand dynamically in the sense of a std::map.
|
||||||
* If you want this behavior, see the Sparse module.</dd>
|
* If you want this behavior, see the Sparse module.</dd>
|
||||||
@ -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
|
* 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.</dd>
|
* are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.</dd>
|
||||||
*
|
*
|
||||||
* <dt><b>\anchor alloca Usage of alloca():</b></dt>
|
|
||||||
* <dd>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.</dd>
|
|
||||||
* </dl>
|
|
||||||
*
|
|
||||||
* \see MatrixBase for the majority of the API methods for matrices
|
* \see MatrixBase for the majority of the API methods for matrices
|
||||||
*/
|
*/
|
||||||
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
|
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
||||||
struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
|
struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
||||||
{
|
{
|
||||||
typedef _Scalar Scalar;
|
typedef _Scalar Scalar;
|
||||||
enum {
|
enum {
|
||||||
@ -113,27 +111,34 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols
|
|||||||
ColsAtCompileTime = _Cols,
|
ColsAtCompileTime = _Cols,
|
||||||
MaxRowsAtCompileTime = _MaxRows,
|
MaxRowsAtCompileTime = _MaxRows,
|
||||||
MaxColsAtCompileTime = _MaxCols,
|
MaxColsAtCompileTime = _MaxCols,
|
||||||
Flags = ei_compute_matrix_flags<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::ret,
|
Flags = ei_compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
SupportedAccessPatterns = RandomAccessPattern
|
SupportedAccessPatterns = RandomAccessPattern
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
|
template<int Options,
|
||||||
|
bool NeedsToAlign = (Options&Matrix_AutoAlign)>
|
||||||
|
struct ei_matrix_with_aligned_operator_new : WithAlignedOperatorNew {};
|
||||||
|
|
||||||
|
template<int Options>
|
||||||
|
struct ei_matrix_with_aligned_operator_new<Options, false> {};
|
||||||
|
|
||||||
|
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
||||||
class Matrix
|
class Matrix
|
||||||
: public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
|
: public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
||||||
, public ei_with_aligned_operator_new<_Scalar,ei_size_at_compile_time<_Rows,_Cols>::ret>
|
, public ei_matrix_with_aligned_operator_new<_Options>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
|
EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
|
||||||
enum { StorageOrder = _StorageOrder };
|
enum { Options = _Options };
|
||||||
friend class Eigen::Map<Matrix, Unaligned>;
|
friend class Eigen::Map<Matrix, Unaligned>;
|
||||||
typedef class Eigen::Map<Matrix, Unaligned> UnalignedMapType;
|
typedef class Eigen::Map<Matrix, Unaligned> UnalignedMapType;
|
||||||
friend class Eigen::Map<Matrix, Aligned>;
|
friend class Eigen::Map<Matrix, Aligned>;
|
||||||
typedef class Eigen::Map<Matrix, Aligned> AlignedMapType;
|
typedef class Eigen::Map<Matrix, Aligned> AlignedMapType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime> m_storage;
|
ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime, Options> m_storage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -26,6 +26,27 @@
|
|||||||
#ifndef EIGEN_MATRIXSTORAGE_H
|
#ifndef EIGEN_MATRIXSTORAGE_H
|
||||||
#define 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 <typename T, int Size, int MatrixOptions,
|
||||||
|
bool Align = (MatrixOptions&Matrix_AutoAlign) && (((Size*sizeof(T))&0xf)==0)
|
||||||
|
> struct ei_matrix_array
|
||||||
|
{
|
||||||
|
EIGEN_ALIGN_128 T array[Size];
|
||||||
|
|
||||||
|
ei_matrix_array()
|
||||||
|
{
|
||||||
|
ei_assert((reinterpret_cast<size_t>(array) & 0xf) == 0
|
||||||
|
&& "this assertion is explained here: http://eigen.tuxfamily.org/api/UnalignedArrayAssert.html **** READ THIS WEB PAGE !!! ****");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, int Size, int MatrixOptions> struct ei_matrix_array<T,Size,MatrixOptions,false>
|
||||||
|
{
|
||||||
|
T array[Size];
|
||||||
|
};
|
||||||
|
|
||||||
/** \internal
|
/** \internal
|
||||||
*
|
*
|
||||||
* \class ei_matrix_storage
|
* \class ei_matrix_storage
|
||||||
@ -37,12 +58,12 @@
|
|||||||
*
|
*
|
||||||
* \sa Matrix
|
* \sa Matrix
|
||||||
*/
|
*/
|
||||||
template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage;
|
template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage;
|
||||||
|
|
||||||
// purely fixed-size matrix
|
// purely fixed-size matrix
|
||||||
template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage
|
template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage
|
||||||
{
|
{
|
||||||
ei_aligned_array<T,Size,((Size*sizeof(T))%16)==0> m_data;
|
ei_matrix_array<T,Size,_Options> m_data;
|
||||||
public:
|
public:
|
||||||
inline explicit ei_matrix_storage() {}
|
inline explicit ei_matrix_storage() {}
|
||||||
inline ei_matrix_storage(int,int,int) {}
|
inline ei_matrix_storage(int,int,int) {}
|
||||||
@ -55,9 +76,9 @@ template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage
|
|||||||
};
|
};
|
||||||
|
|
||||||
// dynamic-size matrix with fixed-size storage
|
// dynamic-size matrix with fixed-size storage
|
||||||
template<typename T, int Size> class ei_matrix_storage<T, Size, Dynamic, Dynamic>
|
template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dynamic, Dynamic, _Options>
|
||||||
{
|
{
|
||||||
ei_aligned_array<T,Size,((Size*sizeof(T))%16)==0> m_data;
|
ei_matrix_array<T,Size,_Options> m_data;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
int m_cols;
|
int m_cols;
|
||||||
public:
|
public:
|
||||||
@ -78,9 +99,9 @@ template<typename T, int Size> class ei_matrix_storage<T, Size, Dynamic, Dynamic
|
|||||||
};
|
};
|
||||||
|
|
||||||
// dynamic-size matrix with fixed-size storage and fixed width
|
// dynamic-size matrix with fixed-size storage and fixed width
|
||||||
template<typename T, int Size, int _Cols> class ei_matrix_storage<T, Size, Dynamic, _Cols>
|
template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<T, Size, Dynamic, _Cols, _Options>
|
||||||
{
|
{
|
||||||
ei_aligned_array<T,Size,((Size*sizeof(T))%16)==0> m_data;
|
ei_matrix_array<T,Size,_Options> m_data;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
public:
|
public:
|
||||||
inline explicit ei_matrix_storage() : m_rows(0) {}
|
inline explicit ei_matrix_storage() : m_rows(0) {}
|
||||||
@ -98,9 +119,9 @@ template<typename T, int Size, int _Cols> class ei_matrix_storage<T, Size, Dynam
|
|||||||
};
|
};
|
||||||
|
|
||||||
// dynamic-size matrix with fixed-size storage and fixed height
|
// dynamic-size matrix with fixed-size storage and fixed height
|
||||||
template<typename T, int Size, int _Rows> class ei_matrix_storage<T, Size, _Rows, Dynamic>
|
template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<T, Size, _Rows, Dynamic, _Options>
|
||||||
{
|
{
|
||||||
ei_aligned_array<T,Size,((Size*sizeof(T))%16)==0> m_data;
|
ei_matrix_array<T,Size,_Options> m_data;
|
||||||
int m_cols;
|
int m_cols;
|
||||||
public:
|
public:
|
||||||
inline explicit ei_matrix_storage() : m_cols(0) {}
|
inline explicit ei_matrix_storage() : m_cols(0) {}
|
||||||
@ -118,7 +139,7 @@ template<typename T, int Size, int _Rows> class ei_matrix_storage<T, Size, _Rows
|
|||||||
};
|
};
|
||||||
|
|
||||||
// purely dynamic matrix.
|
// purely dynamic matrix.
|
||||||
template<typename T> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic>
|
template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options>
|
||||||
{
|
{
|
||||||
T *m_data;
|
T *m_data;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
@ -147,7 +168,7 @@ template<typename T> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic>
|
|||||||
};
|
};
|
||||||
|
|
||||||
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
|
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
|
||||||
template<typename T, int _Rows> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic>
|
template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options>
|
||||||
{
|
{
|
||||||
T *m_data;
|
T *m_data;
|
||||||
int m_cols;
|
int m_cols;
|
||||||
@ -172,7 +193,7 @@ template<typename T, int _Rows> class ei_matrix_storage<T, Dynamic, _Rows, Dynam
|
|||||||
};
|
};
|
||||||
|
|
||||||
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
|
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
|
||||||
template<typename T, int _Cols> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols>
|
template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options>
|
||||||
{
|
{
|
||||||
T *m_data;
|
T *m_data;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
|
@ -223,8 +223,15 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ColMajor = 0,
|
Matrix_ColMajor = 0,
|
||||||
RowMajor = RowMajorBit
|
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 {
|
enum {
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
template<typename T> struct ei_traits;
|
template<typename T> struct ei_traits;
|
||||||
template<typename T> struct NumTraits;
|
template<typename T> struct NumTraits;
|
||||||
|
|
||||||
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder = ColMajor,
|
template<typename _Scalar, int _Rows, int _Cols,
|
||||||
|
int _Options = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION | Matrix_AutoAlign,
|
||||||
int _MaxRows = _Rows, int _MaxCols = _Cols> class Matrix;
|
int _MaxRows = _Rows, int _MaxCols = _Cols> class Matrix;
|
||||||
|
|
||||||
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged;
|
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged;
|
||||||
|
@ -28,6 +28,12 @@
|
|||||||
|
|
||||||
#undef minor
|
#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.
|
/** \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",
|
* 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
|
* it does not correspond to the number of iterations or the number of instructions
|
||||||
|
@ -31,25 +31,6 @@
|
|||||||
extern "C" int posix_memalign (void **, size_t, size_t) throw ();
|
extern "C" int posix_memalign (void **, size_t, size_t) throw ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \internal
|
|
||||||
* Static array automatically aligned if the total byte size is a multiple of 16
|
|
||||||
*/
|
|
||||||
template <typename T, int Size, bool Align> struct ei_aligned_array
|
|
||||||
{
|
|
||||||
EIGEN_ALIGN_128 T array[Size];
|
|
||||||
|
|
||||||
ei_aligned_array()
|
|
||||||
{
|
|
||||||
ei_assert((reinterpret_cast<size_t>(array) & 0xf) == 0
|
|
||||||
&& "this assertion is explained here: http://eigen.tuxfamily.org/api/UnalignedArrayAssert.html **** READ THIS WEB PAGE !!! ****");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, int Size> struct ei_aligned_array<T,Size,false>
|
|
||||||
{
|
|
||||||
T array[Size];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ei_byte_forcing_aligned_malloc
|
struct ei_byte_forcing_aligned_malloc
|
||||||
{
|
{
|
||||||
unsigned char c; // sizeof must be 1.
|
unsigned char c; // sizeof must be 1.
|
||||||
|
@ -85,22 +85,16 @@ template<typename T> struct ei_unpacket_traits
|
|||||||
enum {size=1};
|
enum {size=1};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||||
template<typename Scalar, int Rows, int Cols, int StorageOrder, int MaxRows, int MaxCols>
|
|
||||||
class ei_compute_matrix_flags
|
class ei_compute_matrix_flags
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
row_major_bit = (Rows != 1 && Cols != 1) // if this is not a vector,
|
row_major_bit = Options&Matrix_RowMajor ? RowMajorBit : 0,
|
||||||
// then the storage order really matters,
|
|
||||||
// so let us strictly honor the user's choice.
|
|
||||||
? StorageOrder
|
|
||||||
: Cols > 1 ? RowMajorBit : 0,
|
|
||||||
inner_max_size = row_major_bit ? MaxCols : MaxRows,
|
inner_max_size = row_major_bit ? MaxCols : MaxRows,
|
||||||
is_big = inner_max_size == Dynamic,
|
is_big = inner_max_size == Dynamic,
|
||||||
is_packet_size_multiple = (Cols*Rows) % ei_packet_traits<Scalar>::size == 0,
|
is_packet_size_multiple = (Cols*Rows) % ei_packet_traits<Scalar>::size == 0,
|
||||||
packet_access_bit = ei_packet_traits<Scalar>::size > 1
|
aligned_bit = ((Options&Matrix_AutoAlign) && (is_big || is_packet_size_multiple)) ? AlignedBit : 0,
|
||||||
&& (is_big || is_packet_size_multiple) ? PacketAccessBit : 0,
|
packet_access_bit = ei_packet_traits<Scalar>::size > 1 && aligned_bit ? PacketAccessBit : 0
|
||||||
aligned_bit = packet_access_bit && (is_big || is_packet_size_multiple) ? AlignedBit : 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -123,7 +117,7 @@ template<typename T> struct ei_eval<T,IsDense>
|
|||||||
typedef Matrix<typename ei_traits<T>::Scalar,
|
typedef Matrix<typename ei_traits<T>::Scalar,
|
||||||
ei_traits<T>::RowsAtCompileTime,
|
ei_traits<T>::RowsAtCompileTime,
|
||||||
ei_traits<T>::ColsAtCompileTime,
|
ei_traits<T>::ColsAtCompileTime,
|
||||||
ei_traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor,
|
Matrix_AutoAlign | (ei_traits<T>::Flags&RowMajorBit ? Matrix_RowMajor : Matrix_ColMajor),
|
||||||
ei_traits<T>::MaxRowsAtCompileTime,
|
ei_traits<T>::MaxRowsAtCompileTime,
|
||||||
ei_traits<T>::MaxColsAtCompileTime
|
ei_traits<T>::MaxColsAtCompileTime
|
||||||
> type;
|
> type;
|
||||||
@ -144,7 +138,7 @@ template<typename T> struct ei_plain_matrix_type
|
|||||||
typedef Matrix<typename ei_traits<T>::Scalar,
|
typedef Matrix<typename ei_traits<T>::Scalar,
|
||||||
ei_traits<T>::RowsAtCompileTime,
|
ei_traits<T>::RowsAtCompileTime,
|
||||||
ei_traits<T>::ColsAtCompileTime,
|
ei_traits<T>::ColsAtCompileTime,
|
||||||
ei_traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor,
|
Matrix_AutoAlign | (ei_traits<T>::Flags&RowMajorBit ? Matrix_RowMajor : Matrix_ColMajor),
|
||||||
ei_traits<T>::MaxRowsAtCompileTime,
|
ei_traits<T>::MaxRowsAtCompileTime,
|
||||||
ei_traits<T>::MaxColsAtCompileTime
|
ei_traits<T>::MaxColsAtCompileTime
|
||||||
> type;
|
> type;
|
||||||
@ -157,7 +151,7 @@ template<typename T> struct ei_plain_matrix_type_column_major
|
|||||||
typedef Matrix<typename ei_traits<T>::Scalar,
|
typedef Matrix<typename ei_traits<T>::Scalar,
|
||||||
ei_traits<T>::RowsAtCompileTime,
|
ei_traits<T>::RowsAtCompileTime,
|
||||||
ei_traits<T>::ColsAtCompileTime,
|
ei_traits<T>::ColsAtCompileTime,
|
||||||
ColMajor,
|
Matrix_AutoAlign | Matrix_ColMajor,
|
||||||
ei_traits<T>::MaxRowsAtCompileTime,
|
ei_traits<T>::MaxRowsAtCompileTime,
|
||||||
ei_traits<T>::MaxColsAtCompileTime
|
ei_traits<T>::MaxColsAtCompileTime
|
||||||
> type;
|
> type;
|
||||||
|
@ -76,7 +76,7 @@ template<typename MatrixType> class LU
|
|||||||
MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix" is the number of cols of the original matrix
|
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
|
// so that the product "matrix * kernel = zero" makes sense
|
||||||
Dynamic, // we don't know at compile-time the dimension of the kernel
|
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, // see explanation for 2nd template parameter
|
||||||
MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, whose dimension is the number
|
MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, whose dimension is the number
|
||||||
// of columns of the original matrix
|
// of columns of the original matrix
|
||||||
@ -86,7 +86,7 @@ template<typename MatrixType> class LU
|
|||||||
MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose dimension is the number
|
MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose dimension is the number
|
||||||
// of rows of the original matrix
|
// of rows of the original matrix
|
||||||
Dynamic, // we don't know at compile time the dimension of the image (the rank)
|
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::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.
|
MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns.
|
||||||
> ImageResultType;
|
> ImageResultType;
|
||||||
@ -436,7 +436,7 @@ void LU<MatrixType>::computeKernel(KernelMatrixType *result) const
|
|||||||
* independent vectors in Ker U.
|
* independent vectors in Ker U.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Matrix<Scalar, Dynamic, Dynamic, MatrixType::StorageOrder,
|
Matrix<Scalar, Dynamic, Dynamic, MatrixType::Options,
|
||||||
MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime>
|
MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime>
|
||||||
y(-m_lu.corner(TopRight, m_rank, dimker));
|
y(-m_lu.corner(TopRight, m_rank, dimker));
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ bool LU<MatrixType>::solve(
|
|||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime,
|
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime,
|
||||||
MatrixType::StorageOrder,
|
MatrixType::Options,
|
||||||
MatrixType::MaxRowsAtCompileTime,
|
MatrixType::MaxRowsAtCompileTime,
|
||||||
MatrixType::MaxRowsAtCompileTime> l(rows, rows);
|
MatrixType::MaxRowsAtCompileTime> l(rows, rows);
|
||||||
l.setZero();
|
l.setZero();
|
||||||
@ -523,7 +523,7 @@ bool LU<MatrixType>::solve(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Matrix<Scalar, Dynamic, OtherDerived::ColsAtCompileTime,
|
Matrix<Scalar, Dynamic, OtherDerived::ColsAtCompileTime,
|
||||||
MatrixType::StorageOrder,
|
MatrixType::Options,
|
||||||
MatrixType::MaxRowsAtCompileTime, OtherDerived::MaxColsAtCompileTime>
|
MatrixType::MaxRowsAtCompileTime, OtherDerived::MaxColsAtCompileTime>
|
||||||
d(c.corner(TopLeft, m_rank, c.cols()));
|
d(c.corner(TopLeft, m_rank, c.cols()));
|
||||||
m_lu.corner(TopLeft, m_rank, m_rank)
|
m_lu.corner(TopLeft, m_rank, m_rank)
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
# - Try to find eigen2 headers
|
# - Try to find Eigen2 lib
|
||||||
# Once done this will define
|
# Once done this will define
|
||||||
#
|
#
|
||||||
# EIGEN2_FOUND - system has eigen2 lib
|
# EIGEN2_FOUND - system has eigen lib
|
||||||
# EIGEN2_INCLUDE_DIR - the eigen2 include directory
|
# EIGEN2_INCLUDE_DIR - the eigen include directory
|
||||||
#
|
|
||||||
# Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
|
||||||
# Adapted from FindEigen.cmake:
|
|
||||||
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
||||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||||
@ -19,13 +17,15 @@ else (EIGEN2_INCLUDE_DIR)
|
|||||||
|
|
||||||
find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core
|
find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core
|
||||||
PATHS
|
PATHS
|
||||||
${Eigen_SOURCE_DIR}/
|
|
||||||
${INCLUDE_INSTALL_DIR}
|
${INCLUDE_INSTALL_DIR}
|
||||||
|
${KDE4_INCLUDE_DIR}
|
||||||
|
PATH_SUFFIXES eigen2
|
||||||
)
|
)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
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)
|
mark_as_advanced(EIGEN2_INCLUDE_DIR)
|
||||||
|
|
||||||
endif(EIGEN2_INCLUDE_DIR)
|
endif(EIGEN2_INCLUDE_DIR)
|
||||||
|
@ -38,8 +38,8 @@ template<typename MatrixType> void determinant(const MatrixType& m)
|
|||||||
m2.setRandom();
|
m2.setRandom();
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
Scalar x = ei_random<Scalar>();
|
Scalar x = ei_random<Scalar>();
|
||||||
VERIFY(ei_isApprox(MatrixType::Identity(size, size).determinant(), Scalar(1)));
|
VERIFY_IS_APPROX(MatrixType::Identity(size, size).determinant(), Scalar(1));
|
||||||
VERIFY(ei_isApprox((m1*m2).determinant(), m1.determinant() * m2.determinant()));
|
VERIFY_IS_APPROX((m1*m2).determinant(), m1.determinant() * m2.determinant());
|
||||||
if(size==1) return;
|
if(size==1) return;
|
||||||
int i = ei_random<int>(0, size-1);
|
int i = ei_random<int>(0, size-1);
|
||||||
int j;
|
int j;
|
||||||
@ -48,18 +48,18 @@ template<typename MatrixType> void determinant(const MatrixType& m)
|
|||||||
} while(j==i);
|
} while(j==i);
|
||||||
m2 = m1;
|
m2 = m1;
|
||||||
m2.row(i).swap(m2.row(j));
|
m2.row(i).swap(m2.row(j));
|
||||||
VERIFY(ei_isApprox(m2.determinant(), -m1.determinant()));
|
VERIFY_IS_APPROX(m2.determinant(), -m1.determinant());
|
||||||
m2 = m1;
|
m2 = m1;
|
||||||
m2.col(i).swap(m2.col(j));
|
m2.col(i).swap(m2.col(j));
|
||||||
VERIFY(ei_isApprox(m2.determinant(), -m1.determinant()));
|
VERIFY_IS_APPROX(m2.determinant(), -m1.determinant());
|
||||||
VERIFY(ei_isApprox(m2.determinant(), m2.transpose().determinant()));
|
VERIFY_IS_APPROX(m2.determinant(), m2.transpose().determinant());
|
||||||
VERIFY(ei_isApprox(ei_conj(m2.determinant()), m2.adjoint().determinant()));
|
VERIFY_IS_APPROX(ei_conj(m2.determinant()), m2.adjoint().determinant());
|
||||||
m2 = m1;
|
m2 = m1;
|
||||||
m2.row(i) += x*m2.row(j);
|
m2.row(i) += x*m2.row(j);
|
||||||
VERIFY(ei_isApprox(m2.determinant(), m1.determinant()));
|
VERIFY_IS_APPROX(m2.determinant(), m1.determinant());
|
||||||
m2 = m1;
|
m2 = m1;
|
||||||
m2.row(i) *= x;
|
m2.row(i) *= x;
|
||||||
VERIFY(ei_isApprox(m2.determinant(), m1.determinant() * x));
|
VERIFY_IS_APPROX(m2.determinant(), m1.determinant() * x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_determinant()
|
void test_determinant()
|
||||||
@ -72,4 +72,5 @@ void test_determinant()
|
|||||||
CALL_SUBTEST( determinant(Matrix<std::complex<double>, 10, 10>()) );
|
CALL_SUBTEST( determinant(Matrix<std::complex<double>, 10, 10>()) );
|
||||||
CALL_SUBTEST( determinant(MatrixXd(20, 20)) );
|
CALL_SUBTEST( determinant(MatrixXd(20, 20)) );
|
||||||
}
|
}
|
||||||
|
CALL_SUBTEST( determinant(MatrixXd(200, 200)) );
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,12 @@ struct Good8 : Eigen::WithAlignedOperatorNew
|
|||||||
Matrix4f m;
|
Matrix4f m;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Good9
|
||||||
|
{
|
||||||
|
Matrix<float,2,2,Matrix_DontAlign> m; // good: no alignment requested
|
||||||
|
float f;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void check_unalignedassert_good()
|
void check_unalignedassert_good()
|
||||||
{
|
{
|
||||||
@ -80,7 +86,7 @@ void check_unalignedassert_good()
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void check_unalignedassert_bad()
|
void check_unalignedassert_bad()
|
||||||
{
|
{
|
||||||
float buf[1000];
|
float buf[sizeof(T)+16];
|
||||||
float *unaligned = buf;
|
float *unaligned = buf;
|
||||||
while((reinterpret_cast<size_t>(unaligned)&0xf)==0) ++unaligned; // make sure unaligned is really unaligned
|
while((reinterpret_cast<size_t>(unaligned)&0xf)==0) ++unaligned; // make sure unaligned is really unaligned
|
||||||
T *x = new(static_cast<void*>(unaligned)) T;
|
T *x = new(static_cast<void*>(unaligned)) T;
|
||||||
@ -97,6 +103,7 @@ void unalignedassert()
|
|||||||
VERIFY_RAISES_ASSERT(check_unalignedassert_bad<Bad6>());
|
VERIFY_RAISES_ASSERT(check_unalignedassert_bad<Bad6>());
|
||||||
check_unalignedassert_good<Good7>();
|
check_unalignedassert_good<Good7>();
|
||||||
check_unalignedassert_good<Good8>();
|
check_unalignedassert_good<Good8>();
|
||||||
|
check_unalignedassert_good<Good9>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_unalignedassert()
|
void test_unalignedassert()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user