mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
- move: DerivedTraits becomes MatrixBase::Traits
- the static constants are private again in the Derived classes - more documentation and code snippets - new isDiagonal() method
This commit is contained in:
@@ -26,37 +26,6 @@
|
||||
#ifndef EIGEN_MATRIXBASE_H
|
||||
#define EIGEN_MATRIXBASE_H
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
template <typename Derived>
|
||||
struct DerivedTraits
|
||||
{
|
||||
/** The number of rows at compile-time. This is just a copy of the value provided
|
||||
* by the \a Derived type. If a value is not known at compile-time,
|
||||
* it is set to the \a Dynamic constant.
|
||||
* \sa rows(), cols(), ColsAtCompileTime, SizeAtCompileTime */
|
||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime;
|
||||
|
||||
/** The number of columns at compile-time. This is just a copy of the value provided
|
||||
* by the \a Derived type. If a value is not known at compile-time,
|
||||
* it is set to the \a Dynamic constant.
|
||||
* \sa rows(), cols(), RowsAtCompileTime, SizeAtCompileTime */
|
||||
static const int ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||
|
||||
/** This is equal to the number of coefficients, i.e. the number of
|
||||
* rows times the number of columns, or to \a Dynamic if this is not
|
||||
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
|
||||
static const int SizeAtCompileTime
|
||||
= Derived::RowsAtCompileTime == Dynamic || Derived::ColsAtCompileTime == Dynamic
|
||||
? Dynamic : Derived::RowsAtCompileTime * Derived::ColsAtCompileTime;
|
||||
|
||||
/** This is set to true if either the number of rows or the number of
|
||||
* columns is known at compile-time to be equal to 1. Indeed, in that case,
|
||||
* we are dealing with a column-vector (if there is only one column) or with
|
||||
* a row-vector (if there is only one row). */
|
||||
static const bool IsVectorAtCompileTime = Derived::RowsAtCompileTime == 1 || Derived::ColsAtCompileTime == 1;
|
||||
};
|
||||
|
||||
/** \class MatrixBase
|
||||
*
|
||||
* \brief Base class for all matrices, vectors, and expressions
|
||||
@@ -88,7 +57,37 @@ struct DerivedTraits
|
||||
template<typename Scalar, typename Derived> class MatrixBase
|
||||
{
|
||||
public:
|
||||
typedef DerivedTraits<Derived> Traits;
|
||||
|
||||
/** \brief Some traits provided by the Derived type.
|
||||
* Grouping these in a nested subclass is what was needed for ICC compatibility. */
|
||||
struct Traits
|
||||
{
|
||||
/** The number of rows at compile-time. This is just a copy of the value provided
|
||||
* by the \a Derived type. If a value is not known at compile-time,
|
||||
* it is set to the \a Dynamic constant.
|
||||
* \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
|
||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime;
|
||||
|
||||
/** The number of columns at compile-time. This is just a copy of the value provided
|
||||
* by the \a Derived type. If a value is not known at compile-time,
|
||||
* it is set to the \a Dynamic constant.
|
||||
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
|
||||
static const int ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||
|
||||
/** This is equal to the number of coefficients, i.e. the number of
|
||||
* rows times the number of columns, or to \a Dynamic if this is not
|
||||
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
|
||||
static const int SizeAtCompileTime
|
||||
= Derived::RowsAtCompileTime == Dynamic || Derived::ColsAtCompileTime == Dynamic
|
||||
? Dynamic : Derived::RowsAtCompileTime * Derived::ColsAtCompileTime;
|
||||
|
||||
/** This is set to true if either the number of rows or the number of
|
||||
* columns is known at compile-time to be equal to 1. Indeed, in that case,
|
||||
* we are dealing with a column-vector (if there is only one column) or with
|
||||
* a row-vector (if there is only one row). */
|
||||
static const bool IsVectorAtCompileTime
|
||||
= Derived::RowsAtCompileTime == 1 || Derived::ColsAtCompileTime == 1;
|
||||
};
|
||||
|
||||
/** 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
|
||||
@@ -104,17 +103,17 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
* \a Scalar is \a std::complex<T> then RealScalar is \a T. */
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
|
||||
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
|
||||
/** \returns the number of rows. \sa cols(), DerivedTraits::RowsAtCompileTime */
|
||||
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
|
||||
/** \returns the number of columns. \sa row(), ColsAtCompileTime*/
|
||||
/** \returns the number of columns. \sa row(), DerivedTraits::ColsAtCompileTime*/
|
||||
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
||||
/** \returns the number of coefficients, which is \a rows()*cols().
|
||||
* \sa rows(), cols(), SizeAtCompileTime. */
|
||||
* \sa rows(), cols(), DerivedTraits::SizeAtCompileTime. */
|
||||
int size() const { return rows() * cols(); }
|
||||
/** \returns true if either the number of rows or the number of columns is equal to 1.
|
||||
* In other words, this function returns
|
||||
* \code rows()==1 || cols()==1 \endcode
|
||||
* \sa rows(), cols(), IsVectorAtCompileTime. */
|
||||
* \sa rows(), cols(), DerivedTraits::IsVectorAtCompileTime. */
|
||||
bool isVector() const { return rows()==1 || cols()==1; }
|
||||
/** \returns a Ref to *this. \sa Ref */
|
||||
Ref ref() const
|
||||
@@ -164,9 +163,8 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
RealScalar norm() const;
|
||||
const ScalarMultiple<RealScalar, Derived> normalized() const;
|
||||
template<typename OtherDerived>
|
||||
bool isOrtho(const OtherDerived& other,
|
||||
const typename NumTraits<Scalar>::Real& prec) const;
|
||||
bool isOrtho(const typename NumTraits<Scalar>::Real& prec) const;
|
||||
bool isOrtho(const OtherDerived& other, RealScalar prec) const;
|
||||
bool isOrtho(RealScalar prec) const;
|
||||
|
||||
static const Eval<Random<Derived> > random(int rows, int cols);
|
||||
static const Eval<Random<Derived> > random(int size);
|
||||
@@ -179,9 +177,10 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
static const Ones<Derived> ones();
|
||||
static const Identity<Derived> identity(int rows = Derived::RowsAtCompileTime);
|
||||
|
||||
bool isZero(const typename NumTraits<Scalar>::Real& prec) const;
|
||||
bool isOnes(const typename NumTraits<Scalar>::Real& prec) const;
|
||||
bool isIdentity(const typename NumTraits<Scalar>::Real& prec) const;
|
||||
bool isZero(RealScalar prec) const;
|
||||
bool isOnes(RealScalar prec) const;
|
||||
bool isIdentity(RealScalar prec) const;
|
||||
bool isDiagonal(RealScalar prec) const;
|
||||
|
||||
const DiagonalMatrix<Derived> asDiagonal() const;
|
||||
|
||||
@@ -189,19 +188,12 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
const DiagonalCoeffs<Derived> diagonal() const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
bool isApprox(
|
||||
const OtherDerived& other,
|
||||
const typename NumTraits<Scalar>::Real& prec
|
||||
) const;
|
||||
bool isMuchSmallerThan(
|
||||
const typename NumTraits<Scalar>::Real& other,
|
||||
const typename NumTraits<Scalar>::Real& prec
|
||||
) const;
|
||||
bool isApprox(const OtherDerived& other, RealScalar prec) const;
|
||||
bool isMuchSmallerThan
|
||||
(const typename NumTraits<Scalar>::Real& other, RealScalar prec) const;
|
||||
template<typename OtherDerived>
|
||||
bool isMuchSmallerThan(
|
||||
const MatrixBase<Scalar, OtherDerived>& other,
|
||||
const typename NumTraits<Scalar>::Real& prec
|
||||
) const;
|
||||
bool isMuchSmallerThan
|
||||
(const MatrixBase<Scalar, OtherDerived>& other, RealScalar prec) const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
const Product<Derived, OtherDerived>
|
||||
|
||||
Reference in New Issue
Block a user