MatrixBase.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_MATRIXBASE_H
00012 #define EIGEN_MATRIXBASE_H
00013 
00014 namespace Eigen {
00015 
00048 template<typename Derived> class MatrixBase
00049   : public DenseBase<Derived>
00050 {
00051   public:
00052 #ifndef EIGEN_PARSED_BY_DOXYGEN
00053     typedef MatrixBase StorageBaseType;
00054     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00055     typedef typename internal::traits<Derived>::Index Index;
00056     typedef typename internal::traits<Derived>::Scalar Scalar;
00057     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00058     typedef typename NumTraits<Scalar>::Real RealScalar;
00059 
00060     typedef DenseBase<Derived> Base;
00061     using Base::RowsAtCompileTime;
00062     using Base::ColsAtCompileTime;
00063     using Base::SizeAtCompileTime;
00064     using Base::MaxRowsAtCompileTime;
00065     using Base::MaxColsAtCompileTime;
00066     using Base::MaxSizeAtCompileTime;
00067     using Base::IsVectorAtCompileTime;
00068     using Base::Flags;
00069     using Base::CoeffReadCost;
00070 
00071     using Base::derived;
00072     using Base::const_cast_derived;
00073     using Base::rows;
00074     using Base::cols;
00075     using Base::size;
00076     using Base::coeff;
00077     using Base::coeffRef;
00078     using Base::lazyAssign;
00079     using Base::eval;
00080     using Base::operator+=;
00081     using Base::operator-=;
00082     using Base::operator*=;
00083     using Base::operator/=;
00084 
00085     typedef typename Base::CoeffReturnType CoeffReturnType;
00086     typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
00087     typedef typename Base::RowXpr RowXpr;
00088     typedef typename Base::ColXpr ColXpr;
00089 #endif // not EIGEN_PARSED_BY_DOXYGEN
00090 
00091 
00092 
00093 #ifndef EIGEN_PARSED_BY_DOXYGEN
00094 
00095     typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
00096                           EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
00097 #endif // not EIGEN_PARSED_BY_DOXYGEN
00098 
00101     inline Index diagonalSize() const { return (std::min)(rows(),cols()); }
00102 
00109     typedef Matrix<typename internal::traits<Derived>::Scalar,
00110                 internal::traits<Derived>::RowsAtCompileTime,
00111                 internal::traits<Derived>::ColsAtCompileTime,
00112                 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
00113                 internal::traits<Derived>::MaxRowsAtCompileTime,
00114                 internal::traits<Derived>::MaxColsAtCompileTime
00115           > PlainObject;
00116 
00117 #ifndef EIGEN_PARSED_BY_DOXYGEN
00118 
00119     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00121     typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
00122                         CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
00123                         ConstTransposeReturnType
00124                      >::type AdjointReturnType;
00126     typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
00128     typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,Derived> IdentityReturnType;
00130     typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
00131                   internal::traits<Derived>::RowsAtCompileTime,
00132                   internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
00133 #endif // not EIGEN_PARSED_BY_DOXYGEN
00134 
00135 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
00136 #   include "../plugins/CommonCwiseUnaryOps.h"
00137 #   include "../plugins/CommonCwiseBinaryOps.h"
00138 #   include "../plugins/MatrixCwiseUnaryOps.h"
00139 #   include "../plugins/MatrixCwiseBinaryOps.h"
00140 #   ifdef EIGEN_MATRIXBASE_PLUGIN
00141 #     include EIGEN_MATRIXBASE_PLUGIN
00142 #   endif
00143 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00144 
00148     Derived& operator=(const MatrixBase& other);
00149 
00150     // We cannot inherit here via Base::operator= since it is causing
00151     // trouble with MSVC.
00152 
00153     template <typename OtherDerived>
00154     Derived& operator=(const DenseBase<OtherDerived>& other);
00155 
00156     template <typename OtherDerived>
00157     Derived& operator=(const EigenBase<OtherDerived>& other);
00158 
00159     template<typename OtherDerived>
00160     Derived& operator=(const ReturnByValue<OtherDerived>& other);
00161 
00162     template<typename ProductDerived, typename Lhs, typename Rhs>
00163     Derived& lazyAssign(const ProductBase<ProductDerived, Lhs,Rhs>& other);
00164 
00165     template<typename MatrixPower, typename Lhs, typename Rhs>
00166     Derived& lazyAssign(const MatrixPowerProduct<MatrixPower, Lhs,Rhs>& other);
00167 
00168     template<typename OtherDerived>
00169     Derived& operator+=(const MatrixBase<OtherDerived>& other);
00170     template<typename OtherDerived>
00171     Derived& operator-=(const MatrixBase<OtherDerived>& other);
00172 
00173     template<typename OtherDerived>
00174     const typename ProductReturnType<Derived,OtherDerived>::Type
00175     operator*(const MatrixBase<OtherDerived> &other) const;
00176 
00177     template<typename OtherDerived>
00178     const typename LazyProductReturnType<Derived,OtherDerived>::Type
00179     lazyProduct(const MatrixBase<OtherDerived> &other) const;
00180 
00181     template<typename OtherDerived>
00182     Derived& operator*=(const EigenBase<OtherDerived>& other);
00183 
00184     template<typename OtherDerived>
00185     void applyOnTheLeft(const EigenBase<OtherDerived>& other);
00186 
00187     template<typename OtherDerived>
00188     void applyOnTheRight(const EigenBase<OtherDerived>& other);
00189 
00190     template<typename DiagonalDerived>
00191     const DiagonalProduct<Derived, DiagonalDerived, OnTheRight>
00192     operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
00193 
00194     template<typename OtherDerived>
00195     typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
00196     dot(const MatrixBase<OtherDerived>& other) const;
00197 
00198     #ifdef EIGEN2_SUPPORT
00199       template<typename OtherDerived>
00200       Scalar eigen2_dot(const MatrixBase<OtherDerived>& other) const;
00201     #endif
00202 
00203     RealScalar squaredNorm() const;
00204     RealScalar norm() const;
00205     RealScalar stableNorm() const;
00206     RealScalar blueNorm() const;
00207     RealScalar hypotNorm() const;
00208     const PlainObject normalized() const;
00209     void normalize();
00210 
00211     const AdjointReturnType adjoint() const;
00212     void adjointInPlace();
00213 
00214     typedef Diagonal<Derived> DiagonalReturnType;
00215     DiagonalReturnType diagonal();
00216     typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType;
00217     ConstDiagonalReturnType diagonal() const;
00218 
00219     template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
00220     template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };
00221 
00222     template<int Index> typename DiagonalIndexReturnType<Index>::Type diagonal();
00223     template<int Index> typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;
00224     
00225     typedef Diagonal<Derived,DynamicIndex> DiagonalDynamicIndexReturnType;
00226     typedef typename internal::add_const<Diagonal<const Derived,DynamicIndex> >::type ConstDiagonalDynamicIndexReturnType;
00227 
00228     DiagonalDynamicIndexReturnType diagonal(Index index);
00229     ConstDiagonalDynamicIndexReturnType diagonal(Index index) const;
00230 
00231     #ifdef EIGEN2_SUPPORT
00232     template<unsigned int Mode> typename internal::eigen2_part_return_type<Derived, Mode>::type part();
00233     template<unsigned int Mode> const typename internal::eigen2_part_return_type<Derived, Mode>::type part() const;
00234     
00235     // huuuge hack. make Eigen2's matrix.part<Diagonal>() work in eigen3. Problem: Diagonal is now a class template instead
00236     // of an integer constant. Solution: overload the part() method template wrt template parameters list.
00237     template<template<typename T, int N> class U>
00238     const DiagonalWrapper<ConstDiagonalReturnType> part() const
00239     { return diagonal().asDiagonal(); }
00240     #endif // EIGEN2_SUPPORT
00241 
00242     template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
00243     template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
00244 
00245     template<unsigned int Mode> typename TriangularViewReturnType<Mode>::Type triangularView();
00246     template<unsigned int Mode> typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
00247 
00248     template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
00249     template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
00250 
00251     template<unsigned int UpLo> typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
00252     template<unsigned int UpLo> typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
00253 
00254     const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
00255                                          const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
00256     static const IdentityReturnType Identity();
00257     static const IdentityReturnType Identity(Index rows, Index cols);
00258     static const BasisReturnType Unit(Index size, Index i);
00259     static const BasisReturnType Unit(Index i);
00260     static const BasisReturnType UnitX();
00261     static const BasisReturnType UnitY();
00262     static const BasisReturnType UnitZ();
00263     static const BasisReturnType UnitW();
00264 
00265     const DiagonalWrapper<const Derived> asDiagonal() const;
00266     const PermutationWrapper<const Derived> asPermutation() const;
00267 
00268     Derived& setIdentity();
00269     Derived& setIdentity(Index rows, Index cols);
00270 
00271     bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00272     bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00273 
00274     bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00275     bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00276 
00277     template<typename OtherDerived>
00278     bool isOrthogonal(const MatrixBase<OtherDerived>& other,
00279                       const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00280     bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00281 
00286     template<typename OtherDerived>
00287     inline bool operator==(const MatrixBase<OtherDerived>& other) const
00288     { return cwiseEqual(other).all(); }
00289 
00294     template<typename OtherDerived>
00295     inline bool operator!=(const MatrixBase<OtherDerived>& other) const
00296     { return cwiseNotEqual(other).any(); }
00297 
00298     NoAlias<Derived,Eigen::MatrixBase > noalias();
00299 
00300     inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00301     inline ForceAlignedAccess<Derived> forceAlignedAccess();
00302     template<bool Enable> inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type forceAlignedAccessIf() const;
00303     template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00304 
00305     Scalar trace() const;
00306 
00308 
00309     template<int p> RealScalar lpNorm() const;
00310 
00311     MatrixBase<Derived>& matrix() { return *this; }
00312     const MatrixBase<Derived>& matrix() const { return *this; }
00313 
00316     ArrayWrapper<Derived> array() { return derived(); }
00317     const ArrayWrapper<const Derived> array() const { return derived(); }
00318 
00320 
00321     const FullPivLU<PlainObject> fullPivLu() const;
00322     const PartialPivLU<PlainObject> partialPivLu() const;
00323 
00324     #if EIGEN2_SUPPORT_STAGE < STAGE20_RESOLVE_API_CONFLICTS
00325     const LU<PlainObject> lu() const;
00326     #endif
00327 
00328     #ifdef EIGEN2_SUPPORT
00329     const LU<PlainObject> eigen2_lu() const;
00330     #endif
00331 
00332     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00333     const PartialPivLU<PlainObject> lu() const;
00334     #endif
00335     
00336     #ifdef EIGEN2_SUPPORT
00337     template<typename ResultType>
00338     void computeInverse(MatrixBase<ResultType> *result) const {
00339       *result = this->inverse();
00340     }
00341     #endif
00342 
00343     const internal::inverse_impl<Derived> inverse() const;
00344     template<typename ResultType>
00345     void computeInverseAndDetWithCheck(
00346       ResultType& inverse,
00347       typename ResultType::Scalar& determinant,
00348       bool& invertible,
00349       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00350     ) const;
00351     template<typename ResultType>
00352     void computeInverseWithCheck(
00353       ResultType& inverse,
00354       bool& invertible,
00355       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00356     ) const;
00357     Scalar determinant() const;
00358 
00360 
00361     const LLT<PlainObject>  llt() const;
00362     const LDLT<PlainObject> ldlt() const;
00363 
00365 
00366     const HouseholderQR<PlainObject> householderQr() const;
00367     const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
00368     const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
00369     
00370     #ifdef EIGEN2_SUPPORT
00371     const QR<PlainObject> qr() const;
00372     #endif
00373 
00374     EigenvaluesReturnType eigenvalues() const;
00375     RealScalar operatorNorm() const;
00376 
00378 
00379     JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
00380 
00381     #ifdef EIGEN2_SUPPORT
00382     SVD<PlainObject> svd() const;
00383     #endif
00384 
00386 
00387     #ifndef EIGEN_PARSED_BY_DOXYGEN
00388 
00389     template<typename OtherDerived> struct cross_product_return_type {
00390       typedef typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
00391       typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
00392     };
00393     #endif // EIGEN_PARSED_BY_DOXYGEN
00394     template<typename OtherDerived>
00395     typename cross_product_return_type<OtherDerived>::type
00396     cross(const MatrixBase<OtherDerived>& other) const;
00397     template<typename OtherDerived>
00398     PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
00399     PlainObject unitOrthogonal(void) const;
00400     Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
00401     
00402     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00403     ScalarMultipleReturnType operator*(const UniformScaling<Scalar>& s) const;
00404     // put this as separate enum value to work around possible GCC 4.3 bug (?)
00405     enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1?Vertical:Horizontal };
00406     typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
00407     HomogeneousReturnType homogeneous() const;
00408     #endif
00409     
00410     enum {
00411       SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
00412     };
00413     typedef Block<const Derived,
00414                   internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
00415                   internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
00416     typedef CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>,
00417                 const ConstStartMinusOne > HNormalizedReturnType;
00418 
00419     const HNormalizedReturnType hnormalized() const;
00420 
00422 
00423     void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
00424     template<typename EssentialPart>
00425     void makeHouseholder(EssentialPart& essential,
00426                          Scalar& tau, RealScalar& beta) const;
00427     template<typename EssentialPart>
00428     void applyHouseholderOnTheLeft(const EssentialPart& essential,
00429                                    const Scalar& tau,
00430                                    Scalar* workspace);
00431     template<typename EssentialPart>
00432     void applyHouseholderOnTheRight(const EssentialPart& essential,
00433                                     const Scalar& tau,
00434                                     Scalar* workspace);
00435 
00437 
00438     template<typename OtherScalar>
00439     void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00440     template<typename OtherScalar>
00441     void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00442 
00444 
00445     typedef typename internal::stem_function<Scalar>::type StemFunction;
00446     const MatrixExponentialReturnValue<Derived> exp() const;
00447     const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
00448     const MatrixFunctionReturnValue<Derived> cosh() const;
00449     const MatrixFunctionReturnValue<Derived> sinh() const;
00450     const MatrixFunctionReturnValue<Derived> cos() const;
00451     const MatrixFunctionReturnValue<Derived> sin() const;
00452     const MatrixSquareRootReturnValue<Derived> sqrt() const;
00453     const MatrixLogarithmReturnValue<Derived> log() const;
00454     const MatrixPowerReturnValue<Derived> pow(const RealScalar& p) const;
00455 
00456 #ifdef EIGEN2_SUPPORT
00457     template<typename ProductDerived, typename Lhs, typename Rhs>
00458     Derived& operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00459                                       EvalBeforeAssigningBit>& other);
00460 
00461     template<typename ProductDerived, typename Lhs, typename Rhs>
00462     Derived& operator-=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00463                                       EvalBeforeAssigningBit>& other);
00464 
00467     template<typename OtherDerived>
00468     Derived& lazyAssign(const Flagged<OtherDerived, 0, EvalBeforeAssigningBit>& other)
00469     { return lazyAssign(other._expression()); }
00470 
00471     template<unsigned int Added>
00472     const Flagged<Derived, Added, 0> marked() const;
00473     const Flagged<Derived, 0, EvalBeforeAssigningBit> lazy() const;
00474 
00475     inline const Cwise<Derived> cwise() const;
00476     inline Cwise<Derived> cwise();
00477 
00478     VectorBlock<Derived> start(Index size);
00479     const VectorBlock<const Derived> start(Index size) const;
00480     VectorBlock<Derived> end(Index size);
00481     const VectorBlock<const Derived> end(Index size) const;
00482     template<int Size> VectorBlock<Derived,Size> start();
00483     template<int Size> const VectorBlock<const Derived,Size> start() const;
00484     template<int Size> VectorBlock<Derived,Size> end();
00485     template<int Size> const VectorBlock<const Derived,Size> end() const;
00486 
00487     Minor<Derived> minor(Index row, Index col);
00488     const Minor<Derived> minor(Index row, Index col) const;
00489 #endif
00490 
00491   protected:
00492     MatrixBase() : Base() {}
00493 
00494   private:
00495     explicit MatrixBase(int);
00496     MatrixBase(int,int);
00497     template<typename OtherDerived> explicit MatrixBase(const MatrixBase<OtherDerived>&);
00498   protected:
00499     // mixing arrays and matrices is not legal
00500     template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
00501     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
00502     // mixing arrays and matrices is not legal
00503     template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
00504     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
00505 };
00506 
00507 
00508 /***************************************************************************
00509 * Implementation of matrix base methods
00510 ***************************************************************************/
00511 
00519 template<typename Derived>
00520 template<typename OtherDerived>
00521 inline Derived&
00522 MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
00523 {
00524   other.derived().applyThisOnTheRight(derived());
00525   return derived();
00526 }
00527 
00533 template<typename Derived>
00534 template<typename OtherDerived>
00535 inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
00536 {
00537   other.derived().applyThisOnTheRight(derived());
00538 }
00539 
00545 template<typename Derived>
00546 template<typename OtherDerived>
00547 inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
00548 {
00549   other.derived().applyThisOnTheLeft(derived());
00550 }
00551 
00552 } // end namespace Eigen
00553 
00554 #endif // EIGEN_MATRIXBASE_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:59:06