* #define EIGEN_NDEBUG now also disables asserts. Useful

to disable eigen's asserts without disabling one's own program's
  asserts. Notice that Eigen code should now use ei_assert()
  instead of assert().
* Remove findBiggestCoeff() as it's now almost redundant.
* Improve echelon.cpp: inner for loop replaced by xprs.
* remove useless "(*this)." here and there. I think they were
  first introduced by automatic search&replace.
* fix compilation in Visitor.h (issue triggered by echelon.cpp)
* improve comment on swap().
This commit is contained in:
Benoit Jacob 2008-03-26 08:48:04 +00:00
parent 4342f024d9
commit 729618c945
22 changed files with 105 additions and 100 deletions

View File

@ -90,7 +90,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
m_blockRows(matrix.rows()), // if it is a row, then m_blockRows has a fixed-size of 1, so no pb to try to overwrite it m_blockRows(matrix.rows()), // if it is a row, then m_blockRows has a fixed-size of 1, so no pb to try to overwrite it
m_blockCols(matrix.cols()) // same for m_blockCols m_blockCols(matrix.cols()) // same for m_blockCols
{ {
assert( (i>=0) && ( ei_assert( (i>=0) && (
((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows()) ((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows())
||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols()))); ||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols())));
} }
@ -100,8 +100,8 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
Block(const MatrixType& matrix, int startRow, int startCol) Block(const MatrixType& matrix, int startRow, int startCol)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol) : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol)
{ {
assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic); ei_assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic);
assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows() ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows()
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols()); && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols());
} }
@ -113,9 +113,9 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol), : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
m_blockRows(blockRows), m_blockCols(blockCols) m_blockRows(blockRows), m_blockCols(blockCols)
{ {
assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==1) ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==1)
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==1)); && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==1));
assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows() ei_assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows()
&& startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols()); && startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols());
} }
@ -197,7 +197,7 @@ template<typename Derived>
Block<Derived> MatrixBase<Derived> Block<Derived> MatrixBase<Derived>
::block(int start, int size) ::block(int start, int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
@ -209,7 +209,7 @@ template<typename Derived>
const Block<Derived> MatrixBase<Derived> const Block<Derived> MatrixBase<Derived>
::block(int start, int size) const ::block(int start, int size) const
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
@ -235,7 +235,7 @@ template<typename Derived>
Block<Derived> MatrixBase<Derived> Block<Derived> MatrixBase<Derived>
::start(int size) ::start(int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), 0, 0, return Block<Derived>(derived(), 0, 0,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -246,7 +246,7 @@ template<typename Derived>
const Block<Derived> MatrixBase<Derived> const Block<Derived> MatrixBase<Derived>
::start(int size) const ::start(int size) const
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), 0, 0, return Block<Derived>(derived(), 0, 0,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -271,7 +271,7 @@ template<typename Derived>
Block<Derived> MatrixBase<Derived> Block<Derived> MatrixBase<Derived>
::end(int size) ::end(int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), return Block<Derived>(derived(),
RowsAtCompileTime == 1 ? 0 : rows() - size, RowsAtCompileTime == 1 ? 0 : rows() - size,
ColsAtCompileTime == 1 ? 0 : cols() - size, ColsAtCompileTime == 1 ? 0 : cols() - size,
@ -284,7 +284,7 @@ template<typename Derived>
const Block<Derived> MatrixBase<Derived> const Block<Derived> MatrixBase<Derived>
::end(int size) const ::end(int size) const
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
return Block<Derived>(derived(), return Block<Derived>(derived(),
RowsAtCompileTime == 1 ? 0 : rows() - size, RowsAtCompileTime == 1 ? 0 : rows() - size,
ColsAtCompileTime == 1 ? 0 : cols() - size, ColsAtCompileTime == 1 ? 0 : cols() - size,

View File

@ -43,7 +43,7 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar MatrixBase<Derived> typename ei_traits<Derived>::Scalar MatrixBase<Derived>
::coeff(int row, int col) const ::coeff(int row, int col) const
{ {
eigen_internal_assert(row >= 0 && row < rows() ei_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && col >= 0 && col < cols());
return derived()._coeff(row, col); return derived()._coeff(row, col);
} }
@ -56,7 +56,7 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar MatrixBase<Derived> typename ei_traits<Derived>::Scalar MatrixBase<Derived>
::operator()(int row, int col) const ::operator()(int row, int col) const
{ {
assert(row >= 0 && row < rows() ei_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && col >= 0 && col < cols());
return derived()._coeff(row, col); return derived()._coeff(row, col);
} }
@ -79,7 +79,7 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar& MatrixBase<Derived> typename ei_traits<Derived>::Scalar& MatrixBase<Derived>
::coeffRef(int row, int col) ::coeffRef(int row, int col)
{ {
eigen_internal_assert(row >= 0 && row < rows() ei_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && col >= 0 && col < cols());
return derived()._coeffRef(row, col); return derived()._coeffRef(row, col);
} }
@ -92,7 +92,7 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar& MatrixBase<Derived> typename ei_traits<Derived>::Scalar& MatrixBase<Derived>
::operator()(int row, int col) ::operator()(int row, int col)
{ {
assert(row >= 0 && row < rows() ei_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && col >= 0 && col < cols());
return derived()._coeffRef(row, col); return derived()._coeffRef(row, col);
} }
@ -115,15 +115,15 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar MatrixBase<Derived> typename ei_traits<Derived>::Scalar MatrixBase<Derived>
::coeff(int index) const ::coeff(int index) const
{ {
eigen_internal_assert(IsVectorAtCompileTime); ei_internal_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) if(RowsAtCompileTime == 1)
{ {
eigen_internal_assert(index >= 0 && index < cols()); ei_internal_assert(index >= 0 && index < cols());
return coeff(0, index); return coeff(0, index);
} }
else else
{ {
eigen_internal_assert(index >= 0 && index < rows()); ei_internal_assert(index >= 0 && index < rows());
return coeff(index, 0); return coeff(index, 0);
} }
} }
@ -139,15 +139,15 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar MatrixBase<Derived> typename ei_traits<Derived>::Scalar MatrixBase<Derived>
::operator[](int index) const ::operator[](int index) const
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) if(RowsAtCompileTime == 1)
{ {
assert(index >= 0 && index < cols()); ei_assert(index >= 0 && index < cols());
return coeff(0, index); return coeff(0, index);
} }
else else
{ {
assert(index >= 0 && index < rows()); ei_assert(index >= 0 && index < rows());
return coeff(index, 0); return coeff(index, 0);
} }
} }
@ -170,15 +170,15 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar& MatrixBase<Derived> typename ei_traits<Derived>::Scalar& MatrixBase<Derived>
::coeffRef(int index) ::coeffRef(int index)
{ {
eigen_internal_assert(IsVectorAtCompileTime); ei_internal_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) if(RowsAtCompileTime == 1)
{ {
eigen_internal_assert(index >= 0 && index < cols()); ei_internal_assert(index >= 0 && index < cols());
return coeffRef(0, index); return coeffRef(0, index);
} }
else else
{ {
eigen_internal_assert(index >= 0 && index < rows()); ei_internal_assert(index >= 0 && index < rows());
return coeffRef(index, 0); return coeffRef(index, 0);
} }
} }
@ -193,15 +193,15 @@ template<typename Derived>
typename ei_traits<Derived>::Scalar& MatrixBase<Derived> typename ei_traits<Derived>::Scalar& MatrixBase<Derived>
::operator[](int index) ::operator[](int index)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) if(RowsAtCompileTime == 1)
{ {
assert(index >= 0 && index < cols()); ei_assert(index >= 0 && index < cols());
return coeffRef(0, index); return coeffRef(0, index);
} }
else else
{ {
assert(index >= 0 && index < rows()); ei_assert(index >= 0 && index < rows());
return coeffRef(index, 0); return coeffRef(index, 0);
} }
} }

