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 #ifndef EIGEN_PARSED_BY_DOXYGEN
00163     template<typename ProductDerived, typename Lhs, typename Rhs>
00164     Derived& lazyAssign(const ProductBase<ProductDerived, Lhs,Rhs>& other);
00165 
00166     template<typename MatrixPower, typename Lhs, typename Rhs>
00167     Derived& lazyAssign(const MatrixPowerProduct<MatrixPower, Lhs,Rhs>& other);
00168 #endif // not EIGEN_PARSED_BY_DOXYGEN
00169 
00170     template<typename OtherDerived>
00171     Derived& operator+=(const MatrixBase<OtherDerived>& other);
00172     template<typename OtherDerived>
00173     Derived& operator-=(const MatrixBase<OtherDerived>& other);
00174 
00175     template<typename OtherDerived>
00176     const typename ProductReturnType<Derived,OtherDerived>::Type
00177     operator*(const MatrixBase<OtherDerived> &other) const;
00178 
00179     template<typename OtherDerived>
00180     const typename LazyProductReturnType<Derived,OtherDerived>::Type
00181     lazyProduct(const MatrixBase<OtherDerived> &other) const;
00182 
00183     template<typename OtherDerived>
00184     Derived& operator*=(const EigenBase<OtherDerived>& other);
00185 
00186     template<typename OtherDerived>
00187     void applyOnTheLeft(const EigenBase<OtherDerived>& other);
00188 
00189     template<typename OtherDerived>
00190     void applyOnTheRight(const EigenBase<OtherDerived>& other);
00191 
00192     template<typename DiagonalDerived>
00193     const DiagonalProduct<Derived, DiagonalDerived, OnTheRight>
00194     operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
00195 
00196     template<typename OtherDerived>
00197     typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
00198     dot(const MatrixBase<OtherDerived>& other) const;
00199 
00200     #ifdef EIGEN2_SUPPORT
00201       template<typename OtherDerived>
00202       Scalar eigen2_dot(const MatrixBase<OtherDerived>& other) const;
00203     #endif
00204 
00205     RealScalar squaredNorm() const;
00206     RealScalar norm() const;
00207     RealScalar stableNorm() const;
00208     RealScalar blueNorm() const;
00209     RealScalar hypotNorm() const;
00210     const PlainObject normalized() const;
00211     void normalize();
00212 
00213     const AdjointReturnType adjoint() const;
00214     void adjointInPlace();
00215 
00216     typedef Diagonal<Derived> DiagonalReturnType;
00217     DiagonalReturnType diagonal();
00218         typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType;
00219     ConstDiagonalReturnType diagonal() const;
00220 
00221     template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
00222     template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };
00223 
00224     template<int Index> typename DiagonalIndexReturnType<Index>::Type diagonal();
00225     template<int Index> typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;
00226 
00227     // Note: The "MatrixBase::" prefixes are added to help MSVC9 to match these declarations with the later implementations.
00228     // On the other hand they confuse MSVC8...
00229     #if (defined _MSC_VER) && (_MSC_VER >= 1500) // 2008 or later
00230     typename MatrixBase::template DiagonalIndexReturnType<DynamicIndex>::Type diagonal(Index index);
00231     typename MatrixBase::template ConstDiagonalIndexReturnType<DynamicIndex>::Type diagonal(Index index) const;
00232     #else
00233     typename DiagonalIndexReturnType<DynamicIndex>::Type diagonal(Index index);
00234     typename ConstDiagonalIndexReturnType<DynamicIndex>::Type diagonal(Index index) const;
00235     #endif
00236 
00237     #ifdef EIGEN2_SUPPORT
00238     template<unsigned int Mode> typename internal::eigen2_part_return_type<Derived, Mode>::type part();
00239     template<unsigned int Mode> const typename internal::eigen2_part_return_type<Derived, Mode>::type part() const;
00240     
00241     // huuuge hack. make Eigen2's matrix.part<Diagonal>() work in eigen3. Problem: Diagonal is now a class template instead
00242     // of an integer constant. Solution: overload the part() method template wrt template parameters list.
00243     template<template<typename T, int N> class U>
00244     const DiagonalWrapper<ConstDiagonalReturnType> part() const
00245     { return diagonal().asDiagonal(); }
00246     #endif // EIGEN2_SUPPORT
00247 
00248     template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
00249     template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
00250 
00251     template<unsigned int Mode> typename TriangularViewReturnType<Mode>::Type triangularView();
00252     template<unsigned int Mode> typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
00253 
00254     template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
00255     template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
00256 
00257     template<unsigned int UpLo> typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
00258     template<unsigned int UpLo> typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
00259 
00260     const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
00261                                          const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
00262     static const IdentityReturnType Identity();
00263     static const IdentityReturnType Identity(Index rows, Index cols);
00264     static const BasisReturnType Unit(Index size, Index i);
00265     static const BasisReturnType Unit(Index i);
00266     static const BasisReturnType UnitX();
00267     static const BasisReturnType UnitY();
00268     static const BasisReturnType UnitZ();
00269     static const BasisReturnType UnitW();
00270 
00271     const DiagonalWrapper<const Derived> asDiagonal() const;
00272     const PermutationWrapper<const Derived> asPermutation() const;
00273 
00274     Derived& setIdentity();
00275     Derived& setIdentity(Index rows, Index cols);
00276 
00277     bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00278     bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00279 
00280     bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00281     bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00282 
00283     template<typename OtherDerived>
00284     bool isOrthogonal(const MatrixBase<OtherDerived>& other,
00285                       const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00286     bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00287 
00292     template<typename OtherDerived>
00293     inline bool operator==(const MatrixBase<OtherDerived>& other) const
00294     { return cwiseEqual(other).all(); }
00295 
00300     template<typename OtherDerived>
00301     inline bool operator!=(const MatrixBase<OtherDerived>& other) const
00302     { return cwiseNotEqual(other).any(); }
00303 
00304     NoAlias<Derived,Eigen::MatrixBase > noalias();
00305 
00306     inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00307     inline ForceAlignedAccess<Derived> forceAlignedAccess();
00308     template<bool Enable> inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type forceAlignedAccessIf() const;
00309     template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00310 
00311     Scalar trace() const;
00312 
00314 
00315     template<int p> RealScalar lpNorm() const;
00316 
00317     MatrixBase<Derived>& matrix() { return *this; }
00318     const MatrixBase<Derived>& matrix() const { return *this; }
00319 
00322     ArrayWrapper<Derived> array() { return derived(); }
00323     const ArrayWrapper<const Derived> array() const { return derived(); }
00324 
00326 
00327     const FullPivLU<PlainObject> fullPivLu() const;
00328     const PartialPivLU<PlainObject> partialPivLu() const;
00329 
00330     #if EIGEN2_SUPPORT_STAGE < STAGE20_RESOLVE_API_CONFLICTS
00331     const LU<PlainObject> lu() const;
00332     #endif
00333 
00334     #ifdef EIGEN2_SUPPORT
00335     const LU<PlainObject> eigen2_lu() const;
00336     #endif
00337 
00338     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00339     const PartialPivLU<PlainObject> lu() const;
00340     #endif
00341     
00342     #ifdef EIGEN2_SUPPORT
00343     template<typename ResultType>
00344     void computeInverse(MatrixBase<ResultType> *result) const {
00345       *result = this->inverse();
00346     }
00347     #endif
00348 
00349     const internal::inverse_impl<Derived> inverse() const;
00350     template<typename ResultType>
00351     void computeInverseAndDetWithCheck(
00352       ResultType& inverse,
00353       typename ResultType::Scalar& determinant,
00354       bool& invertible,
00355       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00356     ) const;
00357     template<typename ResultType>
00358     void computeInverseWithCheck(
00359       ResultType& inverse,
00360       bool& invertible,
00361       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00362     ) const;
00363     Scalar determinant() const;
00364 
00366 
00367     const LLT<PlainObject>  llt() const;
00368     const LDLT<PlainObject> ldlt() const;
00369 
00371 
00372     const HouseholderQR<PlainObject> householderQr() const;
00373     const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
00374     const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
00375     
00376     #ifdef EIGEN2_SUPPORT
00377     const QR<PlainObject> qr() const;
00378     #endif
00379 
00380     EigenvaluesReturnType eigenvalues() const;
00381     RealScalar operatorNorm() const;
00382 
00384 
00385     JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
00386 
00387     #ifdef EIGEN2_SUPPORT
00388     SVD<PlainObject> svd() const;
00389     #endif
00390 
00392 
00393     #ifndef EIGEN_PARSED_BY_DOXYGEN
00394 
00395     template<typename OtherDerived> struct cross_product_return_type {
00396       typedef typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
00397       typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
00398     };
00399     #endif // EIGEN_PARSED_BY_DOXYGEN
00400     template<typename OtherDerived>
00401     typename cross_product_return_type<OtherDerived>::type
00402     cross(const MatrixBase<OtherDerived>& other) const;
00403     template<typename OtherDerived>
00404     PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
00405     PlainObject unitOrthogonal(void) const;
00406     Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
00407     
00408     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00409     ScalarMultipleReturnType operator*(const UniformScaling<Scalar>& s) const;
00410     // put this as separate enum value to work around possible GCC 4.3 bug (?)
00411     enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1?Vertical:Horizontal };
00412     typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
00413     HomogeneousReturnType homogeneous() const;
00414     #endif
00415     
00416     enum {
00417       SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
00418     };
00419     typedef Block<const Derived,
00420                   internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
00421                   internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
00422     typedef CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>,
00423                 const ConstStartMinusOne > HNormalizedReturnType;
00424 
00425     const HNormalizedReturnType hnormalized() const;
00426 
00428 
00429     void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
00430     template<typename EssentialPart>
00431     void makeHouseholder(EssentialPart& essential,
00432                          Scalar& tau, RealScalar& beta) const;
00433     template<typename EssentialPart>
00434     void applyHouseholderOnTheLeft(const EssentialPart& essential,
00435                                    const Scalar& tau,
00436                                    Scalar* workspace);
00437     template<typename EssentialPart>
00438     void applyHouseholderOnTheRight(const EssentialPart& essential,
00439                                     const Scalar& tau,
00440                                     Scalar* workspace);
00441 
00443 
00444     template<typename OtherScalar>
00445     void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00446     template<typename OtherScalar>
00447     void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00448 
00450 
00451     typedef typename internal::stem_function<Scalar>::type StemFunction;
00452     const MatrixExponentialReturnValue<Derived> exp() const;
00453     const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
00454     const MatrixFunctionReturnValue<Derived> cosh() const;
00455     const MatrixFunctionReturnValue<Derived> sinh() const;
00456     const MatrixFunctionReturnValue<Derived> cos() const;
00457     const MatrixFunctionReturnValue<Derived> sin() const;
00458     const MatrixSquareRootReturnValue<Derived> sqrt() const;
00459     const MatrixLogarithmReturnValue<Derived> log() const;
00460     const MatrixPowerReturnValue<Derived> pow(const RealScalar& p) const;
00461 
00462 #ifdef EIGEN2_SUPPORT
00463     template<typename ProductDerived, typename Lhs, typename Rhs>
00464     Derived& operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00465                                       EvalBeforeAssigningBit>& other);
00466 
00467     template<typename ProductDerived, typename Lhs, typename Rhs>
00468     Derived& operator-=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00469                                       EvalBeforeAssigningBit>& other);
00470 
00473     template<typename OtherDerived>
00474     Derived& lazyAssign(const Flagged<OtherDerived, 0, EvalBeforeAssigningBit>& other)
00475     { return lazyAssign(other._expression()); }
00476 
00477     template<unsigned int Added>
00478     const Flagged<Derived, Added, 0> marked() const;
00479     const Flagged<Derived, 0, EvalBeforeAssigningBit> lazy() const;
00480 
00481     inline const Cwise<Derived> cwise() const;
00482     inline Cwise<Derived> cwise();
00483 
00484     VectorBlock<Derived> start(Index size);
00485     const VectorBlock<const Derived> start(Index size) const;
00486     VectorBlock<Derived> end(Index size);
00487     const VectorBlock<const Derived> end(Index size) const;
00488     template<int Size> VectorBlock<Derived,Size> start();
00489     template<int Size> const VectorBlock<const Derived,Size> start() const;
00490     template<int Size> VectorBlock<Derived,Size> end();
00491     template<int Size> const VectorBlock<const Derived,Size> end() const;
00492 
00493     Minor<Derived> minor(Index row, Index col);
00494     const Minor<Derived> minor(Index row, Index col) const;
00495 #endif
00496 
00497   protected:
00498     MatrixBase() : Base() {}
00499 
00500   private:
00501     explicit MatrixBase(int);
00502     MatrixBase(int,int);
00503     template<typename OtherDerived> explicit MatrixBase(const MatrixBase<OtherDerived>&);
00504   protected:
00505     // mixing arrays and matrices is not legal
00506     template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
00507     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
00508     // mixing arrays and matrices is not legal
00509     template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
00510     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
00511 };
00512 
00513 } // end namespace Eigen
00514 
00515 #endif // EIGEN_MATRIXBASE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:13