mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-20 16:49:38 +08:00
- eigen2 now fully enforces constness! found a way to achieve that
with minimal code duplication. There now are only two (2) const_cast remaining in the whole source code. - eigen2 now fully allows copying a row-vector into a column-vector. added a unit-test for that. - split unit tests, improve docs, various improvements.
This commit is contained in:
parent
3cd2a125b2
commit
dad245af56
@ -95,8 +95,9 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
|
|||||||
|
|
||||||
/** \returns a fixed-size expression of a block in *this.
|
/** \returns a fixed-size expression of a block in *this.
|
||||||
*
|
*
|
||||||
* \param blockRows the number of rows in the block
|
* The template parameters \a blockRows and \a blockCols are the number of
|
||||||
* \param blockCols the number of columns in the block
|
* rows and columns in the block
|
||||||
|
*
|
||||||
* \param startRow the first row in the block
|
* \param startRow the first row in the block
|
||||||
* \param startCol the first column in the block
|
* \param startCol the first column in the block
|
||||||
*
|
*
|
||||||
@ -108,10 +109,18 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
template<int BlockRows, int BlockCols>
|
template<int BlockRows, int BlockCols>
|
||||||
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
||||||
|
::block(int startRow, int startCol)
|
||||||
|
{
|
||||||
|
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of block(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
template<int BlockRows, int BlockCols>
|
||||||
|
const Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
||||||
::block(int startRow, int startCol) const
|
::block(int startRow, int startCol) const
|
||||||
{
|
{
|
||||||
return Block<Derived, BlockRows, BlockCols>
|
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
|
||||||
(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), startRow, startCol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_BLOCK_H
|
#endif // EIGEN_BLOCK_H
|
||||||
|
@ -116,7 +116,7 @@ template<typename Scalar, typename Derived>
|
|||||||
Scalar MatrixBase<Scalar, Derived>
|
Scalar MatrixBase<Scalar, Derived>
|
||||||
::coeff(int index) const
|
::coeff(int index) const
|
||||||
{
|
{
|
||||||
eigen_internal_assert(IsVector);
|
eigen_internal_assert(IsVectorAtCompileTime);
|
||||||
if(RowsAtCompileTime == 1)
|
if(RowsAtCompileTime == 1)
|
||||||
{
|
{
|
||||||
eigen_internal_assert(index >= 0 && index < cols());
|
eigen_internal_assert(index >= 0 && index < cols());
|
||||||
@ -140,7 +140,7 @@ template<typename Scalar, typename Derived>
|
|||||||
Scalar MatrixBase<Scalar, Derived>
|
Scalar MatrixBase<Scalar, Derived>
|
||||||
::operator[](int index) const
|
::operator[](int index) const
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
assert(IsVectorAtCompileTime);
|
||||||
if(RowsAtCompileTime == 1)
|
if(RowsAtCompileTime == 1)
|
||||||
{
|
{
|
||||||
assert(index >= 0 && index < cols());
|
assert(index >= 0 && index < cols());
|
||||||
@ -171,7 +171,7 @@ template<typename Scalar, typename Derived>
|
|||||||
Scalar& MatrixBase<Scalar, Derived>
|
Scalar& MatrixBase<Scalar, Derived>
|
||||||
::coeffRef(int index)
|
::coeffRef(int index)
|
||||||
{
|
{
|
||||||
eigen_internal_assert(IsVector);
|
eigen_internal_assert(IsVectorAtCompileTime);
|
||||||
if(RowsAtCompileTime == 1)
|
if(RowsAtCompileTime == 1)
|
||||||
{
|
{
|
||||||
eigen_internal_assert(index >= 0 && index < cols());
|
eigen_internal_assert(index >= 0 && index < cols());
|
||||||
@ -194,7 +194,7 @@ template<typename Scalar, typename Derived>
|
|||||||
Scalar& MatrixBase<Scalar, Derived>
|
Scalar& MatrixBase<Scalar, Derived>
|
||||||
::operator[](int index)
|
::operator[](int index)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
assert(IsVectorAtCompileTime);
|
||||||
if(RowsAtCompileTime == 1)
|
if(RowsAtCompileTime == 1)
|
||||||
{
|
{
|
||||||
assert(index >= 0 && index < cols());
|
assert(index >= 0 && index < cols());
|
||||||
|
@ -89,15 +89,23 @@ template<typename MatrixType> class Column
|
|||||||
|
|
||||||
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
|
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
|
||||||
*
|
*
|
||||||
* Example: \include MatrixBase_col.cpp
|
* Example: \include MatrixBase_column.cpp
|
||||||
* Output: \verbinclude MatrixBase_col.out
|
* Output: \verbinclude MatrixBase_column.out
|
||||||
*
|
*
|
||||||
* \sa row(), class Column */
|
* \sa row(), class Column */
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Column<Derived>
|
Column<Derived>
|
||||||
|
MatrixBase<Scalar, Derived>::col(int i)
|
||||||
|
{
|
||||||
|
return Column<Derived>(ref(), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of col(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const Column<Derived>
|
||||||
MatrixBase<Scalar, Derived>::col(int i) const
|
MatrixBase<Scalar, Derived>::col(int i) const
|
||||||
{
|
{
|
||||||
return Column<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), i);
|
return Column<Derived>(ref(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_COLUMN_H
|
#endif // EIGEN_COLUMN_H
|
||||||
|
@ -64,10 +64,17 @@ template<typename MatrixType> class DiagonalCoeffs
|
|||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
DiagonalCoeffs<Derived>
|
DiagonalCoeffs<Derived>
|
||||||
|
MatrixBase<Scalar, Derived>::diagonal()
|
||||||
|
{
|
||||||
|
return DiagonalCoeffs<Derived>(ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of diagonal(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const DiagonalCoeffs<Derived>
|
||||||
MatrixBase<Scalar, Derived>::diagonal() const
|
MatrixBase<Scalar, Derived>::diagonal() const
|
||||||
{
|
{
|
||||||
return DiagonalCoeffs<Derived>
|
return DiagonalCoeffs<Derived>(ref());
|
||||||
(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_DIAGONALCOEFFS_H
|
#endif // EIGEN_DIAGONALCOEFFS_H
|
||||||
|
@ -38,7 +38,7 @@ class DiagonalMatrix : NoOperatorEquals,
|
|||||||
|
|
||||||
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)
|
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)
|
||||||
{
|
{
|
||||||
assert(CoeffsVectorType::IsVector
|
assert(CoeffsVectorType::IsVectorAtCompileTime
|
||||||
&& _RowsAtCompileTime == _ColsAtCompileTime
|
&& _RowsAtCompileTime == _ColsAtCompileTime
|
||||||
&& _RowsAtCompileTime == CoeffsVectorType::SizeAtCompileTime
|
&& _RowsAtCompileTime == CoeffsVectorType::SizeAtCompileTime
|
||||||
&& coeffs.size() > 0);
|
&& coeffs.size() > 0);
|
||||||
|
@ -62,7 +62,7 @@ template<typename Scalar, typename Derived>
|
|||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
|
Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
|
||||||
{
|
{
|
||||||
assert(IsVector && OtherDerived::IsVector && size() == other.size());
|
assert(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime && size() == other.size());
|
||||||
Scalar res;
|
Scalar res;
|
||||||
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 16)
|
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 16)
|
||||||
DotUnroller<SizeAtCompileTime-1, SizeAtCompileTime, Derived, OtherDerived>
|
DotUnroller<SizeAtCompileTime-1, SizeAtCompileTime, Derived, OtherDerived>
|
||||||
|
@ -109,10 +109,18 @@ template<typename MatrixType> class DynBlock
|
|||||||
*/
|
*/
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
DynBlock<Derived> MatrixBase<Scalar, Derived>
|
DynBlock<Derived> MatrixBase<Scalar, Derived>
|
||||||
::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const
|
::dynBlock(int startRow, int startCol, int blockRows, int blockCols)
|
||||||
{
|
{
|
||||||
return DynBlock<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(),
|
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
|
||||||
startRow, startCol, blockRows, blockCols);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This is the const version of dynBlock(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const DynBlock<Derived> MatrixBase<Scalar, Derived>
|
||||||
|
::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const
|
||||||
|
{
|
||||||
|
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // EIGEN_DYNBLOCK_H
|
#endif // EIGEN_DYNBLOCK_H
|
||||||
|
@ -34,7 +34,7 @@ bool MatrixBase<Scalar, Derived>::isApprox(
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
assert(rows() == other.rows() && cols() == other.cols());
|
assert(rows() == other.rows() && cols() == other.cols());
|
||||||
if(IsVector)
|
if(IsVectorAtCompileTime)
|
||||||
{
|
{
|
||||||
return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec);
|
return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec);
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ bool MatrixBase<Scalar, Derived>::isMuchSmallerThan(
|
|||||||
const typename NumTraits<Scalar>::Real& prec
|
const typename NumTraits<Scalar>::Real& prec
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if(IsVector)
|
if(IsVectorAtCompileTime)
|
||||||
{
|
{
|
||||||
return(norm2() <= abs2(other * prec));
|
return(norm2() <= abs2(other * prec));
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ bool MatrixBase<Scalar, Derived>::isMuchSmallerThan(
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
assert(rows() == other.rows() && cols() == other.cols());
|
assert(rows() == other.rows() && cols() == other.cols());
|
||||||
if(IsVector)
|
if(IsVectorAtCompileTime)
|
||||||
{
|
{
|
||||||
return(norm2() <= other.norm2() * prec * prec);
|
return(norm2() <= other.norm2() * prec * prec);
|
||||||
}
|
}
|
||||||
|
@ -66,23 +66,23 @@ template<typename MatrixType> class Map
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int rows, int cols)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int rows, int cols)
|
||||||
{
|
{
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), rows, cols);
|
return Map<Derived>(data, rows, cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
assert(IsVectorAtCompileTime);
|
||||||
if(ColsAtCompileTime == 1)
|
if(ColsAtCompileTime == 1)
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), size, 1);
|
return Map<Derived>(data, size, 1);
|
||||||
else
|
else
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), 1, size);
|
return Map<Derived>(data, 1, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data)
|
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data)
|
||||||
{
|
{
|
||||||
return Map<Derived>(const_cast<Scalar*>(data), RowsAtCompileTime, ColsAtCompileTime);
|
return Map<Derived>(data, RowsAtCompileTime, ColsAtCompileTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
@ -94,7 +94,7 @@ Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int rows, int cols)
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int size)
|
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
assert(IsVectorAtCompileTime);
|
||||||
if(ColsAtCompileTime == 1)
|
if(ColsAtCompileTime == 1)
|
||||||
return Map<Derived>(data, size, 1);
|
return Map<Derived>(data, size, 1);
|
||||||
else
|
else
|
||||||
|
@ -63,14 +63,23 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
|
|||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
Matrix& operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
Matrix& operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
||||||
{
|
{
|
||||||
resize(other.rows(), other.cols());
|
if(_RowsAtCompileTime == 1)
|
||||||
|
{
|
||||||
|
assert(other.isVector());
|
||||||
|
resize(1, other.size());
|
||||||
|
}
|
||||||
|
else if(_ColsAtCompileTime == 1)
|
||||||
|
{
|
||||||
|
assert(other.isVector());
|
||||||
|
resize(other.size(), 1);
|
||||||
|
}
|
||||||
|
else resize(other.rows(), other.cols());
|
||||||
return Base::operator=(other);
|
return Base::operator=(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix& operator=(const Matrix& other)
|
Matrix& operator=(const Matrix& other)
|
||||||
{
|
{
|
||||||
resize(other.rows(), other.cols());
|
return operator=<Matrix>(other);
|
||||||
return Base::operator=(other);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
|
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
|
||||||
|
@ -77,7 +77,7 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
* columns is known at compile-time to be equal to 1. Indeed, in that case,
|
* 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
|
* we are dealing with a column-vector (if there is only one column) or with
|
||||||
* a row-vector (if there is only one row). */
|
* a row-vector (if there is only one row). */
|
||||||
static const bool IsVector = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
|
static const bool IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
|
||||||
|
|
||||||
/** This is the "reference type" used to pass objects of type MatrixBase as arguments
|
/** This is the "reference type" used to pass objects of type MatrixBase as arguments
|
||||||
* to functions. If this MatrixBase type represents an expression, then \a Ref
|
* to functions. If this MatrixBase type represents an expression, then \a Ref
|
||||||
@ -98,9 +98,11 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
/** \returns the number of columns. \sa row(), ColsAtCompileTime*/
|
/** \returns the number of columns. \sa row(), ColsAtCompileTime*/
|
||||||
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
||||||
/** \returns the number of coefficients, which is \a rows()*cols().
|
/** \returns the number of coefficients, which is \a rows()*cols().
|
||||||
* \sa rows(), cols(). */
|
* \sa rows(), cols(), SizeAtCompileTime. */
|
||||||
int size() const { return rows() * cols(); }
|
int size() const { return rows() * cols(); }
|
||||||
|
/** \returns true if either the number of rows or the number of columns is equal to 1.
|
||||||
|
* \sa rows(), cols(), IsVectorAtCompileTime. */
|
||||||
|
bool isVector() const { return rows()==1 || cols()==1; }
|
||||||
/** \returns a Ref to *this. \sa Ref */
|
/** \returns a Ref to *this. \sa Ref */
|
||||||
Ref ref() const
|
Ref ref() const
|
||||||
{ return static_cast<const Derived *>(this)->_ref(); }
|
{ return static_cast<const Derived *>(this)->_ref(); }
|
||||||
@ -118,15 +120,27 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
|
|
||||||
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
|
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
|
||||||
|
|
||||||
Row<Derived> row(int i) const;
|
Row<Derived> row(int i);
|
||||||
Column<Derived> col(int i) const;
|
const Row<Derived> row(int i) const;
|
||||||
Minor<Derived> minor(int row, int col) const;
|
|
||||||
DynBlock<Derived> dynBlock(int startRow, int startCol,
|
Column<Derived> col(int i);
|
||||||
int blockRows, int blockCols) const;
|
const Column<Derived> col(int i) const;
|
||||||
template<int BlockRows, int BlockCols>
|
|
||||||
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
|
Minor<Derived> minor(int row, int col);
|
||||||
|
const Minor<Derived> minor(int row, int col) const;
|
||||||
|
|
||||||
|
DynBlock<Derived> dynBlock(int startRow, int startCol, int blockRows, int blockCols);
|
||||||
|
const DynBlock<Derived>
|
||||||
|
dynBlock(int startRow, int startCol, int blockRows, int blockCols) const;
|
||||||
|
|
||||||
|
template<int BlockRows, int BlockCols>
|
||||||
|
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol);
|
||||||
|
template<int BlockRows, int BlockCols>
|
||||||
|
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
|
||||||
|
|
||||||
|
Transpose<Derived> transpose();
|
||||||
|
const Transpose<Derived> transpose() const;
|
||||||
|
|
||||||
Transpose<Derived> transpose() const;
|
|
||||||
const Conjugate<Derived> conjugate() const;
|
const Conjugate<Derived> conjugate() const;
|
||||||
const Transpose<Conjugate<Derived> > adjoint() const;
|
const Transpose<Conjugate<Derived> > adjoint() const;
|
||||||
Scalar trace() const;
|
Scalar trace() const;
|
||||||
@ -151,7 +165,9 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
static const DiagonalMatrix<Derived, OtherDerived>
|
static const DiagonalMatrix<Derived, OtherDerived>
|
||||||
diagonal(const OtherDerived& coeffs);
|
diagonal(const OtherDerived& coeffs);
|
||||||
DiagonalCoeffs<Derived> diagonal() const;
|
|
||||||
|
DiagonalCoeffs<Derived> diagonal();
|
||||||
|
const DiagonalCoeffs<Derived> diagonal() const;
|
||||||
|
|
||||||
static const Map<Derived> map(const Scalar* array, int rows, int cols);
|
static const Map<Derived> map(const Scalar* array, int rows, int cols);
|
||||||
static const Map<Derived> map(const Scalar* array, int size);
|
static const Map<Derived> map(const Scalar* array, int size);
|
||||||
|
@ -33,7 +33,7 @@ template<typename MatrixType> class MatrixRef
|
|||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
friend class MatrixBase<Scalar, MatrixRef>;
|
friend class MatrixBase<Scalar, MatrixRef>;
|
||||||
|
|
||||||
MatrixRef(const MatrixType& matrix) : m_matrix(*const_cast<MatrixType*>(&matrix)) {}
|
MatrixRef(const MatrixType& matrix) : m_matrix(matrix) {}
|
||||||
MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {}
|
MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {}
|
||||||
~MatrixRef() {}
|
~MatrixRef() {}
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ template<typename MatrixType> class MatrixRef
|
|||||||
|
|
||||||
Scalar& _coeffRef(int row, int col)
|
Scalar& _coeffRef(int row, int col)
|
||||||
{
|
{
|
||||||
return m_matrix.coeffRef(row, col);
|
return const_cast<MatrixType*>(&m_matrix)->_coeffRef(row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MatrixType& m_matrix;
|
const MatrixType& m_matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EIGEN_MATRIXREF_H
|
#endif // EIGEN_MATRIXREF_H
|
||||||
|
@ -78,9 +78,17 @@ template<typename MatrixType> class Minor
|
|||||||
* row and column. */
|
* row and column. */
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Minor<Derived>
|
Minor<Derived>
|
||||||
|
MatrixBase<Scalar, Derived>::minor(int row, int col)
|
||||||
|
{
|
||||||
|
return Minor<Derived>(ref(), row, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of minor(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const Minor<Derived>
|
||||||
MatrixBase<Scalar, Derived>::minor(int row, int col) const
|
MatrixBase<Scalar, Derived>::minor(int row, int col) const
|
||||||
{
|
{
|
||||||
return Minor<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), row, col);
|
return Minor<Derived>(ref(), row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_MINOR_H
|
#endif // EIGEN_MINOR_H
|
||||||
|
@ -64,7 +64,7 @@ const Ones<Derived> MatrixBase<Scalar, Derived>::ones(int rows, int cols)
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
const Ones<Derived> MatrixBase<Scalar, Derived>::ones(int size)
|
const Ones<Derived> MatrixBase<Scalar, Derived>::ones(int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ template<typename OtherDerived>
|
|||||||
Derived& MatrixBase<Scalar, Derived>
|
Derived& MatrixBase<Scalar, Derived>
|
||||||
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
||||||
{
|
{
|
||||||
if(IsVector && OtherDerived::IsVector) // copying a vector expression into a vector
|
if(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) // copying a vector expression into a vector
|
||||||
{
|
{
|
||||||
assert(size() == other.size());
|
assert(size() == other.size());
|
||||||
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
|
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
|
||||||
|
@ -64,7 +64,7 @@ Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int rows, int cols)
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int size)
|
Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
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();
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,17 @@ template<typename MatrixType> class Row
|
|||||||
* \sa col(), class Row */
|
* \sa col(), class Row */
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Row<Derived>
|
Row<Derived>
|
||||||
|
MatrixBase<Scalar, Derived>::row(int i)
|
||||||
|
{
|
||||||
|
return Row<Derived>(ref(), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of row(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const Row<Derived>
|
||||||
MatrixBase<Scalar, Derived>::row(int i) const
|
MatrixBase<Scalar, Derived>::row(int i) const
|
||||||
{
|
{
|
||||||
return Row<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), i);
|
return Row<Derived>(ref(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_ROW_H
|
#endif // EIGEN_ROW_H
|
||||||
|
@ -65,9 +65,17 @@ template<typename MatrixType> class Transpose
|
|||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
Transpose<Derived>
|
Transpose<Derived>
|
||||||
|
MatrixBase<Scalar, Derived>::transpose()
|
||||||
|
{
|
||||||
|
return Transpose<Derived>(ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is the const version of transpose(). */
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
const Transpose<Derived>
|
||||||
MatrixBase<Scalar, Derived>::transpose() const
|
MatrixBase<Scalar, Derived>::transpose() const
|
||||||
{
|
{
|
||||||
return Transpose<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref());
|
return Transpose<Derived>(ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_TRANSPOSE_H
|
#endif // EIGEN_TRANSPOSE_H
|
||||||
|
@ -64,7 +64,7 @@ const Zero<Derived> MatrixBase<Scalar, Derived>::zero(int rows, int cols)
|
|||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
const Zero<Derived> MatrixBase<Scalar, Derived>::zero(int size)
|
const Zero<Derived> MatrixBase<Scalar, Derived>::zero(int size)
|
||||||
{
|
{
|
||||||
assert(IsVector);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ SEPARATE_MEMBER_PAGES = NO
|
|||||||
TAB_SIZE = 8
|
TAB_SIZE = 8
|
||||||
ALIASES = \
|
ALIASES = \
|
||||||
"only_for_vectors=This is only for vectors (either row-vectors or column-vectors), \
|
"only_for_vectors=This is only for vectors (either row-vectors or column-vectors), \
|
||||||
as determined by \link MatrixBase::IsVector \endlink."
|
as determined by \link MatrixBase::IsVectorAtCompileTime \endlink."
|
||||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||||
OPTIMIZE_OUTPUT_JAVA = NO
|
OPTIMIZE_OUTPUT_JAVA = NO
|
||||||
BUILTIN_STL_SUPPORT = NO
|
BUILTIN_STL_SUPPORT = NO
|
||||||
|
@ -7,10 +7,13 @@ INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
|
|||||||
SET(test_SRCS
|
SET(test_SRCS
|
||||||
main.cpp
|
main.cpp
|
||||||
basicstuff.cpp
|
basicstuff.cpp
|
||||||
|
linearstructure.cpp
|
||||||
|
product.cpp
|
||||||
adjoint.cpp
|
adjoint.cpp
|
||||||
submatrices.cpp
|
submatrices.cpp
|
||||||
miscmatrices.cpp
|
miscmatrices.cpp
|
||||||
smallvectors.cpp
|
smallvectors.cpp
|
||||||
|
map.cpp
|
||||||
)
|
)
|
||||||
QT4_AUTOMOC(${test_SRCS})
|
QT4_AUTOMOC(${test_SRCS})
|
||||||
|
|
||||||
|
@ -29,18 +29,9 @@ namespace Eigen {
|
|||||||
|
|
||||||
template<typename MatrixType> void basicStuff(const MatrixType& m)
|
template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||||
{
|
{
|
||||||
/* this test covers the following files:
|
|
||||||
1) Explicitly (see comments below):
|
|
||||||
Random.h Zero.h Identity.h Fuzzy.h Sum.h Difference.h
|
|
||||||
Opposite.h Product.h ScalarMultiple.h Map.h
|
|
||||||
|
|
||||||
2) Implicitly (the core stuff):
|
|
||||||
MatrixBase.h Matrix.h MatrixStorage.h CopyHelper.h MatrixRef.h
|
|
||||||
NumTraits.h Util.h MathFunctions.h OperatorEquals.h Coeffs.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||||
|
|
||||||
int rows = m.rows();
|
int rows = m.rows();
|
||||||
int cols = m.cols();
|
int cols = m.cols();
|
||||||
|
|
||||||
@ -58,13 +49,9 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
|||||||
v2 = VectorType::random(rows),
|
v2 = VectorType::random(rows),
|
||||||
vzero = VectorType::zero(rows);
|
vzero = VectorType::zero(rows);
|
||||||
|
|
||||||
Scalar s1 = random<Scalar>(),
|
|
||||||
s2 = random<Scalar>();
|
|
||||||
|
|
||||||
int r = random<int>(0, rows-1),
|
int r = random<int>(0, rows-1),
|
||||||
c = random<int>(0, cols-1);
|
c = random<int>(0, cols-1);
|
||||||
|
|
||||||
// test Fuzzy.h and Zero.h.
|
|
||||||
VERIFY_IS_APPROX( v1, v1);
|
VERIFY_IS_APPROX( v1, v1);
|
||||||
VERIFY_IS_NOT_APPROX( v1, 2*v1);
|
VERIFY_IS_NOT_APPROX( v1, 2*v1);
|
||||||
VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1);
|
VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1);
|
||||||
@ -86,80 +73,13 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
|||||||
// operator() that gets called, which in turn calls _read().
|
// operator() that gets called, which in turn calls _read().
|
||||||
VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::zero(rows,cols)(r,c), static_cast<Scalar>(1));
|
VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::zero(rows,cols)(r,c), static_cast<Scalar>(1));
|
||||||
|
|
||||||
// test the linear structure, i.e. the following files:
|
// now test copying a row-vector into a (column-)vector and conversely.
|
||||||
// Sum.h Difference.h Opposite.h ScalarMultiple.h
|
square.col(r) = square.row(r).eval();
|
||||||
VERIFY_IS_APPROX(-(-m1), m1);
|
Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> rv(rows);
|
||||||
VERIFY_IS_APPROX(m1+m1, 2*m1);
|
Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> cv(rows);
|
||||||
VERIFY_IS_APPROX(m1+m2-m1, m2);
|
rv = square.col(r);
|
||||||
VERIFY_IS_APPROX(-m2+m1+m2, m1);
|
cv = square.row(r);
|
||||||
VERIFY_IS_APPROX(m1*s1, s1*m1);
|
VERIFY_IS_APPROX(rv, cv.transpose());
|
||||||
VERIFY_IS_APPROX((m1+m2)*s1, s1*m1+s1*m2);
|
|
||||||
VERIFY_IS_APPROX((s1+s2)*m1, m1*s1+m1*s2);
|
|
||||||
VERIFY_IS_APPROX((m1-m2)*s1, s1*m1-s1*m2);
|
|
||||||
VERIFY_IS_APPROX((s1-s2)*m1, m1*s1-m1*s2);
|
|
||||||
VERIFY_IS_APPROX((-m1+m2)*s1, -s1*m1+s1*m2);
|
|
||||||
VERIFY_IS_APPROX((-s1+s2)*m1, -m1*s1+m1*s2);
|
|
||||||
m3 = m2; m3 += m1;
|
|
||||||
VERIFY_IS_APPROX(m3, m1+m2);
|
|
||||||
m3 = m2; m3 -= m1;
|
|
||||||
VERIFY_IS_APPROX(m3, m2-m1);
|
|
||||||
m3 = m2; m3 *= s1;
|
|
||||||
VERIFY_IS_APPROX(m3, s1*m2);
|
|
||||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
|
||||||
{
|
|
||||||
m3 = m2; m3 /= s1;
|
|
||||||
VERIFY_IS_APPROX(m3, m2/s1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// again, test operator() to check const-qualification
|
|
||||||
VERIFY_IS_APPROX((-m1)(r,c), -(m1(r,c)));
|
|
||||||
VERIFY_IS_APPROX((m1-m2)(r,c), (m1(r,c))-(m2(r,c)));
|
|
||||||
VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
|
|
||||||
VERIFY_IS_APPROX((s1*m1)(r,c), s1*(m1(r,c)));
|
|
||||||
VERIFY_IS_APPROX((m1*s1)(r,c), (m1(r,c))*s1);
|
|
||||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
|
||||||
VERIFY_IS_APPROX((m1/s1)(r,c), (m1(r,c))/s1);
|
|
||||||
|
|
||||||
// begin testing Product.h: only associativity for now
|
|
||||||
// (we use Transpose.h but this doesn't count as a test for it)
|
|
||||||
VERIFY_IS_APPROX((m1*m1.transpose())*m2, m1*(m1.transpose()*m2));
|
|
||||||
m3 = m1;
|
|
||||||
m3 *= (m1.transpose() * m2);
|
|
||||||
VERIFY_IS_APPROX(m3, m1*(m1.transpose()*m2));
|
|
||||||
VERIFY_IS_APPROX(m3, m1.lazyProduct(m1.transpose()*m2));
|
|
||||||
|
|
||||||
// continue testing Product.h: distributivity
|
|
||||||
VERIFY_IS_APPROX(square*(m1 + m2), square*m1+square*m2);
|
|
||||||
VERIFY_IS_APPROX(square*(m1 - m2), square*m1-square*m2);
|
|
||||||
|
|
||||||
// continue testing Product.h: compatibility with ScalarMultiple.h
|
|
||||||
VERIFY_IS_APPROX(s1*(square*m1), (s1*square)*m1);
|
|
||||||
VERIFY_IS_APPROX(s1*(square*m1), square*(m1*s1));
|
|
||||||
|
|
||||||
// continue testing Product.h: lazyProduct
|
|
||||||
VERIFY_IS_APPROX(square.lazyProduct(m1), square*m1);
|
|
||||||
// again, test operator() to check const-qualification
|
|
||||||
s1 += square.lazyProduct(m1)(r,c);
|
|
||||||
|
|
||||||
// test Product.h together with Identity.h
|
|
||||||
VERIFY_IS_APPROX(m1, identity*m1);
|
|
||||||
VERIFY_IS_APPROX(v1, identity*v1);
|
|
||||||
// again, test operator() to check const-qualification
|
|
||||||
VERIFY_IS_APPROX(MatrixType::identity(std::max(rows,cols))(r,c), static_cast<Scalar>(r==c));
|
|
||||||
|
|
||||||
// test Map.h
|
|
||||||
Scalar* array1 = new Scalar[rows];
|
|
||||||
Scalar* array2 = new Scalar[rows];
|
|
||||||
typedef Matrix<Scalar, Dynamic, 1> VectorX;
|
|
||||||
VectorX::map(array1, rows) = VectorX::random(rows);
|
|
||||||
VectorX::map(array2, rows) = VectorX::map(array1, rows);
|
|
||||||
VectorX ma1 = VectorX::map(array1, rows);
|
|
||||||
VectorX ma2 = VectorX::map(array2, rows);
|
|
||||||
VERIFY_IS_APPROX(ma1, ma2);
|
|
||||||
VERIFY_IS_APPROX(ma1, VectorX(array2, rows));
|
|
||||||
|
|
||||||
delete[] array1;
|
|
||||||
delete[] array2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EigenTest::testBasicStuff()
|
void EigenTest::testBasicStuff()
|
||||||
|
106
test/linearstructure.cpp
Normal file
106
test/linearstructure.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// 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-2007 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.
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
namespace Eigen {
|
||||||
|
|
||||||
|
template<typename MatrixType> void linearStructure(const MatrixType& m)
|
||||||
|
{
|
||||||
|
/* this test covers the following files:
|
||||||
|
Sum.h Difference.h Opposite.h ScalarMultiple.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||||
|
|
||||||
|
int rows = m.rows();
|
||||||
|
int cols = m.cols();
|
||||||
|
|
||||||
|
// this test relies a lot on Random.h, and there's not much more that we can do
|
||||||
|
// to test it, hence I consider that we will have tested Random.h
|
||||||
|
MatrixType m1 = MatrixType::random(rows, cols),
|
||||||
|
m2 = MatrixType::random(rows, cols),
|
||||||
|
m3(rows, cols),
|
||||||
|
mzero = MatrixType::zero(rows, cols),
|
||||||
|
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
||||||
|
::identity(rows),
|
||||||
|
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
||||||
|
::random(rows, rows);
|
||||||
|
VectorType v1 = VectorType::random(rows),
|
||||||
|
v2 = VectorType::random(rows),
|
||||||
|
vzero = VectorType::zero(rows);
|
||||||
|
|
||||||
|
Scalar s1 = random<Scalar>(),
|
||||||
|
s2 = random<Scalar>();
|
||||||
|
|
||||||
|
int r = random<int>(0, rows-1),
|
||||||
|
c = random<int>(0, cols-1);
|
||||||
|
|
||||||
|
VERIFY_IS_APPROX(-(-m1), m1);
|
||||||
|
VERIFY_IS_APPROX(m1+m1, 2*m1);
|
||||||
|
VERIFY_IS_APPROX(m1+m2-m1, m2);
|
||||||
|
VERIFY_IS_APPROX(-m2+m1+m2, m1);
|
||||||
|
VERIFY_IS_APPROX(m1*s1, s1*m1);
|
||||||
|
VERIFY_IS_APPROX((m1+m2)*s1, s1*m1+s1*m2);
|
||||||
|
VERIFY_IS_APPROX((s1+s2)*m1, m1*s1+m1*s2);
|
||||||
|
VERIFY_IS_APPROX((m1-m2)*s1, s1*m1-s1*m2);
|
||||||
|
VERIFY_IS_APPROX((s1-s2)*m1, m1*s1-m1*s2);
|
||||||
|
VERIFY_IS_APPROX((-m1+m2)*s1, -s1*m1+s1*m2);
|
||||||
|
VERIFY_IS_APPROX((-s1+s2)*m1, -m1*s1+m1*s2);
|
||||||
|
m3 = m2; m3 += m1;
|
||||||
|
VERIFY_IS_APPROX(m3, m1+m2);
|
||||||
|
m3 = m2; m3 -= m1;
|
||||||
|
VERIFY_IS_APPROX(m3, m2-m1);
|
||||||
|
m3 = m2; m3 *= s1;
|
||||||
|
VERIFY_IS_APPROX(m3, s1*m2);
|
||||||
|
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||||
|
{
|
||||||
|
m3 = m2; m3 /= s1;
|
||||||
|
VERIFY_IS_APPROX(m3, m2/s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// again, test operator() to check const-qualification
|
||||||
|
VERIFY_IS_APPROX((-m1)(r,c), -(m1(r,c)));
|
||||||
|
VERIFY_IS_APPROX((m1-m2)(r,c), (m1(r,c))-(m2(r,c)));
|
||||||
|
VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
|
||||||
|
VERIFY_IS_APPROX((s1*m1)(r,c), s1*(m1(r,c)));
|
||||||
|
VERIFY_IS_APPROX((m1*s1)(r,c), (m1(r,c))*s1);
|
||||||
|
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||||
|
VERIFY_IS_APPROX((m1/s1)(r,c), (m1(r,c))/s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EigenTest::testLinearStructure()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < m_repeat; i++) {
|
||||||
|
linearStructure(Matrix<float, 1, 1>());
|
||||||
|
linearStructure(Matrix4d());
|
||||||
|
linearStructure(MatrixXcf(3, 3));
|
||||||
|
linearStructure(MatrixXi(8, 12));
|
||||||
|
linearStructure(MatrixXcd(20, 20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Eigen
|
@ -114,10 +114,13 @@ class EigenTest : public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void testBasicStuff();
|
void testBasicStuff();
|
||||||
|
void testLinearStructure();
|
||||||
|
void testProduct();
|
||||||
void testAdjoint();
|
void testAdjoint();
|
||||||
void testSubmatrices();
|
void testSubmatrices();
|
||||||
void testMiscMatrices();
|
void testMiscMatrices();
|
||||||
void testSmallVectors();
|
void testSmallVectors();
|
||||||
|
void testMap();
|
||||||
protected:
|
protected:
|
||||||
int m_repeat;
|
int m_repeat;
|
||||||
};
|
};
|
||||||
|
60
test/map.cpp
Normal file
60
test/map.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// 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-2007 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.
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
namespace Eigen {
|
||||||
|
|
||||||
|
template<typename VectorType> void tmap(const VectorType& m)
|
||||||
|
{
|
||||||
|
typedef typename VectorType::Scalar Scalar;
|
||||||
|
|
||||||
|
int size = m.size();
|
||||||
|
|
||||||
|
// test Map.h
|
||||||
|
Scalar* array1 = new Scalar[size];
|
||||||
|
Scalar* array2 = new Scalar[size];
|
||||||
|
VectorType::map(array1, size) = VectorType::random(size);
|
||||||
|
VectorType::map(array2, size) = VectorType::map(array1, size);
|
||||||
|
VectorType ma1 = VectorType::map(array1, size);
|
||||||
|
VectorType ma2 = VectorType::map(array2, size);
|
||||||
|
VERIFY_IS_APPROX(ma1, ma2);
|
||||||
|
VERIFY_IS_APPROX(ma1, VectorType(array2, size));
|
||||||
|
delete[] array1;
|
||||||
|
delete[] array2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EigenTest::testMap()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < m_repeat; i++) {
|
||||||
|
tmap(Matrix<float, 1, 1>());
|
||||||
|
tmap(Vector4d());
|
||||||
|
tmap(RowVector4f());
|
||||||
|
tmap(VectorXcf(8));
|
||||||
|
tmap(VectorXi(12));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Eigen
|
100
test/product.cpp
Normal file
100
test/product.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
// 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-2007 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.
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
namespace Eigen {
|
||||||
|
|
||||||
|
template<typename MatrixType> void product(const MatrixType& m)
|
||||||
|
{
|
||||||
|
/* this test covers the following files:
|
||||||
|
Identity.h Product.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||||
|
|
||||||
|
int rows = m.rows();
|
||||||
|
int cols = m.cols();
|
||||||
|
|
||||||
|
// this test relies a lot on Random.h, and there's not much more that we can do
|
||||||
|
// to test it, hence I consider that we will have tested Random.h
|
||||||
|
MatrixType m1 = MatrixType::random(rows, cols),
|
||||||
|
m2 = MatrixType::random(rows, cols),
|
||||||
|
m3(rows, cols),
|
||||||
|
mzero = MatrixType::zero(rows, cols),
|
||||||
|
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
||||||
|
::identity(rows),
|
||||||
|
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
||||||
|
::random(rows, rows);
|
||||||
|
VectorType v1 = VectorType::random(rows),
|
||||||
|
v2 = VectorType::random(rows),
|
||||||
|
vzero = VectorType::zero(rows);
|
||||||
|
|
||||||
|
Scalar s1 = random<Scalar>();
|
||||||
|
|
||||||
|
int r = random<int>(0, rows-1),
|
||||||
|
c = random<int>(0, cols-1);
|
||||||
|
|
||||||
|
// begin testing Product.h: only associativity for now
|
||||||
|
// (we use Transpose.h but this doesn't count as a test for it)
|
||||||
|
VERIFY_IS_APPROX((m1*m1.transpose())*m2, m1*(m1.transpose()*m2));
|
||||||
|
m3 = m1;
|
||||||
|
m3 *= (m1.transpose() * m2);
|
||||||
|
VERIFY_IS_APPROX(m3, m1*(m1.transpose()*m2));
|
||||||
|
VERIFY_IS_APPROX(m3, m1.lazyProduct(m1.transpose()*m2));
|
||||||
|
|
||||||
|
// continue testing Product.h: distributivity
|
||||||
|
VERIFY_IS_APPROX(square*(m1 + m2), square*m1+square*m2);
|
||||||
|
VERIFY_IS_APPROX(square*(m1 - m2), square*m1-square*m2);
|
||||||
|
|
||||||
|
// continue testing Product.h: compatibility with ScalarMultiple.h
|
||||||
|
VERIFY_IS_APPROX(s1*(square*m1), (s1*square)*m1);
|
||||||
|
VERIFY_IS_APPROX(s1*(square*m1), square*(m1*s1));
|
||||||
|
|
||||||
|
// continue testing Product.h: lazyProduct
|
||||||
|
VERIFY_IS_APPROX(square.lazyProduct(m1), square*m1);
|
||||||
|
// again, test operator() to check const-qualification
|
||||||
|
s1 += square.lazyProduct(m1)(r,c);
|
||||||
|
|
||||||
|
// test Product.h together with Identity.h
|
||||||
|
VERIFY_IS_APPROX(m1, identity*m1);
|
||||||
|
VERIFY_IS_APPROX(v1, identity*v1);
|
||||||
|
// again, test operator() to check const-qualification
|
||||||
|
VERIFY_IS_APPROX(MatrixType::identity(std::max(rows,cols))(r,c), static_cast<Scalar>(r==c));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EigenTest::testProduct()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < m_repeat; i++) {
|
||||||
|
product(Matrix<float, 1, 1>());
|
||||||
|
product(Matrix4d());
|
||||||
|
product(MatrixXcf(3, 3));
|
||||||
|
product(MatrixXi(8, 12));
|
||||||
|
product(MatrixXcd(20, 20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Eigen
|
Loading…
x
Reference in New Issue
Block a user