* Merge Extract and Part to the Part expression.

Renamed "MatrixBase::extract() const" to "MatrixBase::part() const"
* Renamed static functions identity, zero, ones, random with an upper case
  first letter: Identity, Zero, Ones and Random.
This commit is contained in:
Gael Guennebaud 2008-07-21 00:34:46 +00:00
parent ce425d92f1
commit c10f069b6b
80 changed files with 434 additions and 500 deletions

View File

@ -57,7 +57,6 @@ namespace Eigen {
#include "src/Core/IO.h"
#include "src/Core/Swap.h"
#include "src/Core/CommaInitializer.h"
#include "src/Core/Extract.h"
#include "src/Core/Part.h"
#include "src/Core/CacheFriendlyProduct.h"

View File

@ -53,7 +53,7 @@ struct ei_functor_traits<ei_scalar_random_op<Scalar> >
*/
template<typename Derived>
inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random(int rows, int cols)
MatrixBase<Derived>::Random(int rows, int cols)
{
return NullaryExpr(rows, cols, ei_scalar_random_op<Scalar>());
}
@ -78,7 +78,7 @@ MatrixBase<Derived>::random(int rows, int cols)
*/
template<typename Derived>
inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random(int size)
MatrixBase<Derived>::Random(int size)
{
return NullaryExpr(size, ei_scalar_random_op<Scalar>());
}
@ -98,7 +98,7 @@ MatrixBase<Derived>::random(int size)
*/
template<typename Derived>
inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random()
MatrixBase<Derived>::Random()
{
return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>());
}
@ -115,7 +115,7 @@ MatrixBase<Derived>::random()
template<typename Derived>
inline Derived& MatrixBase<Derived>::setRandom()
{
return *this = random(rows(), cols());
return *this = Random(rows(), cols());
}
#endif // EIGEN_RANDOM_H

View File

