remove all the _Order mechanics, now we are always traversing matrices in

column-major order, even if storage is row-major. Benchmark showed that adapting
the traversal order to the storage order brought no benefit.

Also do some cleanup after Gael's big patch.
This commit is contained in:
Benoit Jacob 2008-01-06 13:57:29 +00:00
parent 495eb7053a
commit aaf889e72b
25 changed files with 37 additions and 76 deletions

View File

@ -66,7 +66,6 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = BlockRows,
ColsAtCompileTime = BlockCols;

View File

@ -57,9 +57,8 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
Cast(const MatRef& matrix) : m_matrix(matrix) {}
private:
static const TraversalOrder _Order = MatrixType::Order;
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Cast& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }

View File

@ -62,7 +62,6 @@ template<typename MatrixType> class Column
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Column)
static const TraversalOrder Order = ColumnMajor;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = 1;

View File

@ -48,7 +48,6 @@ template<typename MatrixType> class Conjugate : NoOperatorEquals,
Conjugate(const MatRef& matrix) : m_matrix(matrix) {}
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -50,7 +50,6 @@ template<typename MatrixType> class DiagonalCoeffs
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs)
static const TraversalOrder Order = ColumnMajor;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = 1;

View File

@ -55,7 +55,6 @@ class DiagonalMatrix : NoOperatorEquals,
&& coeffs.size() > 0);
}
static const TraversalOrder Order = Indifferent;
static const int RowsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime,
ColsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime;

View File

@ -41,7 +41,6 @@ template<typename Lhs, typename Rhs> class Difference : NoOperatorEquals,
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
}
static const TraversalOrder Order = Lhs::Order;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
ColsAtCompileTime = Rhs::ColsAtCompileTime;

View File

@ -66,7 +66,6 @@ template<typename MatrixType> class DynBlock
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DynBlock)
static const TraversalOrder Order = MatrixType::Order;
static const int
RowsAtCompileTime = MatrixType::RowsAtCompileTime == 1 ? 1 : Dynamic,
ColsAtCompileTime = MatrixType::ColsAtCompileTime == 1 ? 1 : Dynamic;

View File

@ -33,20 +33,15 @@ template<typename MatrixType> class Identity : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Identity<MatrixType> >;
Identity(int rows) : m_rows(rows)
{
assert(rows > 0 && _RowsAtCompileTime == _ColsAtCompileTime);
}
static const TraversalOrder Order = Indifferent;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
Identity(int rows) : m_rows(rows)
{
assert(rows > 0 && RowsAtCompileTime == ColsAtCompileTime);
}
private:
static const TraversalOrder _Order = Indifferent;
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Identity& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_rows; }

View File

@ -46,9 +46,9 @@ template<typename MatrixType> class Map
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Map<MatrixType> >;
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
static const MatrixStorageOrder Order = MatrixType::Order;
private:
const Map& _ref() const { return *this; }
@ -88,7 +88,7 @@ template<typename MatrixType> class Map
};
/** This is the const version of map(Scalar*,int,int). */
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int rows, int cols)
{
@ -96,7 +96,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int rows,
}
/** This is the const version of map(Scalar*,int). */
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int size)
{
@ -108,7 +108,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int size)
}
/** This is the const version of map(Scalar*). */
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data)
{
@ -126,7 +126,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data)
*
* \sa map(const Scalar*, int, int), map(Scalar*, int), map(Scalar*), class Map
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int rows, int cols)
{
@ -145,7 +145,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int rows, int co
*
* \sa map(const Scalar*, int), map(Scalar*, int, int), map(Scalar*), class Map
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int size)
{
@ -165,7 +165,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int size)
*
* \sa map(const Scalar*), map(Scalar*, int), map(Scalar*, int, int), class Map
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data)
{
@ -180,7 +180,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data)
*
* \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int, int)
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data, int rows, int cols)
: Storage(rows, cols)
@ -198,7 +198,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
*
* \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int)
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data, int size)
: Storage(size)
@ -216,7 +216,7 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
* \sa Matrix(const Scalar *, int), Matrix(const Scalar *, int, int),
* Matrix::map(const Scalar *)
*/
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data)
: Storage()

View File

