aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-01-13 19:55:23 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-01-13 19:55:23 +0000
commit89a134ba0b40b7cfc4554e3f06813fd32bbe2ede (patch)
tree2d0aa14b49b6b80802371f6bb5ac8ee6360d87d1
parente05a1aba1d83a7286e48576a053276c16633a7f1 (diff)
big architecture change dissociating "actual" dimensions from "maximum possible"
dimension. The advantage is that evaluating a dynamic-sized block in a fixed-size matrix no longer causes a dynamic memory allocation. Other new thing: IntAtRunTimeIfDynamic allows storing an integer at zero cost if it is known at compile time.
-rw-r--r--Eigen/Core1
-rw-r--r--Eigen/src/Core/Block.h4
-rw-r--r--Eigen/src/Core/Cast.h4
-rw-r--r--Eigen/src/Core/Column.h4
-rw-r--r--Eigen/src/Core/Conjugate.h4
-rw-r--r--Eigen/src/Core/DiagonalCoeffs.h10
-rw-r--r--Eigen/src/Core/DiagonalMatrix.h4
-rw-r--r--Eigen/src/Core/Difference.h4
-rw-r--r--Eigen/src/Core/DynBlock.h4
-rw-r--r--Eigen/src/Core/Eval.h9
-rw-r--r--Eigen/src/Core/ForwardDeclarations.h8
-rw-r--r--Eigen/src/Core/Identity.h11
-rw-r--r--Eigen/src/Core/Map.h59
-rw-r--r--Eigen/src/Core/Matrix.h136
-rw-r--r--Eigen/src/Core/MatrixBase.h36
-rw-r--r--Eigen/src/Core/MatrixRef.h4
-rw-r--r--Eigen/src/Core/MatrixStorage.h183
-rw-r--r--Eigen/src/Core/Minor.h6
-rw-r--r--Eigen/src/Core/Ones.h11
-rw-r--r--Eigen/src/Core/Opposite.h4
-rw-r--r--Eigen/src/Core/Product.h4
-rw-r--r--Eigen/src/Core/Random.h11
-rw-r--r--Eigen/src/Core/Row.h4
-rw-r--r--Eigen/src/Core/ScalarMultiple.h4
-rw-r--r--Eigen/src/Core/Sum.h4
-rw-r--r--Eigen/src/Core/Transpose.h4
-rw-r--r--Eigen/src/Core/Util.h22
-rw-r--r--Eigen/src/Core/Zero.h11
-rw-r--r--doc/benchmark.cpp2
29 files changed, 280 insertions, 292 deletions
diff --git a/Eigen/Core b/Eigen/Core
index 6c2589957..b1aaa8774 100644
--- a/Eigen/Core
+++ b/Eigen/Core
@@ -12,7 +12,6 @@ namespace Eigen {
#include "src/Core/Coeffs.h"
#include "src/Core/OperatorEquals.h"
#include "src/Core/MatrixRef.h"
-#include "src/Core/MatrixStorage.h"
#include "src/Core/Matrix.h"
#include "src/Core/Cast.h"
#include "src/Core/Eval.h"
diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h
index 45a1eb707..22410b9be 100644
--- a/Eigen/src/Core/Block.h
+++ b/Eigen/src/Core/Block.h
@@ -69,7 +69,9 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
private:
enum{
RowsAtCompileTime = BlockRows,
- ColsAtCompileTime = BlockCols
+ ColsAtCompileTime = BlockCols,
+ MaxRowsAtCompileTime = BlockRows,
+ MaxColsAtCompileTime = BlockCols
};
const Block& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Cast.h b/Eigen/src/Core/Cast.h
index fb90217f8..433be3ad7 100644
--- a/Eigen/src/Core/Cast.h
+++ b/Eigen/src/Core/Cast.h
@@ -59,7 +59,9 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Cast& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
diff --git a/Eigen/src/Core/Column.h b/Eigen/src/Core/Column.h
index 5265bcbb1..bb92c3b11 100644
--- a/Eigen/src/Core/Column.h
+++ b/Eigen/src/Core/Column.h
@@ -65,7 +65,9 @@ template<typename MatrixType> class Column
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = 1
+ ColsAtCompileTime = 1,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = 1
};
const Column& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Conjugate.h b/Eigen/src/Core/Conjugate.h
index c36a64eff..16cebccb6 100644
--- a/Eigen/src/Core/Conjugate.h
+++ b/Eigen/src/Core/Conjugate.h
@@ -51,7 +51,9 @@ template<typename MatrixType> class Conjugate : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Conjugate& _ref() const { return *this; }
diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h
index bd8ac2c8b..80f402305 100644
--- a/Eigen/src/Core/DiagonalCoeffs.h
+++ b/Eigen/src/Core/DiagonalCoeffs.h
@@ -52,8 +52,14 @@ template<typename MatrixType> class DiagonalCoeffs
private:
enum {
- RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = 1
+ RowsAtCompileTime = MatrixType::Traits::SizeAtCompileTime == Dynamic ? Dynamic
+ : EIGEN_ENUM_MIN(MatrixType::Traits::RowsAtCompileTime,
+ MatrixType::Traits::ColsAtCompileTime),
+ ColsAtCompileTime = 1,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxSizeAtCompileTime == Dynamic ? Dynamic
+ : EIGEN_ENUM_MIN(MatrixType::Traits::MaxRowsAtCompileTime,
+ MatrixType::Traits::MaxColsAtCompileTime),
+ MaxColsAtCompileTime = 1
};
const DiagonalCoeffs& _ref() const { return *this; }
diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h
index c1031d032..7c55db920 100644
--- a/Eigen/src/Core/DiagonalMatrix.h
+++ b/Eigen/src/Core/DiagonalMatrix.h
@@ -58,7 +58,9 @@ class DiagonalMatrix : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime,
- ColsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime
+ ColsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime,
+ MaxRowsAtCompileTime = CoeffsVectorType::Traits::MaxSizeAtCompileTime,
+ MaxColsAtCompileTime = CoeffsVectorType::Traits::MaxSizeAtCompileTime
};
const DiagonalMatrix& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Difference.h b/Eigen/src/Core/Difference.h
index ae4424a75..99cf5674f 100644
--- a/Eigen/src/Core/Difference.h
+++ b/Eigen/src/Core/Difference.h
@@ -57,7 +57,9 @@ template<typename Lhs, typename Rhs> class Difference : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = Lhs::Traits::RowsAtCompileTime,
- ColsAtCompileTime = Rhs::Traits::ColsAtCompileTime
+ ColsAtCompileTime = Lhs::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = Lhs::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = Lhs::Traits::MaxColsAtCompileTime
};
const Difference& _ref() const { return *this; }
diff --git a/Eigen/src/Core/DynBlock.h b/Eigen/src/Core/DynBlock.h
index 7291314d9..3c863bb80 100644
--- a/Eigen/src/Core/DynBlock.h
+++ b/Eigen/src/Core/DynBlock.h
@@ -69,7 +69,9 @@ template<typename MatrixType> class DynBlock
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime == 1 ? 1 : Dynamic,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime == 1 ? 1 : Dynamic
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime == 1 ? 1 : Dynamic,
+ MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 : MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 : MatrixType::Traits::MaxColsAtCompileTime
};
const DynBlock& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Eval.h b/Eigen/src/Core/Eval.h
index 7fa661c48..abb8cafcd 100644
--- a/Eigen/src/Core/Eval.h
+++ b/Eigen/src/Core/Eval.h
@@ -48,11 +48,16 @@
template<typename Expression> class Eval : NoOperatorEquals,
public Matrix< typename Expression::Scalar,
Expression::Traits::RowsAtCompileTime,
- Expression::Traits::ColsAtCompileTime >
+ Expression::Traits::ColsAtCompileTime,
+ EIGEN_DEFAULT_MATRIX_STORAGE_ORDER,
+ Expression::Traits::MaxRowsAtCompileTime,
+ Expression::Traits::MaxColsAtCompileTime>
{
public:
typedef typename Expression::Scalar Scalar;
- typedef Matrix<Scalar, Expression::Traits::RowsAtCompileTime, Expression::Traits::ColsAtCompileTime> MatrixType;
+ typedef Matrix<Scalar, Expression::Traits::RowsAtCompileTime, Expression::Traits::ColsAtCompileTime, EIGEN_DEFAULT_MATRIX_STORAGE_ORDER,
+ Expression::Traits::MaxRowsAtCompileTime,
+ Expression::Traits::MaxColsAtCompileTime> MatrixType;
typedef Expression Base;
friend class MatrixBase<Scalar, Expression>;
diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h
index ea5d0dd36..07c6e3f69 100644
--- a/Eigen/src/Core/ForwardDeclarations.h
+++ b/Eigen/src/Core/ForwardDeclarations.h
@@ -26,7 +26,7 @@
#ifndef EIGEN_FORWARDDECLARATIONS_H
#define EIGEN_FORWARDDECLARATIONS_H
-template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder> class Matrix;
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> class Matrix;
template<typename MatrixType> class MatrixRef;
template<typename NewScalar, typename MatrixType> class Cast;
template<typename MatrixType> class Row;
@@ -55,10 +55,10 @@ template<typename T> struct Reference
typedef T Type;
};
-template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder>
-struct Reference<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+struct Reference<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
{
- typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> > Type;
+ typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > Type;
};
#endif // EIGEN_FORWARDDECLARATIONS_H
diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h
index 77c7c3efe..f5b4edcfc 100644
--- a/Eigen/src/Core/Identity.h
+++ b/Eigen/src/Core/Identity.h
@@ -50,12 +50,14 @@ template<typename MatrixType> class Identity : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Identity& _ref() const { return *this; }
- int _rows() const { return m_rows; }
- int _cols() const { return m_cols; }
+ int _rows() const { return m_rows.value(); }
+ int _cols() const { return m_cols.value(); }
Scalar _coeff(int row, int col) const
{
@@ -63,7 +65,8 @@ template<typename MatrixType> class Identity : NoOperatorEquals,
}
protected:
- const int m_rows, m_cols;
+ const IntAtRunTimeIfDynamic<RowsAtCompileTime> m_rows;
+ const IntAtRunTimeIfDynamic<ColsAtCompileTime> m_cols;
};
/** \returns an expression of the identity matrix (not necessarily square).
diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h
index 28ab3f657..6b342491d 100644
--- a/Eigen/src/Core/Map.h
+++ b/Eigen/src/Core/Map.h
@@ -50,7 +50,9 @@ template<typename MatrixType> class Map
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
- Order = MatrixType::StorageOrder
+ Order = MatrixType::StorageOrder,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Map& _ref() const { return *this; }
@@ -90,17 +92,17 @@ template<typename MatrixType> class Map
};
/** This is the const version of map(Scalar*,int,int). */
-template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder>
-const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int rows, int cols)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int rows, int cols)
{
return Map<Matrix>(data, rows, cols);
}
/** This is the const version of map(Scalar*,int). */
-template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder>
-const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int size)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int size)
{
assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1)
@@ -110,9 +112,9 @@ 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, int _StorageOrder>
-const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data)
{
return Map<Matrix>(data, _Rows, _Cols);
}
@@ -128,9 +130,9 @@ 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, int _StorageOrder>
-Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int rows, int cols)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int rows, int cols)
{
return Map<Matrix>(data, rows, cols);
}
@@ -147,9 +149,9 @@ 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, int _StorageOrder>
-Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int size)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int size)
{
assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1)
@@ -167,9 +169,9 @@ 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, int _StorageOrder>
-Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data)
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data)
{
return Map<Matrix>(data, _Rows, _Cols);
}
@@ -182,10 +184,10 @@ 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, int _StorageOrder>
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>
::Matrix(const Scalar *data, int rows, int cols)
- : Storage(rows, cols)
+ : m_rows(rows), m_cols(cols), m_array(rows*cols)
{
*this = map(data, rows, cols);
}
@@ -200,10 +202,12 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
*
* \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int)
*/
-template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder>
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>
::Matrix(const Scalar *data, int size)
- : Storage(size)
+ : m_rows(RowsAtCompileTime == 1 ? 1 : size),
+ m_cols(ColsAtCompileTime == 1 ? 1 : size),
+ m_array(size)
{
*this = map(data, size);
}
@@ -218,10 +222,9 @@ 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, int _StorageOrder>
-Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
+template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
+Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>
::Matrix(const Scalar *data)
- : Storage()
{
*this = map(data);
}
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index fc80959a8..6a1d22fda 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -26,6 +26,32 @@
#ifndef EIGEN_MATRIX_H
#define EIGEN_MATRIX_H
+template<typename T, int Size> class Array
+{
+ T m_data[Size];
+ public:
+ Array() {}
+ explicit Array(int) {}
+ void resize(int) {}
+ const T *data() const { return m_data; }
+ T *data() { return m_data; }
+};
+
+template<typename T> class Array<T, Dynamic>
+{
+ T *m_data;
+ public:
+ explicit Array(int size) : m_data(new T[size]) {}
+ ~Array() { delete[] m_data; }
+ void resize(int size)
+ {
+ delete[] m_data;
+ m_data = new T[size];
+ }
+ const T *data() const { return m_data; }
+ T *data() { return m_data; }
+};
+
/** \class Matrix
*
* \brief The matrix class, also used for vectors and row-vectors
@@ -69,58 +95,81 @@
* fixed-size matrix with 3 rows and 5 columns, there is no typedef for that, so you should use
* \c Matrix<double,3,5>.
*
- * Note that most of the API is in the base class MatrixBase, and that the base class
- * MatrixStorage also provides the MatrixStorage::resize() public method.
+ * Note that most of the API is in the base class MatrixBase.
*/
template<typename _Scalar, int _Rows, int _Cols,
- int _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER>
-class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >,
- public MatrixStorage<_Scalar, _Rows, _Cols>
+ int _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER,
+ int _MaxRows = _Rows, int _MaxCols = _Cols>
+class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols,
+ _StorageOrder, _MaxRows, _MaxCols> >
{
public:
friend class MatrixBase<_Scalar, Matrix>;
friend class Map<Matrix>;
typedef MatrixBase<_Scalar, Matrix> Base;
- typedef MatrixStorage<_Scalar, _Rows, _Cols> Storage;
typedef _Scalar Scalar;
typedef MatrixRef<Matrix> Ref;
friend class MatrixRef<Matrix>;
-
- /** \returns a const pointer to the data array of this matrix */
- const Scalar* data() const
- { return Storage::m_data; }
-
- /** \returns a pointer to the data array of this matrix */
- Scalar* data()
- { return Storage::m_data; }
-
+
private:
enum {
RowsAtCompileTime = _Rows,
ColsAtCompileTime = _Cols,
- StorageOrder = _StorageOrder
+ StorageOrder = _StorageOrder,
+ MaxRowsAtCompileTime = _MaxRows,
+ MaxColsAtCompileTime = _MaxCols,
+ MaxSizeAtCompileTime = _MaxRows == Dynamic || _MaxCols == Dynamic
+ ? Dynamic
+ : _MaxRows * _MaxCols
};
+ IntAtRunTimeIfDynamic<RowsAtCompileTime> m_rows;
+ IntAtRunTimeIfDynamic<ColsAtCompileTime> m_cols;
+ Array<Scalar, MaxSizeAtCompileTime> m_array;
+
Ref _ref() const { return Ref(*this); }
+ int _rows() const { return m_rows.value(); }
+ int _cols() const { return m_cols.value(); }
const Scalar& _coeff(int row, int col) const
{
- if(_StorageOrder == ColumnMajor)
- return (Storage::m_data)[row + col * Storage::_rows()];
+ if(StorageOrder == ColumnMajor)
+ return m_array.data()[row + col * m_rows.value()];
else // RowMajor
- return (Storage::m_data)[col + row * Storage::_cols()];
+ return m_array.data()[col + row * m_cols.value()];
}
Scalar& _coeffRef(int row, int col)
{
- if(_StorageOrder == ColumnMajor)
- return (Storage::m_data)[row + col * Storage::_rows()];
+ if(StorageOrder == ColumnMajor)
+ return m_array.data()[row + col * m_rows.value()];
else // RowMajor
- return (Storage::m_data)[col + row * Storage::_cols()];
+ return m_array.data()[col + row * m_cols.value()];
}
public:
+ /** \returns a const pointer to the data array of this matrix */
+ const Scalar *data() const
+ { return m_array.data(); }
+
+ /** \returns a pointer to the data array of this matrix */
+ Scalar *data()
+ { return m_array.data(); }
+
+ void resize(int rows, int cols)
+ {
+ assert(rows > 0
+ && (MaxRowsAtCompileTime == Dynamic || MaxRowsAtCompileTime >= rows)
+ && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
+ && cols > 0
+ && (MaxColsAtCompileTime == Dynamic || MaxColsAtCompileTime >= cols)
+ && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
+ m_rows.setValue(rows);
+ m_cols.setValue(cols);
+ m_array.resize(rows * cols);
+ }
+
/** Copies the value of the expression \a other into *this.
*
* *this is resized (if possible) to match the dimensions of \a other.
@@ -170,7 +219,7 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
* For dynamic-size matrices and vectors, this constructor is forbidden (guarded by
* an assertion) because it would leave the matrix without an allocated data buffer.
*/
- explicit Matrix() : Storage()
+ explicit Matrix()
{
assert(RowsAtCompileTime > 0 && ColsAtCompileTime > 0);
}
@@ -181,7 +230,9 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
* it is redundant to pass the dimension here, so it makes more sense to use the default
* constructor Matrix() instead.
*/
- explicit Matrix(int dim) : Storage(dim)
+ explicit Matrix(int dim) : m_rows(RowsAtCompileTime == 1 ? 1 : dim),
+ m_cols(ColsAtCompileTime == 1 ? 1 : dim),
+ m_array(dim)
{
assert(dim > 0);
assert((RowsAtCompileTime == 1
@@ -200,13 +251,13 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
* it is redundant to pass these parameters, so one should use the default constructor
* Matrix() instead.
*/
- Matrix(int x, int y) : Storage(x, y)
+ Matrix(int x, int y) : m_rows(x), m_cols(y), m_array(x*y)
{
if((RowsAtCompileTime == 1 && ColsAtCompileTime == 2)
|| (RowsAtCompileTime == 2 && ColsAtCompileTime == 1))
{
- (Storage::m_data)[0] = x;
- (Storage::m_data)[1] = y;
+ m_array.data()[0] = x;
+ m_array.data()[1] = y;
}
else
{
@@ -219,35 +270,35 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
{
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2)
|| (RowsAtCompileTime == 2 && ColsAtCompileTime == 1));
- (Storage::m_data)[0] = x;
- (Storage::m_data)[1] = y;
+ m_array.data()[0] = x;
+ m_array.data()[1] = y;
}
/** constructs an initialized 2D vector with given coefficients */
Matrix(const double& x, const double& y)
{
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2)
|| (RowsAtCompileTime == 2 && ColsAtCompileTime == 1));
- (Storage::m_data)[0] = x;
- (Storage::m_data)[1] = y;
+ m_array.data()[0] = x;
+ m_array.data()[1] = y;
}
/** constructs an initialized 3D vector with given coefficients */
Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
{
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 3)
|| (RowsAtCompileTime == 3 && ColsAtCompileTime == 1));
- (Storage::m_data)[0] = x;
- (Storage::m_data)[1] = y;
- (Storage::m_data)[2] = z;
+ m_array.data()[0] = x;
+ m_array.data()[1] = y;
+ m_array.data()[2] = z;
}
/** constructs an initialized 4D vector with given coefficients */
Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
{
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 4)
|| (RowsAtCompileTime == 4 && ColsAtCompileTime == 1));
- (Storage::m_data)[0] = x;
- (Storage::m_data)[1] = y;
- (Storage::m_data)[2] = z;
- (Storage::m_data)[3] = w;
+ m_array.data()[0] = x;
+ m_array.data()[1] = y;
+ m_array.data()[2] = z;
+ m_array.data()[3] = w;
}
Matrix(const Scalar *data, int rows, int cols);
Matrix(const Scalar *data, int size);
@@ -256,12 +307,17 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
/** Constructor copying the value of the expression \a other */
template<typename OtherDerived>
Matrix(const MatrixBase<Scalar, OtherDerived>& other)
- : Storage(other.rows(), other.cols())
+ : m_rows(other.rows()),
+ m_cols(other.cols()),
+ m_array(other.rows() * other.cols())
{
*this = other;
}
/** Copy constructor */
- Matrix(const Matrix& other) : Storage(other.rows(), other.cols())
+ Matrix(const Matrix& other)
+ : m_rows(other.rows()),
+ m_cols(other.cols()),
+ m_array(other.rows() * other.cols())
{
*this = other;
}
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index 2fd2bb86c..6dd9d00b0 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -79,7 +79,43 @@ template<typename Scalar, typename Derived> class MatrixBase
= Derived::RowsAtCompileTime == Dynamic || Derived::ColsAtCompileTime == Dynamic
? Dynamic : Derived::RowsAtCompileTime * Derived::ColsAtCompileTime
};
+
+ /** This value is equal to the maximum possible number of rows that this expression
+ * might have. If this expression might have an arbitrarily high number of rows,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
+ */
+ enum { MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime };
+
+ /** This value is equal to the maximum possible number of columns that this expression
+ * might have. If this expression might have an arbitrarily high number of columns,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
+ */
+ enum { MaxColsAtCompileTime = Derived::MaxColsAtCompileTime };
+ /** This value is equal to the maximum possible number of coefficients that this expression
+ * might have. If this expression might have an arbitrarily high number of coefficients,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
+ */
+ enum { MaxSizeAtCompileTime
+ = Derived::MaxRowsAtCompileTime == Dynamic || Derived::MaxColsAtCompileTime == Dynamic
+ ? Dynamic : Derived::MaxRowsAtCompileTime * Derived::MaxColsAtCompileTime
+ };
+
/** This is set to true if either the number of rows or the number of
* columns is known at compile-time to be equal to 1. Indeed, in that case,
* we are dealing with a column-vector (if there is only one column) or with
diff --git a/Eigen/src/Core/MatrixRef.h b/Eigen/src/Core/MatrixRef.h
index ce097fd3b..ae5c6d1a7 100644
--- a/Eigen/src/Core/MatrixRef.h
+++ b/Eigen/src/Core/MatrixRef.h
@@ -41,7 +41,9 @@ template<typename MatrixType> class MatrixRef
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
int _rows() const { return m_matrix.rows(); }
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
deleted file mode 100644
index ebeaf4922..000000000
--- a/Eigen/src/Core/MatrixStorage.h
+++ /dev/null
@@ -1,183 +0,0 @@
-// This file is part of Eigen, a lightweight C++ template library
-// for linear algebra. Eigen itself is part of the KDE project.
-//
-// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
-//
-// Eigen is free software; 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 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 General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along
-// with Eigen; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// As a special exception, if other files instantiate templates or use macros
-// or functions from this file, or you compile this file and link it
-// with other works to produce a work based on this file, this file does not
-// by itself cause the resulting work to be covered by the GNU General Public
-// License. This exception does not invalidate any other reasons why a work
-// based on this file might be covered by the GNU General Public License.
-
-#ifndef EIGEN_MATRIXSTORAGE_H
-#define EIGEN_MATRIXSTORAGE_H
-
-template<typename Scalar,
- int RowsAtCompileTime,
- int ColsAtCompileTime>
-class MatrixStorage
-{
- protected:
- Scalar m_data[RowsAtCompileTime * ColsAtCompileTime];
-
- void resize(int rows, int cols)
- {
- EIGEN_ONLY_USED_FOR_DEBUG(rows);
- EIGEN_ONLY_USED_FOR_DEBUG(cols);
- assert(rows == RowsAtCompileTime && cols == ColsAtCompileTime);
- }
-
- int _rows() const
- { return RowsAtCompileTime; }
-
- int _cols() const
- { return ColsAtCompileTime; }
-
- public:
- MatrixStorage() {}
- MatrixStorage(int) {}
- MatrixStorage(int, int) {}
- ~MatrixStorage() {};
-};
-
-template<typename Scalar, int ColsAtCompileTime>
-class MatrixStorage<Scalar, Dynamic, ColsAtCompileTime>
-{
- protected:
- int m_rows;
- Scalar* m_data;
-
- void resize(int rows, int cols)
- {
- EIGEN_ONLY_USED_FOR_DEBUG(cols);
- assert(rows > 0 && cols == ColsAtCompileTime);
- if(rows > m_rows)
- {
- delete[] m_data;
- m_data = new Scalar[rows * ColsAtCompileTime];
- }
- m_rows = rows;
- }
-
- int _rows() const
- { return m_rows; }
-
- int _cols() const
- { return ColsAtCompileTime; }
-
- public:
- MatrixStorage(int dim) : m_rows(dim)
- {
- m_data = new Scalar[m_rows * ColsAtCompileTime];
- }
-
- MatrixStorage(int rows, int) : m_rows(rows)
- {
- m_data = new Scalar[m_rows * ColsAtCompileTime];
- }
-
- ~MatrixStorage()
- { delete[] m_data; }
-
- private:
- MatrixStorage();
-};
-
-template<typename Scalar, int RowsAtCompileTime>
-class MatrixStorage<Scalar, RowsAtCompileTime, Dynamic>
-{
- protected:
- int m_cols;
- Scalar* m_data;
-
- void resize(int rows, int cols)
- {
- EIGEN_ONLY_USED_FOR_DEBUG(rows);
- assert(rows == RowsAtCompileTime && cols > 0);
- if(cols > m_cols)
- {
- delete[] m_data;
- m_data = new Scalar[cols * RowsAtCompileTime];
- }
- m_cols = cols;
- }
-
- int _rows() const
- { return RowsAtCompileTime; }
-
- int _cols() const
- { return m_cols; }
-
- public:
- MatrixStorage(int dim) : m_cols(dim)
- {
- m_data = new Scalar[m_cols * RowsAtCompileTime];
- }
-
- MatrixStorage(int, int cols) : m_cols(cols)
- {
- m_data = new Scalar[m_cols * RowsAtCompileTime];
- }
-
- ~MatrixStorage()
- { delete[] m_data; }
-
- private:
- MatrixStorage();
-};
-
-template<typename Scalar>
-class MatrixStorage<Scalar, Dynamic, Dynamic>
-{
- protected:
- int m_rows, m_cols;
- Scalar* m_data;
-
- void resize(int rows, int cols)
- {
- assert(rows > 0 && cols > 0);
- if(rows * cols > m_rows * m_cols)
- {
- delete[] m_data;
- m_data = new Scalar[rows * cols];
- }
- m_rows = rows;
- m_cols = cols;
- }
-
- int _rows() const
- { return m_rows; }
-
- int _cols() const
- { return m_cols; }
-
- public:
-
- MatrixStorage(int rows, int cols) : m_rows(rows), m_cols(cols)
- {
- m_data = new Scalar[m_rows * m_cols];
- }
-
- ~MatrixStorage()
- { delete[] m_data; }
-
- private:
- MatrixStorage();
- MatrixStorage(int dim);
-};
-
-#endif // EIGEN_MATRIXSTORAGE_H
diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h
index 84419c8f6..1e50f039e 100644
--- a/Eigen/src/Core/Minor.h
+++ b/Eigen/src/Core/Minor.h
@@ -61,7 +61,11 @@ template<typename MatrixType> class Minor
RowsAtCompileTime = (MatrixType::Traits::RowsAtCompileTime != Dynamic) ?
MatrixType::Traits::RowsAtCompileTime - 1 : Dynamic,
ColsAtCompileTime = (MatrixType::Traits::ColsAtCompileTime != Dynamic) ?
- MatrixType::Traits::ColsAtCompileTime - 1 : Dynamic
+ MatrixType::Traits::ColsAtCompileTime - 1 : Dynamic,
+ MaxRowsAtCompileTime = (MatrixType::Traits::MaxRowsAtCompileTime != Dynamic) ?
+ MatrixType::Traits::MaxRowsAtCompileTime - 1 : Dynamic,
+ MaxColsAtCompileTime = (MatrixType::Traits::MaxColsAtCompileTime != Dynamic) ?
+ MatrixType::Traits::MaxColsAtCompileTime - 1 : Dynamic
};
const Minor& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h
index 1d3ee6af0..02011ec48 100644
--- a/Eigen/src/Core/Ones.h
+++ b/Eigen/src/Core/Ones.h
@@ -43,12 +43,14 @@ template<typename MatrixType> class Ones : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Ones& _ref() const { return *this; }
- int _rows() const { return m_rows; }
- int _cols() const { return m_cols; }
+ int _rows() const { return m_rows.value(); }
+ int _cols() const { return m_cols.value(); }
Scalar _coeff(int, int) const
{
@@ -65,7 +67,8 @@ template<typename MatrixType> class Ones : NoOperatorEquals,
}
protected:
- const int m_rows, m_cols;
+ const IntAtRunTimeIfDynamic<RowsAtCompileTime> m_rows;
+ const IntAtRunTimeIfDynamic<ColsAtCompileTime> m_cols;
};
/** \returns an expression of a matrix where all coefficients equal one.
diff --git a/Eigen/src/Core/Opposite.h b/Eigen/src/Core/Opposite.h
index 6ef2e9f77..6e38b5f6c 100644
--- a/Eigen/src/Core/Opposite.h
+++ b/Eigen/src/Core/Opposite.h
@@ -51,7 +51,9 @@ template<typename MatrixType> class Opposite : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Opposite& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h
index 29685b344..0e3bd9b0c 100644
--- a/Eigen/src/Core/Product.h
+++ b/Eigen/src/Core/Product.h
@@ -91,7 +91,9 @@ template<typename Lhs, typename Rhs> class Product : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = Lhs::Traits::RowsAtCompileTime,
- ColsAtCompileTime = Rhs::Traits::ColsAtCompileTime
+ ColsAtCompileTime = Rhs::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = Lhs::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = Rhs::Traits::MaxColsAtCompileTime
};
const Product& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h
index 6a8a9e726..0b6892d2e 100644
--- a/Eigen/src/Core/Random.h
+++ b/Eigen/src/Core/Random.h
@@ -43,12 +43,14 @@ template<typename MatrixType> class Random : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Random& _ref() const { return *this; }
- int _rows() const { return m_rows; }
- int _cols() const { return m_cols; }
+ int _rows() const { return m_rows.value(); }
+ int _cols() const { return m_cols.value(); }
Scalar _coeff(int, int) const
{
@@ -65,7 +67,8 @@ template<typename MatrixType> class Random : NoOperatorEquals,
}
protected:
- const int m_rows, m_cols;
+ const IntAtRunTimeIfDynamic<RowsAtCompileTime> m_rows;
+ const IntAtRunTimeIfDynamic<ColsAtCompileTime> m_cols;
};
/** \returns a random matrix (not an expression, the matrix is immediately evaluated).
diff --git a/Eigen/src/Core/Row.h b/Eigen/src/Core/Row.h
index f120f0c5c..55def78f3 100644
--- a/Eigen/src/Core/Row.h
+++ b/Eigen/src/Core/Row.h
@@ -71,7 +71,9 @@ template<typename MatrixType> class Row
private:
enum {
RowsAtCompileTime = 1,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = 1,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Row& _ref() const { return *this; }
diff --git a/Eigen/src/Core/ScalarMultiple.h b/Eigen/src/Core/ScalarMultiple.h
index c9f15bffb..1df09eee2 100644
--- a/Eigen/src/Core/ScalarMultiple.h
+++ b/Eigen/src/Core/ScalarMultiple.h
@@ -51,7 +51,9 @@ template<typename FactorType, typename MatrixType> class ScalarMultiple : NoOper
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const ScalarMultiple& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Sum.h b/Eigen/src/Core/Sum.h
index 7cdedcfca..325125956 100644
--- a/Eigen/src/Core/Sum.h
+++ b/Eigen/src/Core/Sum.h
@@ -57,7 +57,9 @@ template<typename Lhs, typename Rhs> class Sum : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = Lhs::Traits::RowsAtCompileTime,
- ColsAtCompileTime = Rhs::Traits::ColsAtCompileTime
+ ColsAtCompileTime = Lhs::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = Lhs::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = Lhs::Traits::MaxColsAtCompileTime
};
const Sum& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h
index 21e6168f5..87da4e39d 100644
--- a/Eigen/src/Core/Transpose.h
+++ b/Eigen/src/Core/Transpose.h
@@ -53,7 +53,9 @@ template<typename MatrixType> class Transpose
private:
enum {
RowsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::RowsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Transpose& _ref() const { return *this; }
diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h
index 7c68d25ca..d8db03caf 100644
--- a/Eigen/src/Core/Util.h
+++ b/Eigen/src/Core/Util.h
@@ -88,6 +88,8 @@ EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
+#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
+
const int Dynamic = -10;
const int ColumnMajor = 0;
const int RowMajor = 1;
@@ -99,4 +101,24 @@ class NoOperatorEquals
NoOperatorEquals& operator=(const NoOperatorEquals&);
};
+template<int Value> class IntAtRunTimeIfDynamic
+{
+ public:
+ IntAtRunTimeIfDynamic() {}
+ explicit IntAtRunTimeIfDynamic(int) {}
+ static int value() { return Value; }
+ void setValue(int) {}
+};
+
+template<> class IntAtRunTimeIfDynamic<Dynamic>
+{
+ int m_value;
+ public:
+ explicit IntAtRunTimeIfDynamic(int value) : m_value(value) {}
+ int value() const { return m_value; }
+ void setValue(int value) { m_value = value; }
+ private:
+ IntAtRunTimeIfDynamic() {}
+};
+
#endif // EIGEN_UTIL_H
diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h
index 40ee926ed..c0fdcffe3 100644
--- a/Eigen/src/Core/Zero.h
+++ b/Eigen/src/Core/Zero.h
@@ -43,12 +43,14 @@ template<typename MatrixType> class Zero : NoOperatorEquals,
private:
enum {
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
- ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime
+ ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
};
const Zero& _ref() const { return *this; }
- int _rows() const { return m_rows; }
- int _cols() const { return m_cols; }
+ int _rows() const { return m_rows.value(); }
+ int _cols() const { return m_cols.value(); }
Scalar _coeff(int, int) const
{
@@ -65,7 +67,8 @@ template<typename MatrixType> class Zero : NoOperatorEquals,
}
protected:
- const int m_rows, m_cols;
+ const IntAtRunTimeIfDynamic<RowsAtCompileTime> m_rows;
+ const IntAtRunTimeIfDynamic<ColsAtCompileTime> m_cols;
};
/** \returns an expression of a zero matrix.
diff --git a/doc/benchmark.cpp b/doc/benchmark.cpp
index 51f594583..b2ab9a3b0 100644
--- a/doc/benchmark.cpp
+++ b/doc/benchmark.cpp
@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
}
for(int a = 0; a < 400000000; a++)
{
- m = Matrix3d::identity() + 0.00005 * (m + m*m);
+ m = I + 0.00005 * (m + m*m);
}
cout << m << endl;
return 0;