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


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:25:18