mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-21 17:19:36 +08:00
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.
This commit is contained in:
parent
e05a1aba1d
commit
89a134ba0b
@ -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"
|
||||
|
@ -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; }
|
||||
|
@ -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(); }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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>;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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).
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -80,6 +80,42 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
? 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
|
||||
|
@ -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(); }
|
||||
|
@ -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
|
@ -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; }
|
||||
|
@ -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.
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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).
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user