View File

@ -52,12 +52,12 @@ struct MatrixBase<Derived>::CommaInitializer
m_row+=m_currentBlockRows; m_row+=m_currentBlockRows;
m_col = 0; m_col = 0;
m_currentBlockRows = 1; m_currentBlockRows = 1;
assert(m_row<m_matrix.rows() ei_assert(m_row<m_matrix.rows()
&& "Too many rows passed to MatrixBase::operator<<"); && "Too many rows passed to MatrixBase::operator<<");
} }
assert(m_col<m_matrix.cols() ei_assert(m_col<m_matrix.cols()
&& "Too many coefficients passed to MatrixBase::operator<<"); && "Too many coefficients passed to MatrixBase::operator<<");
assert(m_currentBlockRows==1); ei_assert(m_currentBlockRows==1);
m_matrix.coeffRef(m_row, m_col++) = s; m_matrix.coeffRef(m_row, m_col++) = s;
return *this; return *this;
} }
@ -70,12 +70,12 @@ struct MatrixBase<Derived>::CommaInitializer
m_row+=m_currentBlockRows; m_row+=m_currentBlockRows;
m_col = 0; m_col = 0;
m_currentBlockRows = other.rows(); m_currentBlockRows = other.rows();
assert(m_row+m_currentBlockRows<=m_matrix.rows() ei_assert(m_row+m_currentBlockRows<=m_matrix.rows()
&& "Too many rows passed to MatrixBase::operator<<"); && "Too many rows passed to MatrixBase::operator<<");
} }
assert(m_col<m_matrix.cols() ei_assert(m_col<m_matrix.cols()
&& "Too many coefficients passed to MatrixBase::operator<<"); && "Too many coefficients passed to MatrixBase::operator<<");
assert(m_currentBlockRows==other.rows()); ei_assert(m_currentBlockRows==other.rows());
if (OtherDerived::RowsAtCompileTime>0 && OtherDerived::ColsAtCompileTime>0) if (OtherDerived::RowsAtCompileTime>0 && OtherDerived::ColsAtCompileTime>0)
m_matrix.block< (OtherDerived::RowsAtCompileTime>0?OtherDerived::RowsAtCompileTime:1) , m_matrix.block< (OtherDerived::RowsAtCompileTime>0?OtherDerived::RowsAtCompileTime:1) ,
(OtherDerived::ColsAtCompileTime>0?OtherDerived::ColsAtCompileTime:1) >(m_row, m_col) = other; (OtherDerived::ColsAtCompileTime>0?OtherDerived::ColsAtCompileTime:1) >(m_row, m_col) = other;
@ -87,7 +87,7 @@ struct MatrixBase<Derived>::CommaInitializer
~CommaInitializer(void) ~CommaInitializer(void)
{ {
assert((m_row+m_currentBlockRows) == m_matrix.rows() ei_assert((m_row+m_currentBlockRows) == m_matrix.rows()
&& m_col == m_matrix.cols() && m_col == m_matrix.cols()
&& "Too few coefficients passed to Matrix::operator<<"); && "Too few coefficients passed to Matrix::operator<<");
} }