@ -58,7 +58,7 @@ template<typename MatrixType> class Cholesky
compute(matrix);
}
Extract<MatrixType, Lower> matrixL(void) const
Part<MatrixType, Lower> matrixL(void) const
{
return m_matrix;
}
@ -79,7 +79,7 @@ template<typename MatrixType> class Cholesky
bool m_isPositiveDefinite;
};
/** Compute / recompute the Cholesky decomposition A = LL^* = U^*U of \a matrix
/** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix
*/
template<typename MatrixType>
void Cholesky<MatrixType>::compute(const MatrixType& a)
@ -124,7 +124,7 @@ typename Derived::Eval Cholesky<MatrixType>::solve(const MatrixBase<Derived> &b)
const int size = m_matrix.rows();
ei_assert(size==b.rows());
return m_matrix.adjoint().template extract<Upper>().inverseProduct(matrixL().inverseProduct(b));
return m_matrix.adjoint().template part<Upper>().inverseProduct(matrixL().inverseProduct(b));
}
/** \cholesky_module

View File

@ -58,7 +58,7 @@ template<typename MatrixType> class CholeskyWithoutSquareRoot
}
/** \returns the lower triangular matrix L */
Extract<MatrixType, UnitLower> matrixL(void) const
Part<MatrixType, UnitLower> matrixL(void) const
{
return m_matrix;
}
@ -136,7 +136,7 @@ typename Derived::Eval CholeskyWithoutSquareRoot<MatrixType>::solve(const Matrix
const int size = m_matrix.rows();
ei_assert(size==b.rows());
return m_matrix.adjoint().template extract<UnitUpper>()
return m_matrix.adjoint().template part<UnitUpper>()
.inverseProduct(
(matrixL()
.inverseProduct(b))

View File

@ -32,7 +32,7 @@
* \param NullaryOp template functor implementing the operator
*
* This class represents an expression of a generic nullary operator.
* It is the return type of the ones(), zero(), constant(), identity() and random() functions,
* It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() functions,
* and most of the time this is the only way it is used.
*
* However, if you want to write a function returning such an expression, you
@ -113,7 +113,7 @@ class CwiseNullaryOp : ei_no_assignment_operator,
* the returned matrix. Must be compatible with this MatrixBase type.
*
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
* it is redundant to pass \a rows and \a cols as arguments, so zero() should be used
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
* instead.
*
* The template parameter \a CustomNullaryOp is the type of the functor.
@ -136,7 +136,7 @@ MatrixBase<Derived>::NullaryExpr(int rows, int cols, const CustomNullaryOp& func
* \only_for_vectors
*
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
* it is redundant to pass \a size as argument, so zero() should be used
* it is redundant to pass \a size as argument, so Zero() should be used
* instead.
*
* The template parameter \a CustomNullaryOp is the type of the functor.
@ -176,7 +176,7 @@ MatrixBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
* the returned matrix. Must be compatible with this MatrixBase type.
*
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
* it is redundant to pass \a rows and \a cols as arguments, so zero() should be used
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
* instead.
*
* The template parameter \a CustomNullaryOp is the type of the functor.
@ -185,7 +185,7 @@ MatrixBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::constant(int rows, int cols, const Scalar& value)
MatrixBase<Derived>::Constant(int rows, int cols, const Scalar& value)
{
return NullaryExpr(rows, cols, ei_scalar_constant_op<Scalar>(value));
}
@ -198,7 +198,7 @@ MatrixBase<Derived>::constant(int rows, int cols, const Scalar& value)
* \only_for_vectors
*
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
* it is redundant to pass \a size as argument, so zero() should be used
* it is redundant to pass \a size as argument, so Zero() should be used
* instead.
*
* The template parameter \a CustomNullaryOp is the type of the functor.
@ -207,7 +207,7 @@ MatrixBase<Derived>::constant(int rows, int cols, const Scalar& value)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::constant(int size, const Scalar& value)
MatrixBase<Derived>::Constant(int size, const Scalar& value)
{
return NullaryExpr(size, ei_scalar_constant_op<Scalar>(value));
}
@ -223,7 +223,7 @@ MatrixBase<Derived>::constant(int size, const Scalar& value)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::constant(const Scalar& value)
MatrixBase<Derived>::Constant(const Scalar& value)
{
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op<Scalar>(value));
@ -242,12 +242,12 @@ bool MatrixBase<Derived>::isApproxToConstant
/** Sets all coefficients in this expression to \a value.
*
* \sa class CwiseNullaryOp, zero(), ones()
* \sa class CwiseNullaryOp, Zero(), Ones()
*/
template<typename Derived>
Derived& MatrixBase<Derived>::setConstant(const Scalar& value)
{
return *this = constant(rows(), cols(), value);
return derived() = Constant(rows(), cols(), value);
}
// zero:
@ -258,7 +258,7 @@ Derived& MatrixBase<Derived>::setConstant(const Scalar& value)
* the returned matrix. Must be compatible with this MatrixBase type.
*
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
* it is redundant to pass \a rows and \a cols as arguments, so zero() should be used
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
* instead.
*
* \addexample Zero \label How to take get a zero matrix
@ -266,13 +266,13 @@ Derived& MatrixBase<Derived>::setConstant(const Scalar& value)
* Example: \include MatrixBase_zero_int_int.cpp
* Output: \verbinclude MatrixBase_zero_int_int.out
*
* \sa zero(), zero(int)
* \sa Zero(), Zero(int)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::zero(int rows, int cols)
MatrixBase<Derived>::Zero(int rows, int cols)
{
return constant(rows, cols, Scalar(0));
return Constant(rows, cols, Scalar(0));
}
/** \returns an expression of a zero vector.
@ -283,19 +283,19 @@ MatrixBase<Derived>::zero(int rows, int cols)
* \only_for_vectors
*
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
* it is redundant to pass \a size as argument, so zero() should be used
* it is redundant to pass \a size as argument, so Zero() should be used
* instead.
*
* Example: \include MatrixBase_zero_int.cpp
* Output: \verbinclude MatrixBase_zero_int.out
*
* \sa zero(), zero(int,int)
* \sa Zero(), Zero(int,int)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::zero(int size)
MatrixBase<Derived>::Zero(int size)
{
return constant(size, Scalar(0));
return Constant(size, Scalar(0));
}
/** \returns an expression of a fixed-size zero matrix or vector.
@ -306,13 +306,13 @@ MatrixBase<Derived>::zero(int size)
* Example: \include MatrixBase_zero.cpp
* Output: \verbinclude MatrixBase_zero.out
*
* \sa zero(int), zero(int,int)
* \sa Zero(int), Zero(int,int)
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::zero()
MatrixBase<Derived>::Zero()
{
return constant(Scalar(0));
return Constant(Scalar(0));
}
/** \returns true if *this is approximately equal to the zero matrix,
@ -321,7 +321,7 @@ MatrixBase<Derived>::zero()
* Example: \include MatrixBase_isZero.cpp
* Output: \verbinclude MatrixBase_isZero.out
*
* \sa class CwiseNullaryOp, zero()
* \sa class CwiseNullaryOp, Zero()
*/
template<typename Derived>
bool MatrixBase<Derived>::isZero
@ -339,7 +339,7 @@ bool MatrixBase<Derived>::isZero
* Example: \include MatrixBase_setZero.cpp
* Output: \verbinclude MatrixBase_setZero.out
*
* \sa class CwiseNullaryOp, zero()
* \sa class CwiseNullaryOp, Zero()
*/
template<typename Derived>
Derived& MatrixBase<Derived>::setZero()
@ -355,7 +355,7 @@ Derived& MatrixBase<Derived>::setZero()
* the returned matrix. Must be compatible with this MatrixBase type.
*
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
* it is redundant to pass \a rows and \a cols as arguments, so ones() should be used
* it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used
* instead.
*
* \addexample One \label How to get a matrix with all coefficients equal one
@ -363,13 +363,13 @@ Derived& MatrixBase<Derived>::setZero()
* Example: \include MatrixBase_ones_int_int.cpp
* Output: \verbinclude MatrixBase_ones_int_int.out
*
* \sa ones(), ones(int), isOnes(), class Ones
* \sa Ones(), Ones(int), isOnes(), class Ones
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::ones(int rows, int cols)
MatrixBase<Derived>::Ones(int rows, int cols)
{
return constant(rows, cols, Scalar(1));
return Constant(rows, cols, Scalar(1));
}
/** \returns an expression of a vector where all coefficients equal one.
@ -380,19 +380,19 @@ MatrixBase<Derived>::ones(int rows, int cols)
* \only_for_vectors
*
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
* it is redundant to pass \a size as argument, so ones() should be used
* it is redundant to pass \a size as argument, so Ones() should be used
* instead.
*
* Example: \include MatrixBase_ones_int.cpp
* Output: \verbinclude MatrixBase_ones_int.out
*
* \sa ones(), ones(int,int), isOnes(), class Ones
* \sa Ones(), Ones(int,int), isOnes(), class Ones
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::ones(int size)
MatrixBase<Derived>::Ones(int size)
{
return constant(size, Scalar(1));
return Constant(size, Scalar(1));
}
/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one.
@ -403,13 +403,13 @@ MatrixBase<Derived>::ones(int size)
* Example: \include MatrixBase_ones.cpp
* Output: \verbinclude MatrixBase_ones.out
*
* \sa ones(int), ones(int,int), isOnes(), class Ones
* \sa Ones(int), Ones(int,int), isOnes(), class Ones
*/
template<typename Derived>
const typename MatrixBase<Derived>::ConstantReturnType
MatrixBase<Derived>::ones()
MatrixBase<Derived>::Ones()
{
return constant(Scalar(1));
return Constant(Scalar(1));
}
/** \returns true if *this is approximately equal to the matrix where all coefficients
@ -418,7 +418,7 @@ MatrixBase<Derived>::ones()
* Example: \include MatrixBase_isOnes.cpp
* Output: \verbinclude MatrixBase_isOnes.out
*
* \sa class CwiseNullaryOp, ones()
* \sa class CwiseNullaryOp, Ones()
*/
template<typename Derived>
bool MatrixBase<Derived>::isOnes
@ -432,7 +432,7 @@ bool MatrixBase<Derived>::isOnes
* Example: \include MatrixBase_setOnes.cpp
* Output: \verbinclude MatrixBase_setOnes.out
*
* \sa class CwiseNullaryOp, ones()
* \sa class CwiseNullaryOp, Ones()
*/
template<typename Derived>
Derived& MatrixBase<Derived>::setOnes()
@ -448,7 +448,7 @@ Derived& MatrixBase<Derived>::setOnes()
* the returned matrix. Must be compatible with this MatrixBase type.
*
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
* it is redundant to pass \a rows and \a cols as arguments, so identity() should be used
* it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used
* instead.
*
* \addexample Identity \label How to get an identity matrix
@ -456,11 +456,11 @@ Derived& MatrixBase<Derived>::setOnes()
* Example: \include MatrixBase_identity_int_int.cpp
* Output: \verbinclude MatrixBase_identity_int_int.out
*
* \sa identity(), setIdentity(), isIdentity()
* \sa Identity(), setIdentity(), isIdentity()
*/
template<typename Derived>
inline const typename MatrixBase<Derived>::IdentityReturnType
MatrixBase<Derived>::identity(int rows, int cols)
MatrixBase<Derived>::Identity(int rows, int cols)
{
return NullaryExpr(rows, cols, ei_scalar_identity_op<Scalar>());
}
@ -473,11 +473,11 @@ MatrixBase<Derived>::identity(int rows, int cols)
* Example: \include MatrixBase_identity.cpp
* Output: \verbinclude MatrixBase_identity.out
*
* \sa identity(int,int), setIdentity(), isIdentity()
* \sa Identity(int,int), setIdentity(), isIdentity()
*/
template<typename Derived>
inline const typename MatrixBase<Derived>::IdentityReturnType
MatrixBase<Derived>::identity()
MatrixBase<Derived>::Identity()
{
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_identity_op<Scalar>());
@ -490,7 +490,7 @@ MatrixBase<Derived>::identity()
* Example: \include MatrixBase_isIdentity.cpp
* Output: \verbinclude MatrixBase_isIdentity.out
*
* \sa class CwiseNullaryOp, identity(), identity(int,int), setIdentity()
* \sa class CwiseNullaryOp, Identity(), Identity(int,int), setIdentity()
*/
template<typename Derived>
bool MatrixBase<Derived>::isIdentity
@ -520,12 +520,12 @@ bool MatrixBase<Derived>::isIdentity
* Example: \include MatrixBase_setIdentity.cpp
* Output: \verbinclude MatrixBase_setIdentity.out
*
* \sa class CwiseNullaryOp, identity(), identity(int,int), isIdentity()
* \sa class CwiseNullaryOp, Identity(), Identity(int,int), isIdentity()
*/
template<typename Derived>
inline Derived& MatrixBase<Derived>::setIdentity()
{
return *this = identity(rows(), cols());
return derived() = Identity(rows(), cols());
}
/** \returns an expression of the i-th unit (basis) vector.
@ -538,7 +538,7 @@ template<typename Derived>
const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(int size, int i)
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
return BasisReturnType(SquareMatrixType::identity(size,size), i);
return BasisReturnType(SquareMatrixType::Identity(size,size), i);
}
/** \returns an expression of the i-th unit (basis) vector.
@ -553,7 +553,7 @@ template<typename Derived>
const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(int i)
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
return BasisReturnType(SquareMatrixType::identity(),i);
return BasisReturnType(SquareMatrixType::Identity(),i);
}
/** \returns an expression of the X axis unit vector (1{,0}^*)

View File

@ -1,155 +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) 2008 Gael Guennebaud <g.gael@free.fr>
// Copyright (C) 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 Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// Alternatively, 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 of
// the License, 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 Lesser General Public License or the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.
#ifndef EIGEN_EXTRACT_H
#define EIGEN_EXTRACT_H
/** \class Extract
*
* \brief Expression of a triangular matrix extracted from a given matrix
*
* \param MatrixType the type of the object in which we are taking the triangular part
* \param Mode the kind of triangular matrix expression to construct. Can be Upper, StrictlyUpper,
* UnitUpper, Lower, StrictlyLower, UnitLower. This is in fact a bit field; it must have either
* UpperTriangularBit or LowerTriangularBit, and additionnaly it may have either ZeroDiagBit or
* UnitDiagBit.
*
* This class represents an expression of the upper or lower triangular part of
* a square matrix, possibly with a further assumption on the diagonal. It is the return type
* of MatrixBase::extract() and most of the time this is the only way it is used.
*
* \sa MatrixBase::extract()
*/
template<typename MatrixType, unsigned int Mode>
struct ei_traits<Extract<MatrixType, Mode> >
{
typedef typename MatrixType::Scalar Scalar;
typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
enum {
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
Flags = (_MatrixTypeNested::Flags & ~(PacketAccessBit | LinearAccessBit | DirectAccessBit)) | Mode,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
};
};
template<typename MatrixType, unsigned int Mode> class Extract
: public MatrixBase<Extract<MatrixType, Mode> >
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Extract)
inline Extract(const MatrixType& matrix) : m_matrix(matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Extract)
inline int rows() const { return m_matrix.rows(); }
inline int cols() const { return m_matrix.cols(); }
inline Scalar coeff(int row, int col) const
{
if(Flags & LowerTriangularBit ? col>row : row>col)
return (Flags & SelfAdjointBit) ? ei_conj(m_matrix.coeff(col, row)) : (Scalar)0;
if(Flags & UnitDiagBit)
return col==row ? (Scalar)1 : m_matrix.coeff(row, col);
else if(Flags & ZeroDiagBit)
return col==row ? (Scalar)0 : m_matrix.coeff(row, col);
else
return m_matrix.coeff(row, col);
}
protected:
const typename MatrixType::Nested m_matrix;
};
/** \returns an expression of a triangular matrix extracted from the current matrix
*
* The parameter \a Mode can have the following values: \c Upper, \c StrictlyUpper, \c UnitUpper,
* \c Lower, \c StrictlyLower, \c UnitLower.
*
* \addexample ExtractExample \label How to extract a triangular part of an arbitrary matrix
*
* Example: \include MatrixBase_extract.cpp
* Output: \verbinclude MatrixBase_extract.out
*
* \sa class Extract, part(), marked()
*/
template<typename Derived>
template<unsigned int Mode>
const Extract<Derived, Mode> MatrixBase<Derived>::extract() const
{
return derived();
}
/** \returns true if *this is approximately equal to an upper triangular matrix,
* within the precision given by \a prec.
*
* \sa isLower(), extract(), part(), marked()
*/
template<typename Derived>
bool MatrixBase<Derived>::isUpper(RealScalar prec) const
{
if(cols() != rows()) return false;
RealScalar maxAbsOnUpperPart = static_cast<RealScalar>(-1);
for(int j = 0; j < cols(); j++)
for(int i = 0; i <= j; i++)
{
RealScalar absValue = ei_abs(coeff(i,j));
if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
}
for(int j = 0; j < cols()-1; j++)
for(int i = j+1; i < rows(); i++)
if(!ei_isMuchSmallerThan(coeff(i, j), maxAbsOnUpperPart, prec)) return false;
return true;
}
/** \returns true if *this is approximately equal to a lower triangular matrix,
* within the precision given by \a prec.
*
* \sa isUpper(), extract(), part(), marked()
*/
template<typename Derived>
bool MatrixBase<Derived>::isLower(RealScalar prec) const
{
if(cols() != rows()) return false;
RealScalar maxAbsOnLowerPart = static_cast<RealScalar>(-1);
for(int j = 0; j < cols(); j++)
for(int i = j; i < rows(); i++)
{
RealScalar absValue = ei_abs(coeff(i,j));
if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
}
for(int j = 1; j < cols(); j++)
for(int i = 0; i < j; i++)
if(!ei_isMuchSmallerThan(coeff(i, j), maxAbsOnLowerPart, prec)) return false;
return true;
}
#endif // EIGEN_EXTRACT_H

View File

@ -376,15 +376,15 @@ template<typename Derived> class MatrixBase
const DiagonalCoeffs<Derived> diagonal() const;
template<unsigned int Mode> Part<Derived, Mode> part();
template<unsigned int Mode> const Extract<Derived, Mode> extract() const;
template<unsigned int Mode> const Part<Derived, Mode> part() const;
static const ConstantReturnType
constant(int rows, int cols, const Scalar& value);
Constant(int rows, int cols, const Scalar& value);
static const ConstantReturnType
constant(int size, const Scalar& value);
Constant(int size, const Scalar& value);
static const ConstantReturnType
constant(const Scalar& value);
Constant(const Scalar& value);
template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomNullaryOp, Derived>
@ -396,14 +396,14 @@ template<typename Derived> class MatrixBase
static const CwiseNullaryOp<CustomNullaryOp, Derived>
NullaryExpr(const CustomNullaryOp& func);
static const ConstantReturnType zero(int rows, int cols);
static const ConstantReturnType zero(int size);
static const ConstantReturnType zero();
static const ConstantReturnType ones(int rows, int cols);
static const ConstantReturnType ones(int size);
static const ConstantReturnType ones();
static const IdentityReturnType identity();
static const IdentityReturnType identity(int rows, int cols);
static const ConstantReturnType Zero(int rows, int cols);
static const ConstantReturnType Zero(int size);
static const ConstantReturnType Zero();
static const ConstantReturnType Ones(int rows, int cols);
static const ConstantReturnType Ones(int size);
static const ConstantReturnType Ones();
static const IdentityReturnType Identity();
static const IdentityReturnType Identity(int rows, int cols);
static const BasisReturnType Unit(int size, int i);
static const BasisReturnType Unit(int i);
static const BasisReturnType UnitX();
@ -521,9 +521,9 @@ template<typename Derived> class MatrixBase
const PartialRedux<Derived,Horizontal> rowwise() const;
const PartialRedux<Derived,Vertical> colwise() const;
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int rows, int cols);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int size);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random();
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random(int rows, int cols);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random(int size);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> Random();
/////////// LU module ///////////

