diff options
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/Core | 15 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Cast.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/Conjugate.h | 95 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOp.h | 48 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOp.h | 171 | ||||
-rw-r--r-- | Eigen/src/Core/ForwardDeclarations.h | 11 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 118 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixStorage.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Opposite.h | 81 | ||||
-rw-r--r-- | Eigen/src/Core/Transpose.h | 13 | ||||
-rw-r--r-- | Eigen/src/Core/Util.h | 6 |
12 files changed, 325 insertions, 244 deletions
diff --git a/Eigen/Core b/Eigen/Core index 3ced3e88a..e4dcfc96e 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -4,6 +4,14 @@ #include <cassert> #include <iostream> +#if ((defined __GNUC__) && ( (__GNUC__==3) || (__GNUC__==4) && __GNUC_MINOR__==0)) +/* This very ugly hack to fix a bug of gcc <4.1 with the Curiously recurring template pattern and friend class. + Note that gcc-4.0.1 is still the default compiler on MACOSX Leopard. +*/ +#define private public +#warning "Your compiler (gcc<4.1) has issue with friend and CRT, all private members of Eigen's classes are made public" +#endif + namespace Eigen { #include "src/Core/Util.h" @@ -19,7 +27,7 @@ namespace Eigen { #include "src/Core/Cast.h" #include "src/Core/Eval.h" #include "src/Core/CwiseBinaryOp.h" -#include "src/Core/Opposite.h" +#include "src/Core/CwiseUnaryOp.h" #include "src/Core/ScalarMultiple.h" #include "src/Core/Product.h" #include "src/Core/Row.h" @@ -27,7 +35,6 @@ namespace Eigen { #include "src/Core/Block.h" #include "src/Core/Minor.h" #include "src/Core/Transpose.h" -#include "src/Core/Conjugate.h" #include "src/Core/Trace.h" #include "src/Core/Dot.h" #include "src/Core/Random.h" @@ -42,3 +49,7 @@ namespace Eigen { #include "src/Core/Swap.h" } // namespace Eigen + +#if ((defined __GNUC__) && (__GNUC_MINOR__==0)) +#undef private +#endif diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 9ed69d03f..74e1cd1c5 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com> +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> // Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> // // Eigen is free software; you can redistribute it and/or @@ -328,6 +328,9 @@ const Block<Derived> MatrixBase<Scalar, Derived> * Example: \include MatrixBase_block_int_int.cpp * Output: \verbinclude MatrixBase_block_int_int.out * + * \note since block is a templated member, the keyword template as to be used + * if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode + * * \sa class Block, block(int,int,int,int) */ template<typename Scalar, typename Derived> diff --git a/Eigen/src/Core/Cast.h b/Eigen/src/Core/Cast.h index cf1466476..42c0a7f0f 100644 --- a/Eigen/src/Core/Cast.h +++ b/Eigen/src/Core/Cast.h @@ -67,9 +67,9 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _coeff(int row, int col) const + NewScalar _coeff(int row, int col) const { - return static_cast<Scalar>(m_matrix.coeff(row, col)); + return static_cast<NewScalar>(m_matrix.coeff(row, col)); } protected: diff --git a/Eigen/src/Core/Conjugate.h b/Eigen/src/Core/Conjugate.h deleted file mode 100644 index a95caf75b..000000000 --- a/Eigen/src/Core/Conjugate.h +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see <http://www.gnu.org/licenses/>. - -#ifndef EIGEN_CONJUGATE_H -#define EIGEN_CONJUGATE_H - -/** \class Conjugate - * - * \brief Expression of the complex conjugate of a matrix - * - * \param MatrixType the type of the object of which we are taking the complex conjugate - * - * This class represents an expression of the complex conjugate of a matrix. - * It is the return type of MatrixBase::conjugate() and is also used by - * MatrixBase::adjoint() and most of the time these are the only ways it is used. - * - * \sa MatrixBase::conjugate(), MatrixBase::adjoint() - */ -template<typename MatrixType> class Conjugate : NoOperatorEquals, - public MatrixBase<typename MatrixType::Scalar, Conjugate<MatrixType> > -{ - public: - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::Ref MatRef; - friend class MatrixBase<Scalar, Conjugate>; - typedef MatrixBase<Scalar, Conjugate> Base; - - Conjugate(const MatRef& matrix) : m_matrix(matrix) {} - - private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; - - const Conjugate& _ref() const { return *this; } - int _rows() const { return m_matrix.rows(); } - int _cols() const { return m_matrix.cols(); } - - Scalar _coeff(int row, int col) const - { - return ei_conj(m_matrix.coeff(row, col)); - } - - protected: - const MatRef m_matrix; -}; - -/** \returns an expression of the complex conjugate of *this. - * - * \sa adjoint(), class Conjugate */ -template<typename Scalar, typename Derived> -const Conjugate<Derived> -MatrixBase<Scalar, Derived>::conjugate() const -{ - return Conjugate<Derived>(ref()); -} - -/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this. - * - * Example: \include MatrixBase_adjoint.cpp - * Output: \verbinclude MatrixBase_adjoint.out - * - * \sa transpose(), conjugate(), class Transpose, class Conjugate */ -template<typename Scalar, typename Derived> -const Transpose<Conjugate<Derived> > -MatrixBase<Scalar, Derived>::adjoint() const -{ - return conjugate().transpose(); -} - -#endif // EIGEN_CONJUGATE_H diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 8a344b540..348f1f393 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com> +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> // Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> // // Eigen is free software; you can redistribute it and/or @@ -35,12 +35,18 @@ * \param Rhs the type of the right-hand side * * This class represents an expression of a generic binary operator of two matrices or vectors. - * It is the return type of the operator+, operator-, cwiseiseProduct, cwiseQuotient between matrices or vectors, and most + * It is the return type of the operator+, operator-, cwiseProduct, cwiseQuotient between matrices or vectors, and most * of the time this is the only way it is used. * + * However, if you want to write a function returning such an expression, you + * will need to use this class. + * + * Here is an example illustrating this: + * \include class_CwiseBinaryOp.cpp + * * \sa class CwiseProductOp, class CwiseQuotientOp */ -template<template<typename BinaryOpScalar> class BinaryOp, typename Lhs, typename Rhs> +template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp : NoOperatorEquals, public MatrixBase<typename Lhs::Scalar, CwiseBinaryOp<BinaryOp, Lhs, Rhs> > { @@ -71,7 +77,7 @@ class CwiseBinaryOp : NoOperatorEquals, Scalar _coeff(int row, int col) const { - return BinaryOp<Scalar>::op(m_lhs.coeff(row, col), m_rhs.coeff(row, col)); + return BinaryOp::template op<Scalar>(m_lhs.coeff(row, col), m_rhs.coeff(row, col)); } protected: @@ -83,32 +89,32 @@ class CwiseBinaryOp : NoOperatorEquals, * * \sa class CwiseBinaryOp, MatrixBase::operator+ */ -template<typename Scalar> struct CwiseSumOp { - static Scalar op(const Scalar& a, const Scalar& b) { return a + b; } +struct CwiseSumOp { + template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a + b; } }; /** \brief Template functor to compute the difference of two scalars * * \sa class CwiseBinaryOp, MatrixBase::operator- */ -template<typename Scalar> struct CwiseDifferenceOp { - static Scalar op(const Scalar& a, const Scalar& b) { return a - b; } +struct CwiseDifferenceOp { + template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a - b; } }; /** \brief Template functor to compute the product of two scalars * * \sa class CwiseBinaryOp, MatrixBase::cwiseProduct() */ -template<typename Scalar> struct CwiseProductOp { - static Scalar op(const Scalar& a, const Scalar& b) { return a * b; } +struct CwiseProductOp { + template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a * b; } }; /** \brief Template functor to compute the quotient of two scalars * * \sa class CwiseBinaryOp, MatrixBase::cwiseQuotient() */ -template<typename Scalar> struct CwiseQuotientOp { - static Scalar op(const Scalar& a, const Scalar& b) { return a / b; } +struct CwiseQuotientOp { + template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a / b; } }; /** \relates MatrixBase @@ -193,11 +199,12 @@ MatrixBase<Scalar, Derived>::cwiseQuotient(const MatrixBase<Scalar, OtherDerived * * \returns an expression of a custom coefficient-wise operator of \a mat1 and \a mat2 * - * \param CustomBinaryOp template functor of the custom operator + * The template parameter \a CustomBinaryOp is the template functor + * of the custom operator (see class CwiseBinaryOp for an example) * * \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct, MatrixBase::cwiseQuotient */ -template<template<typename BinaryOpScalar> class CustomBinaryOp, typename Scalar, typename Derived1, typename Derived2> +template<typename CustomBinaryOp, typename Scalar, typename Derived1, typename Derived2> const CwiseBinaryOp<CustomBinaryOp, Derived1, Derived2> cwise(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2) { @@ -206,12 +213,21 @@ cwise(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived /** \returns an expression of a custom coefficient-wise operator of *this and \a other * - * \param CustomBinaryOp template functor of the custom operator + * The template parameter \a CustomBinaryOp is the template functor + * of the custom operator (see class CwiseBinaryOp for an example) + * + * \note since cwise is a templated member with a mandatory template parameter, + * the keyword template as to be used if the matrix type is also a template parameter: + * \code + * template <typename MatrixType> void foo(const MatrixType& m1, const MatrixType& m2) { + * m1.template cwise<CwiseProductOp>(m2); + * } + * \endcode * * \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct, MatrixBase::cwiseQuotient */ template<typename Scalar, typename Derived> -template<template<typename BinaryOpScalar> class CustomBinaryOp, typename OtherDerived> +template<typename CustomBinaryOp, typename OtherDerived> const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> MatrixBase<Scalar, Derived>::cwise(const MatrixBase<Scalar, OtherDerived> &other) const { diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h new file mode 100644 index 000000000..27e8c288f --- /dev/null +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -0,0 +1,171 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_CWISE_UNARY_OP_H +#define EIGEN_CWISE_UNARY_OP_H + +/** \class CwiseUnaryOp + * + * \brief Generic expression of a coefficient-wise unary operator of a matrix or a vector + * + * \param UnaryOp template functor implementing the operator + * \param MatrixType the type of the matrix we are applying the unary operator + * + * This class represents an expression of a generic unary operator of a matrix or a vector. + * It is the return type of the unary operator-, of a matrix or a vector, and most + * of the time this is the only way it is used. + * + * \sa class CwiseBinaryOp + */ +template<typename UnaryOp, typename MatrixType> +class CwiseUnaryOp : NoOperatorEquals, + public MatrixBase<typename MatrixType::Scalar, CwiseUnaryOp<UnaryOp, MatrixType> > +{ + public: + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Ref MatRef; + friend class MatrixBase<Scalar, CwiseUnaryOp>; + typedef MatrixBase<Scalar, CwiseUnaryOp> Base; + + CwiseUnaryOp(const MatRef& mat) : m_matrix(mat) {} + + private: + enum { + RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime + }; + + const CwiseUnaryOp& _ref() const { return *this; } + int _rows() const { return m_matrix.rows(); } + int _cols() const { return m_matrix.cols(); } + + Scalar _coeff(int row, int col) const + { + return UnaryOp::template op<Scalar>(m_matrix.coeff(row, col)); + } + + protected: + const MatRef m_matrix; +}; + +/** \brief Template functor to compute the opposite of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::operator- + */ +struct CwiseOppositeOp { + template<typename Scalar> static Scalar op(const Scalar& a) { return -a; } +}; + +/** \brief Template functor to compute the absolute value of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseAbs + */ +struct CwiseAbsOp { + template<typename Scalar> static Scalar op(const Scalar& a) { return ei_abs(a); } +}; + + +/** \returns an expression of the opposite of \c *this + */ +template<typename Scalar, typename Derived> +const CwiseUnaryOp<CwiseOppositeOp,Derived> +MatrixBase<Scalar, Derived>::operator-() const +{ + return CwiseUnaryOp<CwiseOppositeOp,Derived>(ref()); +} + +/** \returns an expression of the opposite of \c *this + */ +template<typename Scalar, typename Derived> +const CwiseUnaryOp<CwiseAbsOp,Derived> +MatrixBase<Scalar, Derived>::cwiseAbs() const +{ + return CwiseUnaryOp<CwiseAbsOp,Derived>(ref()); +} + + +/** \relates MatrixBase + * + * \returns an expression of a custom coefficient-wise unary operator of \a mat + * + * The template parameter \a CustomUnaryOp is the template functor + * of the custom unary operator. + * + * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::cwise, MatrixBase::operator-, MatrixBase::cwiseAbs + */ +template<typename CustomUnaryOp, typename Scalar, typename Derived> +const CwiseUnaryOp<CustomUnaryOp, Derived> +cwise(const MatrixBase<Scalar, Derived> &mat) +{ + return CwiseUnaryOp<CustomUnaryOp, Derived>(mat.ref()); +} + +/** \returns an expression of a custom coefficient-wise unary operator of *this + * + * The template parameter \a CustomUnaryOp is the template functor + * of the custom unary operator. + * + * \note since cwise is a templated member with a mandatory template parameter, + * the keyword template as to be used if the matrix type is also a template parameter: + * \code + * template <typename MatrixType> void foo(const MatrixType& m) { + * m.template cwise<CwiseAbsOp>(); + * } + * \endcode + * + * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, MatrixBase::cwiseAbs + */ +template<typename Scalar, typename Derived> +template<typename CustomUnaryOp> +const CwiseUnaryOp<CustomUnaryOp, Derived> +MatrixBase<Scalar, Derived>::cwise() const +{ + return CwiseUnaryOp<CustomUnaryOp, Derived>(ref()); +} + + +/** \brief Template functor to compute the conjugate of a complex value + * + * \sa class CwiseUnaryOp, MatrixBase::conjugate() + */ +struct ConjugateOp { + template<typename Scalar> static Scalar op(const Scalar& a) { return ei_conj(a); } +}; + +/** \returns an expression of the complex conjugate of *this. + * + * \sa adjoint(), class Conjugate */ +template<typename Scalar, typename Derived> +const CwiseUnaryOp<ConjugateOp, Derived> +MatrixBase<Scalar, Derived>::conjugate() const +{ + return CwiseUnaryOp<ConjugateOp, Derived>(ref()); +} + + + +#endif // EIGEN_CWISE_UNARY_OP_H diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index 59c088c19..9561abc51 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -34,10 +34,13 @@ template<typename MatrixType> class Minor; template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block; template<typename MatrixType> class Transpose; template<typename MatrixType> class Conjugate; -template<typename MatrixType> class Opposite; -template<template<typename BinaryOpScalar> class BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp; -template<typename Scalar> struct CwiseProductOp; -template<typename Scalar> struct CwiseQuotientOp; +template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp; +struct CwiseProductOp; +struct CwiseQuotientOp; +template<typename UnaryOp, typename MatrixType> class CwiseUnaryOp; +struct CwiseOppositeOp; +struct ConjugateOp; +struct CwiseAbsOp; template<typename Lhs, typename Rhs> class Product; template<typename MatrixType> class ScalarMultiple; template<typename MatrixType> class Random; diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 1d3e90d40..b53a74290 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -144,6 +144,8 @@ template<typename Scalar, typename Derived> class MatrixBase */ typedef typename NumTraits<Scalar>::Real RealScalar; + /// \name a - matrix properties + //@{ /** \returns the number of rows. \sa cols(), Traits::RowsAtCompileTime */ int rows() const { return static_cast<const Derived *>(this)->_rows(); } /** \returns the number of columns. \sa row(), Traits::ColsAtCompileTime*/ @@ -156,10 +158,13 @@ template<typename Scalar, typename Derived> class MatrixBase * \code rows()==1 || cols()==1 \endcode * \sa rows(), cols(), Traits::IsVectorAtCompileTime. */ bool isVector() const { return rows()==1 || cols()==1; } + //@} + /** \returns a Ref to *this. \sa Ref */ Ref ref() const { return static_cast<const Derived *>(this)->_ref(); } + //@{ /** Copies \a other into *this. \returns a reference to *this. */ template<typename OtherDerived> Derived& operator=(const MatrixBase<Scalar, OtherDerived>& other); @@ -172,8 +177,18 @@ template<typename Scalar, typename Derived> class MatrixBase return this->operator=<Derived>(other); } - template<typename NewScalar> const Cast<NewScalar, Derived> cast() const; + /** swaps *this with the expression \a other. + * + * \note \a other is only marked const because I couln't find another way + * to get g++ 4.2 to accept that template parameter resolution. It gets const_cast'd + * of course. TODO: get rid of const here. + */ + template<typename OtherDerived> + void swap(const MatrixBase<Scalar, OtherDerived>& other); + //@} + /// \name c - sub-matrices + //@{ Row<Derived> row(int i); const Row<Derived> row(int i) const; @@ -204,22 +219,34 @@ template<typename Scalar, typename Derived> class MatrixBase template<int BlockRows, int BlockCols> const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const; + DiagonalCoeffs<Derived> diagonal(); + const DiagonalCoeffs<Derived> diagonal() const; + //@} + + /// \name d - matrix transformation + //@{ + template<typename NewScalar> const Cast<NewScalar, Derived> cast() const; + + const DiagonalMatrix<Derived> asDiagonal() const; + Transpose<Derived> transpose(); const Transpose<Derived> transpose() const; - const Conjugate<Derived> conjugate() const; - const Transpose<Conjugate<Derived> > adjoint() const; + const CwiseUnaryOp<ConjugateOp, Derived> conjugate() const; + const Transpose<CwiseUnaryOp<ConjugateOp, Derived> > adjoint() const; + + const ScalarMultiple<Derived> normalized() const; + //@} + + /// \name f - metrics (??) + //@{ Scalar trace() const; template<typename OtherDerived> Scalar dot(const MatrixBase<Scalar, OtherDerived>& other) const; RealScalar norm2() const; RealScalar norm() const; - const ScalarMultiple<Derived> normalized() const; - template<typename OtherDerived> - bool isOrtho(const MatrixBase<Scalar, OtherDerived>& other, - RealScalar prec = precision<Scalar>()) const; - bool isOrtho(RealScalar prec = precision<Scalar>()) const; + //@} static const Eval<Random<Derived> > random(int rows, int cols); static const Eval<Random<Derived> > random(int size); @@ -233,20 +260,22 @@ template<typename Scalar, typename Derived> class MatrixBase static const Identity<Derived> identity(); static const Identity<Derived> identity(int rows, int cols); - bool isZero(RealScalar prec = precision<Scalar>()) const; - bool isOnes(RealScalar prec = precision<Scalar>()) const; - bool isIdentity(RealScalar prec = precision<Scalar>()) const; - bool isDiagonal(RealScalar prec = precision<Scalar>()) const; - Derived& setZero(); Derived& setOnes(); Derived& setRandom(); Derived& setIdentity(); - const DiagonalMatrix<Derived> asDiagonal() const; + /// \name g - matrix diagnostic and comparison + //@{ + bool isZero(RealScalar prec = precision<Scalar>()) const; + bool isOnes(RealScalar prec = precision<Scalar>()) const; + bool isIdentity(RealScalar prec = precision<Scalar>()) const; + bool isDiagonal(RealScalar prec = precision<Scalar>()) const; - DiagonalCoeffs<Derived> diagonal(); - const DiagonalCoeffs<Derived> diagonal() const; + template<typename OtherDerived> + bool isOrtho(const MatrixBase<Scalar, OtherDerived>& other, + RealScalar prec = precision<Scalar>()) const; + bool isOrtho(RealScalar prec = precision<Scalar>()) const; template<typename OtherDerived> bool isApprox(const OtherDerived& other, @@ -256,24 +285,11 @@ template<typename Scalar, typename Derived> class MatrixBase template<typename OtherDerived> bool isMuchSmallerThan(const MatrixBase<Scalar, OtherDerived>& other, RealScalar prec = precision<Scalar>()) const; + //@} - template<typename OtherDerived> - const Product<Derived, OtherDerived> - lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE; - - const Opposite<Derived> operator-() const; - - template<typename OtherDerived> - const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived> - cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const; - - template<typename OtherDerived> - const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived> - cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const; - - template<template<typename BinaryOpScalar> class CustomBinaryOp, typename OtherDerived> - const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> - cwise(const MatrixBase<Scalar, OtherDerived> &other) const; + /// \name e - arithemetic operators + //@{ + const CwiseUnaryOp<CwiseOppositeOp,Derived> operator-() const; template<typename OtherDerived> Derived& operator+=(const MatrixBase<Scalar, OtherDerived>& other); @@ -293,6 +309,23 @@ template<typename Scalar, typename Derived> class MatrixBase const MatrixBase& matrix) { return matrix*scalar; } + template<typename OtherDerived> + const Product<Derived, OtherDerived> + lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE; + + const CwiseUnaryOp<CwiseAbsOp,Derived> cwiseAbs() const; + + template<typename OtherDerived> + const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived> + cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const; + + template<typename OtherDerived> + const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived> + cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const; + //@} + + /// \name b - coefficient accessors + //@{ Scalar coeff(int row, int col) const; Scalar operator()(int row, int col) const; @@ -313,9 +346,20 @@ template<typename Scalar, typename Derived> class MatrixBase Scalar& y(); Scalar& z(); Scalar& w(); + //@} + /// \name h - special functions + //@{ const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE; + template<typename CustomUnaryOp> + const CwiseUnaryOp<CustomUnaryOp, Derived> cwise() const; + + template<typename CustomBinaryOp, typename OtherDerived> + const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> + cwise(const MatrixBase<Scalar, OtherDerived> &other) const; + //@} + /** puts in *row and *col the location of the coefficient of *this * which has the biggest absolute value. */ @@ -335,14 +379,6 @@ template<typename Scalar, typename Derived> class MatrixBase } } - /** swaps *this with the expression \a other. - * - * \note \a other is only marked const because I couln't find another way - * to get g++ 4.2 to accept that template parameter resolution. It gets const_cast'd - * of course. TODO: get rid of const here. - */ - template<typename OtherDerived> - void swap(const MatrixBase<Scalar, OtherDerived>& other); }; #endif // EIGEN_MATRIXBASE_H diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h index e441f0a77..a3ffc4064 100644 --- a/Eigen/src/Core/MatrixStorage.h +++ b/Eigen/src/Core/MatrixStorage.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com> +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> // Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> // // Eigen is free software; you can redistribute it and/or diff --git a/Eigen/src/Core/Opposite.h b/Eigen/src/Core/Opposite.h deleted file mode 100644 index 43ed8cb57..000000000 --- a/Eigen/src/Core/Opposite.h +++ /dev/null @@ -1,81 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see <http://www.gnu.org/licenses/>. - -#ifndef EIGEN_OPPOSITE_H -#define EIGEN_OPPOSITE_H - -/** \class Opposite - * - * \brief Expression of the opposite of a matrix or vector - * - * \param MatrixType the type of which we are taking the opposite - * - * This class represents an expression of the opposite of a matrix or vector. - * It is the return type of the unary operator- for matrices or vectors, and most - * of the time this is the only way it is used. - * - * \sa class Difference - */ -template<typename MatrixType> class Opposite : NoOperatorEquals, - public MatrixBase<typename MatrixType::Scalar, Opposite<MatrixType> > -{ - public: - typedef typename MatrixType::Scalar Scalar; - typedef typename MatrixType::Ref MatRef; - friend class MatrixBase<Scalar, Opposite>; - typedef MatrixBase<Scalar, Opposite> Base; - - Opposite(const MatRef& matrix) : m_matrix(matrix) {} - - private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; - - const Opposite& _ref() const { return *this; } - int _rows() const { return m_matrix.rows(); } - int _cols() const { return m_matrix.cols(); } - - Scalar _coeff(int row, int col) const - { - return -(m_matrix.coeff(row, col)); - } - - protected: - const MatRef m_matrix; -}; - -/** \returns an expression of the opposite of \c *this - */ -template<typename Scalar, typename Derived> -const Opposite<Derived> -MatrixBase<Scalar, Derived>::operator-() const -{ - return Opposite<Derived>(ref()); -} - -#endif // EIGEN_OPPOSITE_H diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 94c068db7..5320ad522 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -97,4 +97,17 @@ MatrixBase<Scalar, Derived>::transpose() const return Transpose<Derived>(ref()); } +/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this. + * + * Example: \include MatrixBase_adjoint.cpp + * Output: \verbinclude MatrixBase_adjoint.out + * + * \sa transpose(), conjugate(), class Transpose, class ConjugateOp */ +template<typename Scalar, typename Derived> +const Transpose<CwiseUnaryOp<ConjugateOp, Derived> > +MatrixBase<Scalar, Derived>::adjoint() const +{ + return conjugate().transpose(); +} + #endif // EIGEN_TRANSPOSE_H diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h index 42177dfb5..b11c27653 100644 --- a/Eigen/src/Core/Util.h +++ b/Eigen/src/Core/Util.h @@ -56,7 +56,11 @@ using Eigen::MatrixBase; #define EIGEN_ONLY_USED_FOR_DEBUG(x) #endif -#ifdef __GNUC__ +// FIXME with the always_inline attribute, +// gcc 3.4.x reports the following compilation error: +// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const' +// : function body not available +#if (defined __GNUC__) && (__GNUC__!=3) #define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) #else #define EIGEN_ALWAYS_INLINE |