View File

@ -74,7 +74,7 @@ class CwiseBinaryOp : ei_no_assignment_operator,
CwiseBinaryOp(const Lhs& lhs, const Rhs& rhs, const BinaryOp& func = BinaryOp()) CwiseBinaryOp(const Lhs& lhs, const Rhs& rhs, const BinaryOp& func = BinaryOp())
: m_lhs(lhs), m_rhs(rhs), m_functor(func) : m_lhs(lhs), m_rhs(rhs), m_functor(func)
{ {
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); ei_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
} }
private: private:

View File

@ -60,7 +60,7 @@ class DiagonalMatrix : ei_no_assignment_operator,
DiagonalMatrix(const CoeffsVectorType& coeffs) : m_coeffs(coeffs) DiagonalMatrix(const CoeffsVectorType& coeffs) : m_coeffs(coeffs)
{ {
assert(CoeffsVectorType::IsVectorAtCompileTime ei_assert(CoeffsVectorType::IsVectorAtCompileTime
&& coeffs.size() > 0); && coeffs.size() > 0);
} }

View File

@ -72,7 +72,7 @@ template<typename OtherDerived>
typename ei_traits<Derived>::Scalar typename ei_traits<Derived>::Scalar
MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
{ {
assert(IsVectorAtCompileTime ei_assert(IsVectorAtCompileTime
&& OtherDerived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime
&& size() == other.size()); && size() == other.size());
Scalar res; Scalar res;

View File

@ -48,7 +48,7 @@ bool MatrixBase<Derived>::isApprox(
typename NumTraits<Scalar>::Real prec typename NumTraits<Scalar>::Real prec
) const ) const
{ {
assert(rows() == other.rows() && cols() == other.cols()); ei_assert(rows() == other.rows() && cols() == other.cols());
if(IsVectorAtCompileTime) if(IsVectorAtCompileTime)
{ {
return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec); return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec);
@ -109,7 +109,7 @@ bool MatrixBase<Derived>::isMuchSmallerThan(
typename NumTraits<Scalar>::Real prec typename NumTraits<Scalar>::Real prec
) const ) const
{ {
assert(rows() == other.rows() && cols() == other.cols()); ei_assert(rows() == other.rows() && cols() == other.cols());
if(IsVectorAtCompileTime) if(IsVectorAtCompileTime)
{ {
return(norm2() <= other.norm2() * prec * prec); return(norm2() <= other.norm2() * prec * prec);

View File

@ -52,7 +52,7 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator,
Identity(int rows, int cols) : m_rows(rows), m_cols(cols) Identity(int rows, int cols) : m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));

View File

@ -81,7 +81,7 @@ template<typename MatrixType> class Map
public: public:
Map(const Scalar* data, int rows, int cols) : m_data(data), m_rows(rows), m_cols(cols) Map(const Scalar* data, int rows, int cols) : m_data(data), m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
@ -107,7 +107,7 @@ template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int size) Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int size)
{ {
assert(_Cols == 1 || _Rows ==1); ei_assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1) if(_Cols == 1)
return Map<Matrix>(data, size, 1); return Map<Matrix>(data, size, 1);
else else
@ -156,7 +156,7 @@ template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int size) Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int size)
{ {
assert(_Cols == 1 || _Rows ==1); ei_assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1) if(_Cols == 1)
return Map<Matrix>(data, size, 1); return Map<Matrix>(data, size, 1);
else else

View File

@ -35,11 +35,11 @@ inline int ei_imag(int) { return 0; }
inline int ei_conj(int x) { return x; } inline int ei_conj(int x) { return x; }
inline int ei_abs(int x) { return abs(x); } inline int ei_abs(int x) { return abs(x); }
inline int ei_abs2(int x) { return x*x; } inline int ei_abs2(int x) { return x*x; }
inline int ei_sqrt(int) { assert(false); return 0; } inline int ei_sqrt(int) { ei_assert(false); return 0; }
inline int ei_exp(int) { assert(false); return 0; } inline int ei_exp(int) { ei_assert(false); return 0; }
inline int ei_log(int) { assert(false); return 0; } inline int ei_log(int) { ei_assert(false); return 0; }
inline int ei_sin(int) { assert(false); return 0; } inline int ei_sin(int) { ei_assert(false); return 0; }
inline int ei_cos(int) { assert(false); return 0; } inline int ei_cos(int) { ei_assert(false); return 0; }
#if (defined __ICC) || (defined __GNUC__ && (__GNUC__<4 || __GNUC_MINOR__<3)) #if (defined __ICC) || (defined __GNUC__ && (__GNUC__<4 || __GNUC_MINOR__<3))
inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); } inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); }
#else #else