View File

@ -28,58 +28,120 @@
/** \class Part
*
* \brief Pseudo-expression allowing to write to a special part of a matrix
* \brief Expression of a triangular matrix extracted from a given matrix
*
* This lvalue-only pseudo-expression allows to perform special operations
* on a matrix, such as writing only to the upper (above diagonal) part.
* \param MatrixType the type of the object in which we are taking the triangular part
* \param Mode the kind of triangular matrix expression to construct. Can be Upper, StrictlyUpper,
* UnitUpper, Lower, StrictlyLower, UnitLower. This is in fact a bit field; it must have either
* UpperTriangularBit or LowerTriangularBit, and additionnaly it may have either ZeroDiagBit or
* UnitDiagBit.
*
* It is the return type of MatrixBase::part() and most of the time this is
* the only way that it is used.
* This class represents an expression of the upper or lower triangular part of
* a square matrix, possibly with a further assumption on the diagonal. It is the return type
* of MatrixBase::part() and most of the time this is the only way it is used.
*
* \sa class Extract, MatrixBase::part()
* \sa MatrixBase::part()
*/
template<typename MatrixType, unsigned int Mode>
class Part
struct ei_traits<Part<MatrixType, Mode> >
{
typedef typename MatrixType::Scalar Scalar;
typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
enum {
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
Flags = (_MatrixTypeNested::Flags & ~(PacketAccessBit | LinearAccessBit | DirectAccessBit)) | Mode,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
};
};
template<typename MatrixType, unsigned int Mode> class Part
: public MatrixBase<Part<MatrixType, Mode> >
{
public:
Part(MatrixType& matrix);
EIGEN_GENERIC_PUBLIC_INTERFACE(Part)
inline Part(const MatrixType& matrix) : m_matrix(matrix)
{ ei_assert(ei_are_flags_consistent<Mode>::ret); }
/** \sa MatrixBase::operator+=() */
template<typename Other> Part& operator+=(const Other& other);
/** \sa MatrixBase::operator-=() */
template<typename Other> Part& operator-=(const Other& other);
/** \sa MatrixBase::operator*=() */
Part& operator*=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa MatrixBase::operator/=() */
Part& operator/=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa operator=(), MatrixBase::lazyAssign() */
template<typename Other> void lazyAssign(const Other& other);
/** \sa MatrixBase::operator=() */
template<typename Other> void operator=(const Other& other);
/** \sa MatrixBase::operator+=() */
template<typename Other> void operator+=(const Other& other);
/** \sa MatrixBase::operator-=() */
template<typename Other> void operator-=(const Other& other);
/** \sa MatrixBase::operator*=() */
void operator*=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa MatrixBase::operator/=() */
void operator/=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa MatrixBase::setConstant() */
void setConstant(const typename ei_traits<MatrixType>::Scalar& value);
/** \sa MatrixBase::setZero() */
void setZero();
/** \sa MatrixBase::setOnes() */
void setOnes();
/** \sa MatrixBase::setRandom() */
void setRandom();
/** \sa MatrixBase::setIdentity() */
void setIdentity();
template<typename Other> Part& operator=(const Other& other);
private:
MatrixType& m_matrix;
inline int rows() const { return m_matrix.rows(); }
inline int cols() const { return m_matrix.cols(); }
inline Scalar coeff(int row, int col) const
{
if(Flags & LowerTriangularBit ? col>row : row>col)
return (Flags & SelfAdjointBit) ? ei_conj(m_matrix.coeff(col, row)) : (Scalar)0;
if(Flags & UnitDiagBit)
return col==row ? (Scalar)1 : m_matrix.coeff(row, col);
else if(Flags & ZeroDiagBit)
return col==row ? (Scalar)0 : m_matrix.coeff(row, col);
else
return m_matrix.coeff(row, col);
}
inline Scalar coeffRef(int row, int col) const
{
EIGEN_STATIC_ASSERT(!(Flags & UnitDiagBit), writting_to_triangular_part_with_unit_diag_is_not_supported);
EIGEN_STATIC_ASSERT(!(Flags & SelfAdjointBit), default_writting_to_selfadjoint_not_supported);
ei_assert( (Mode==Upper && col>=row)
|| (Mode==Lower && col<=row)
|| (Mode==StrictlyUpper && col>row)
|| (Mode==StrictlyLower && col<row));
return m_matrix.coeffRef(row, col);
}
/** discard any writes to a row */
const Block<Part, 1, ColsAtCompileTime> row(int i) { return Base::row(i); }
const Block<Part, 1, ColsAtCompileTime> row(int i) const { return Base::row(i); }
/** discard any writes to a column */
const Block<Part, RowsAtCompileTime, 1> col(int i) { return Base::col(i); }
const Block<Part, RowsAtCompileTime, 1> col(int i) const { return Base::col(i); }
protected:
const typename MatrixType::Nested m_matrix;
};
template<typename MatrixType, unsigned int Mode>
inline Part<MatrixType, Mode>::Part(MatrixType& matrix)
: m_matrix(matrix)
/** \returns an expression of a triangular matrix extracted from the current matrix
*
* The parameter \a Mode can have the following values: \c Upper, \c StrictlyUpper, \c UnitUpper,
* \c Lower, \c StrictlyLower, \c UnitLower.
*
* \addexample PartExample \label How to extract a triangular part of an arbitrary matrix
*
* Example: \include MatrixBase_extract.cpp
* Output: \verbinclude MatrixBase_extract.out
*
* \sa class Part, part(), marked()
*/
template<typename Derived>
template<unsigned int Mode>
const Part<Derived, Mode> MatrixBase<Derived>::part() const
{
ei_assert(ei_are_flags_consistent<Mode>::ret);
return derived();
}
template<typename MatrixType, unsigned int Mode>
template<typename Other>
inline void Part<MatrixType, Mode>::operator=(const Other& other)
inline Part<MatrixType, Mode>& Part<MatrixType, Mode>::operator=(const Other& other)
{
if(Other::Flags & EvalBeforeAssigningBit)
{
@ -89,6 +151,7 @@ inline void Part<MatrixType, Mode>::operator=(const Other& other)
}
else
lazyAssign(other.derived());
return *this;
}
template<typename Derived1, typename Derived2, unsigned int Mode, int UnrollCount>
@ -204,57 +267,7 @@ void Part<MatrixType, Mode>::lazyAssign(const Other& other)
ei_part_assignment_impl
<MatrixType, Other, Mode,
unroll ? int(MatrixType::SizeAtCompileTime) : Dynamic
>::run(m_matrix, other.derived());
}
template<typename MatrixType, unsigned int Mode>
template<typename Other> inline void Part<MatrixType, Mode>::operator+=(const Other& other)
{
*this = m_matrix + other;
}
template<typename MatrixType, unsigned int Mode>
template<typename Other> inline void Part<MatrixType, Mode>::operator-=(const Other& other)
{
*this = m_matrix - other;
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::operator*=
(const typename ei_traits<MatrixType>::Scalar& other)
{
*this = m_matrix * other;
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::operator/=
(const typename ei_traits<MatrixType>::Scalar& other)
{
*this = m_matrix / other;
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::setConstant(const typename ei_traits<MatrixType>::Scalar& value)
{
*this = MatrixType::constant(m_matrix.rows(), m_matrix.cols(), value);
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::setZero()
{
setConstant((typename ei_traits<MatrixType>::Scalar)(0));
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::setOnes()
{
setConstant((typename ei_traits<MatrixType>::Scalar)(1));
}
template<typename MatrixType, unsigned int Mode>
inline void Part<MatrixType, Mode>::setRandom()
{
*this = MatrixType::random(m_matrix.rows(), m_matrix.cols());
>::run(m_matrix.const_cast_derived(), other.derived());
}
/** \returns a lvalue pseudo-expression allowing to perform special operations on \c *this.
@ -276,4 +289,76 @@ inline Part<Derived, Mode> MatrixBase<Derived>::part()
return Part<Derived, Mode>(derived());
}
/** \returns true if *this is approximately equal to an upper triangular matrix,
* within the precision given by \a prec.
*
* \sa isLower(), extract(), part(), marked()
*/
template<typename Derived>
bool MatrixBase<Derived>::isUpper(RealScalar prec) const
{
if(cols() != rows()) return false;
RealScalar maxAbsOnUpperPart = static_cast<RealScalar>(-1);
for(int j = 0; j < cols(); j++)
for(int i = 0; i <= j; i++)
{
RealScalar absValue = ei_abs(coeff(i,j));
if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
}
for(int j = 0; j < cols()-1; j++)
for(int i = j+1; i < rows(); i++)
if(!ei_isMuchSmallerThan(coeff(i, j), maxAbsOnUpperPart, prec)) return false;
return true;
}
/** \returns true if *this is approximately equal to a lower triangular matrix,
* within the precision given by \a prec.
*
* \sa isUpper(), extract(), part(), marked()
*/
template<typename Derived>
bool MatrixBase<Derived>::isLower(RealScalar prec) const
{
if(cols() != rows()) return false;
RealScalar maxAbsOnLowerPart = static_cast<RealScalar>(-1);
for(int j = 0; j < cols(); j++)
for(int i = j; i < rows(); i++)
{
RealScalar absValue = ei_abs(coeff(i,j));
if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
}
for(int j = 1; j < cols(); j++)
for(int i = 0; i < j; i++)
if(!ei_isMuchSmallerThan(coeff(i, j), maxAbsOnLowerPart, prec)) return false;
return true;
}
template<typename MatrixType, unsigned int Mode>
template<typename Other>
inline Part<MatrixType, Mode>& Part<MatrixType, Mode>::operator+=(const Other& other)
{
return *this = m_matrix + other;
}
template<typename MatrixType, unsigned int Mode>
template<typename Other>
inline Part<MatrixType, Mode>& Part<MatrixType, Mode>::operator-=(const Other& other)
{
return *this = m_matrix - other;
}
template<typename MatrixType, unsigned int Mode>
inline Part<MatrixType, Mode>& Part<MatrixType, Mode>::operator*=
(const typename ei_traits<MatrixType>::Scalar& other)
{
return *this = m_matrix * other;
}
template<typename MatrixType, unsigned int Mode>
inline Part<MatrixType, Mode>& Part<MatrixType, Mode>::operator/=
(const typename ei_traits<MatrixType>::Scalar& other)
{
return *this = m_matrix / other;
}
#endif // EIGEN_PART_H

View File

@ -61,7 +61,10 @@
this_method_is_only_for_vectors_of_a_specific_size,
you_did_a_programming_error,
you_called_a_fixed_size_method_on_a_dynamic_size_matrix_or_vector,
unaligned_load_and_store_operations_unimplemented_on_AltiVec
unaligned_load_and_store_operations_unimplemented_on_AltiVec,
scalar_type_must_be_floating_point,
default_writting_to_selfadjoint_not_supported,
writting_to_triangular_part_with_unit_diag_is_not_supported
};
};

View File

@ -132,11 +132,11 @@ public:
operator Matrix3 () const { return toRotationMatrix(); }
/** \returns a quaternion representing an identity rotation
* \sa MatrixBase::identity()
* \sa MatrixBase::Identity()
*/
inline static Quaternion identity() { return Quaternion(1, 0, 0, 0); }
inline static Quaternion Identity() { return Quaternion(1, 0, 0, 0); }
/** \sa Quaternion::identity(), MatrixBase::setIdentity()
/** \sa Quaternion::Identity(), MatrixBase::setIdentity()
*/
inline Quaternion& setIdentity() { m_coeffs << 1, 0, 0, 0; return *this; }
@ -328,7 +328,7 @@ inline Quaternion<Scalar> Quaternion<Scalar>::inverse() const
else
{
// return an invalid result to flag the error
return Quaternion(Coefficients::zero());
return Quaternion(Coefficients::Zero());
}
}

View File

@ -240,7 +240,7 @@ template<typename OtherDerived>
Transform<Scalar,Dim>&
Transform<Scalar,Dim>::scale(const MatrixBase<OtherDerived> &other)
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,Dim);
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim));
affine() = (affine() * other.asDiagonal()).lazy();
return *this;
}
@ -254,7 +254,7 @@ template<typename OtherDerived>
Transform<Scalar,Dim>&
Transform<Scalar,Dim>::prescale(const MatrixBase<OtherDerived> &other)
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,Dim);
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim));
m_matrix.template block<Dim,HDim>(0,0) = (other.asDiagonal() * m_matrix.template block<Dim,HDim>(0,0)).lazy();
return *this;
}
@ -268,7 +268,7 @@ template<typename OtherDerived>
Transform<Scalar,Dim>&
Transform<Scalar,Dim>::translate(const MatrixBase<OtherDerived> &other)
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,Dim);
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim));
translation() += affine() * other;
return *this;
}
@ -282,7 +282,7 @@ template<typename OtherDerived>
Transform<Scalar,Dim>&
Transform<Scalar,Dim>::pretranslate(const MatrixBase<OtherDerived> &other)
{
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,Dim);
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim));
translation() += other;
return *this;
}