@ -73,7 +73,7 @@
* MatrixStorage also provides the MatrixStorage::resize() public method.
*/
template<typename _Scalar, int _Rows, int _Cols,
TraversalOrder _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER>
MatrixStorageOrder _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER>
class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >,
public MatrixStorage<_Scalar, _Rows, _Cols>
{
@ -91,7 +91,7 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
Scalar* data()
{ return Storage::m_data; }
static const TraversalOrder Order = _StorageOrder;
static const MatrixStorageOrder Order = _StorageOrder;
static const int RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols;
private:

View File

@ -31,8 +31,6 @@
template <typename Derived>
struct DerivedTraits
{
static const TraversalOrder Order = Derived::Order;
/** The number of rows at compile-time. This is just a copy of the value provided
* by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant.

View File

@ -38,7 +38,6 @@ template<typename MatrixType> class MatrixRef
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRef)
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -56,7 +56,6 @@ template<typename MatrixType> class Minor
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Minor)
static const TraversalOrder Order = MatrixType::Order;
static const int
RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ?
MatrixType::RowsAtCompileTime - 1 : Dynamic,

View File

@ -39,7 +39,6 @@ template<typename MatrixType> class Ones : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Ones<MatrixType> >;
static const TraversalOrder Order = Indifferent;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -27,25 +27,21 @@
#ifndef EIGEN_OPERATOREQUALS_H
#define EIGEN_OPERATOREQUALS_H
template<typename Derived1, typename Derived2, int UnrollCount, TraversalOrder Order>
template<typename Derived1, typename Derived2, int UnrollCount>
struct MatrixOperatorEqualsUnroller
{
static const int col = (Order == ColumnMajor)
? (UnrollCount-1) / Derived1::RowsAtCompileTime
: (UnrollCount-1) % Derived1::ColsAtCompileTime;
static const int row = (Order == ColumnMajor)
? (UnrollCount-1) % Derived1::RowsAtCompileTime
: (UnrollCount-1) / Derived1::ColsAtCompileTime;
static const int col = (UnrollCount-1) / Derived1::RowsAtCompileTime;
static const int row = (UnrollCount-1) % Derived1::RowsAtCompileTime;
static void run(Derived1 &dst, const Derived2 &src)
{
MatrixOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1, Order>::run(dst, src);
MatrixOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1>::run(dst, src);
dst.coeffRef(row, col) = src.coeff(row, col);
}
};
template<typename Derived1, typename Derived2, TraversalOrder Order>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 1, Order>
template<typename Derived1, typename Derived2>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 1>
{
static void run(Derived1 &dst, const Derived2 &src)
{
@ -54,14 +50,14 @@ struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 1, Order>
};
// prevent buggy user code from causing an infinite recursion
template<typename Derived1, typename Derived2, TraversalOrder Order>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 0, Order>
template<typename Derived1, typename Derived2>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 0>
{
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2, TraversalOrder Order>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, Dynamic, Order>
template<typename Derived1, typename Derived2>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, Dynamic>
{
static void run(Derived1 &, const Derived2 &) {}
};
@ -123,19 +119,12 @@ Derived& MatrixBase<Scalar, Derived>
assert(rows() == other.rows() && cols() == other.cols());
if(EIGEN_UNROLLED_LOOPS && Traits::SizeAtCompileTime != Dynamic && Traits::SizeAtCompileTime <= 25)
MatrixOperatorEqualsUnroller
<Derived, OtherDerived, Traits::SizeAtCompileTime, Traits::Order>::run
<Derived, OtherDerived, Traits::SizeAtCompileTime>::run
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
else
{
if(Traits::Order == ColumnMajor)
for(int j = 0; j < cols(); j++)
for(int i = 0; i < rows(); i++)
coeffRef(i, j) = other.coeff(i, j);
else // RowMajor
for(int j = 0; j < cols(); j++)
for(int i = 0; i < rows(); i++)
for(int j = 0; j < cols(); j++)
coeffRef(i, j) = other.coeff(i, j);
}
coeffRef(i, j) = other.coeff(i, j);
return *static_cast<Derived*>(this);
}
}

View File

@ -36,7 +36,6 @@ template<typename MatrixType> class Opposite : NoOperatorEquals,
Opposite(const MatRef& matrix) : m_matrix(matrix) {}
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -75,7 +75,6 @@ template<typename Lhs, typename Rhs> class Product : NoOperatorEquals,
assert(lhs.cols() == rhs.rows());
}
static const TraversalOrder Order = Lhs::Order;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
ColsAtCompileTime = Rhs::ColsAtCompileTime;

View File

@ -39,7 +39,6 @@ template<typename MatrixType> class Random : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Random<MatrixType> >;
static const TraversalOrder Order = Indifferent;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -68,7 +68,6 @@ template<typename MatrixType> class Row
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Row)
static const TraversalOrder Order = RowMajor;
static const int RowsAtCompileTime = 1,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -37,7 +37,6 @@ template<typename FactorType, typename MatrixType> class ScalarMultiple : NoOper
ScalarMultiple(const MatRef& matrix, FactorType factor)
: m_matrix(matrix), m_factor(factor) {}
static const TraversalOrder Order = MatrixType::Order;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;

View File

@ -41,7 +41,6 @@ template<typename Lhs, typename Rhs> class Sum : NoOperatorEquals,
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
}
static const TraversalOrder Order = Lhs::Order;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
ColsAtCompileTime = Rhs::ColsAtCompileTime;

View File

@ -50,8 +50,6 @@ template<typename MatrixType> class Transpose
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
static const TraversalOrder Order = (MatrixType::Order == ColumnMajor)
? RowMajor : ColumnMajor;
static const int RowsAtCompileTime = MatrixType::ColsAtCompileTime,
ColsAtCompileTime = MatrixType::RowsAtCompileTime;

View File

@ -33,7 +33,7 @@
#endif
#ifndef EIGEN_DEFAULT_MATRIX_STORAGE_ORDER
#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER Indifferent
#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER ColumnMajor
#endif
#undef minor
@ -88,15 +88,14 @@ EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
const int Dynamic = -1;
enum TraversalOrder
enum MatrixStorageOrder
{
ColumnMajor,
RowMajor,
Indifferent = ColumnMajor
RowMajor
};
//forward declarations
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
class Matrix;
template<typename MatrixType> class MatrixRef;
template<typename NewScalar, typename MatrixType> class Cast;
@ -126,7 +125,7 @@ template<typename T> struct ForwardDecl
typedef T Ref;
};
template<typename _Scalar, int _Rows, int _Cols, TraversalOrder _StorageOrder>
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
struct ForwardDecl<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
{
typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> > Ref;

View File

@ -39,7 +39,6 @@ template<typename MatrixType> class Zero : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Zero<MatrixType> >;
static const TraversalOrder Order = Indifferent;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;