View File

@ -131,7 +131,7 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
void resize(int rows, int cols) void resize(int rows, int cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (MaxRowsAtCompileTime == Dynamic || MaxRowsAtCompileTime >= rows) && (MaxRowsAtCompileTime == Dynamic || MaxRowsAtCompileTime >= rows)
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
@ -153,12 +153,12 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
{ {
if(RowsAtCompileTime == 1) if(RowsAtCompileTime == 1)
{ {
assert(other.isVector()); ei_assert(other.isVector());
resize(1, other.size()); resize(1, other.size());
} }
else if(ColsAtCompileTime == 1) else if(ColsAtCompileTime == 1)
{ {
assert(other.isVector()); ei_assert(other.isVector());
resize(other.size(), 1); resize(other.size(), 1);
} }
else resize(other.rows(), other.cols()); else resize(other.rows(), other.cols());
@ -191,7 +191,7 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
*/ */
explicit Matrix() explicit Matrix()
{ {
assert(RowsAtCompileTime > 0 && ColsAtCompileTime > 0); ei_assert(RowsAtCompileTime > 0 && ColsAtCompileTime > 0);
} }
/** Constructs a vector or row-vector with given dimension. \only_for_vectors /** Constructs a vector or row-vector with given dimension. \only_for_vectors
@ -202,8 +202,8 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
*/ */
explicit Matrix(int dim) : m_storage(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim) explicit Matrix(int dim) : m_storage(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
{ {
assert(dim > 0); ei_assert(dim > 0);
assert((RowsAtCompileTime == 1 ei_assert((RowsAtCompileTime == 1
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == dim)) && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == dim))
|| (ColsAtCompileTime == 1 || (ColsAtCompileTime == 1
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == dim))); && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == dim)));
@ -229,14 +229,14 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
} }
else else
{ {
assert(x > 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == x) ei_assert(x > 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == x)
&& y > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == y)); && y > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == y));
} }
} }
/** constructs an initialized 2D vector with given coefficients */ /** constructs an initialized 2D vector with given coefficients */
Matrix(const float& x, const float& y) Matrix(const float& x, const float& y)
{ {
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2) ei_assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2)
|| (RowsAtCompileTime == 2 && ColsAtCompileTime == 1)); || (RowsAtCompileTime == 2 && ColsAtCompileTime == 1));
m_storage.data()[0] = x; m_storage.data()[0] = x;
m_storage.data()[1] = y; m_storage.data()[1] = y;
@ -244,7 +244,7 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
/** constructs an initialized 2D vector with given coefficients */ /** constructs an initialized 2D vector with given coefficients */
Matrix(const double& x, const double& y) Matrix(const double& x, const double& y)
{ {
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2) ei_assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 2)
|| (RowsAtCompileTime == 2 && ColsAtCompileTime == 1)); || (RowsAtCompileTime == 2 && ColsAtCompileTime == 1));
m_storage.data()[0] = x; m_storage.data()[0] = x;
m_storage.data()[1] = y; m_storage.data()[1] = y;
@ -252,7 +252,7 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
/** constructs an initialized 3D vector with given coefficients */ /** constructs an initialized 3D vector with given coefficients */
Matrix(const Scalar& x, const Scalar& y, const Scalar& z) Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
{ {
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 3) ei_assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 3)
|| (RowsAtCompileTime == 3 && ColsAtCompileTime == 1)); || (RowsAtCompileTime == 3 && ColsAtCompileTime == 1));
m_storage.data()[0] = x; m_storage.data()[0] = x;
m_storage.data()[1] = y; m_storage.data()[1] = y;
@ -261,7 +261,7 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
/** constructs an initialized 4D vector with given coefficients */ /** constructs an initialized 4D vector with given coefficients */
Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
{ {
assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 4) ei_assert((RowsAtCompileTime == 1 && ColsAtCompileTime == 4)
|| (RowsAtCompileTime == 4 && ColsAtCompileTime == 1)); || (RowsAtCompileTime == 4 && ColsAtCompileTime == 1));
m_storage.data()[0] = x; m_storage.data()[0] = x;
m_storage.data()[1] = y; m_storage.data()[1] = y;