View File

@ -305,7 +305,7 @@ inline void MatrixBase<Derived>::computeInverse(typename ei_eval<Derived>::type
{
typedef typename ei_eval<Derived>::type MatrixType;
ei_assert(rows() == cols());
ei_assert(NumTraits<Scalar>::HasFloatingPoint);
EIGEN_STATIC_ASSERT(NumTraits<Scalar>::HasFloatingPoint,scalar_type_must_be_floating_point);
ei_compute_inverse<MatrixType>::run(eval(), result);
}

View File

@ -209,7 +209,7 @@ typename HessenbergDecomposition<MatrixType>::MatrixType
HessenbergDecomposition<MatrixType>::matrixQ(void) const
{
int n = m_matrix.rows();
MatrixType matQ = MatrixType::identity(n,n);
MatrixType matQ = MatrixType::Identity(n,n);
for (int i = n-2; i>=0; i--)
{
Scalar tmp = m_matrix.coeff(i+1,i);

View File

@ -57,11 +57,11 @@ template<typename MatrixType> class QR
bool isFullRank() const { return ei_isMuchSmallerThan(m_hCoeffs.cwise().abs().minCoeff(), Scalar(1)); }
/** \returns a read-only expression of the matrix R of the actual the QR decomposition */
const Extract<NestByValue<MatrixRBlockType>, Upper>
const Part<NestByValue<MatrixRBlockType>, Upper>
matrixR(void) const
{
int cols = m_qr.cols();
return MatrixRBlockType(m_qr, 0, 0, cols, cols).nestByValue().template extract<Upper>();
return MatrixRBlockType(m_qr, 0, 0, cols, cols).nestByValue().template part<Upper>();
}
MatrixType matrixQ(void) const;
@ -144,7 +144,7 @@ MatrixType QR<MatrixType>::matrixQ(void) const
// and v_k is the k-th Householder vector [1,m_qr(k+1,k), m_qr(k+2,k), ...]
int rows = m_qr.rows();
int cols = m_qr.cols();
MatrixType res = MatrixType::identity(rows, cols);
MatrixType res = MatrixType::Identity(rows, cols);
for (int k = cols-1; k >= 0; k--)
{
// to make easier the computation of the transformation, let's temporarily

View File

@ -79,6 +79,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
void compute(const MatrixType& matA, const MatrixType& matB, bool computeEigenvectors = true);
/** \returns the computed eigen vectors as a matrix of column vectors */
MatrixType eigenvectors(void) const
{
#ifndef NDEBUG
@ -87,6 +88,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
return m_eivec;
}
/** \returns the computed eigen values */
RealVectorType eigenvalues(void) const { return m_eivalues; }
protected:

View File

@ -215,7 +215,7 @@ void Tridiagonalization<MatrixType>::_compute(MatrixType& matA, CoeffVectorType&
matA.col(i).coeffRef(i+1) = 1;
// let's use the end of hCoeffs to store temporary values
hCoeffs.end(n-i-1) = h * (matA.corner(BottomRight,n-i-1,n-i-1).template extract<Lower|SelfAdjoint>()
hCoeffs.end(n-i-1) = h * (matA.corner(BottomRight,n-i-1,n-i-1).template part<Lower|SelfAdjoint>()
* matA.col(i).end(n-i-1));
@ -261,7 +261,7 @@ typename Tridiagonalization<MatrixType>::MatrixType
Tridiagonalization<MatrixType>::matrixQ(void) const
{
int n = m_matrix.rows();
MatrixType matQ = MatrixType::identity(n,n);
MatrixType matQ = MatrixType::Identity(n,n);
for (int i = n-2; i>=0; i--)
{
Scalar tmp = m_matrix.coeff(i+1,i);

View File

@ -18,7 +18,7 @@ topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
int main(int, char**)
{
Matrix4d m = Matrix4d::identity();
Matrix4d m = Matrix4d::Identity();
cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;

View File

@ -11,7 +11,7 @@ template<typename Scalar> struct MakeComplexOp EIGEN_EMPTY_STRUCT {
int main(int, char**)
{
Matrix4d m1 = Matrix4d::random(), m2 = Matrix4d::random();
Matrix4d m1 = Matrix4d::Random(), m2 = Matrix4d::Random();
cout << m1.binaryExpr(m2, MakeComplexOp<double>()) << endl;
return 0;
}

View File

@ -13,7 +13,7 @@ struct CwiseClampOp {
int main(int, char**)
{
Matrix4d m1 = Matrix4d::random();
Matrix4d m1 = Matrix4d::Random();
cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << endl;
return 0;
}

View File

@ -18,7 +18,7 @@ topLeft2x2Corner(const MatrixBase<Derived>& m)
int main(int, char**)
{
Matrix3d m = Matrix3d::identity();
Matrix3d m = Matrix3d::Identity();
cout << topLeft2x2Corner(4*m) << endl; // calls the const version
topLeft2x2Corner(m) *= 2; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;

View File

@ -1,6 +1,6 @@
typedef Matrix<float,Dynamic,2> DataMatrix;
// let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise)
DataMatrix samples = DataMatrix::random(12,2);
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::random(12)*0.1;
DataMatrix samples = DataMatrix::Random(12,2);
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::Random(12)*0.1;
// and let's solve samples * x = elevations in least square sense:
cout << (samples.adjoint() * samples).cholesky().solve((samples.adjoint()*elevations).eval()) << endl;

View File

@ -1,3 +1,3 @@
Matrix2cf m = Matrix2cf::random();
Matrix2cf m = Matrix2cf::Random();
cout << "Here is the 2x2 complex matrix m:" << endl << m << endl;
cout << "Here is the adjoint of m:" << endl << m.adjoint() << endl;

View File

@ -1,4 +1,4 @@
RowVector4i v = RowVector4i::random();
RowVector4i v = RowVector4i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.block(1, 2):" << endl << v.block(1, 2) << endl;
v.block(1, 2).setZero();

View File

@ -1,4 +1,4 @@
Matrix4i m = Matrix4i::random();
Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.block(1, 1, 2, 2):" << endl << m.block(1, 1, 2, 2) << endl;
m.block(1, 1, 2, 2).setZero();

View File

@ -1,3 +1,3 @@
Matrix2d md = Matrix2d::identity() * 0.45;
Matrix2f mf = Matrix2f::identity();
Matrix2d md = Matrix2d::Identity() * 0.45;
Matrix2f mf = Matrix2f::Identity();
cout << md + mf.cast<double>() << endl;

View File

@ -1,3 +1,3 @@
Matrix3d m = Matrix3d::identity();
Matrix3d m = Matrix3d::Identity();
m.col(1) = Vector3d(4,5,6);
cout << m << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3d::random();
Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
Matrix3d inv;
m.computeInverse(&inv);

View File

@ -1,4 +1,4 @@
Matrix4i m = Matrix4i::random();
Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the bottom-right 2x3 corner in m:" << endl
<< m.corner(Eigen::BottomRight, 2, 3) << endl;

View File

@ -1,4 +1,4 @@
Matrix3i m = Matrix3i::random();
Matrix3i m = Matrix3i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here are the coefficients on the main diagonal of m:" << endl
<< m.diagonal() << endl;

View File

@ -1,4 +1,4 @@
RowVector4i v = RowVector4i::random();
RowVector4i v = RowVector4i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.end(2):" << endl << v.end(2) << endl;
v.end(2).setZero();

View File

@ -1,4 +1,4 @@
Matrix2f M = Matrix2f::random();
Matrix2f M = Matrix2f::Random();
Matrix2f m;
m = M;
cout << "Here is the matrix m:" << endl << m << endl;

View File

@ -1,8 +1,8 @@
Matrix3i m = Matrix3i::random();
Matrix3i m = Matrix3i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the upper-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::Upper>() << endl;
<< m.part<Eigen::Upper>() << endl;
cout << "Here is the strictly-upper-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::StrictlyUpper>() << endl;
<< m.part<Eigen::StrictlyUpper>() << endl;
cout << "Here is the unit-lower-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::UnitLower>() << endl;
<< m.part<Eigen::UnitLower>() << endl;

View File

@ -1 +1 @@
cout << Matrix<double, 3, 4>::identity() << endl;
cout << Matrix<double, 3, 4>::Identity() << endl;

View File

@ -1 +1 @@
cout << MatrixXd::identity(4, 3) << endl;
cout << MatrixXd::Identity(4, 3) << endl;

View File

@ -1,3 +1,3 @@
Matrix3d m = Matrix3d::random();
Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Its inverse is:" << endl << m.inverse() << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = 10000 * Matrix3d::identity();
Matrix3d m = 10000 * Matrix3d::Identity();
m(0,2) = 1;
cout << "Here's the matrix m:" << endl << m << endl;
cout << "m.isDiagonal() returns: " << m.isDiagonal() << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3d::identity();
Matrix3d m = Matrix3d::Identity();
m(0,2) = 1e-4;
cout << "Here's the matrix m:" << endl << m << endl;
cout << "m.isIdentity() returns: " << m.isIdentity() << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3d::ones();
Matrix3d m = Matrix3d::Ones();
m(0,2) += 1e-4;
cout << "Here's the matrix m:" << endl << m << endl;
cout << "m.isOnes() returns: " << m.isOnes() << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3d::identity();
Matrix3d m = Matrix3d::Identity();
m(0,2) = 1e-4;
cout << "Here's the matrix m:" << endl << m << endl;
cout << "m.isUnitary() returns: " << m.isUnitary() << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3d::zero();
Matrix3d m = Matrix3d::Zero();
m(0,2) = 1e-4;
cout << "Here's the matrix m:" << endl << m << endl;
cout << "m.isZero() returns: " << m.isZero() << endl;

View File

@ -1,7 +1,7 @@
Matrix3d m = Matrix3d::zero();
Matrix3d m = Matrix3d::Zero();
m.part<Eigen::Upper>().setOnes();
cout << "Here is the matrix m:" << endl << m << endl;
Matrix3d n = Matrix3d::ones();
Matrix3d n = Matrix3d::Ones();
n.part<Eigen::Lower>() *= 2;
cout << "Here is the matrix n:" << endl << n << endl;
cout << "And now here is m.inverse()*n, taking advantage of the fact that"

View File

@ -1,3 +1,3 @@
Matrix3i m = Matrix3i::random();
Matrix3i m = Matrix3i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.minor(1,1):" << endl << m.minor(1,1) << endl;

View File

@ -1,2 +1,2 @@
cout << Matrix2d::ones() << endl;
cout << 6 * RowVector4i::ones() << endl;
cout << Matrix2d::Ones() << endl;
cout << 6 * RowVector4i::Ones() << endl;

View File

@ -1,2 +1,2 @@
cout << 6 * RowVectorXi::ones(4) << endl;
cout << VectorXf::ones(2) << endl;
cout << 6 * RowVectorXi::Ones(4) << endl;
cout << VectorXf::Ones(2) << endl;

View File

@ -1 +1 @@
cout << MatrixXi::ones(2,3) << endl;
cout << MatrixXi::Ones(2,3) << endl;

View File

@ -1,4 +1,4 @@
Matrix3d m = Matrix3i::zero();
Matrix3d m = Matrix3i::Zero();
m.part<Eigen::StrictlyUpper>().setOnes();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "And let us now compute m*m.adjoint() in a very optimized way" << endl

View File

@ -1 +1 @@
cout << 100 * Matrix2i::random() << endl;
cout << 100 * Matrix2i::Random() << endl;

View File

@ -1 +1 @@
cout << VectorXi::random(2) << endl;
cout << VectorXi::Random(2) << endl;

View File

@ -1 +1 @@
cout << MatrixXi::random(2,3) << endl;
cout << MatrixXi::Random(2,3) << endl;

View File

@ -1,3 +1,3 @@
Matrix3d m = Matrix3d::identity();
Matrix3d m = Matrix3d::Identity();
m.row(1) = Vector3d(4,5,6);
cout << m << endl;

View File

@ -3,7 +3,7 @@ m1 << 1, 2, 3,
4, 5, 6,
7, 8, 9;
cout << m1 << endl << endl;
Matrix3i m2 = Matrix3i::identity();
Matrix3i m2 = Matrix3i::Identity();
m2.block(0,0, 2,2) << 10, 11, 12, 13;
cout << m2 << endl << endl;
Vector2i v1;

View File

@ -1,3 +1,3 @@
Matrix4i m = Matrix4i::zero();
Matrix4i m = Matrix4i::Zero();
m.block<3,3>(1,0).setIdentity();
cout << m << endl;

View File

@ -1,3 +1,3 @@
Matrix4i m = Matrix4i::random();
Matrix4i m = Matrix4i::Random();
m.row(1).setOnes();
cout << m << endl;

View File

@ -1,3 +1,3 @@
Matrix4i m = Matrix4i::zero();
Matrix4i m = Matrix4i::Zero();
m.col(1).setRandom();
cout << m << endl;

View File

@ -1,3 +1,3 @@
Matrix4i m = Matrix4i::random();
Matrix4i m = Matrix4i::Random();
m.row(1).setZero();
cout << m << endl;

View File

@ -1,4 +1,4 @@
RowVector4i v = RowVector4i::random();
RowVector4i v = RowVector4i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.start(2):" << endl << v.start(2) << endl;
v.start(2).setZero();

View File

@ -1,4 +1,4 @@
RowVector4i v = RowVector4i::random();
RowVector4i v = RowVector4i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.end(2):" << endl << v.end<2>() << endl;
v.end<2>().setZero();

View File

@ -1,4 +1,4 @@
Matrix4i m = Matrix4i::random();
Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the bottom-right 2x3 corner in m:" << endl
<< m.corner<2,3>(Eigen::BottomRight) << endl;

View File

@ -1,4 +1,4 @@
RowVector4i v = RowVector4i::random();
RowVector4i v = RowVector4i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.start(2):" << endl << v.start<2>() << endl;
v.start<2>().setZero();

View File

@ -1,4 +1,4 @@
Matrix2i m = Matrix2i::random();
Matrix2i m = Matrix2i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the transpose of m:" << endl << m.transpose() << endl;
cout << "Here is the coefficient (1,0) in the transpose of m:" << endl

View File

@ -1,2 +1,2 @@
cout << Matrix2d::zero() << endl;
cout << RowVector4i::zero() << endl;
cout << Matrix2d::Zero() << endl;
cout << RowVector4i::Zero() << endl;

View File

@ -1,2 +1,2 @@
cout << RowVectorXi::zero(4) << endl;
cout << VectorXf::zero(2) << endl;
cout << RowVectorXi::Zero(4) << endl;
cout << VectorXf::Zero(2) << endl;

View File

@ -1 +1 @@
cout << MatrixXi::zero(2,3) << endl;
cout << MatrixXi::Zero(2,3) << endl;

View File

@ -35,18 +35,18 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
v3 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
v3 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
Scalar s1 = ei_random<Scalar>(),
s2 = ei_random<Scalar>();

View File

@ -37,16 +37,16 @@ template<typename MatrixType> void scalarAdd(const MatrixType& m)
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols);
Scalar s1 = ei_random<Scalar>(),
s2 = ei_random<Scalar>();
VERIFY_IS_APPROX(m1.cwise() + s1, s1 + m1.cwise());
VERIFY_IS_APPROX(m1.cwise() + s1, MatrixType::constant(rows,cols,s1) + m1);
VERIFY_IS_APPROX((m1*Scalar(2)).cwise() - s2, (m1+m1) - MatrixType::constant(rows,cols,s2) );
VERIFY_IS_APPROX(m1.cwise() + s1, MatrixType::Constant(rows,cols,s1) + m1);
VERIFY_IS_APPROX((m1*Scalar(2)).cwise() - s2, (m1+m1) - MatrixType::Constant(rows,cols,s2) );
m3 = m1;
m3.cwise() += s2;
VERIFY_IS_APPROX(m3, m1.cwise() + s2);
@ -71,8 +71,8 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols);
VERIFY(((m1.cwise() + Scalar(1)).cwise() > m1).all());

View File

@ -34,17 +34,17 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
// 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),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);
@ -68,7 +68,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
// hence has no _write() method, the corresponding MatrixBase method (here zero())
// should return a const-qualified object so that it is the const-qualified
// 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));
// now test copying a row-vector into a (column-)vector and conversely.
square.col(r) = square.row(r).eval();

View File

@ -38,8 +38,8 @@ template<typename MatrixType> void cholesky(const MatrixType& m)
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
MatrixType a = MatrixType::random(rows,cols);
VectorType b = VectorType::random(rows);
MatrixType a = MatrixType::Random(rows,cols);
VectorType b = VectorType::Random(rows);
SquareMatrixType covMat = a * a.adjoint();
CholeskyWithoutSquareRoot<SquareMatrixType> cholnosqrt(covMat);

View File

@ -35,7 +35,7 @@ void test_commainitializer()
double data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
m3 = Matrix3d::random();
m3 = Matrix3d::Random();
m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
VERIFY_IS_APPROX(m3, (Matrix<double,3,3,RowMajorBit>::map(data)) );
@ -43,14 +43,14 @@ void test_commainitializer()
vec[0] << 1, 4, 7;
vec[1] << 2, 5, 8;
vec[2] << 3, 6, 9;
m3 = Matrix3d::random();
m3 = Matrix3d::Random();
m3 << vec[0], vec[1], vec[2];
VERIFY_IS_APPROX(m3, (Matrix<double,3,3,RowMajorBit>::map(data)) );
vec[0] << 1, 2, 3;
vec[1] << 4, 5, 6;
vec[2] << 7, 8, 9;
m3 = Matrix3d::random();
m3 = Matrix3d::Random();
m3 << vec[0].transpose(),
4, 5, 6,
vec[2].transpose();

View File

@ -42,18 +42,18 @@ template<typename MatrixType> void cwiseops(const MatrixType& m)
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mones = MatrixType::ones(rows, cols),
mzero = MatrixType::Zero(rows, cols),
mones = MatrixType::Ones(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
m2 = m2.template binaryExpr<AddIfNull<Scalar> >(mones);

View File

@ -35,14 +35,14 @@ template<typename MatrixType> void eigensolver(const MatrixType& m)
typedef typename std::complex<typename NumTraits<typename MatrixType::Scalar>::Real> Complex;
MatrixType a = MatrixType::random(rows,cols);
MatrixType a = MatrixType::Random(rows,cols);
MatrixType symmA = a.adjoint() * a;
SelfAdjointEigenSolver<MatrixType> eiSymm(symmA);
VERIFY_IS_APPROX(symmA * eiSymm.eigenvectors(), (eiSymm.eigenvectors() * eiSymm.eigenvalues().asDiagonal().eval()));
// generalized eigen problem Ax = lBx
MatrixType b = MatrixType::random(rows,cols);
MatrixType b = MatrixType::Random(rows,cols);
MatrixType symmB = b.adjoint() * b;
eiSymm.compute(symmA,symmB);
VERIFY_IS_APPROX(symmA * eiSymm.eigenvectors(), symmB * (eiSymm.eigenvectors() * eiSymm.eigenvalues().asDiagonal().eval()));

View File

@ -42,9 +42,9 @@ template<typename Scalar> void geometry(void)
typedef AngleAxis<Scalar> AngleAxis;
Quaternion q1, q2;
Vector3 v0 = Vector3::random(),
v1 = Vector3::random(),
v2 = Vector3::random();
Vector3 v0 = Vector3::Random(),
v1 = Vector3::Random(),
v2 = Vector3::Random();
Matrix3 matrot1;
Scalar a = ei_random<Scalar>(-M_PI, M_PI);
@ -116,7 +116,7 @@ template<typename Scalar> void geometry(void)
t1.setIdentity();
t1.affine() = q1.toRotationMatrix();
v0 << 50, 2, 1;//= Vector3::random().cwiseProduct(Vector3(10,2,0.5));
v0 << 50, 2, 1;//= Vector3::Random().cwiseProduct(Vector3(10,2,0.5));
t0.scale(v0);
t1.prescale(v0);
@ -140,8 +140,8 @@ template<typename Scalar> void geometry(void)
// 2D transformation
Transform2 t20, t21;
Vector2 v20 = Vector2::random();
Vector2 v21 = Vector2::random();
Vector2 v20 = Vector2::Random();
Vector2 v21 = Vector2::Random();
t21.setIdentity();
t21.affine() = Rotation2D<Scalar>(a).toRotationMatrix();
VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(),

View File

@ -36,10 +36,10 @@ template<typename MatrixType> void inverse(const MatrixType& m)
typedef typename MatrixType::Scalar Scalar;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
mzero = MatrixType::zero(rows, cols),
identity = MatrixType::identity(rows, rows);
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = MatrixType::Identity(rows, rows);
m2 = m1.inverse();
VERIFY_IS_APPROX(m1, m2.inverse() );

View File

@ -38,17 +38,17 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
// 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),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
Scalar s1 = ei_random<Scalar>();

View File

@ -33,7 +33,7 @@ template<typename VectorType> void tmap(const VectorType& m)
// test Map.h
Scalar* array1 = ei_aligned_malloc<Scalar>(size);
Scalar* array2 = ei_aligned_malloc<Scalar>(size);
Map<VectorType, Aligned>(array1, size) = VectorType::random(size);
Map<VectorType, Aligned>(array1, size) = VectorType::Random(size);
Map<VectorType>(array2, size) = Map<VectorType>(array1, size);
VectorType ma1 = Map<VectorType>(array1, size);
VectorType ma2 = Map<VectorType, Aligned>(array2, size);

View File

@ -37,18 +37,18 @@ template<typename MatrixType> void miscMatrices(const MatrixType& m)
int cols = m.cols();
int r = ei_random<int>(0, rows-1), r2 = ei_random<int>(0, rows-1), c = ei_random<int>(0, cols-1);
VERIFY_IS_APPROX(MatrixType::ones(rows,cols)(r,c), static_cast<Scalar>(1));
MatrixType m1 = MatrixType::ones(rows,cols);
VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
MatrixType m1 = MatrixType::Ones(rows,cols);
VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
VectorType v1 = VectorType::random(rows);
VectorType v1 = VectorType::Random(rows);
v1[0];
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
square = v1.asDiagonal();
if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
square = MatrixType::zero(rows, rows);
square.diagonal() = VectorType::ones(rows);
VERIFY_IS_APPROX(square, MatrixType::identity(rows, rows));
square = MatrixType::Zero(rows, rows);
square.diagonal() = VectorType::Ones(rows);
VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
}
void test_miscmatrices()

View File

@ -56,17 +56,17 @@ template<typename MatrixType> void nomalloc(const MatrixType& m)
// 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),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
Scalar s1 = ei_random<Scalar>();
@ -82,7 +82,7 @@ template<typename MatrixType> void nomalloc(const MatrixType& m)
void test_nomalloc()
{
// check that our operator new is indeed called:
VERIFY_RAISES_ASSERT(MatrixXd dummy = MatrixXd::random(3,3));
VERIFY_RAISES_ASSERT(MatrixXd dummy = MatrixXd::Random(3,3));
CALL_SUBTEST( nomalloc(Matrix<float, 1, 1>()) );
CALL_SUBTEST( nomalloc(Matrix4d()) );
}

View File

@ -54,21 +54,21 @@ template<typename MatrixType> void product(const MatrixType& m)
// 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),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols);
mzero = MatrixType::Zero(rows, cols);
RowSquareMatrixType
identity = RowSquareMatrixType::identity(rows, rows),
square = RowSquareMatrixType::random(rows, rows),
res = RowSquareMatrixType::random(rows, rows);
identity = RowSquareMatrixType::Identity(rows, rows),
square = RowSquareMatrixType::Random(rows, rows),
res = RowSquareMatrixType::Random(rows, rows);
ColSquareMatrixType
square2 = ColSquareMatrixType::random(cols, cols),
res2 = ColSquareMatrixType::random(cols, cols);
RowVectorType v1 = RowVectorType::random(rows),
v2 = RowVectorType::random(rows),
vzero = RowVectorType::zero(rows);
ColVectorType vc2 = ColVectorType::random(cols), vcres;
square2 = ColSquareMatrixType::Random(cols, cols),
res2 = ColSquareMatrixType::Random(cols, cols);
RowVectorType v1 = RowVectorType::Random(rows),
v2 = RowVectorType::Random(rows),
vzero = RowVectorType::Zero(rows);
ColVectorType vc2 = ColVectorType::Random(cols), vcres;
OtherMajorMatrixType tm1 = m1;
Scalar s1 = ei_random<Scalar>();
@ -99,7 +99,7 @@ template<typename MatrixType> void product(const MatrixType& m)
VERIFY_IS_APPROX(v1, identity*v1);
VERIFY_IS_APPROX(v1.transpose(), v1.transpose() * identity);
// again, test operator() to check const-qualification
VERIFY_IS_APPROX(MatrixType::identity(rows, cols)(r,c), static_cast<Scalar>(r==c));
VERIFY_IS_APPROX(MatrixType::Identity(rows, cols)(r,c), static_cast<Scalar>(r==c));
if (rows!=cols)
VERIFY_RAISES_ASSERT(m3 = m1*m1);

View File

@ -37,10 +37,10 @@ template<typename MatrixType> void qr(const MatrixType& m)
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> SquareMatrixType;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, 1> VectorType;
MatrixType a = MatrixType::random(rows,cols);
MatrixType a = MatrixType::Random(rows,cols);
QR<MatrixType> qrOfA(a);
VERIFY_IS_APPROX(a, qrOfA.matrixQ() * qrOfA.matrixR());
VERIFY_IS_NOT_APPROX(a+MatrixType::identity(rows, cols), qrOfA.matrixQ() * qrOfA.matrixR());
VERIFY_IS_NOT_APPROX(a+MatrixType::Identity(rows, cols), qrOfA.matrixQ() * qrOfA.matrixR());
SquareMatrixType b = a.adjoint() * a;
@ -52,7 +52,7 @@ template<typename MatrixType> void qr(const MatrixType& m)
HessenbergDecomposition<SquareMatrixType> hess(b);
VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
VERIFY_IS_APPROX(tridiag.matrixT(), hess.matrixH());
b = SquareMatrixType::random(cols,cols);
b = SquareMatrixType::Random(cols,cols);
hess.compute(b);
VERIFY_IS_APPROX(b, hess.matrixQ() * hess.matrixH() * hess.matrixQ().adjoint());
}

View File

@ -62,18 +62,18 @@ template<typename MatrixType> void submatrices(const MatrixType& m)
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
mzero = MatrixType::zero(rows, cols),
mzero = MatrixType::Zero(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
v3 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
v3 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
Scalar s1 = ei_random<Scalar>();

View File

@ -32,23 +32,23 @@ template<typename MatrixType> void triangular(const MatrixType& m)
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::random(rows, cols),
m2 = MatrixType::random(rows, cols),
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols),
m3(rows, cols),
r1(rows, cols),
r2(rows, cols),
mzero = MatrixType::zero(rows, cols),
mones = MatrixType::ones(rows, cols),
mzero = MatrixType::Zero(rows, cols),
mones = MatrixType::Ones(rows, cols),
identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::identity(rows, rows),
::Identity(rows, rows),
square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
::random(rows, rows);
VectorType v1 = VectorType::random(rows),
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
::Random(rows, rows);
VectorType v1 = VectorType::Random(rows),
v2 = VectorType::Random(rows),
vzero = VectorType::Zero(rows);
MatrixType m1up = m1.template extract<Eigen::Upper>();
MatrixType m2up = m2.template extract<Eigen::Upper>();
MatrixType m1up = m1.template part<Eigen::Upper>();
MatrixType m2up = m2.template part<Eigen::Upper>();
if (rows*cols>1)
{
@ -70,18 +70,18 @@ template<typename MatrixType> void triangular(const MatrixType& m)
m1.setZero();
m1.template part<Eigen::Upper>() = (m2.transpose() * m2).lazy();
m3 = m2.transpose() * m2;
VERIFY_IS_APPROX(m3.template extract<Eigen::Lower>().transpose(), m1);
VERIFY_IS_APPROX(m3.template part<Eigen::Lower>().transpose(), m1);
// test overloaded operator=
m1.setZero();
m1.template part<Eigen::Lower>() = (m2.transpose() * m2).lazy();
VERIFY_IS_APPROX(m3.template extract<Eigen::Lower>(), m1);
VERIFY_IS_APPROX(m3.template part<Eigen::Lower>(), m1);
// test back and forward subsitution
m1 = MatrixType::random(rows, cols);
VERIFY_IS_APPROX(m1.template extract<Eigen::Upper>() * (m1.template extract<Eigen::Upper>().inverseProduct(m2)), m2);
VERIFY_IS_APPROX(m1.template extract<Eigen::Lower>() * (m1.template extract<Eigen::Lower>().inverseProduct(m2)), m2);
VERIFY((m1.template extract<Eigen::Upper>() * m2.template extract<Eigen::Upper>()).isUpper());
m1 = MatrixType::Random(rows, cols);
VERIFY_IS_APPROX(m1.template part<Eigen::Upper>() * (m1.template part<Eigen::Upper>().inverseProduct(m2)), m2);
VERIFY_IS_APPROX(m1.template part<Eigen::Lower>() * (m1.template part<Eigen::Lower>().inverseProduct(m2)), m2);
VERIFY((m1.template part<Eigen::Upper>() * m2.template part<Eigen::Upper>()).isUpper());
}