From 8e05f9cfa1538d76a9d3e01e08ba565bd581806a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 4 Dec 2009 23:17:14 +0100 Subject: add a DenseBase class for MAtrixBase and ArrayBase and more code factorisation --- Eigen/Array | 3 + Eigen/Core | 1 + Eigen/src/Array/Array.h | 526 +----------------------------- Eigen/src/Array/ArrayBase.h | 233 +++++++++++++ Eigen/src/Array/ArrayWrapper.h | 161 +++++++++ Eigen/src/Array/BooleanRedux.h | 14 +- Eigen/src/Array/Random.h | 8 +- Eigen/src/Core/Assign.h | 15 +- Eigen/src/Core/Block.h | 44 +-- Eigen/src/Core/Coeffs.h | 36 +- Eigen/src/Core/CommaInitializer.h | 8 +- Eigen/src/Core/CwiseBinaryOp.h | 3 +- Eigen/src/Core/CwiseNullaryOp.h | 80 ++--- Eigen/src/Core/CwiseUnaryOp.h | 3 +- Eigen/src/Core/DenseBase.h | 517 +++++++++++++++++++++++++++++ Eigen/src/Core/Fuzzy.h | 28 +- Eigen/src/Core/IO.h | 10 +- Eigen/src/Core/Map.h | 6 +- Eigen/src/Core/MapBase.h | 6 +- Eigen/src/Core/MatrixBase.h | 213 ++---------- Eigen/src/Core/ProductBase.h | 7 +- Eigen/src/Core/Redux.h | 14 +- Eigen/src/Core/StableNorm.h | 4 +- Eigen/src/Core/Transpose.h | 39 +-- Eigen/src/Core/VectorBlock.h | 32 +- Eigen/src/Core/Visitor.h | 24 +- Eigen/src/Core/util/ForwardDeclarations.h | 1 + Eigen/src/Core/util/Macros.h | 21 +- Eigen/src/Core/util/XprHelper.h | 1 + Eigen/src/Geometry/AlignedBox.h | 6 +- Eigen/src/Householder/Householder.h | 8 +- Eigen/src/Jacobi/Jacobi.h | 8 +- Eigen/src/QR/ColPivHouseholderQR.h | 8 +- Eigen/src/QR/FullPivHouseholderQR.h | 8 +- Eigen/src/QR/HouseholderQR.h | 2 +- Eigen/src/SVD/SVD.h | 7 +- Eigen/src/plugins/ArrayCwiseBinaryOps.h | 243 ++++++++++++++ Eigen/src/plugins/ArrayCwiseUnaryOps.h | 148 +++++++++ Eigen/src/plugins/CommonCwiseBinaryOps.h | 16 +- 39 files changed, 1577 insertions(+), 935 deletions(-) create mode 100644 Eigen/src/Array/ArrayBase.h create mode 100644 Eigen/src/Array/ArrayWrapper.h create mode 100644 Eigen/src/Core/DenseBase.h create mode 100644 Eigen/src/plugins/ArrayCwiseBinaryOps.h create mode 100644 Eigen/src/plugins/ArrayCwiseUnaryOps.h (limited to 'Eigen') diff --git a/Eigen/Array b/Eigen/Array index dbb4a7ca6..276fdec2f 100644 --- a/Eigen/Array +++ b/Eigen/Array @@ -36,6 +36,9 @@ namespace Eigen { #include "src/Array/Norms.h" #include "src/Array/Replicate.h" #include "src/Array/Reverse.h" +#include "src/Array/ArrayBase.h" +#include "src/Array/ArrayWrapper.h" +#include "src/Array/Array.h" } // namespace Eigen diff --git a/Eigen/Core b/Eigen/Core index dd5f54924..a3abe0598 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -152,6 +152,7 @@ struct Dense {}; #endif #include "src/Core/Functors.h" +#include "src/Core/DenseBase.h" #include "src/Core/MatrixBase.h" #include "src/Core/AnyMatrixBase.h" #include "src/Core/Coeffs.h" diff --git a/Eigen/src/Array/Array.h b/Eigen/src/Array/Array.h index ff3dfe7e4..2619d8597 100644 --- a/Eigen/src/Array/Array.h +++ b/Eigen/src/Array/Array.h @@ -22,528 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_ARRAYBASE_H -#define EIGEN_ARRAYBASE_H +#ifndef EIGEN_ARRAY_H +#define EIGEN_ARRAY_H -/** \ingroup Array_Module - * - * \class ArrayBase - * - * \brief Base class for all 1D and 2D array, and related expressions - * - * An array is similar to a dense vector or matrix. While matrices are mathematical - * objects with well defined linear algebra operators, an array is just a collection - * of scalar values arranged in a one or two dimensionnal fashion. The main consequence, - * is that all operations applied to an array are performed coefficient wise. Furthermore, - * arays support scalar math functions of the c++ standard library, and convenient - * constructors allowing to easily write generic code working for both scalar values - * and arrays. - * - * This class is the base that is inherited by all array expression types. - * - * \param Derived is the derived type, e.g. an array type, or an expression, etc. - * - * \sa class ArrayBase - */ -template class ArrayBase -#ifndef EIGEN_PARSED_BY_DOXYGEN - : public ei_special_scalar_op_base::Scalar, - typename NumTraits::Scalar>::Real> -#endif // not EIGEN_PARSED_BY_DOXYGEN -{ - public: -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** The base class for a given storage type. */ - typedef ArrayBase StorageBaseType; - /** Construct the base class type for the derived class OtherDerived */ - template struct MakeBase { typedef ArrayBase Type; }; - using ei_special_scalar_op_base::Scalar, - typename NumTraits::Scalar>::Real>::operator*; - - class InnerIterator; - - typedef typename ei_traits::Scalar Scalar; - typedef typename ei_packet_traits::type PacketScalar; -#endif // not EIGEN_PARSED_BY_DOXYGEN - - // FIXME A lot of this stuff could be moved to AnyArrayBase, I guess - - enum { - - RowsAtCompileTime = ei_traits::RowsAtCompileTime, - /**< 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 ArrayBase::rows(), ArrayBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ - - ColsAtCompileTime = ei_traits::ColsAtCompileTime, - /**< 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 ArrayBase::rows(), ArrayBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - - - SizeAtCompileTime = (ei_size_at_compile_time::RowsAtCompileTime, - ei_traits::ColsAtCompileTime>::ret), - /**< 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 */ - - MaxRowsAtCompileTime = ei_traits::MaxRowsAtCompileTime, - /**< This value is equal to the maximum possible number of rows that this expression - * might have. If this expression might have an arbitrarily high number of rows, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime - */ - - MaxColsAtCompileTime = ei_traits::MaxColsAtCompileTime, - /**< This value is equal to the maximum possible number of columns that this expression - * might have. If this expression might have an arbitrarily high number of columns, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime - */ - - MaxSizeAtCompileTime = (ei_size_at_compile_time::MaxRowsAtCompileTime, - ei_traits::MaxColsAtCompileTime>::ret), - /**< This value is equal to the maximum possible number of coefficients that this expression - * might have. If this expression might have an arbitrarily high number of coefficients, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime - */ - - IsVectorAtCompileTime = ei_traits::RowsAtCompileTime == 1 - || ei_traits::ColsAtCompileTime == 1, - /**< 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). */ - - Flags = ei_traits::Flags, - /**< This stores expression \ref flags flags which may or may not be inherited by new expressions - * constructed from this one. See the \ref flags "list of flags". - */ - - CoeffReadCost = ei_traits::CoeffReadCost, - /**< This is a rough measure of how expensive it is to read one coefficient from - * this expression. - */ - -#ifndef EIGEN_PARSED_BY_DOXYGEN - _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC -#endif - }; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** This is the "real scalar" type; if the \a Scalar type is already real numbers - * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If - * \a Scalar is \a std::complex then RealScalar is \a T. - * - * \sa class NumTraits - */ - typedef typename NumTraits::Real RealScalar; - - /** type of the equivalent square matrix */ - typedef Matrix SquareMatrixType; -#endif // not EIGEN_PARSED_BY_DOXYGEN - - /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline int rows() const { return derived().rows(); } - /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline int cols() const { return derived().cols(); } - /** \returns the number of coefficients, which is rows()*cols(). - * \sa rows(), cols(), SizeAtCompileTime. */ - inline int size() const { return rows() * cols(); } - /** \returns the number of nonzero coefficients which is in practice the number - * of stored coefficients. */ - inline int nonZeros() const { return size(); } - /** \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. */ - inline bool isVector() const { return rows()==1 || cols()==1; } - /** \returns the size of the storage major dimension, - * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ - int outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); } - /** \returns the size of the inner dimension according to the storage order, - * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ - int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } - - /** Only plain matrices, not expressions may be resized; therefore the only useful resize method is - * Matrix::resize(). The present method only asserts that the new size equals the old size, and does - * nothing else. - */ - void resize(int size) - { - ei_assert(size == this->size() - && "ArrayBase::resize() does not actually allow to resize."); - } - /** Only plain matrices, not expressions may be resized; therefore the only useful resize method is - * Matrix::resize(). The present method only asserts that the new size equals the old size, and does - * nothing else. - */ - void resize(int rows, int cols) - { - ei_assert(rows == this->rows() && cols == this->cols() - && "ArrayBase::resize() does not actually allow to resize."); - } - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal the plain matrix type corresponding to this expression. Note that is not necessarily - * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const - * reference to a matrix, not a matrix! It is however guaranteed that the return type of eval() is either - * PlainMatrixType or const PlainMatrixType&. - */ - typedef typename ei_plain_matrix_type::type PlainMatrixType; - /** \internal the column-major plain matrix type corresponding to this expression. Note that is not necessarily - * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const - * reference to a matrix, not a matrix! - * The only difference from PlainMatrixType is that PlainMatrixType_ColMajor is guaranteed to be column-major. - */ - typedef typename ei_plain_matrix_type::type PlainMatrixType_ColMajor; - - /** \internal the return type of coeff() - */ - typedef typename ei_meta_if<_HasDirectAccess, const Scalar&, Scalar>::ret CoeffReturnType; - - /** \internal Represents a matrix with all coefficients equal to one another*/ - typedef CwiseNullaryOp,Derived> ConstantReturnType; - /** \internal expression tyepe of a column */ - typedef Block::RowsAtCompileTime, 1> ColXpr; - /** \internal expression tyepe of a column */ - typedef Block::ColsAtCompileTime> RowXpr; -#endif // not EIGEN_PARSED_BY_DOXYGEN - - #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase - #include "../Core/CommonCwiseUnaryOps.h" - #include "ArrayCwiseUnaryOps.h" - #include "../Core/CommonCwiseBinaryOps.h" - #include "ArrayCwiseBinaryOps.h" - #undef EIGEN_CURRENT_STORAGE_BASE_CLASS - - /** Copies \a other into *this. \returns a reference to *this. */ - template - Derived& operator=(const ArrayBase& other); - - /** Special case of the template operator=, in order to prevent the compiler - * from generating a default operator= (issue hit with g++ 4.1) - */ - Derived& operator=(const ArrayBase& other); - - template - Derived& operator=(const AnyArrayBase &other); - - template - Derived& operator+=(const AnyArrayBase &other); - - template - Derived& operator-=(const AnyArrayBase &other); - - template - Derived& operator=(const ReturnByValue& func); - -#ifndef EIGEN_PARSED_BY_DOXYGEN - /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ - template - Derived& lazyAssign(const ArrayBase& other); -#endif // not EIGEN_PARSED_BY_DOXYGEN - - CommaInitializer operator<< (const Scalar& s); - - template - CommaInitializer operator<< (const ArrayBase& other); - - const CoeffReturnType coeff(int row, int col) const; - const CoeffReturnType operator()(int row, int col) const; - - Scalar& coeffRef(int row, int col); - Scalar& operator()(int row, int col); - - const CoeffReturnType coeff(int index) const; - const CoeffReturnType operator[](int index) const; - const CoeffReturnType operator()(int index) const; - - Scalar& coeffRef(int index); - Scalar& operator[](int index); - Scalar& operator()(int index); - -#ifndef EIGEN_PARSED_BY_DOXYGEN - template - void copyCoeff(int row, int col, const ArrayBase& other); - template - void copyCoeff(int index, const ArrayBase& other); - template - void copyPacket(int row, int col, const ArrayBase& other); - template - void copyPacket(int index, const ArrayBase& other); -#endif // not EIGEN_PARSED_BY_DOXYGEN - - template - PacketScalar packet(int row, int col) const; - template - void writePacket(int row, int col, const PacketScalar& x); - - template - PacketScalar packet(int index) const; - template - void writePacket(int index, const PacketScalar& x); - - template - Derived& operator+=(const ArrayBase& other); - template - Derived& operator-=(const ArrayBase& other); - - template - Derived& operator*=(const ArrayBase& other); - - Eigen::Transpose transpose(); - const Eigen::Transpose transpose() const; - void transposeInPlace(); - - #ifndef EIGEN_NO_DEBUG - template - Derived& lazyAssign(const Transpose& other); - template - Derived& lazyAssign(const CwiseBinaryOp,Transpose,DerivedB>& other); - template - Derived& lazyAssign(const CwiseBinaryOp,DerivedA,Transpose >& other); - - template - Derived& lazyAssign(const CwiseUnaryOp, NestByValue > >& other); - template - Derived& lazyAssign(const CwiseBinaryOp,CwiseUnaryOp, NestByValue > >,DerivedB>& other); - template - Derived& lazyAssign(const CwiseBinaryOp,DerivedA,CwiseUnaryOp, NestByValue > > >& other); - #endif - - RowXpr row(int i); - const RowXpr row(int i) const; - - ColXpr col(int i); - const ColXpr col(int i) const; - - Minor minor(int row, int col); - const Minor minor(int row, int col) const; - - typename BlockReturnType::Type block(int startRow, int startCol, int blockRows, int blockCols); - const typename BlockReturnType::Type - block(int startRow, int startCol, int blockRows, int blockCols) const; - - VectorBlock segment(int start, int size); - const VectorBlock segment(int start, int size) const; - - VectorBlock start(int size); - const VectorBlock start(int size) const; - - VectorBlock end(int size); - const VectorBlock end(int size) const; - - typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols); - const typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols) const; - - template - typename BlockReturnType::Type block(int startRow, int startCol); - template - const typename BlockReturnType::Type block(int startRow, int startCol) const; - - template - typename BlockReturnType::Type corner(CornerType type); - template - const typename BlockReturnType::Type corner(CornerType type) const; - - template VectorBlock start(void); - template const VectorBlock start() const; - - template VectorBlock end(); - template const VectorBlock end() const; - - template VectorBlock segment(int start); - template const VectorBlock segment(int start) const; - - static const ConstantReturnType - Constant(int rows, int cols, const Scalar& value); - static const ConstantReturnType - Constant(int size, const Scalar& value); - static const ConstantReturnType - Constant(const Scalar& value); - - template - static const CwiseNullaryOp - NullaryExpr(int rows, int cols, const CustomNullaryOp& func); - template - static const CwiseNullaryOp - NullaryExpr(int size, const CustomNullaryOp& func); - template - static const CwiseNullaryOp - 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(); - - void fill(const Scalar& value); - Derived& setConstant(const Scalar& value); - Derived& setZero(); - Derived& setOnes(); - Derived& setRandom(); - - - template - bool isApprox(const ArrayBase& other, - RealScalar prec = precision()) const; - bool isMuchSmallerThan(const RealScalar& other, - RealScalar prec = precision()) const; - template - bool isMuchSmallerThan(const ArrayBase& other, - RealScalar prec = precision()) const; - - bool isApproxToConstant(const Scalar& value, RealScalar prec = precision()) const; - bool isConstant(const Scalar& value, RealScalar prec = precision()) const; - bool isZero(RealScalar prec = precision()) const; - bool isOnes(RealScalar prec = precision()) const; - bool isIdentity(RealScalar prec = precision()) const; - bool isDiagonal(RealScalar prec = precision()) const; - - bool isUpperTriangular(RealScalar prec = precision()) const; - bool isLowerTriangular(RealScalar prec = precision()) const; - - template - bool isOrthogonal(const ArrayBase& other, - RealScalar prec = precision()) const; - bool isUnitary(RealScalar prec = precision()) const; - - template - inline bool operator==(const ArrayBase& other) const - { return cwiseEqual(other).all(); } - - template - inline bool operator!=(const ArrayBase& other) const - { return cwiseNotEqual(other).all(); } - - - /** \returns the matrix or vector obtained by evaluating this expression. - * - * Notice that in the case of a plain matrix or vector (not an expression) this function just returns - * a const reference, in order to avoid a useless copy. - */ - EIGEN_STRONG_INLINE const typename ei_eval::type eval() const - { return typename ei_eval::type(derived()); } - - template - void swap(ArrayBase EIGEN_REF_TO_TEMPORARY other); - - NoAlias noalias(); - - /** \returns number of elements to skip to pass from one row (resp. column) to another - * for a row-major (resp. column-major) matrix. - * Combined with coeffRef() and the \ref flags flags, it allows a direct access to the data - * of the underlying matrix. - */ - inline int stride(void) const { return derived().stride(); } - - inline const NestByValue nestByValue() const; - - Scalar sum() const; - Scalar mean() const; - Scalar trace() const; - - Scalar prod() const; - - typename ei_traits::Scalar minCoeff() const; - typename ei_traits::Scalar maxCoeff() const; - - typename ei_traits::Scalar minCoeff(int* row, int* col) const; - typename ei_traits::Scalar maxCoeff(int* row, int* col) const; - - typename ei_traits::Scalar minCoeff(int* index) const; - typename ei_traits::Scalar maxCoeff(int* index) const; - - template - typename ei_result_of::Scalar)>::type - redux(const BinaryOp& func) const; - - template - void visit(Visitor& func) const; - -#ifndef EIGEN_PARSED_BY_DOXYGEN - using AnyArrayBase::derived; - inline Derived& const_cast_derived() const - { return *static_cast(const_cast(this)); } -#endif // not EIGEN_PARSED_BY_DOXYGEN - - inline const WithFormat format(const IOFormat& fmt) const; - - bool all(void) const; - bool any(void) const; - int count() const; - - const VectorwiseOp rowwise() const; - VectorwiseOp rowwise(); - const VectorwiseOp colwise() const; - VectorwiseOp colwise(); - - static const CwiseNullaryOp,Derived> Random(int rows, int cols); - static const CwiseNullaryOp,Derived> Random(int size); - static const CwiseNullaryOp,Derived> Random(); - - template - const Select - select(const ArrayBase& thenMatrix, - const ArrayBase& elseMatrix) const; - - template - inline const Select > - select(const ArrayBase& thenMatrix, typename ThenDerived::Scalar elseScalar) const; - - template - inline const Select, ElseDerived > - select(typename ElseDerived::Scalar thenScalar, const ArrayBase& elseMatrix) const; - - template - const Replicate replicate() const; - const Replicate replicate(int rowFacor,int colFactor) const; - - Eigen::Reverse reverse(); - const Eigen::Reverse reverse() const; - void reverseInPlace(); - - #ifdef EIGEN_MATRIXBASE_PLUGIN - #include EIGEN_MATRIXBASE_PLUGIN - #endif - - protected: - /** Default constructor. Do nothing. */ - ArrayBase() - { - /* Just checks for self-consistency of the flags. - * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down - */ -#ifdef EIGEN_INTERNAL_DEBUGGING - EIGEN_STATIC_ASSERT(ei_are_flags_consistent::ret, - INVALID_MATRIXBASE_TEMPLATE_PARAMETERS) -#endif - } - - private: - explicit ArrayBase(int); - ArrayBase(int,int); - template explicit ArrayBase(const ArrayBase&); -}; - -#endif // EIGEN_ARRAYBASE_H +#endif // EIGEN_ARRAY_H diff --git a/Eigen/src/Array/ArrayBase.h b/Eigen/src/Array/ArrayBase.h new file mode 100644 index 000000000..644c3bc1f --- /dev/null +++ b/Eigen/src/Array/ArrayBase.h @@ -0,0 +1,233 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 . + +#ifndef EIGEN_ARRAYBASE_H +#define EIGEN_ARRAYBASE_H + +template class MatrixWrapper; + +/** \ingroup Array_Module + * + * \class ArrayBase + * + * \brief Base class for all 1D and 2D array, and related expressions + * + * An array is similar to a dense vector or matrix. While matrices are mathematical + * objects with well defined linear algebra operators, an array is just a collection + * of scalar values arranged in a one or two dimensionnal fashion. The main consequence, + * is that all operations applied to an array are performed coefficient wise. Furthermore, + * arays support scalar math functions of the c++ standard library, and convenient + * constructors allowing to easily write generic code working for both scalar values + * and arrays. + * + * This class is the base that is inherited by all array expression types. + * + * \param Derived is the derived type, e.g. an array type, or an expression, etc. + * + * \sa class ArrayBase + */ +template class ArrayBase + : public DenseBase +{ + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** The base class for a given storage type. */ + typedef ArrayBase StorageBaseType; + /** Construct the base class type for the derived class OtherDerived */ + template struct MakeBase { typedef ArrayBase Type; }; + + using ei_special_scalar_op_base::Scalar, + typename NumTraits::Scalar>::Real>::operator*; + + class InnerIterator; + + typedef typename ei_traits::Scalar Scalar; + typedef typename ei_packet_traits::type PacketScalar; + + typedef DenseBase Base; + using Base::RowsAtCompileTime; + using Base::ColsAtCompileTime; + using Base::SizeAtCompileTime; + using Base::MaxRowsAtCompileTime; + using Base::MaxColsAtCompileTime; + using Base::MaxSizeAtCompileTime; + using Base::IsVectorAtCompileTime; + using Base::Flags; + using Base::CoeffReadCost; + using Base::_HasDirectAccess; + + using Base::rows; + using Base::cols; + using Base::size; + using Base::coeff; + using Base::coeffRef; +// using Base::; +// using Base::; + + typedef typename Base::RealScalar RealScalar; + typedef typename Base::CoeffReturnType CoeffReturnType; +// typedef typename Base::ColXpr ColXpr; +// typedef typename Base::RowXpr RowXpr; +// typedef typename Base::; +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal the plain matrix type corresponding to this expression. Note that is not necessarily + * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const + * reference to a matrix, not a matrix! It is however guaranteed that the return type of eval() is either + * PlainMatrixType or const PlainMatrixType&. + */ + typedef typename ei_plain_matrix_type::type PlainMatrixType; + /** \internal the column-major plain matrix type corresponding to this expression. Note that is not necessarily + * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const + * reference to a matrix, not a matrix! + * The only difference from PlainMatrixType is that PlainMatrixType_ColMajor is guaranteed to be column-major. + */ + typedef typename ei_plain_matrix_type::type PlainMatrixType_ColMajor; + + + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp,Derived> ConstantReturnType; +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#ifndef EIGEN_PARSED_BY_DOXYGEN + using AnyMatrixBase::derived; + inline Derived& const_cast_derived() const + { return *static_cast(const_cast(this)); } +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase +# include "../plugins/CommonCwiseUnaryOps.h" +# include "../plugins/MatrixCwiseUnaryOps.h" +# include "../plugins/ArrayCwiseUnaryOps.h" +# include "../plugins/CommonCwiseBinaryOps.h" +# include "../plugins/ArrayCwiseBinaryOps.h" +#undef EIGEN_CURRENT_STORAGE_BASE_CLASS + + + /** Copies \a other into *this. \returns a reference to *this. */ +// template +// Derived& operator=(const ArrayBase& other); + + /** Special case of the template operator=, in order to prevent the compiler + * from generating a default operator= (issue hit with g++ 4.1) + */ + Derived& operator=(const ArrayBase& other) + { + return ei_assign_selector::run(derived(), other.derived()); + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ +// template +// Derived& lazyAssign(const ArrayBase& other); +#endif // not EIGEN_PARSED_BY_DOXYGEN + + + template + Derived& operator+=(const ArrayBase& other); + template + Derived& operator-=(const ArrayBase& other); + + template + Derived& operator*=(const ArrayBase& other); + + template + inline bool operator==(const ArrayBase& other) const + { return cwiseEqual(other).all(); } + + template + inline bool operator!=(const ArrayBase& other) const + { return cwiseNotEqual(other).all(); } + + + /** \returns the matrix or vector obtained by evaluating this expression. + * + * Notice that in the case of a plain matrix or vector (not an expression) this function just returns + * a const reference, in order to avoid a useless copy. + */ +// EIGEN_STRONG_INLINE const typename ei_eval::type eval() const +// { return typename ei_eval::type(derived()); } + +// template +// void swap(ArrayBase EIGEN_REF_TO_TEMPORARY other); + + +// const VectorwiseOp rowwise() const; +// VectorwiseOp rowwise(); +// const VectorwiseOp colwise() const; +// VectorwiseOp colwise(); + +// template +// const Select +// select(const ArrayBase& thenMatrix, +// const ArrayBase& elseMatrix) const; + +// template +// inline const Select > +// select(const ArrayBase& thenMatrix, typename ThenDerived::Scalar elseScalar) const; + +// template +// inline const Select, ElseDerived > +// select(typename ElseDerived::Scalar thenScalar, const ArrayBase& elseMatrix) const; + +// template +// const Replicate replicate() const; +// const Replicate replicate(int rowFacor,int colFactor) const; + +// Eigen::Reverse reverse(); +// const Eigen::Reverse reverse() const; +// void reverseInPlace(); + + #ifdef EIGEN_ARRAYBASE_PLUGIN + #include EIGEN_ARRAYBASE_PLUGIN + #endif + + public: + MatrixWrapper asMatrix() { return derived(); } + const MatrixWrapper asMatrix() const { return derived(); } + + template + inline void evalTo(Dest& dst) const { dst = asMatrix(); } + + protected: + /** Default constructor. Do nothing. */ + ArrayBase() + { + /* Just checks for self-consistency of the flags. + * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down + */ +#ifdef EIGEN_INTERNAL_DEBUGGING + EIGEN_STATIC_ASSERT(ei_are_flags_consistent::ret, + INVALID_MATRIXBASE_TEMPLATE_PARAMETERS) +#endif + } + + private: + explicit ArrayBase(int); + ArrayBase(int,int); + template explicit ArrayBase(const ArrayBase&); +}; + +#endif // EIGEN_ARRAYBASE_H diff --git a/Eigen/src/Array/ArrayWrapper.h b/Eigen/src/Array/ArrayWrapper.h new file mode 100644 index 000000000..5e9938e83 --- /dev/null +++ b/Eigen/src/Array/ArrayWrapper.h @@ -0,0 +1,161 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 . + +#ifndef EIGEN_ARRAYWRAPPER_H +#define EIGEN_ARRAYWRAPPER_H + +template +struct ei_traits > + : public ei_traits +{}; + +template +class ArrayWrapper : public ArrayBase > +{ + public: + EIGEN_GENERIC_PUBLIC_INTERFACE(ArrayWrapper) + + inline ArrayWrapper(const ExpressionType& matrix) : m_expression(matrix) {} + + inline int rows() const { return m_expression.rows(); } + inline int cols() const { return m_expression.cols(); } + inline int stride() const { return m_expression.stride(); } + + inline const CoeffReturnType coeff(int row, int col) const + { + return m_expression.coeff(row, col); + } + + inline Scalar& coeffRef(int row, int col) + { + return m_expression.const_cast_derived().coeffRef(row, col); + } + + inline const CoeffReturnType coeff(int index) const + { + return m_expression.coeff(index); + } + + inline Scalar& coeffRef(int index) + { + return m_expression.const_cast_derived().coeffRef(index); + } + + template + inline const PacketScalar packet(int row, int col) const + { + return m_expression.template packet(row, col); + } + + template + inline void writePacket(int row, int col, const PacketScalar& x) + { + m_expression.const_cast_derived().template writePacket(row, col, x); + } + + template + inline const PacketScalar packet(int index) const + { + return m_expression.template packet(index); + } + + template + inline void writePacket(int index, const PacketScalar& x) + { + m_expression.const_cast_derived().template writePacket(index, x); + } + + template + inline void evalTo(Dest& dst) const { dst = m_expression; } + + protected: + const ExpressionType& m_expression; +}; + +template +struct ei_traits > + : public ei_traits +{}; + +template +class MatrixWrapper : public MatrixBase > +{ + public: + EIGEN_GENERIC_PUBLIC_INTERFACE(MatrixWrapper) + + inline MatrixWrapper(const ExpressionType& matrix) : m_expression(matrix) {} + + inline int rows() const { return m_expression.rows(); } + inline int cols() const { return m_expression.cols(); } + inline int stride() const { return m_expression.stride(); } + + inline const CoeffReturnType coeff(int row, int col) const + { + return m_expression.coeff(row, col); + } + + inline Scalar& coeffRef(int row, int col) + { + return m_expression.const_cast_derived().coeffRef(row, col); + } + + inline const CoeffReturnType coeff(int index) const + { + return m_expression.coeff(index); + } + + inline Scalar& coeffRef(int index) + { + return m_expression.const_cast_derived().coeffRef(index); + } + + template + inline const PacketScalar packet(int row, int col) const + { + return m_expression.template packet(row, col); + } + + template + inline void writePacket(int row, int col, const PacketScalar& x) + { + m_expression.const_cast_derived().template writePacket(row, col, x); + } + + template + inline const PacketScalar packet(int index) const + { + return m_expression.template packet(index); + } + + template + inline void writePacket(int index, const PacketScalar& x) + { + m_expression.const_cast_derived().template writePacket(index, x); + } + + protected: + const ExpressionType& m_expression; +}; + +#endif // EIGEN_ARRAYWRAPPER_H diff --git a/Eigen/src/Array/BooleanRedux.h b/Eigen/src/Array/BooleanRedux.h index ab6e06d56..9c6985a29 100644 --- a/Eigen/src/Array/BooleanRedux.h +++ b/Eigen/src/Array/BooleanRedux.h @@ -84,10 +84,10 @@ struct ei_any_unroller * Example: \include MatrixBase_all.cpp * Output: \verbinclude MatrixBase_all.out * - * \sa MatrixBase::any(), Cwise::operator<() + * \sa any(), Cwise::operator<() */ template -inline bool MatrixBase::all() const +inline bool DenseBase::all() const { const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT; @@ -108,10 +108,10 @@ inline bool MatrixBase::all() const * * \returns true if at least one coefficient is true * - * \sa MatrixBase::all() + * \sa all() */ template -inline bool MatrixBase::any() const +inline bool DenseBase::any() const { const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT; @@ -132,12 +132,12 @@ inline bool MatrixBase::any() const * * \returns the number of coefficients which evaluate to true * - * \sa MatrixBase::all(), MatrixBase::any() + * \sa all(), any() */ template -inline int MatrixBase::count() const +inline int DenseBase::count() const { - return this->cast().cast().sum(); + return derived().template cast().template cast().sum(); } #endif // EIGEN_ALLANDANY_H diff --git a/Eigen/src/Array/Random.h b/Eigen/src/Array/Random.h index adadf99e3..831e93816 100644 --- a/Eigen/src/Array/Random.h +++ b/Eigen/src/Array/Random.h @@ -55,7 +55,7 @@ struct ei_functor_traits > */ template inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::Random(int rows, int cols) +DenseBase::Random(int rows, int cols) { return NullaryExpr(rows, cols, ei_scalar_random_op()); } @@ -84,7 +84,7 @@ MatrixBase::Random(int rows, int cols) */ template inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::Random(int size) +DenseBase::Random(int size) { return NullaryExpr(size, ei_scalar_random_op()); } @@ -107,7 +107,7 @@ MatrixBase::Random(int size) */ template inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::Random() +DenseBase::Random() { return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op()); } @@ -122,7 +122,7 @@ MatrixBase::Random() * \sa class CwiseNullaryOp, setRandom(int), setRandom(int,int) */ template -inline Derived& MatrixBase::setRandom() +inline Derived& DenseBase::setRandom() { return *this = Random(rows(), cols()); } diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 8dc015715..466205208 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -414,13 +414,13 @@ struct ei_assign_impl }; /*************************************************************************** -* Part 4 : implementation of MatrixBase methods +* Part 4 : implementation of DenseBase methods ***************************************************************************/ template template -EIGEN_STRONG_INLINE Derived& MatrixBase - ::lazyAssign(const MatrixBase& other) +EIGEN_STRONG_INLINE Derived& DenseBase + ::lazyAssign(const DenseBase& other) { EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived) EIGEN_STATIC_ASSERT((ei_is_same_type::ret), @@ -463,16 +463,21 @@ struct ei_assign_selector { template template -EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const MatrixBase& other) +EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) { return ei_assign_selector::run(derived(), other.derived()); } template -EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const MatrixBase& other) +EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) { return ei_assign_selector::run(derived(), other.derived()); } +template +EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const MatrixBase& other) +{ + return ei_assign_selector::run(derived(), other.derived()); +} #endif // EIGEN_ASSIGN_H diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index ef2d791c9..598d846ea 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -36,7 +36,7 @@ * \param _DirectAccessStatus \internal used for partial specialization * * This class represents an expression of either a fixed-size or dynamic-size block. It is the return - * type of MatrixBase::block(int,int,int,int) and MatrixBase::block(int,int) and + * type of DenseBase::block(int,int,int,int) and DenseBase::block(int,int) and * most of the time this is the only way it is used. * * However, if you want to directly maniputate block expressions, @@ -55,7 +55,7 @@ * \include class_FixedBlock.cpp * Output: \verbinclude class_FixedBlock.out * - * \sa MatrixBase::block(int,int,int,int), MatrixBase::block(int,int), class VectorBlock + * \sa DenseBase::block(int,int,int,int), DenseBase::block(int,int), class VectorBlock */ template struct ei_traits > @@ -83,7 +83,7 @@ struct ei_traits > }; template class Block - : public MatrixBase > + :public MatrixType::template MakeBase< Block >::Type { public: @@ -213,11 +213,13 @@ template class Block - : public MapBase > + : public MapBase, + typename MatrixType::template MakeBase< Block >::Type> { public: - _EIGEN_GENERIC_PUBLIC_INTERFACE(Block, MapBase) + typedef MapBase::Type> Base; + _EIGEN_GENERIC_PUBLIC_INTERFACE(Block) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) @@ -301,7 +303,7 @@ class Block * \sa class Block, block(int,int) */ template -inline typename BlockReturnType::Type MatrixBase +inline typename BlockReturnType::Type DenseBase ::block(int startRow, int startCol, int blockRows, int blockCols) { return typename BlockReturnType::Type(derived(), startRow, startCol, blockRows, blockCols); @@ -309,7 +311,7 @@ inline typename BlockReturnType::Type MatrixBase /** This is the const version of block(int,int,int,int). */ template -inline const typename BlockReturnType::Type MatrixBase +inline const typename BlockReturnType::Type DenseBase ::block(int startRow, int startCol, int blockRows, int blockCols) const { return typename BlockReturnType::Type(derived(), startRow, startCol, blockRows, blockCols); @@ -332,7 +334,7 @@ inline const typename BlockReturnType::Type MatrixBase * \sa class Block, block(int,int,int,int) */ template -inline typename BlockReturnType::Type MatrixBase +inline typename BlockReturnType::Type DenseBase ::corner(CornerType type, int cRows, int cCols) { switch(type) @@ -353,7 +355,7 @@ inline typename BlockReturnType::Type MatrixBase /** This is the const version of corner(CornerType, int, int).*/ template inline const typename BlockReturnType::Type -MatrixBase::corner(CornerType type, int cRows, int cCols) const +DenseBase::corner(CornerType type, int cRows, int cCols) const { switch(type) { @@ -385,7 +387,7 @@ MatrixBase::corner(CornerType type, int cRows, int cCols) const template template inline typename BlockReturnType::Type -MatrixBase::corner(CornerType type) +DenseBase::corner(CornerType type) { switch(type) { @@ -406,7 +408,7 @@ MatrixBase::corner(CornerType type) template template inline const typename BlockReturnType::Type -MatrixBase::corner(CornerType type) const +DenseBase::corner(CornerType type) const { switch(type) { @@ -442,7 +444,7 @@ MatrixBase::corner(CornerType type) const template template inline typename BlockReturnType::Type -MatrixBase::block(int startRow, int startCol) +DenseBase::block(int startRow, int startCol) { return Block(derived(), startRow, startCol); } @@ -451,7 +453,7 @@ MatrixBase::block(int startRow, int startCol) template template inline const typename BlockReturnType::Type -MatrixBase::block(int startRow, int startCol) const +DenseBase::block(int startRow, int startCol) const { return Block(derived(), startRow, startCol); } @@ -463,16 +465,16 @@ MatrixBase::block(int startRow, int startCol) const * * \sa row(), class Block */ template -inline typename MatrixBase::ColXpr -MatrixBase::col(int i) +inline typename DenseBase::ColXpr +DenseBase::col(int i) { return ColXpr(derived(), i); } /** This is the const version of col(). */ template -inline const typename MatrixBase::ColXpr -MatrixBase::col(int i) const +inline const typename DenseBase::ColXpr +DenseBase::col(int i) const { return ColXpr(derived(), i); } @@ -484,16 +486,16 @@ MatrixBase::col(int i) const * * \sa col(), class Block */ template -inline typename MatrixBase::RowXpr -MatrixBase::row(int i) +inline typename DenseBase::RowXpr +DenseBase::row(int i) { return RowXpr(derived(), i); } /** This is the const version of row(). */ template -inline const typename MatrixBase::RowXpr -MatrixBase::row(int i) const +inline const typename DenseBase::RowXpr +DenseBase::row(int i) const { return RowXpr(derived(), i); } diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index 2618f0dce..c8bc9db85 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -40,7 +40,7 @@ * \sa operator()(int,int) const, coeffRef(int,int), coeff(int) const */ template -EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase +EIGEN_STRONG_INLINE const typename DenseBase::CoeffReturnType DenseBase ::coeff(int row, int col) const { ei_internal_assert(row >= 0 && row < rows() @@ -53,7 +53,7 @@ EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBa * \sa operator()(int,int), operator[](int) const */ template -EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase +EIGEN_STRONG_INLINE const typename DenseBase::CoeffReturnType DenseBase ::operator()(int row, int col) const { ei_assert(row >= 0 && row < rows() @@ -76,7 +76,7 @@ EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBa * \sa operator()(int,int), coeff(int, int) const, coeffRef(int) */ template -EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase +EIGEN_STRONG_INLINE typename ei_traits::Scalar& DenseBase ::coeffRef(int row, int col) { ei_internal_assert(row >= 0 && row < rows() @@ -89,7 +89,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase * \sa operator()(int,int) const, operator[](int) */ template -EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase +EIGEN_STRONG_INLINE typename ei_traits::Scalar& DenseBase ::operator()(int row, int col) { ei_assert(row >= 0 && row < rows() @@ -112,7 +112,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase * \sa operator[](int) const, coeffRef(int), coeff(int,int) const */ template -EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase +EIGEN_STRONG_INLINE const typename DenseBase::CoeffReturnType DenseBase ::coeff(int index) const { ei_internal_assert(index >= 0 && index < size()); @@ -127,7 +127,7 @@ EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBa * z() const, w() const */ template -EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase +EIGEN_STRONG_INLINE const typename DenseBase::CoeffReturnType DenseBase ::operator[](int index) const { ei_assert(index >= 0 && index < size()); @@ -144,7 +144,7 @@ EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBa * z() const, w() const */ template -EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBase +EIGEN_STRONG_INLINE const typename DenseBase::CoeffReturnType DenseBase ::operator()(int index) const { ei_assert(index >= 0 && index < size()); @@ -166,7 +166,7 @@ EIGEN_STRONG_INLINE const typename MatrixBase::CoeffReturnType MatrixBa * \sa operator[](int), coeff(int) const, coeffRef(int,int) */ template -EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase +EIGEN_STRONG_INLINE typename ei_traits::Scalar& DenseBase ::coeffRef(int index) { ei_internal_assert(index >= 0 && index < size()); @@ -180,7 +180,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase * \sa operator[](int) const, operator()(int,int), x(), y(), z(), w() */ template -EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase +EIGEN_STRONG_INLINE typename ei_traits::Scalar& DenseBase ::operator[](int index) { ei_assert(index >= 0 && index < size()); @@ -196,7 +196,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase * \sa operator[](int) const, operator()(int,int), x(), y(), z(), w() */ template -EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase +EIGEN_STRONG_INLINE typename ei_traits::Scalar& DenseBase ::operator()(int index) { ei_assert(index >= 0 && index < size()); @@ -254,7 +254,7 @@ EIGEN_STRONG_INLINE typename ei_traits::Scalar& MatrixBase template template EIGEN_STRONG_INLINE typename ei_packet_traits::Scalar>::type -MatrixBase::packet(int row, int col) const +DenseBase::packet(int row, int col) const { ei_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); @@ -271,7 +271,7 @@ MatrixBase::packet(int row, int col) const */ template template -EIGEN_STRONG_INLINE void MatrixBase::writePacket +EIGEN_STRONG_INLINE void DenseBase::writePacket (int row, int col, const typename ei_packet_traits::Scalar>::type& x) { ei_internal_assert(row >= 0 && row < rows() @@ -290,7 +290,7 @@ EIGEN_STRONG_INLINE void MatrixBase::writePacket template template EIGEN_STRONG_INLINE typename ei_packet_traits::Scalar>::type -MatrixBase::packet(int index) const +DenseBase::packet(int index) const { ei_internal_assert(index >= 0 && index < size()); return derived().template packet(index); @@ -306,7 +306,7 @@ MatrixBase::packet(int index) const */ template template -EIGEN_STRONG_INLINE void MatrixBase::writePacket +EIGEN_STRONG_INLINE void DenseBase::writePacket (int index, const typename ei_packet_traits::Scalar>::type& x) { ei_internal_assert(index >= 0 && index < size()); @@ -324,7 +324,7 @@ EIGEN_STRONG_INLINE void MatrixBase::writePacket */ template template -EIGEN_STRONG_INLINE void MatrixBase::copyCoeff(int row, int col, const MatrixBase& other) +EIGEN_STRONG_INLINE void DenseBase::copyCoeff(int row, int col, const DenseBase& other) { ei_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); @@ -340,7 +340,7 @@ EIGEN_STRONG_INLINE void MatrixBase::copyCoeff(int row, int col, const */ template template -EIGEN_STRONG_INLINE void MatrixBase::copyCoeff(int index, const MatrixBase& other) +EIGEN_STRONG_INLINE void DenseBase::copyCoeff(int index, const DenseBase& other) { ei_internal_assert(index >= 0 && index < size()); derived().coeffRef(index) = other.derived().coeff(index); @@ -355,7 +355,7 @@ EIGEN_STRONG_INLINE void MatrixBase::copyCoeff(int index, const MatrixB */ template template -EIGEN_STRONG_INLINE void MatrixBase::copyPacket(int row, int col, const MatrixBase& other) +EIGEN_STRONG_INLINE void DenseBase::copyPacket(int row, int col, const DenseBase& other) { ei_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); @@ -372,7 +372,7 @@ EIGEN_STRONG_INLINE void MatrixBase::copyPacket(int row, int col, const */ template template -EIGEN_STRONG_INLINE void MatrixBase::copyPacket(int index, const MatrixBase& other) +EIGEN_STRONG_INLINE void DenseBase::copyPacket(int index, const DenseBase& other) { ei_internal_assert(index >= 0 && index < size()); derived().template writePacket(index, diff --git a/Eigen/src/Core/CommaInitializer.h b/Eigen/src/Core/CommaInitializer.h index 328c5580c..428e4d82d 100644 --- a/Eigen/src/Core/CommaInitializer.h +++ b/Eigen/src/Core/CommaInitializer.h @@ -47,7 +47,7 @@ struct CommaInitializer } template - inline CommaInitializer(MatrixType& mat, const MatrixBase& other) + inline CommaInitializer(MatrixType& mat, const DenseBase& other) : m_matrix(mat), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) { m_matrix.block(0, 0, other.rows(), other.cols()) = other; @@ -73,7 +73,7 @@ struct CommaInitializer /* inserts a matrix expression in the target matrix */ template - CommaInitializer& operator,(const MatrixBase& other) + CommaInitializer& operator,(const DenseBase& other) { if (m_col==m_matrix.cols()) { @@ -133,7 +133,7 @@ private: * \sa CommaInitializer::finished(), class CommaInitializer */ template -inline CommaInitializer MatrixBase::operator<< (const Scalar& s) +inline CommaInitializer DenseBase::operator<< (const Scalar& s) { return CommaInitializer(*static_cast(this), s); } @@ -142,7 +142,7 @@ inline CommaInitializer MatrixBase::operator<< (const Scalar& template template inline CommaInitializer -MatrixBase::operator<<(const MatrixBase& other) +DenseBase::operator<<(const DenseBase& other) { return CommaInitializer(*static_cast(this), other); } diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 0b45261ae..c45c52494 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -140,7 +140,8 @@ class CwiseBinaryOpImpl public: typedef CwiseBinaryOp Derived; - EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) + typedef typename Lhs::template MakeBase< CwiseBinaryOp >::Type Base; + _EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const { diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 7c1984be6..0fc1ce41e 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -38,7 +38,7 @@ * However, if you want to write a function returning such an expression, you * will need to use this class. * - * \sa class CwiseUnaryOp, class CwiseBinaryOp, MatrixBase::NullaryExpr() + * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr() */ template struct ei_traits > : ei_traits @@ -121,7 +121,7 @@ class CwiseNullaryOp : ei_no_assignment_operator, template template EIGEN_STRONG_INLINE const CwiseNullaryOp -MatrixBase::NullaryExpr(int rows, int cols, const CustomNullaryOp& func) +DenseBase::NullaryExpr(int rows, int cols, const CustomNullaryOp& func) { return CwiseNullaryOp(rows, cols, func); } @@ -144,7 +144,7 @@ MatrixBase::NullaryExpr(int rows, int cols, const CustomNullaryOp& func template template EIGEN_STRONG_INLINE const CwiseNullaryOp -MatrixBase::NullaryExpr(int size, const CustomNullaryOp& func) +DenseBase::NullaryExpr(int size, const CustomNullaryOp& func) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) if(RowsAtCompileTime == 1) return CwiseNullaryOp(1, size, func); @@ -153,7 +153,7 @@ MatrixBase::NullaryExpr(int size, const CustomNullaryOp& func) /** \returns an expression of a matrix defined by a custom functor \a func * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * This variant is only for fixed-size DenseBase types. For dynamic-size types, you * need to use the variants taking size arguments. * * The template parameter \a CustomNullaryOp is the type of the functor. @@ -163,7 +163,7 @@ MatrixBase::NullaryExpr(int size, const CustomNullaryOp& func) template template EIGEN_STRONG_INLINE const CwiseNullaryOp -MatrixBase::NullaryExpr(const CustomNullaryOp& func) +DenseBase::NullaryExpr(const CustomNullaryOp& func) { return CwiseNullaryOp(RowsAtCompileTime, ColsAtCompileTime, func); } @@ -171,7 +171,7 @@ MatrixBase::NullaryExpr(const CustomNullaryOp& func) /** \returns an expression of a constant matrix of value \a value * * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. + * the returned matrix. Must be compatible with this DenseBase 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 @@ -182,8 +182,8 @@ MatrixBase::NullaryExpr(const CustomNullaryOp& func) * \sa class CwiseNullaryOp */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Constant(int rows, int cols, const Scalar& value) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(int rows, int cols, const Scalar& value) { return NullaryExpr(rows, cols, ei_scalar_constant_op(value)); } @@ -191,7 +191,7 @@ MatrixBase::Constant(int rows, int cols, const Scalar& value) /** \returns an expression of a constant matrix of value \a value * * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. + * Must be compatible with this DenseBase type. * * \only_for_vectors * @@ -204,15 +204,15 @@ MatrixBase::Constant(int rows, int cols, const Scalar& value) * \sa class CwiseNullaryOp */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Constant(int size, const Scalar& value) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(int size, const Scalar& value) { return NullaryExpr(size, ei_scalar_constant_op(value)); } /** \returns an expression of a constant matrix of value \a value * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * This variant is only for fixed-size DenseBase types. For dynamic-size types, you * need to use the variants taking size arguments. * * The template parameter \a CustomNullaryOp is the type of the functor. @@ -220,8 +220,8 @@ MatrixBase::Constant(int size, const Scalar& value) * \sa class CwiseNullaryOp */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Constant(const Scalar& value) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(const Scalar& value) { EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op(value)); @@ -229,12 +229,12 @@ MatrixBase::Constant(const Scalar& value) /** \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */ template -bool MatrixBase::isApproxToConstant +bool DenseBase::isApproxToConstant (const Scalar& value, RealScalar prec) const { for(int j = 0; j < cols(); ++j) for(int i = 0; i < rows(); ++i) - if(!ei_isApprox(coeff(i, j), value, prec)) + if(!ei_isApprox(this->coeff(i, j), value, prec)) return false; return true; } @@ -243,7 +243,7 @@ bool MatrixBase::isApproxToConstant * * \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */ template -bool MatrixBase::isConstant +bool DenseBase::isConstant (const Scalar& value, RealScalar prec) const { return isApproxToConstant(value, prec); @@ -254,7 +254,7 @@ bool MatrixBase::isConstant * \sa setConstant(), Constant(), class CwiseNullaryOp */ template -EIGEN_STRONG_INLINE void MatrixBase::fill(const Scalar& value) +EIGEN_STRONG_INLINE void DenseBase::fill(const Scalar& value) { setConstant(value); } @@ -264,7 +264,7 @@ EIGEN_STRONG_INLINE void MatrixBase::fill(const Scalar& value) * \sa fill(), setConstant(int,const Scalar&), setConstant(int,int,const Scalar&), setZero(), setOnes(), Constant(), class CwiseNullaryOp, setZero(), setOnes() */ template -EIGEN_STRONG_INLINE Derived& MatrixBase::setConstant(const Scalar& value) +EIGEN_STRONG_INLINE Derived& DenseBase::setConstant(const Scalar& value) { return derived() = Constant(rows(), cols(), value); } @@ -322,8 +322,8 @@ Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setConstant(int row * \sa Zero(), Zero(int) */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Zero(int rows, int cols) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Zero(int rows, int cols) { return Constant(rows, cols, Scalar(0)); } @@ -345,8 +345,8 @@ MatrixBase::Zero(int rows, int cols) * \sa Zero(), Zero(int,int) */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Zero(int size) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Zero(int size) { return Constant(size, Scalar(0)); } @@ -362,8 +362,8 @@ MatrixBase::Zero(int size) * \sa Zero(int), Zero(int,int) */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Zero() +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Zero() { return Constant(Scalar(0)); } @@ -377,11 +377,11 @@ MatrixBase::Zero() * \sa class CwiseNullaryOp, Zero() */ template -bool MatrixBase::isZero(RealScalar prec) const +bool DenseBase::isZero(RealScalar prec) const { for(int j = 0; j < cols(); ++j) for(int i = 0; i < rows(); ++i) - if(!ei_isMuchSmallerThan(coeff(i, j), static_cast(1), prec)) + if(!ei_isMuchSmallerThan(this->coeff(i, j), static_cast(1), prec)) return false; return true; } @@ -394,7 +394,7 @@ bool MatrixBase::isZero(RealScalar prec) const * \sa class CwiseNullaryOp, Zero() */ template -EIGEN_STRONG_INLINE Derived& MatrixBase::setZero() +EIGEN_STRONG_INLINE Derived& DenseBase::setZero() { return setConstant(Scalar(0)); } @@ -406,7 +406,7 @@ EIGEN_STRONG_INLINE Derived& MatrixBase::setZero() * Example: \include Matrix_setZero_int.cpp * Output: \verbinclude Matrix_setZero_int.out * - * \sa MatrixBase::setZero(), setZero(int,int), class CwiseNullaryOp, MatrixBase::Zero() + * \sa DenseBase::setZero(), setZero(int,int), class CwiseNullaryOp, DenseBase::Zero() */ template EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& @@ -424,7 +424,7 @@ Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setZero(int size) * Example: \include Matrix_setZero_int_int.cpp * Output: \verbinclude Matrix_setZero_int_int.out * - * \sa MatrixBase::setZero(), setZero(int), class CwiseNullaryOp, MatrixBase::Zero() + * \sa DenseBase::setZero(), setZero(int), class CwiseNullaryOp, DenseBase::Zero() */ template EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& @@ -451,8 +451,8 @@ Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setZero(int rows, i * \sa Ones(), Ones(int), isOnes(), class Ones */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Ones(int rows, int cols) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Ones(int rows, int cols) { return Constant(rows, cols, Scalar(1)); } @@ -474,8 +474,8 @@ MatrixBase::Ones(int rows, int cols) * \sa Ones(), Ones(int,int), isOnes(), class Ones */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Ones(int size) +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Ones(int size) { return Constant(size, Scalar(1)); } @@ -491,8 +491,8 @@ MatrixBase::Ones(int size) * \sa Ones(int), Ones(int,int), isOnes(), class Ones */ template -EIGEN_STRONG_INLINE const typename MatrixBase::ConstantReturnType -MatrixBase::Ones() +EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Ones() { return Constant(Scalar(1)); } @@ -506,7 +506,7 @@ MatrixBase::Ones() * \sa class CwiseNullaryOp, Ones() */ template -bool MatrixBase::isOnes +bool DenseBase::isOnes (RealScalar prec) const { return isApproxToConstant(Scalar(1), prec); @@ -520,7 +520,7 @@ bool MatrixBase::isOnes * \sa class CwiseNullaryOp, Ones() */ template -EIGEN_STRONG_INLINE Derived& MatrixBase::setOnes() +EIGEN_STRONG_INLINE Derived& DenseBase::setOnes() { return setConstant(Scalar(1)); } @@ -620,12 +620,12 @@ bool MatrixBase::isIdentity { if(i == j) { - if(!ei_isApprox(coeff(i, j), static_cast(1), prec)) + if(!ei_isApprox(this->coeff(i, j), static_cast(1), prec)) return false; } else { - if(!ei_isMuchSmallerThan(coeff(i, j), static_cast(1), prec)) + if(!ei_isMuchSmallerThan(this->coeff(i, j), static_cast(1), prec)) return false; } } diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index abece413b..b4da532e6 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -106,7 +106,8 @@ class CwiseUnaryOpImpl public: typedef CwiseUnaryOp Derived; - EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) + typedef typename MatrixType::template MakeBase< CwiseUnaryOp >::Type Base; + _EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const { diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h new file mode 100644 index 000000000..d4808cf06 --- /dev/null +++ b/Eigen/src/Core/DenseBase.h @@ -0,0 +1,517 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2009 Benoit Jacob +// Copyright (C) 2008-2009 Gael Guennebaud +// +// 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 . + +#ifndef EIGEN_DENSEBASE_H +#define EIGEN_DENSEBASE_H + +/** \class DenseBase + * + * \brief Base class for all dense matrices, vectors, and arrays + * + * This class is the base that is inherited by all dense objects (matrix, vector, arrays, and expression + * types). The common Eigen API for dense object is contained in this class. + * + * \param Derived is the derived type, e.g. a matrix type, or an expression, etc. + */ +template class DenseBase +#ifndef EIGEN_PARSED_BY_DOXYGEN + : public ei_special_scalar_op_base::Scalar, + typename NumTraits::Scalar>::Real> +#endif // not EIGEN_PARSED_BY_DOXYGEN +{ + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + using ei_special_scalar_op_base::Scalar, + typename NumTraits::Scalar>::Real>::operator*; + + class InnerIterator; + + typedef typename ei_traits::Scalar Scalar; + typedef typename ei_packet_traits::type PacketScalar; +#endif // not EIGEN_PARSED_BY_DOXYGEN + + enum { + + RowsAtCompileTime = ei_traits::RowsAtCompileTime, + /**< 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 */ + + ColsAtCompileTime = ei_traits::ColsAtCompileTime, + /**< 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 */ + + + SizeAtCompileTime = (ei_size_at_compile_time::RowsAtCompileTime, + ei_traits::ColsAtCompileTime>::ret), + /**< 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 */ + + MaxRowsAtCompileTime = ei_traits::MaxRowsAtCompileTime, + /**< This value is equal to the maximum possible number of rows that this expression + * might have. If this expression might have an arbitrarily high number of rows, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime + */ + + MaxColsAtCompileTime = ei_traits::MaxColsAtCompileTime, + /**< This value is equal to the maximum possible number of columns that this expression + * might have. If this expression might have an arbitrarily high number of columns, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime + */ + + MaxSizeAtCompileTime = (ei_size_at_compile_time::MaxRowsAtCompileTime, + ei_traits::MaxColsAtCompileTime>::ret), + /**< This value is equal to the maximum possible number of coefficients that this expression + * might have. If this expression might have an arbitrarily high number of coefficients, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime + */ + + IsVectorAtCompileTime = ei_traits::RowsAtCompileTime == 1 + || ei_traits::ColsAtCompileTime == 1, + /**< 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). */ + + Flags = ei_traits::Flags, + /**< This stores expression \ref flags flags which may or may not be inherited by new expressions + * constructed from this one. See the \ref flags "list of flags". + */ + + CoeffReadCost = ei_traits::CoeffReadCost, + /**< This is a rough measure of how expensive it is to read one coefficient from + * this expression. + */ + +#ifndef EIGEN_PARSED_BY_DOXYGEN + _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC +#endif + }; + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** This is the "real scalar" type; if the \a Scalar type is already real numbers + * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If + * \a Scalar is \a std::complex then RealScalar is \a T. + * + * \sa class NumTraits + */ + typedef typename NumTraits::Real RealScalar; +#endif // not EIGEN_PARSED_BY_DOXYGEN + + /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ + inline int rows() const { return derived().rows(); } + /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ + inline int cols() const { return derived().cols(); } + /** \returns the number of coefficients, which is rows()*cols(). + * \sa rows(), cols(), SizeAtCompileTime. */ + inline int size() const { return rows() * cols(); } + /** \returns the number of nonzero coefficients which is in practice the number + * of stored coefficients. */ + inline int nonZeros() const { return size(); } + /** \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. */ + inline bool isVector() const { return rows()==1 || cols()==1; } + /** \returns the size of the storage major dimension, + * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ + int outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); } + /** \returns the size of the inner dimension according to the storage order, + * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ + int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } + + /** Only plain matrices, not expressions may be resized; therefore the only useful resize method is + * Matrix::resize(). The present method only asserts that the new size equals the old size, and does + * nothing else. + */ + void resize(int size) + { + ei_assert(size == this->size() + && "MatrixBase::resize() does not actually allow to resize."); + } + /** Only plain matrices, not expressions may be resized; therefore the only useful resize method is + * Matrix::resize(). The present method only asserts that the new size equals the old size, and does + * nothing else. + */ + void resize(int rows, int cols) + { + ei_assert(rows == this->rows() && cols == this->cols() + && "MatrixBase::resize() does not actually allow to resize."); + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal the return type of coeff() + */ + typedef typename ei_meta_if<_HasDirectAccess, const Scalar&, Scalar>::ret CoeffReturnType; + + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp,Derived> ConstantReturnType; + /** \internal the return type of MatrixBase::eigenvalues() */ + typedef Matrix::Scalar>::Real, ei_traits::ColsAtCompileTime, 1> EigenvaluesReturnType; + /** \internal expression tyepe of a column */ + typedef Block::RowsAtCompileTime, 1> ColXpr; + /** \internal expression tyepe of a column */ + typedef Block::ColsAtCompileTime> RowXpr; +#endif // not EIGEN_PARSED_BY_DOXYGEN + + /** Copies \a other into *this. \returns a reference to *this. */ + template + Derived& operator=(const DenseBase& other); + + /** Special case of the template operator=, in order to prevent the compiler + * from generating a default operator= (issue hit with g++ 4.1) + */ + Derived& operator=(const DenseBase& other); + + template + Derived& operator=(const AnyMatrixBase &other); + + template + Derived& operator+=(const AnyMatrixBase &other); + + template + Derived& operator-=(const AnyMatrixBase &other); + + template + Derived& operator=(const ReturnByValue& func); + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ + template + Derived& lazyAssign(const DenseBase& other); +#endif // not EIGEN_PARSED_BY_DOXYGEN + + CommaInitializer operator<< (const Scalar& s); + + template + CommaInitializer operator<< (const DenseBase& other); + + const CoeffReturnType coeff(int row, int col) const; + const CoeffReturnType operator()(int row, int col) const; + + Scalar& coeffRef(int row, int col); + Scalar& operator()(int row, int col); + + const CoeffReturnType coeff(int index) const; + const CoeffReturnType operator[](int index) const; + const CoeffReturnType operator()(int index) const; + + Scalar& coeffRef(int index); + Scalar& operator[](int index); + Scalar& operator()(int index); + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + void copyCoeff(int row, int col, const DenseBase& other); + template + void copyCoeff(int index, const DenseBase& other); + template + void copyPacket(int row, int col, const DenseBase& other); + template + void copyPacket(int index, const DenseBase& other); +#endif // not EIGEN_PARSED_BY_DOXYGEN + + template + PacketScalar packet(int row, int col) const; + template + void writePacket(int row, int col, const PacketScalar& x); + + template + PacketScalar packet(int index) const; + template + void writePacket(int index, const PacketScalar& x); + + template + Derived& operator+=(const DenseBase& other); + template + Derived& operator-=(const DenseBase& other); + + Eigen::Transpose transpose(); + const Eigen::Transpose transpose() const; + void transposeInPlace(); + #ifndef EIGEN_NO_DEBUG + template + Derived& lazyAssign(const Transpose& other); + template + Derived& lazyAssign(const CwiseBinaryOp,Transpose,DerivedB>& other); + template + Derived& lazyAssign(const CwiseBinaryOp,DerivedA,Transpose >& other); + + template + Derived& lazyAssign(const CwiseUnaryOp, NestByValue > >& other); + template + Derived& lazyAssign(const CwiseBinaryOp,CwiseUnaryOp, NestByValue > >,DerivedB>& other); + template + Derived& lazyAssign(const CwiseBinaryOp,DerivedA,CwiseUnaryOp, NestByValue > > >& other); + #endif + + RowXpr row(int i); + const RowXpr row(int i) const; + + ColXpr col(int i); + const ColXpr col(int i) const; + + typename BlockReturnType::Type block(int startRow, int startCol, int blockRows, int blockCols); + const typename BlockReturnType::Type + block(int startRow, int startCol, int blockRows, int blockCols) const; + + VectorBlock segment(int start, int size); + const VectorBlock segment(int start, int size) const; + + VectorBlock start(int size); + const VectorBlock start(int size) const; + + VectorBlock end(int size); + const VectorBlock end(int size) const; + + typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols); + const typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols) const; + + template + typename BlockReturnType::Type block(int startRow, int startCol); + template + const typename BlockReturnType::Type block(int startRow, int startCol) const; + + template + typename BlockReturnType::Type corner(CornerType type); + template + const typename BlockReturnType::Type corner(CornerType type) const; + + template VectorBlock start(void); + template const VectorBlock start() const; + + template VectorBlock end(); + template const VectorBlock end() const; + + template VectorBlock segment(int start); + template const VectorBlock segment(int start) const; + + Diagonal diagonal(); + const Diagonal diagonal() const; + + template Diagonal diagonal(); + template const Diagonal diagonal() const; + + Diagonal diagonal(int index); + const Diagonal diagonal(int index) const; + + template TriangularView part(); + template const TriangularView part() const; + + template TriangularView triangularView(); + template const TriangularView triangularView() const; + + template SelfAdjointView selfadjointView(); + template const SelfAdjointView selfadjointView() const; + + static const ConstantReturnType + Constant(int rows, int cols, const Scalar& value); + static const ConstantReturnType + Constant(int size, const Scalar& value); + static const ConstantReturnType + Constant(const Scalar& value); + + template + static const CwiseNullaryOp + NullaryExpr(int rows, int cols, const CustomNullaryOp& func); + template + static const CwiseNullaryOp + NullaryExpr(int size, const CustomNullaryOp& func); + template + static const CwiseNullaryOp + 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(); + + void fill(const Scalar& value); + Derived& setConstant(const Scalar& value); + Derived& setZero(); + Derived& setOnes(); + Derived& setRandom(); + + + template + bool isApprox(const DenseBase& other, + RealScalar prec = precision()) const; + bool isMuchSmallerThan(const RealScalar& other, + RealScalar prec = precision()) const; + template + bool isMuchSmallerThan(const DenseBase& other, + RealScalar prec = precision()) const; + + bool isApproxToConstant(const Scalar& value, RealScalar prec = precision()) const; + bool isConstant(const Scalar& value, RealScalar prec = precision()) const; + bool isZero(RealScalar prec = precision()) const; + bool isOnes(RealScalar prec = precision()) const; + +// template +// inline bool operator==(const DenseBase& other) const +// { return cwiseEqual(other).all(); } +// +// template +// inline bool operator!=(const DenseBase& other) const +// { return cwiseNotEqual(other).all(); } + + + /** \returns the matrix or vector obtained by evaluating this expression. + * + * Notice that in the case of a plain matrix or vector (not an expression) this function just returns + * a const reference, in order to avoid a useless copy. + */ + EIGEN_STRONG_INLINE const typename ei_eval::type eval() const + { return typename ei_eval::type(derived()); } + + template + void swap(DenseBase EIGEN_REF_TO_TEMPORARY other); + + /** \returns number of elements to skip to pass from one row (resp. column) to another + * for a row-major (resp. column-major) matrix. + * Combined with coeffRef() and the \ref flags flags, it allows a direct access to the data + * of the underlying matrix. + */ + inline int stride(void) const { return derived().stride(); } + + inline const NestByValue nestByValue() const; + inline const ForceAlignedAccess forceAlignedAccess() const; + inline ForceAlignedAccess forceAlignedAccess(); + template inline const typename ei_meta_if,Derived&>::ret forceAlignedAccessIf() const; + template inline typename ei_meta_if,Derived&>::ret forceAlignedAccessIf(); + + Scalar sum() const; + Scalar mean() const; + Scalar trace() const; + + Scalar prod() const; + + typename ei_traits::Scalar minCoeff() const; + typename ei_traits::Scalar maxCoeff() const; + + typename ei_traits::Scalar minCoeff(int* row, int* col) const; + typename ei_traits::Scalar maxCoeff(int* row, int* col) const; + + typename ei_traits::Scalar minCoeff(int* index) const; + typename ei_traits::Scalar maxCoeff(int* index) const; + + template + typename ei_result_of::Scalar)>::type + redux(const BinaryOp& func) const; + + template + void visit(Visitor& func) const; + +#ifndef EIGEN_PARSED_BY_DOXYGEN + using AnyMatrixBase::derived; + inline Derived& const_cast_derived() const + { return *static_cast(const_cast(this)); } +#endif // not EIGEN_PARSED_BY_DOXYGEN + + inline const WithFormat format(const IOFormat& fmt) const; + +/////////// Array module /////////// + + bool all(void) const; + bool any(void) const; + int count() const; + + const VectorwiseOp rowwise() const; + VectorwiseOp rowwise(); + const VectorwiseOp colwise() const; + VectorwiseOp colwise(); + + static const CwiseNullaryOp,Derived> Random(int rows, int cols); + static const CwiseNullaryOp,Derived> Random(int size); + static const CwiseNullaryOp,Derived> Random(); + + template + const Select + select(const DenseBase& thenMatrix, + const DenseBase& elseMatrix) const; + + template + inline const Select > + select(const DenseBase& thenMatrix, typename ThenDerived::Scalar elseScalar) const; + + template + inline const Select, ElseDerived > + select(typename ElseDerived::Scalar thenScalar, const DenseBase& elseMatrix) const; + + template RealScalar lpNorm() const; + + template + const Replicate replicate() const; + const Replicate replicate(int rowFacor,int colFactor) const; + + Eigen::Reverse reverse(); + const Eigen::Reverse reverse() const; + void reverseInPlace(); + + #ifdef EIGEN_DENSEBASE_PLUGIN + #include EIGEN_DENSEBASE_PLUGIN + #endif + + protected: + /** Default constructor. Do nothing. */ + DenseBase() + { + /* Just checks for self-consistency of the flags. + * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down + */ +#ifdef EIGEN_INTERNAL_DEBUGGING + EIGEN_STATIC_ASSERT(ei_are_flags_consistent::ret, + INVALID_MATRIXBASE_TEMPLATE_PARAMETERS) +#endif + } + + private: + explicit DenseBase(int); + DenseBase(int,int); + template explicit DenseBase(const DenseBase&); +}; + +#endif // EIGEN_DENSEBASE_H diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index 13fcfcdab..fdc13d00d 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -47,8 +47,8 @@ */ template template -bool MatrixBase::isApprox( - const MatrixBase& other, +bool DenseBase::isApprox( + const DenseBase& other, RealScalar prec ) const { @@ -68,15 +68,15 @@ bool MatrixBase::isApprox( * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm * of a reference matrix of same dimensions. * - * \sa isApprox(), isMuchSmallerThan(const MatrixBase&, RealScalar) const + * \sa isApprox(), isMuchSmallerThan(const DenseBase&, RealScalar) const */ template -bool MatrixBase::isMuchSmallerThan( +bool DenseBase::isMuchSmallerThan( const typename NumTraits::Real& other, RealScalar prec ) const { - return cwiseAbs2().sum() <= prec * prec * other * other; + return derived().cwiseAbs2().sum() <= prec * prec * other * other; } /** \returns \c true if the norm of \c *this is much smaller than the norm of \a other, @@ -91,12 +91,12 @@ bool MatrixBase::isMuchSmallerThan( */ template template -bool MatrixBase::isMuchSmallerThan( - const MatrixBase& other, +bool DenseBase::isMuchSmallerThan( + const DenseBase& other, RealScalar prec ) const { - return cwiseAbs2().sum() <= prec * prec * other.cwiseAbs2().sum(); + return derived().cwiseAbs2().sum() <= prec * prec * other.derived().cwiseAbs2().sum(); } #else @@ -122,8 +122,8 @@ struct ei_fuzzy_selector; */ template template -bool MatrixBase::isApprox( - const MatrixBase& other, +bool DenseBase::isApprox( + const DenseBase& other, RealScalar prec ) const { @@ -138,10 +138,10 @@ bool MatrixBase::isApprox( * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f] * For matrices, the comparison is done on all columns. * - * \sa isApprox(), isMuchSmallerThan(const MatrixBase&, RealScalar) const + * \sa isApprox(), isMuchSmallerThan(const DenseBase&, RealScalar) const */ template -bool MatrixBase::isMuchSmallerThan( +bool DenseBase::isMuchSmallerThan( const typename NumTraits::Real& other, RealScalar prec ) const @@ -161,8 +161,8 @@ bool MatrixBase::isMuchSmallerThan( */ template template -bool MatrixBase::isMuchSmallerThan( - const MatrixBase& other, +bool DenseBase::isMuchSmallerThan( + const DenseBase& other, RealScalar prec ) const { diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index a44802ed2..e78b1792f 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -121,7 +121,7 @@ class WithFormat */ template inline const WithFormat -MatrixBase::format(const IOFormat& fmt) const +DenseBase::format(const IOFormat& fmt) const { return WithFormat(derived(), fmt); } @@ -190,21 +190,21 @@ std::ostream & ei_print_matrix(std::ostream & s, const Derived& _m, const IOForm return s; } -/** \relates MatrixBase +/** \relates DenseBase * * Outputs the matrix, to the given stream. * - * If you wish to print the matrix with a format different than the default, use MatrixBase::format(). + * If you wish to print the matrix with a format different than the default, use DenseBase::format(). * * It is also possible to change the default format by defining EIGEN_DEFAULT_IO_FORMAT before including Eigen headers. * If not defined, this will automatically be defined to Eigen::IOFormat(), that is the Eigen::IOFormat with default parameters. * - * \sa MatrixBase::format() + * \sa DenseBase::format() */ template std::ostream & operator << (std::ostream & s, - const MatrixBase & m) + const DenseBase & m) { return ei_print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT); } diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index de93ce30b..18fafdece 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -58,11 +58,13 @@ struct ei_traits > : public ei_traits }; template class Map - : public MapBase > + : public MapBase, + typename MatrixType::template MakeBase< Map >::Type> { public: - _EIGEN_GENERIC_PUBLIC_INTERFACE(Map, MapBase) + typedef MapBase::Type> Base; + _EIGEN_GENERIC_PUBLIC_INTERFACE(Map) inline int stride() const { return this->innerSize(); } diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 31a0dbc6b..0067fbe16 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -32,12 +32,12 @@ * * \sa class Map, class Block */ -template class MapBase - : public MatrixBase +template class MapBase + : public Base { public: - typedef MatrixBase Base; +// typedef MatrixBase Base; enum { IsRowMajor = (int(ei_traits::Flags) & RowMajorBit) ? 1 : 0, RowsAtCompileTime = ei_traits::RowsAtCompileTime, diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 08d404f87..9cb13cf9b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -52,10 +52,7 @@ * \endcode */ template class MatrixBase -#ifndef EIGEN_PARSED_BY_DOXYGEN - : public ei_special_scalar_op_base::Scalar, - typename NumTraits::Scalar>::Real> -#endif // not EIGEN_PARSED_BY_DOXYGEN + : public DenseBase { public: #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -71,6 +68,13 @@ template class MatrixBase typedef typename ei_traits::Scalar Scalar; typedef typename ei_packet_traits::type PacketScalar; + + typedef DenseBase Base; + using Base::rows; + using Base::cols; + using Base::size; + using Base::coeff; + using Base::coeffRef; #endif // not EIGEN_PARSED_BY_DOXYGEN enum { @@ -165,12 +169,12 @@ template class MatrixBase #endif // not EIGEN_PARSED_BY_DOXYGEN /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline int rows() const { return derived().rows(); } +// inline int rows() const { return derived().rows(); } /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline int cols() const { return derived().cols(); } +// inline int cols() const { return derived().cols(); } /** \returns the number of coefficients, which is rows()*cols(). * \sa rows(), cols(), SizeAtCompileTime. */ - inline int size() const { return rows() * cols(); } +// inline int size() const { return rows() * cols(); } /** \returns the size of the main diagonal, which is min(rows(),cols()). * \sa rows(), cols(), SizeAtCompileTime. */ inline int diagonalSize() const { return std::min(rows(),cols()); } @@ -215,12 +219,19 @@ template class MatrixBase * PlainMatrixType or const PlainMatrixType&. */ typedef typename ei_plain_matrix_type::type PlainMatrixType; +// typedef Matrix::Scalar, +// ei_traits::RowsAtCompileTime, +// ei_traits::ColsAtCompileTime, +// AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), +// ei_traits::MaxRowsAtCompileTime, +// ei_traits::MaxColsAtCompileTime +// > PlainMatrixType; /** \internal the column-major plain matrix type corresponding to this expression. Note that is not necessarily * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const * reference to a matrix, not a matrix! * The only difference from PlainMatrixType is that PlainMatrixType_ColMajor is guaranteed to be column-major. */ - typedef typename ei_plain_matrix_type::type PlainMatrixType_ColMajor; +// typedef typename ei_plain_matrix_type::type PlainMatrixType_ColMajor; /** \internal the return type of coeff() */ @@ -249,15 +260,11 @@ template class MatrixBase #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase #include "../plugins/CommonCwiseUnaryOps.h" - #include "../plugins/MatrixCwiseUnaryOps.h" #include "../plugins/CommonCwiseBinaryOps.h" + #include "../plugins/MatrixCwiseUnaryOps.h" #include "../plugins/MatrixCwiseBinaryOps.h" #undef EIGEN_CURRENT_STORAGE_BASE_CLASS - /** Copies \a other into *this. \returns a reference to *this. */ - template - Derived& operator=(const MatrixBase& other); - /** Special case of the template operator=, in order to prevent the compiler * from generating a default operator= (issue hit with g++ 4.1) */ @@ -276,9 +283,10 @@ template class MatrixBase Derived& operator=(const ReturnByValue& func); #ifndef EIGEN_PARSED_BY_DOXYGEN + using DenseBase::lazyAssign; /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ - template - Derived& lazyAssign(const MatrixBase& other); +// template +// Derived& lazyAssign(const MatrixBase& other); template Derived& lazyAssign(const ProductBase& other); @@ -292,46 +300,6 @@ template class MatrixBase EvalBeforeAssigningBit>& other); #endif // not EIGEN_PARSED_BY_DOXYGEN - CommaInitializer operator<< (const Scalar& s); - - template - CommaInitializer operator<< (const MatrixBase& other); - - const CoeffReturnType coeff(int row, int col) const; - const CoeffReturnType operator()(int row, int col) const; - - Scalar& coeffRef(int row, int col); - Scalar& operator()(int row, int col); - - const CoeffReturnType coeff(int index) const; - const CoeffReturnType operator[](int index) const; - const CoeffReturnType operator()(int index) const; - - Scalar& coeffRef(int index); - Scalar& operator[](int index); - Scalar& operator()(int index); - -#ifndef EIGEN_PARSED_BY_DOXYGEN - template - void copyCoeff(int row, int col, const MatrixBase& other); - template - void copyCoeff(int index, const MatrixBase& other); - template - void copyPacket(int row, int col, const MatrixBase& other); - template - void copyPacket(int index, const MatrixBase& other); -#endif // not EIGEN_PARSED_BY_DOXYGEN - - template - PacketScalar packet(int row, int col) const; - template - void writePacket(int row, int col, const PacketScalar& x); - - template - PacketScalar packet(int index) const; - template - void writePacket(int index, const PacketScalar& x); - const CoeffReturnType x() const; const CoeffReturnType y() const; const CoeffReturnType z() const; @@ -373,71 +341,12 @@ template class MatrixBase const PlainMatrixType normalized() const; void normalize(); - Eigen::Transpose transpose(); - const Eigen::Transpose transpose() const; - void transposeInPlace(); const AdjointReturnType adjoint() const; void adjointInPlace(); - #ifndef EIGEN_NO_DEBUG - template - Derived& lazyAssign(const Transpose& other); - template - Derived& lazyAssign(const CwiseBinaryOp,Transpose,DerivedB>& other); - template - Derived& lazyAssign(const CwiseBinaryOp,DerivedA,Transpose >& other); - - template - Derived& lazyAssign(const CwiseUnaryOp, NestByValue > >& other); - template - Derived& lazyAssign(const CwiseBinaryOp,CwiseUnaryOp, NestByValue > >,DerivedB>& other); - template - Derived& lazyAssign(const CwiseBinaryOp,DerivedA,CwiseUnaryOp, NestByValue > > >& other); - #endif - - RowXpr row(int i); - const RowXpr row(int i) const; - - ColXpr col(int i); - const ColXpr col(int i) const; Minor minor(int row, int col); const Minor minor(int row, int col) const; - typename BlockReturnType::Type block(int startRow, int startCol, int blockRows, int blockCols); - const typename BlockReturnType::Type - block(int startRow, int startCol, int blockRows, int blockCols) const; - - VectorBlock segment(int start, int size); - const VectorBlock segment(int start, int size) const; - - VectorBlock start(int size); - const VectorBlock start(int size) const; - - VectorBlock end(int size); - const VectorBlock end(int size) const; - - typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols); - const typename BlockReturnType::Type corner(CornerType type, int cRows, int cCols) const; - - template - typename BlockReturnType::Type block(int startRow, int startCol); - template - const typename BlockReturnType::Type block(int startRow, int startCol) const; - - template - typename BlockReturnType::Type corner(CornerType type); - template - const typename BlockReturnType::Type corner(CornerType type) const; - - template VectorBlock start(void); - template const VectorBlock start() const; - - template VectorBlock end(); - template const VectorBlock end() const; - - template VectorBlock segment(int start); - template const VectorBlock segment(int start) const; - Diagonal diagonal(); const Diagonal diagonal() const; @@ -456,29 +365,6 @@ template class MatrixBase template SelfAdjointView selfadjointView(); template const SelfAdjointView selfadjointView() const; - static const ConstantReturnType - Constant(int rows, int cols, const Scalar& value); - static const ConstantReturnType - Constant(int size, const Scalar& value); - static const ConstantReturnType - Constant(const Scalar& value); - - template - static const CwiseNullaryOp - NullaryExpr(int rows, int cols, const CustomNullaryOp& func); - template - static const CwiseNullaryOp - NullaryExpr(int size, const CustomNullaryOp& func); - template - static const CwiseNullaryOp - 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 BasisReturnType Unit(int size, int i); @@ -490,27 +376,8 @@ template class MatrixBase const DiagonalWrapper asDiagonal() const; - void fill(const Scalar& value); - Derived& setConstant(const Scalar& value); - Derived& setZero(); - Derived& setOnes(); - Derived& setRandom(); Derived& setIdentity(); - - template - bool isApprox(const MatrixBase& other, - RealScalar prec = precision()) const; - bool isMuchSmallerThan(const RealScalar& other, - RealScalar prec = precision()) const; - template - bool isMuchSmallerThan(const MatrixBase& other, - RealScalar prec = precision()) const; - - bool isApproxToConstant(const Scalar& value, RealScalar prec = precision()) const; - bool isConstant(const Scalar& value, RealScalar prec = precision()) const; - bool isZero(RealScalar prec = precision()) const; - bool isOnes(RealScalar prec = precision()) const; bool isIdentity(RealScalar prec = precision()) const; bool isDiagonal(RealScalar prec = precision()) const; @@ -557,28 +424,9 @@ template class MatrixBase template inline const typename ei_meta_if,Derived&>::ret forceAlignedAccessIf() const; template inline typename ei_meta_if,Derived&>::ret forceAlignedAccessIf(); - Scalar sum() const; Scalar mean() const; Scalar trace() const; - Scalar prod() const; - - typename ei_traits::Scalar minCoeff() const; - typename ei_traits::Scalar maxCoeff() const; - - typename ei_traits::Scalar minCoeff(int* row, int* col) const; - typename ei_traits::Scalar maxCoeff(int* row, int* col) const; - - typename ei_traits::Scalar minCoeff(int* index) const; - typename ei_traits::Scalar maxCoeff(int* index) const; - - template - typename ei_result_of::Scalar)>::type - redux(const BinaryOp& func) const; - - template - void visit(Visitor& func) const; - #ifndef EIGEN_PARSED_BY_DOXYGEN using AnyMatrixBase::derived; inline Derived& const_cast_derived() const @@ -589,19 +437,11 @@ template class MatrixBase /////////// Array module /////////// - bool all(void) const; - bool any(void) const; - int count() const; - const VectorwiseOp rowwise() const; VectorwiseOp rowwise(); const VectorwiseOp colwise() const; VectorwiseOp colwise(); - static const CwiseNullaryOp,Derived> Random(int rows, int cols); - static const CwiseNullaryOp,Derived> Random(int size); - static const CwiseNullaryOp,Derived> Random(); - template const Select select(const MatrixBase& thenMatrix, @@ -625,6 +465,9 @@ template class MatrixBase const Eigen::Reverse reverse() const; void reverseInPlace(); + ArrayWrapper array() { return derived(); } + const ArrayWrapper array() const { return derived(); } + /////////// LU module /////////// const FullPivLU fullPivLu() const; @@ -727,9 +570,9 @@ template class MatrixBase inline Cwise cwise(); // a workaround waiting the Array class - inline const Cwise array() const { return cwise(); } +// inline const Cwise array() const { return cwise(); } // a workaround waiting the Array class - inline Cwise array() { return cwise(); } +// inline Cwise array() { return cwise(); } template typename ei_plain_matrix_type_column_major::type diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 68cff12d3..2cac09230 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -54,8 +54,8 @@ struct ei_nested, N, EvalType> }; #define EIGEN_PRODUCT_PUBLIC_INTERFACE(Derived) \ - typedef ProductBase ProductBaseType; \ - _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, ProductBaseType) \ + typedef ProductBase Base; \ + _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ typedef typename Base::LhsNested LhsNested; \ typedef typename Base::_LhsNested _LhsNested; \ typedef typename Base::LhsBlasTraits LhsBlasTraits; \ @@ -73,7 +73,8 @@ template class ProductBase : public MatrixBase { public: - _EIGEN_GENERIC_PUBLIC_INTERFACE(ProductBase,MatrixBase) + typedef MatrixBase Base; + _EIGEN_GENERIC_PUBLIC_INTERFACE(ProductBase) typedef typename Lhs::Nested LhsNested; typedef typename ei_cleantype::type _LhsNested; diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 9f796157a..b6b28c00b 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -309,12 +309,12 @@ struct ei_redux_impl * The template parameter \a BinaryOp is the type of the functor \a func which must be * an associative operator. Both current STL and TR1 functor styles are handled. * - * \sa MatrixBase::sum(), MatrixBase::minCoeff(), MatrixBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise() + * \sa DenseBase::sum(), DenseBase::minCoeff(), DenseBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise() */ template template inline typename ei_result_of::Scalar)>::type -MatrixBase::redux(const Func& func) const +DenseBase::redux(const Func& func) const { typename Derived::Nested nested(derived()); typedef typename ei_cleantype::type ThisNested; @@ -326,7 +326,7 @@ MatrixBase::redux(const Func& func) const */ template EIGEN_STRONG_INLINE typename ei_traits::Scalar -MatrixBase::minCoeff() const +DenseBase::minCoeff() const { return this->redux(Eigen::ei_scalar_min_op()); } @@ -335,7 +335,7 @@ MatrixBase::minCoeff() const */ template EIGEN_STRONG_INLINE typename ei_traits::Scalar -MatrixBase::maxCoeff() const +DenseBase::maxCoeff() const { return this->redux(Eigen::ei_scalar_max_op()); } @@ -346,7 +346,7 @@ MatrixBase::maxCoeff() const */ template EIGEN_STRONG_INLINE typename ei_traits::Scalar -MatrixBase::sum() const +DenseBase::sum() const { return this->redux(Eigen::ei_scalar_sum_op()); } @@ -357,7 +357,7 @@ MatrixBase::sum() const */ template EIGEN_STRONG_INLINE typename ei_traits::Scalar -MatrixBase::mean() const +DenseBase::mean() const { return this->redux(Eigen::ei_scalar_sum_op()) / this->size(); } @@ -371,7 +371,7 @@ MatrixBase::mean() const */ template EIGEN_STRONG_INLINE typename ei_traits::Scalar -MatrixBase::prod() const +DenseBase::prod() const { return this->redux(Eigen::ei_scalar_product_op()); } diff --git a/Eigen/src/Core/StableNorm.h b/Eigen/src/Core/StableNorm.h index c2dd6b847..2874f0fd8 100644 --- a/Eigen/src/Core/StableNorm.h +++ b/Eigen/src/Core/StableNorm.h @@ -67,10 +67,10 @@ MatrixBase::stableNorm() const { bi = ei_alignmentOffset(&const_cast_derived().coeffRef(0), n); if (bi>0) - ei_stable_norm_kernel(start(bi), ssq, scale, invScale); + ei_stable_norm_kernel(this->start(bi), ssq, scale, invScale); } for (; bi(), ssq, scale, invScale); + ei_stable_norm_kernel(this->segment(bi,std::min(blockSize, n - bi)).template forceAlignedAccessIf(), ssq, scale, invScale); return scale * ei_sqrt(ssq); } diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 71821008e..b202f62c4 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -90,7 +90,7 @@ template class Transpose template class TransposeImpl - : public MatrixBase > + : public MatrixType::template MakeBase >::Type { const typename ei_cleantype::type& matrix() const { return derived().nestedExpression(); } @@ -99,8 +99,9 @@ template class TransposeImpl public: - //EIGEN_DENSE_PUBLIC_INTERFACE(TransposeImpl,MatrixBase >) - EIGEN_DENSE_PUBLIC_INTERFACE(Transpose) + //EIGEN_DENSE_PUBLpename IC_INTERFACE(TransposeImpl,MatrixBase >) + typedef typename MatrixType::template MakeBase >::Type Base; + _EIGEN_DENSE_PUBLIC_INTERFACE(Transpose) // EIGEN_EXPRESSION_IMPL_COMMON(MatrixBase >) @@ -174,7 +175,7 @@ template class TransposeImpl * \sa transposeInPlace(), adjoint() */ template inline Transpose -MatrixBase::transpose() +DenseBase::transpose() { return derived(); } @@ -186,7 +187,7 @@ MatrixBase::transpose() * \sa transposeInPlace(), adjoint() */ template inline const Transpose -MatrixBase::transpose() const +DenseBase::transpose() const { return derived(); } @@ -214,7 +215,7 @@ template inline const typename MatrixBase::AdjointReturnType MatrixBase::adjoint() const { - return transpose().nestByValue(); + return this->transpose().nestByValue(); } /*************************************************************************** @@ -261,7 +262,7 @@ struct ei_inplace_transpose_selector { // non square matrix * * \sa transpose(), adjoint(), adjointInPlace() */ template -inline void MatrixBase::transposeInPlace() +inline void DenseBase::transposeInPlace() { ei_inplace_transpose_selector::run(derived()); } @@ -324,61 +325,61 @@ template typename T::Scalar* ei_extract_data(const T& m) template template -Derived& MatrixBase::lazyAssign(const Transpose& other) +Derived& DenseBase::lazyAssign(const Transpose& other) { ei_assert(ei_extract_data(other) != ei_extract_data(derived()) && "aliasing detected during tranposition, please use transposeInPlace()"); - return lazyAssign(static_cast >& >(other)); + return lazyAssign(static_cast >& >(other)); } template template -Derived& MatrixBase:: +Derived& DenseBase:: lazyAssign(const CwiseBinaryOp,Transpose,DerivedB>& other) { ei_assert(ei_extract_data(derived()) != ei_extract_data(other.lhs()) && "aliasing detected during tranposition, please evaluate your expression"); - return lazyAssign(static_cast,Transpose,DerivedB> >& >(other)); + return lazyAssign(static_cast,Transpose,DerivedB> >& >(other)); } template template -Derived& MatrixBase:: +Derived& DenseBase:: lazyAssign(const CwiseBinaryOp,DerivedA,Transpose >& other) { ei_assert(ei_extract_data(derived()) != ei_extract_data(other.rhs()) && "aliasing detected during tranposition, please evaluate your expression"); - return lazyAssign(static_cast,DerivedA,Transpose > >& >(other)); + return lazyAssign(static_cast,DerivedA,Transpose > >& >(other)); } template template Derived& -MatrixBase:: +DenseBase:: lazyAssign(const CwiseUnaryOp, NestByValue > >& other) { ei_assert(ei_extract_data(other) != ei_extract_data(derived()) && "aliasing detected during tranposition, please use adjointInPlace()"); - return lazyAssign(static_cast, NestByValue > > >& >(other)); + return lazyAssign(static_cast, NestByValue > > >& >(other)); } template template -Derived& MatrixBase:: +Derived& DenseBase:: lazyAssign(const CwiseBinaryOp,CwiseUnaryOp, NestByValue > >,DerivedB>& other) { ei_assert(ei_extract_data(derived()) != ei_extract_data(other.lhs()) && "aliasing detected during tranposition, please evaluate your expression"); - return lazyAssign(static_cast,CwiseUnaryOp, NestByValue > >,DerivedB> >& >(other)); + return lazyAssign(static_cast,CwiseUnaryOp, NestByValue > >,DerivedB> >& >(other)); } template template -Derived& MatrixBase:: +Derived& DenseBase:: lazyAssign(const CwiseBinaryOp,DerivedA,CwiseUnaryOp, NestByValue > > >& other) { ei_assert(ei_extract_data(derived()) != ei_extract_data(other.rhs()) && "aliasing detected during tranposition, please evaluate your expression"); - return lazyAssign(static_cast,DerivedA,CwiseUnaryOp, NestByValue > > > >& >(other)); + return lazyAssign(static_cast,DerivedA,CwiseUnaryOp, NestByValue > > > >& >(other)); } #endif diff --git a/Eigen/src/Core/VectorBlock.h b/Eigen/src/Core/VectorBlock.h index f3e4debf5..96af71b36 100644 --- a/Eigen/src/Core/VectorBlock.h +++ b/Eigen/src/Core/VectorBlock.h @@ -34,7 +34,7 @@ * \param Size size of the sub-vector we are taking at compile time (optional) * * This class represents an expression of either a fixed-size or dynamic-size sub-vector. - * It is the return type of MatrixBase::segment(int,int) and MatrixBase::segment(int) and + * It is the return type of DenseBase::segment(int,int) and DenseBase::segment(int) and * most of the time this is the only way it is used. * * However, if you want to directly maniputate sub-vector expressions, @@ -53,7 +53,7 @@ * \include class_FixedVectorBlock.cpp * Output: \verbinclude class_FixedVectorBlock.out * - * \sa class Block, MatrixBase::segment(int,int,int,int), MatrixBase::segment(int,int) + * \sa class Block, DenseBase::segment(int,int,int,int), DenseBase::segment(int,int) */ template struct ei_traits > @@ -70,12 +70,12 @@ template class VectorBlock { typedef Block::RowsAtCompileTime==1 ? 1 : Size, - ei_traits::ColsAtCompileTime==1 ? 1 : Size> _Base; + ei_traits::ColsAtCompileTime==1 ? 1 : Size> Base; enum { IsColVector = ei_traits::ColsAtCompileTime==1 }; public: - _EIGEN_GENERIC_PUBLIC_INTERFACE(VectorBlock, _Base) + _EIGEN_GENERIC_PUBLIC_INTERFACE(VectorBlock) using Base::operator=; using Base::operator+=; @@ -121,7 +121,7 @@ template class VectorBlock * \sa class Block, segment(int) */ template -inline VectorBlock MatrixBase +inline VectorBlock DenseBase ::segment(int start, int size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) @@ -131,7 +131,7 @@ inline VectorBlock MatrixBase /** This is the const version of segment(int,int).*/ template inline const VectorBlock -MatrixBase::segment(int start, int size) const +DenseBase::segment(int start, int size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), start, size); @@ -154,7 +154,7 @@ MatrixBase::segment(int start, int size) const */ template inline VectorBlock -MatrixBase::start(int size) +DenseBase::start(int size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), 0, size); @@ -163,7 +163,7 @@ MatrixBase::start(int size) /** This is the const version of start(int).*/ template inline const VectorBlock -MatrixBase::start(int size) const +DenseBase::start(int size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), 0, size); @@ -186,7 +186,7 @@ MatrixBase::start(int size) const */ template inline VectorBlock -MatrixBase::end(int size) +DenseBase::end(int size) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), this->size() - size, size); @@ -195,7 +195,7 @@ MatrixBase::end(int size) /** This is the const version of end(int).*/ template inline const VectorBlock -MatrixBase::end(int size) const +DenseBase::end(int size) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), this->size() - size, size); @@ -217,7 +217,7 @@ MatrixBase::end(int size) const template template inline VectorBlock -MatrixBase::segment(int start) +DenseBase::segment(int start) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), start); @@ -227,7 +227,7 @@ MatrixBase::segment(int start) template template inline const VectorBlock -MatrixBase::segment(int start) const +DenseBase::segment(int start) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), start); @@ -247,7 +247,7 @@ MatrixBase::segment(int start) const template template inline VectorBlock -MatrixBase::start() +DenseBase::start() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), 0); @@ -257,7 +257,7 @@ MatrixBase::start() template template inline const VectorBlock -MatrixBase::start() const +DenseBase::start() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), 0); @@ -277,7 +277,7 @@ MatrixBase::start() const template template inline VectorBlock -MatrixBase::end() +DenseBase::end() { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), size() - Size); @@ -287,7 +287,7 @@ MatrixBase::end() template template inline const VectorBlock -MatrixBase::end() const +DenseBase::end() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return VectorBlock(derived(), size() - Size); diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 590efc766..e6f02b79b 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -79,11 +79,11 @@ struct ei_visitor_impl * \note compared to one or two \em for \em loops, visitors offer automatic * unrolling for small fixed size matrix. * - * \sa minCoeff(int*,int*), maxCoeff(int*,int*), MatrixBase::redux() + * \sa minCoeff(int*,int*), maxCoeff(int*,int*), DenseBase::redux() */ template template -void MatrixBase::visit(Visitor& visitor) const +void DenseBase::visit(Visitor& visitor) const { const bool unroll = SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * ei_functor_traits::Cost @@ -112,7 +112,7 @@ struct ei_coeff_visitor /** \internal * \brief Visitor computing the min coefficient with its value and coordinates * - * \sa MatrixBase::minCoeff(int*, int*) + * \sa DenseBase::minCoeff(int*, int*) */ template struct ei_min_coeff_visitor : ei_coeff_visitor @@ -138,7 +138,7 @@ struct ei_functor_traits > { /** \internal * \brief Visitor computing the max coefficient with its value and coordinates * - * \sa MatrixBase::maxCoeff(int*, int*) + * \sa DenseBase::maxCoeff(int*, int*) */ template struct ei_max_coeff_visitor : ei_coeff_visitor @@ -164,11 +164,11 @@ struct ei_functor_traits > { /** \returns the minimum of all coefficients of *this * and puts in *row and *col its location. * - * \sa MatrixBase::minCoeff(int*), MatrixBase::maxCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::minCoeff() + * \sa DenseBase::minCoeff(int*), DenseBase::maxCoeff(int*,int*), DenseBase::visitor(), DenseBase::minCoeff() */ template typename ei_traits::Scalar -MatrixBase::minCoeff(int* row, int* col) const +DenseBase::minCoeff(int* row, int* col) const { ei_min_coeff_visitor minVisitor; this->visit(minVisitor); @@ -180,11 +180,11 @@ MatrixBase::minCoeff(int* row, int* col) const /** \returns the minimum of all coefficients of *this * and puts in *index its location. * - * \sa MatrixBase::minCoeff(int*,int*), MatrixBase::maxCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::minCoeff() + * \sa DenseBase::minCoeff(int*,int*), DenseBase::maxCoeff(int*,int*), DenseBase::visitor(), DenseBase::minCoeff() */ template typename ei_traits::Scalar -MatrixBase::minCoeff(int* index) const +DenseBase::minCoeff(int* index) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) ei_min_coeff_visitor minVisitor; @@ -196,11 +196,11 @@ MatrixBase::minCoeff(int* index) const /** \returns the maximum of all coefficients of *this * and puts in *row and *col its location. * - * \sa MatrixBase::minCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::maxCoeff() + * \sa DenseBase::minCoeff(int*,int*), DenseBase::visitor(), DenseBase::maxCoeff() */ template typename ei_traits::Scalar -MatrixBase::maxCoeff(int* row, int* col) const +DenseBase::maxCoeff(int* row, int* col) const { ei_max_coeff_visitor maxVisitor; this->visit(maxVisitor); @@ -212,11 +212,11 @@ MatrixBase::maxCoeff(int* row, int* col) const /** \returns the maximum of all coefficients of *this * and puts in *index its location. * - * \sa MatrixBase::maxCoeff(int*,int*), MatrixBase::minCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::maxCoeff() + * \sa DenseBase::maxCoeff(int*,int*), DenseBase::minCoeff(int*,int*), DenseBase::visitor(), DenseBase::maxCoeff() */ template typename ei_traits::Scalar -MatrixBase::maxCoeff(int* index) const +DenseBase::maxCoeff(int* index) const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) ei_max_coeff_visitor maxVisitor; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 76ac0eb3e..bcd79468c 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -65,6 +65,7 @@ template class SelfAdjointView; template class WithFormat; template struct CommaInitializer; template class ReturnByValue; +template class ArrayWrapper; template struct ei_solve_retval_base; template struct ei_solve_retval; diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 6758d5766..d68538f1a 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -281,8 +281,7 @@ using Eigen::ei_cos; using Base::operator /=; \ EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) -#define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ - typedef BaseClass Base; \ +#define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ typedef typename Eigen::ei_traits::Scalar Scalar; \ typedef typename Eigen::NumTraits::Real RealScalar; \ typedef typename Base::PacketScalar PacketScalar; \ @@ -299,7 +298,8 @@ using Eigen::ei_cos; IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ - _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) + typedef Eigen::MatrixBase Base; \ + _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) #define EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Derived) \ typedef typename Eigen::ei_traits::Scalar Scalar; \ @@ -315,8 +315,7 @@ using Eigen::ei_cos; IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; -#define _EIGEN_DENSE_PUBLIC_INTERFACE(Derived, BaseClass) \ - typedef BaseClass Base; \ +#define _EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \ typedef typename Eigen::ei_traits::Scalar Scalar; \ typedef typename Eigen::NumTraits::Real RealScalar; \ typedef typename Base::PacketScalar PacketScalar; \ @@ -334,7 +333,8 @@ using Eigen::ei_cos; using Base::derived; #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \ - _EIGEN_DENSE_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) + typedef Eigen::MatrixBase Base; \ + _EIGEN_DENSE_PUBLIC_INTERFACE(Derived) #define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) @@ -344,4 +344,13 @@ using Eigen::ei_cos; #define EIGEN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b) #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b))) + +#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \ + template \ + inline const CwiseBinaryOp, Derived, OtherDerived> \ + METHOD(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const \ + { \ + return CwiseBinaryOp, Derived, OtherDerived>(derived(), other.derived()); \ + } + #endif // EIGEN_MACROS_H diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 4e2c24f30..5e37194f3 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -133,6 +133,7 @@ struct ei_eval, */ template struct ei_plain_matrix_type { +// typedef typename T::PlainMatrixType type; typedef Matrix::Scalar, ei_traits::RowsAtCompileTime, ei_traits::ColsAtCompileTime, diff --git a/Eigen/src/Geometry/AlignedBox.h b/Eigen/src/Geometry/AlignedBox.h index 003ceaad1..707cfeb4f 100644 --- a/Eigen/src/Geometry/AlignedBox.h +++ b/Eigen/src/Geometry/AlignedBox.h @@ -67,7 +67,7 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) inline int dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size()-1 : AmbientDimAtCompileTime; } /** \returns true if the box is null, i.e, empty. */ - inline bool isNull() const { return (m_min.array() > m_max).any(); } + inline bool isNull() const { return (m_min.array() > m_max.array()).any(); } /** Makes \c *this a null/empty box. */ inline void setNull() @@ -90,11 +90,11 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) /** \returns true if the point \a p is inside the box \c *this. */ inline bool contains(const VectorType& p) const - { return (m_min.array()<=p).all() && (p.array()<=m_max).all(); } + { return (m_min.array()<=p.array()).all() && (p.array()<=m_max.array()).all(); } /** \returns true if the box \a b is entirely inside the box \c *this. */ inline bool contains(const AlignedBox& b) const - { return (m_min.array()<=b.min()).all() && (b.max().array()<=m_max).all(); } + { return (m_min.array()<=b.min().array()).all() && (b.max().array()<=m_max.array()).all(); } /** Extends \c *this such that it contains the point \a p and returns a reference to \c *this. */ inline AlignedBox& extend(const VectorType& p) diff --git a/Eigen/src/Householder/Householder.h b/Eigen/src/Householder/Householder.h index a54be8c01..1e549633a 100644 --- a/Eigen/src/Householder/Householder.h +++ b/Eigen/src/Householder/Householder.h @@ -102,8 +102,8 @@ void MatrixBase::applyHouseholderOnTheLeft( Map > tmp(workspace,cols()); Block bottom(derived(), 1, 0, rows()-1, cols()); tmp.noalias() = essential.adjoint() * bottom; - tmp += row(0); - row(0) -= tau * tmp; + tmp += this->row(0); + this->row(0) -= tau * tmp; bottom.noalias() -= tau * essential * tmp; } @@ -117,8 +117,8 @@ void MatrixBase::applyHouseholderOnTheRight( Map > tmp(workspace,rows()); Block right(derived(), 0, 1, rows(), cols()-1); tmp.noalias() = right * essential.conjugate(); - tmp += col(0); - col(0) -= tau * tmp; + tmp += this->col(0); + this->col(0) -= tau * tmp; right.noalias() -= tau * tmp * essential.transpose(); } diff --git a/Eigen/src/Jacobi/Jacobi.h b/Eigen/src/Jacobi/Jacobi.h index eeb81c178..727c97583 100644 --- a/Eigen/src/Jacobi/Jacobi.h +++ b/Eigen/src/Jacobi/Jacobi.h @@ -279,8 +279,8 @@ template template inline void MatrixBase::applyOnTheLeft(int p, int q, const PlanarRotation& j) { - RowXpr x(row(p)); - RowXpr y(row(q)); + RowXpr x(this->row(p)); + RowXpr y(this->row(q)); ei_apply_rotation_in_the_plane(x, y, j); } @@ -294,8 +294,8 @@ template template inline void MatrixBase::applyOnTheRight(int p, int q, const PlanarRotation& j) { - ColXpr x(col(p)); - ColXpr y(col(q)); + ColXpr x(this->col(p)); + ColXpr y(this->col(q)); ei_apply_rotation_in_the_plane(x, y, j.transpose()); } diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index d3c6b4c7c..02864caa5 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -252,7 +252,7 @@ typename MatrixType::RealScalar ColPivHouseholderQR::logAbsDetermina { ei_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); ei_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwise().abs().cwise().log().sum(); + return m_qr.diagonal().cwiseAbs().array().log().sum(); } template @@ -311,7 +311,7 @@ ColPivHouseholderQR& ColPivHouseholderQR::compute(const m_qr.corner(BottomRight, rows-k, cols-k-1) .applyHouseholderOnTheLeft(m_qr.col(k).end(rows-k-1), m_hCoeffs.coeffRef(k), &temp.coeffRef(k+1)); - colSqNorms.end(cols-k-1) -= m_qr.row(k).end(cols-k-1).cwise().abs2(); + colSqNorms.end(cols-k-1) -= m_qr.row(k).end(cols-k-1).cwiseAbs2(); } for(int k = 0; k < matrix.cols(); ++k) m_cols_permutation.coeffRef(k) = k; @@ -355,8 +355,8 @@ struct ei_solve_retval, Rhs> if(!dec().isSurjective()) { // is c is in the image of R ? - RealScalar biggest_in_upper_part_of_c = c.corner(TopLeft, dec().rank(), c.cols()).cwise().abs().maxCoeff(); - RealScalar biggest_in_lower_part_of_c = c.corner(BottomLeft, rows-dec().rank(), c.cols()).cwise().abs().maxCoeff(); + RealScalar biggest_in_upper_part_of_c = c.corner(TopLeft, dec().rank(), c.cols()).cwiseAbs().maxCoeff(); + RealScalar biggest_in_lower_part_of_c = c.corner(BottomLeft, rows-dec().rank(), c.cols()).cwiseAbs().maxCoeff(); // FIXME brain dead const RealScalar m_precision = epsilon() * std::min(rows,cols); if(!ei_isMuchSmallerThan(biggest_in_lower_part_of_c, biggest_in_upper_part_of_c, m_precision*4)) diff --git a/Eigen/src/QR/FullPivHouseholderQR.h b/Eigen/src/QR/FullPivHouseholderQR.h index 07df5ed6b..a1eaabf23 100644 --- a/Eigen/src/QR/FullPivHouseholderQR.h +++ b/Eigen/src/QR/FullPivHouseholderQR.h @@ -253,7 +253,7 @@ typename MatrixType::RealScalar FullPivHouseholderQR::logAbsDetermin { ei_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); ei_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwise().abs().cwise().log().sum(); + return m_qr.diagonal().cwiseAbs().array().log().sum(); } template @@ -284,7 +284,7 @@ FullPivHouseholderQR& FullPivHouseholderQR::compute(cons RealScalar biggest_in_corner; biggest_in_corner = m_qr.corner(Eigen::BottomRight, rows-k, cols-k) - .cwise().abs() + .cwiseAbs() .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner); row_of_biggest_in_corner += k; col_of_biggest_in_corner += k; @@ -367,8 +367,8 @@ struct ei_solve_retval, Rhs> if(!dec().isSurjective()) { // is c is in the image of R ? - RealScalar biggest_in_upper_part_of_c = c.corner(TopLeft, dec().rank(), c.cols()).cwise().abs().maxCoeff(); - RealScalar biggest_in_lower_part_of_c = c.corner(BottomLeft, rows-dec().rank(), c.cols()).cwise().abs().maxCoeff(); + RealScalar biggest_in_upper_part_of_c = c.corner(TopLeft, dec().rank(), c.cols()).cwiseAbs().maxCoeff(); + RealScalar biggest_in_lower_part_of_c = c.corner(BottomLeft, rows-dec().rank(), c.cols()).cwiseAbs().maxCoeff(); // FIXME brain dead const RealScalar m_precision = epsilon() * std::min(rows,cols); if(!ei_isMuchSmallerThan(biggest_in_lower_part_of_c, biggest_in_upper_part_of_c, m_precision)) diff --git a/Eigen/src/QR/HouseholderQR.h b/Eigen/src/QR/HouseholderQR.h index 8d842d129..9d8a33610 100644 --- a/Eigen/src/QR/HouseholderQR.h +++ b/Eigen/src/QR/HouseholderQR.h @@ -177,7 +177,7 @@ typename MatrixType::RealScalar HouseholderQR::logAbsDeterminant() c { ei_assert(m_isInitialized && "HouseholderQR is not initialized."); ei_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!"); - return m_qr.diagonal().cwise().abs().cwise().log().sum(); + return m_qr.diagonal().cwiseAbs().array().log().sum(); } template diff --git a/Eigen/src/SVD/SVD.h b/Eigen/src/SVD/SVD.h index 254885873..6ed9db20a 100644 --- a/Eigen/src/SVD/SVD.h +++ b/Eigen/src/SVD/SVD.h @@ -190,7 +190,8 @@ SVD& SVD::compute(const MatrixType& matrix) SingularValuesType& W = m_sigma; bool flag; - int i,its,j,k,l,nm; + int i,its,j,k,nm; + int l=0; Scalar anorm, c, f, g, h, s, scale, x, y, z; bool convergence = true; Scalar eps = precision(); @@ -205,7 +206,7 @@ SVD& SVD::compute(const MatrixType& matrix) g = s = scale = 0.0; if (i < m) { - scale = A.col(i).end(m-i).cwise().abs().sum(); + scale = A.col(i).end(m-i).cwiseAbs().sum(); if (scale != Scalar(0)) { for (k=i; k& SVD::compute(const MatrixType& matrix) g = s = scale = 0.0; if (i+1 <= m && i+1 != n) { - scale = A.row(i).end(n-l+1).cwise().abs().sum(); + scale = A.row(i).end(n-l+1).cwiseAbs().sum(); if (scale != Scalar(0)) { for (k=l-1; k(), operator<=() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less) + +/** \returns an expression of the coefficient-wise \<= operator of *this and \a other + * + * Example: \include Cwise_less_equal.cpp + * Output: \verbinclude Cwise_less_equal.out + * + * \sa all(), any(), operator>=(), operator<() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal) +// template +// template +// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal) +// operator<=(const MatrixBase &other) const +// { +// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived()); +// } + +/** \returns an expression of the coefficient-wise \> operator of *this and \a other + * + * Example: \include Cwise_greater.cpp + * Output: \verbinclude Cwise_greater.out + * + * \sa all(), any(), operator>=(), operator<() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater) +// template +// template +// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater) +// operator>(const MatrixBase &other) const +// { +// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived()); +// } + +/** \returns an expression of the coefficient-wise \>= operator of *this and \a other + * + * Example: \include Cwise_greater_equal.cpp + * Output: \verbinclude Cwise_greater_equal.out + * + * \sa all(), any(), operator>(), operator<=() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal) +// template +// template +// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal) +// operator>=(const MatrixBase &other) const +// { +// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived()); +// } + +/** \returns an expression of the coefficient-wise == operator of *this and \a other + * + * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. + * In order to check for equality between two vectors or matrices with floating-point coefficients, it is + * generally a far better idea to use a fuzzy comparison as provided by isApprox() and + * isMuchSmallerThan(). + * + * Example: \include Cwise_equal_equal.cpp + * Output: \verbinclude Cwise_equal_equal.out + * + * \sa all(), any(), isApprox(), isMuchSmallerThan() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to) +// template +// template +// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to) +// operator==(const MatrixBase &other) const +// { +// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived()); +// } + +/** \returns an expression of the coefficient-wise != operator of *this and \a other + * + * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. + * In order to check for equality between two vectors or matrices with floating-point coefficients, it is + * generally a far better idea to use a fuzzy comparison as provided by isApprox() and + * isMuchSmallerThan(). + * + * Example: \include Cwise_not_equal.cpp + * Output: \verbinclude Cwise_not_equal.out + * + * \sa all(), any(), isApprox(), isMuchSmallerThan() + */ +EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to) +// template +// template +// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to) +// operator!=(const MatrixBase &other) const +// { +// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived()); +// } + +// comparisons to scalar value + +#if 0 + +/** \returns an expression of the coefficient-wise \< operator of *this and a scalar \a s + * + * \sa operator<(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less) +operator<(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \returns an expression of the coefficient-wise \<= operator of *this and a scalar \a s + * + * \sa operator<=(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal) +operator<=(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \returns an expression of the coefficient-wise \> operator of *this and a scalar \a s + * + * \sa operator>(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater) +operator>(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \returns an expression of the coefficient-wise \>= operator of *this and a scalar \a s + * + * \sa operator>=(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal) +operator>=(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \returns an expression of the coefficient-wise == operator of *this and a scalar \a s + * + * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. + * In order to check for equality between two vectors or matrices with floating-point coefficients, it is + * generally a far better idea to use a fuzzy comparison as provided by isApprox() and + * isMuchSmallerThan(). + * + * \sa operator==(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to) +operator==(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \returns an expression of the coefficient-wise != operator of *this and a scalar \a s + * + * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. + * In order to check for equality between two vectors or matrices with floating-point coefficients, it is + * generally a far better idea to use a fuzzy comparison as provided by isApprox() and + * isMuchSmallerThan(). + * + * \sa operator!=(const MatrixBase &) const + */ +template +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to) +operator!=(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +#endif + +// scalar addition + +/** \returns an expression of \c *this with each coeff incremented by the constant \a scalar + * + * Example: \include Cwise_plus.cpp + * Output: \verbinclude Cwise_plus.out + * + * \sa operator+=(), operator-() + */ +inline const CwiseUnaryOp, Derived> +operator+(const Scalar& scalar) const +{ + return CwiseUnaryOp, Derived>(derived(), ei_scalar_add_op(scalar)); +} + +/** Adds the given \a scalar to each coeff of this expression. + * + * Example: \include Cwise_plus_equal.cpp + * Output: \verbinclude Cwise_plus_equal.out + * + * \sa operator+(), operator-=() + */ +// template +// inline ExpressionType& operator+=(const Scalar& scalar) +// { +// return m_matrix.const_cast_derived() = *this + scalar; +// } + +/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar + * + * Example: \include Cwise_minus.cpp + * Output: \verbinclude Cwise_minus.out + * + * \sa operator+(), operator-=() + */ +// template +// inline const typename ScalarAddReturnType +// operator-(const Scalar& scalar) const +// { +// return *this + (-scalar); +// } + +/** Substracts the given \a scalar from each coeff of this expression. + * + * Example: \include Cwise_minus_equal.cpp + * Output: \verbinclude Cwise_minus_equal.out + * + * \sa operator+=(), operator-() + */ + +// template +// inline ExpressionType& operator-=(const Scalar& scalar) +// { +// return m_matrix.const_cast_derived() = *this - scalar; +// } diff --git a/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/Eigen/src/plugins/ArrayCwiseUnaryOps.h new file mode 100644 index 000000000..63bd43871 --- /dev/null +++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h @@ -0,0 +1,148 @@ + + +/** \returns an expression of the coefficient-wise absolute value of \c *this + * + * Example: \include Cwise_abs.cpp + * Output: \verbinclude Cwise_abs.out + * + * \sa abs2() + */ +EIGEN_STRONG_INLINE const CwiseUnaryOp, Derived> +abs() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise squared absolute value of \c *this + * + * Example: \include Cwise_abs2.cpp + * Output: \verbinclude Cwise_abs2.out + * + * \sa abs(), square() + */ +EIGEN_STRONG_INLINE const CwiseUnaryOp, Derived> +abs2() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise exponential of *this. + * + * Example: \include Cwise_exp.cpp + * Output: \verbinclude Cwise_exp.out + * + * \sa pow(), log(), sin(), cos() + */ +inline const CwiseUnaryOp, Derived> +exp() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise logarithm of *this. + * + * Example: \include Cwise_log.cpp + * Output: \verbinclude Cwise_log.out + * + * \sa exp() + */ +inline const CwiseUnaryOp, Derived> +log() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise square root of *this. + * + * Example: \include Cwise_sqrt.cpp + * Output: \verbinclude Cwise_sqrt.out + * + * \sa pow(), square() + */ +inline const CwiseUnaryOp, Derived> +sqrt() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise cosine of *this. + * + * Example: \include Cwise_cos.cpp + * Output: \verbinclude Cwise_cos.out + * + * \sa sin(), exp() + */ +inline const CwiseUnaryOp, Derived> +cos() const +{ + return derived(); +} + + +/** \returns an expression of the coefficient-wise sine of *this. + * + * Example: \include Cwise_sin.cpp + * Output: \verbinclude Cwise_sin.out + * + * \sa cos(), exp() + */ +inline const CwiseUnaryOp, Derived> +sin() const +{ + return derived(); +} + + +/** \returns an expression of the coefficient-wise power of *this to the given exponent. + * + * Example: \include Cwise_pow.cpp + * Output: \verbinclude Cwise_pow.out + * + * \sa exp(), log() + */ +inline const CwiseUnaryOp, Derived> +pow(const Scalar& exponent) const +{ + return CwiseUnaryOp,Derived> + (derived(), ei_scalar_pow_op(exponent)); +} + + +/** \returns an expression of the coefficient-wise inverse of *this. + * + * Example: \include Cwise_inverse.cpp + * Output: \verbinclude Cwise_inverse.out + * + * \sa operator/(), operator*() + */ +inline const CwiseUnaryOp, Derived> +inverse() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise square of *this. + * + * Example: \include Cwise_square.cpp + * Output: \verbinclude Cwise_square.out + * + * \sa operator/(), operator*(), abs2() + */ +inline const CwiseUnaryOp, Derived> +square() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise cube of *this. + * + * Example: \include Cwise_cube.cpp + * Output: \verbinclude Cwise_cube.out + * + * \sa square(), pow() + */ +inline const CwiseUnaryOp, Derived> +cube() const +{ + return derived(); +} diff --git a/Eigen/src/plugins/CommonCwiseBinaryOps.h b/Eigen/src/plugins/CommonCwiseBinaryOps.h index 42e308868..762cb3b8c 100644 --- a/Eigen/src/plugins/CommonCwiseBinaryOps.h +++ b/Eigen/src/plugins/CommonCwiseBinaryOps.h @@ -31,14 +31,7 @@ * * \sa class CwiseBinaryOp, MatrixBase::operator-=() */ -template -EIGEN_STRONG_INLINE const CwiseBinaryOp::Scalar>, - Derived, OtherDerived> -operator-(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const -{ - return CwiseBinaryOp, - Derived, OtherDerived>(derived(), other.derived()); -} +EIGEN_MAKE_CWISE_BINARY_OP(operator-,ei_scalar_difference_op) /** \returns an expression of the sum of \c *this and \a other * @@ -46,12 +39,7 @@ operator-(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const * * \sa class CwiseBinaryOp, MatrixBase::operator+=() */ -template -EIGEN_STRONG_INLINE const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -operator+(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const -{ - return CwiseBinaryOp, Derived, OtherDerived>(derived(), other.derived()); -} +EIGEN_MAKE_CWISE_BINARY_OP(operator+,ei_scalar_sum_op) /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other * -- cgit v1.2.3