View File

@ -343,13 +343,6 @@ template<typename Derived> class MatrixBase
RealScalar prec = precision<Scalar>()) const; RealScalar prec = precision<Scalar>()) const;
bool isOrtho(RealScalar prec = precision<Scalar>()) const; bool isOrtho(RealScalar prec = precision<Scalar>()) const;
/** puts in *row and *col the location of the coefficient of *this
* which has the biggest absolute value.
*/
void findBiggestCoeff(int *row, int *col) const
{ (*this).cwiseAbs().maxCoeff(row, col); }
//@}
/// \name Special functions /// \name Special functions
//@{ //@{
template<typename NewType> template<typename NewType>
@ -358,12 +351,6 @@ template<typename Derived> class MatrixBase
const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE; const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE;
const EvalOMP<Derived> evalOMP() const EIGEN_ALWAYS_INLINE; const EvalOMP<Derived> evalOMP() const EIGEN_ALWAYS_INLINE;
/** swaps *this with the expression \a other.
*
* \note \a other is only marked const because I couln't find another way
* to get g++ 4.2 to accept that template parameter resolution. It gets const_cast'd
* of course. TODO: get rid of const here.
*/
template<typename OtherDerived> template<typename OtherDerived>
void swap(const MatrixBase<OtherDerived>& other); void swap(const MatrixBase<OtherDerived>& other);
//@} //@}

View File

@ -64,7 +64,7 @@ template<typename MatrixType> class Minor
int row, int col) int row, int col)
: m_matrix(matrix), m_row(row), m_col(col) : m_matrix(matrix), m_row(row), m_col(col)
{ {
assert(row >= 0 && row < matrix.rows() ei_assert(row >= 0 && row < matrix.rows()
&& col >= 0 && col < matrix.cols()); && col >= 0 && col < matrix.cols());
} }

View File

@ -64,7 +64,7 @@ template<typename MatrixType> class Ones : ei_no_assignment_operator,
public: public:
Ones(int rows, int cols) : m_rows(rows), m_cols(cols) Ones(int rows, int cols) : m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
@ -114,7 +114,7 @@ const Ones<Derived> MatrixBase<Derived>::ones(int rows, int cols)
template<typename Derived> template<typename Derived>
const Ones<Derived> MatrixBase<Derived>::ones(int size) const Ones<Derived> MatrixBase<Derived>::ones(int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Ones<Derived>(1, size); if(RowsAtCompileTime == 1) return Ones<Derived>(1, size);
else return Ones<Derived>(size, 1); else return Ones<Derived>(size, 1);
} }

View File

@ -105,7 +105,7 @@ Derived& MatrixBase<Derived>
if(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) if(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime)
// copying a vector expression into a vector // copying a vector expression into a vector
{ {
assert(size() == other.size()); ei_assert(size() == other.size());
if(EIGEN_UNROLLED_LOOPS if(EIGEN_UNROLLED_LOOPS
&& SizeAtCompileTime != Dynamic && SizeAtCompileTime != Dynamic
&& SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
@ -120,7 +120,7 @@ Derived& MatrixBase<Derived>
} }
else // copying a matrix expression into a matrix else // copying a matrix expression into a matrix
{ {
assert(rows() == other.rows() && cols() == other.cols()); ei_assert(rows() == other.rows() && cols() == other.cols());
if(EIGEN_UNROLLED_LOOPS if(EIGEN_UNROLLED_LOOPS
&& SizeAtCompileTime != Dynamic && SizeAtCompileTime != Dynamic
&& SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
@ -148,7 +148,7 @@ Derived& MatrixBase<Derived>
coeffRef(i, j) = other.coeff(i, j); coeffRef(i, j) = other.coeff(i, j);
} }
} }
return (*this).derived(); return derived();
} }
} }

View File

@ -106,7 +106,7 @@ template<typename Lhs, typename Rhs, int EvalMode> class Product : ei_no_assignm
Product(const Lhs& lhs, const Rhs& rhs) Product(const Lhs& lhs, const Rhs& rhs)
: m_lhs(lhs), m_rhs(rhs) : m_lhs(lhs), m_rhs(rhs)
{ {
assert(lhs.cols() == rhs.rows()); ei_assert(lhs.cols() == rhs.rows());
} }
/** \internal */ /** \internal */
@ -172,7 +172,7 @@ template<typename OtherDerived>
const Eval<Product<Derived, OtherDerived> > const Eval<Product<Derived, OtherDerived> >
MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
{ {
return (*this).lazyProduct(other).eval(); return lazyProduct(other).eval();
} }
/** replaces \c *this by \c *this * \a other. /** replaces \c *this by \c *this * \a other.
@ -192,7 +192,7 @@ template<typename Derived1, typename Derived2>
Derived& MatrixBase<Derived>::operator=(const Product<Derived1,Derived2,CacheOptimal>& product) Derived& MatrixBase<Derived>::operator=(const Product<Derived1,Derived2,CacheOptimal>& product)
{ {
product._cacheOptimalEval(*this); product._cacheOptimalEval(*this);
return (*this).derived(); return derived();
} }
template<typename Lhs, typename Rhs, int EvalMode> template<typename Lhs, typename Rhs, int EvalMode>

View File

@ -65,7 +65,7 @@ template<typename MatrixType> class Random : ei_no_assignment_operator,
Random(int rows, int cols) : m_rows(rows), m_cols(cols) Random(int rows, int cols) : m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
@ -117,7 +117,7 @@ template<typename Derived>
const Eval<Random<Derived> > const Eval<Random<Derived> >
MatrixBase<Derived>::random(int size) MatrixBase<Derived>::random(int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Random<Derived>(1, size).eval(); if(RowsAtCompileTime == 1) return Random<Derived>(1, size).eval();
else return Random<Derived>(size, 1).eval(); else return Random<Derived>(size, 1).eval();
} }

View File

@ -25,6 +25,15 @@
#ifndef EIGEN_SWAP_H #ifndef EIGEN_SWAP_H
#define EIGEN_SWAP_H #define EIGEN_SWAP_H
/** swaps *this with the expression \a other.
*
* \note \a other is only marked const because I couln't find another way
* to get g++ (4.2 and 4.3) to accept that template parameter resolution.
* The problem seems to be that when swapping expressions as in
* m.row(i).swap(m.row(j)); the Row object returned by row(j) is a temporary
* and g++ doesn't dare to pass it by non-constant reference.
* It gets const_cast'd of course. TODO: get rid of const here.
*/
template<typename Derived> template<typename Derived>
template<typename OtherDerived> template<typename OtherDerived>
void MatrixBase<Derived>::swap(const MatrixBase<OtherDerived>& other) void MatrixBase<Derived>::swap(const MatrixBase<OtherDerived>& other)
@ -35,7 +44,7 @@ void MatrixBase<Derived>::swap(const MatrixBase<OtherDerived>& other)
Scalar tmp; Scalar tmp;
if(IsVectorAtCompileTime) if(IsVectorAtCompileTime)
{ {
assert(OtherDerived::IsVectorAtCompileTime && size() == _other->size()); ei_assert(OtherDerived::IsVectorAtCompileTime && size() == _other->size());
for(int i = 0; i < size(); i++) for(int i = 0; i < size(); i++)
{ {
tmp = coeff(i); tmp = coeff(i);

View File

@ -49,10 +49,16 @@ EIGEN_USING_MATRIX_TYPEDEFS \
using Eigen::Matrix; \ using Eigen::Matrix; \
using Eigen::MatrixBase; using Eigen::MatrixBase;
#ifdef EIGEN_INTERNAL_DEBUGGING #ifdef EIGEN_NDEBUG
#define eigen_internal_assert(x) assert(x); #define ei_assert(x)
#else #else
#define eigen_internal_assert(x) #define ei_assert(x) assert(x)
#endif
#ifdef EIGEN_INTERNAL_DEBUGGING
#define ei_internal_assert(x) ei_assert(x);
#else
#define ei_internal_assert(x)
#endif #endif
#ifdef NDEBUG #ifdef NDEBUG

View File

@ -82,13 +82,12 @@ void MatrixBase<Derived>::visit(Visitor& visitor) const
SizeAtCompileTime : Dynamic>::run(derived(), visitor); SizeAtCompileTime : Dynamic>::run(derived(), visitor);
else else
{ {
Scalar res;
visitor.init(coeff(0,0), 0, 0); visitor.init(coeff(0,0), 0, 0);
for(int i = 1; i < rows(); i++) for(int i = 1; i < rows(); i++)
visitor(res, coeff(i, 0), i, 0); visitor(coeff(i, 0), i, 0);
for(int j = 1; j < cols(); j++) for(int j = 1; j < cols(); j++)
for(int i = 0; i < rows(); i++) for(int i = 0; i < rows(); i++)
visitor(res, coeff(i, j), i, j); visitor(coeff(i, j), i, j);
} }
} }

View File

@ -65,7 +65,7 @@ template<typename MatrixType> class Zero : ei_no_assignment_operator,
Zero(int rows, int cols) : m_rows(rows), m_cols(cols) Zero(int rows, int cols) : m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 ei_assert(rows > 0
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
&& cols > 0 && cols > 0
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
@ -115,7 +115,7 @@ const Zero<Derived> MatrixBase<Derived>::zero(int rows, int cols)
template<typename Derived> template<typename Derived>
const Zero<Derived> MatrixBase<Derived>::zero(int size) const Zero<Derived> MatrixBase<Derived>::zero(int size)
{ {
assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Zero<Derived>(1, size); if(RowsAtCompileTime == 1) return Zero<Derived>(1, size);
else return Zero<Derived>(size, 1); else return Zero<Derived>(size, 1);
} }

View File

@ -7,19 +7,22 @@ namespace Eigen {
template<typename Derived> template<typename Derived>
void echelon(MatrixBase<Derived>& m) void echelon(MatrixBase<Derived>& m)
{ {
const int N = std::min(m.rows(), m.cols()); for(int k = 0; k < m.diagonal().size(); k++)
for(int k = 0; k < N; k++)
{ {
int rowOfBiggest, colOfBiggest; int rowOfBiggest, colOfBiggest;
int cornerRows = m.rows()-k; int cornerRows = m.rows()-k, cornerCols = m.cols()-k;
int cornerCols = m.cols()-k;
m.corner(BottomRight, cornerRows, cornerCols) m.corner(BottomRight, cornerRows, cornerCols)
.findBiggestCoeff(&rowOfBiggest, &colOfBiggest); .cwiseAbs()
.maxCoeff(&rowOfBiggest, &colOfBiggest);
m.row(k).swap(m.row(k+rowOfBiggest)); m.row(k).swap(m.row(k+rowOfBiggest));
m.col(k).swap(m.col(k+colOfBiggest)); m.col(k).swap(m.col(k+colOfBiggest));
for(int r = k+1; r < m.rows(); r++) // important performance tip:
m.row(r).end(cornerCols) -= m.row(k).end(cornerCols) * m(r,k) / m(k,k); // in a complex expression such as below it can be very important to fine-tune
// exactly where evaluation occurs. The parentheses and .eval() below ensure
// that the quotient is computed only once, and that the evaluation caused
// by operator* occurs last.
m.corner(BottomRight, cornerRows-1, cornerCols)
-= m.col(k).end(cornerRows-1) * (m.row(k).end(cornerCols) / m(k,k)).eval();
} }
} }
@ -65,6 +68,7 @@ int main(int, char **)
cout << "Here's the matrix m:" << endl << m << endl; cout << "Here's the matrix m:" << endl << m << endl;
cout << "Now let's echelon m:" << endl; cout << "Now let's echelon m:" << endl;
for(int i = 0; i < 1000000; i++)
echelon(m); echelon(m);
cout << "Now m is:" << endl << m << endl; cout << "Now m is:" << endl << m << endl;