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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_MATRIXBASE_H
00027 #define EIGEN_MATRIXBASE_H
00028 
00061 template<typename Derived> class MatrixBase
00062   : public DenseBase<Derived>
00063 {
00064   public:
00065 #ifndef EIGEN_PARSED_BY_DOXYGEN
00066     typedef MatrixBase StorageBaseType;
00067     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00068     typedef typename internal::traits<Derived>::Index Index;
00069     typedef typename internal::traits<Derived>::Scalar Scalar;
00070     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00071     typedef typename NumTraits<Scalar>::Real RealScalar;
00072 
00073     typedef DenseBase<Derived> Base;
00074     using Base::RowsAtCompileTime;
00075     using Base::ColsAtCompileTime;
00076     using Base::SizeAtCompileTime;
00077     using Base::MaxRowsAtCompileTime;
00078     using Base::MaxColsAtCompileTime;
00079     using Base::MaxSizeAtCompileTime;
00080     using Base::IsVectorAtCompileTime;
00081     using Base::Flags;
00082     using Base::CoeffReadCost;
00083 
00084     using Base::derived;
00085     using Base::const_cast_derived;
00086     using Base::rows;
00087     using Base::cols;
00088     using Base::size;
00089     using Base::coeff;
00090     using Base::coeffRef;
00091     using Base::lazyAssign;
00092     using Base::eval;
00093     using Base::operator+=;
00094     using Base::operator-=;
00095     using Base::operator*=;
00096     using Base::operator/=;
00097 
00098     typedef typename Base::CoeffReturnType CoeffReturnType;
00099     typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
00100     typedef typename Base::RowXpr RowXpr;
00101     typedef typename Base::ColXpr ColXpr;
00102 #endif // not EIGEN_PARSED_BY_DOXYGEN
00103 
00104 
00105 
00106 #ifndef EIGEN_PARSED_BY_DOXYGEN
00107 
00108     typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
00109                           EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
00110 #endif // not EIGEN_PARSED_BY_DOXYGEN
00111 
00114     inline Index diagonalSize() const { return (std::min)(rows(),cols()); }
00115 
00122     typedef Matrix<typename internal::traits<Derived>::Scalar,
00123                 internal::traits<Derived>::RowsAtCompileTime,
00124                 internal::traits<Derived>::ColsAtCompileTime,
00125                 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
00126                 internal::traits<Derived>::MaxRowsAtCompileTime,
00127                 internal::traits<Derived>::MaxColsAtCompileTime
00128           > PlainObject;
00129 
00130 #ifndef EIGEN_PARSED_BY_DOXYGEN
00131 
00132     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00134     typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
00135                         CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
00136                         ConstTransposeReturnType
00137                      >::type AdjointReturnType;
00139     typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
00141     typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,Derived> IdentityReturnType;
00143     typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
00144                   internal::traits<Derived>::RowsAtCompileTime,
00145                   internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
00146 #endif // not EIGEN_PARSED_BY_DOXYGEN
00147 
00148 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
00149 #   include "../plugins/CommonCwiseUnaryOps.h"
00150 #   include "../plugins/CommonCwiseBinaryOps.h"
00151 #   include "../plugins/MatrixCwiseUnaryOps.h"
00152 #   include "../plugins/MatrixCwiseBinaryOps.h"
00153 #   ifdef EIGEN_MATRIXBASE_PLUGIN
00154 #     include EIGEN_MATRIXBASE_PLUGIN
00155 #   endif
00156 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00157 
00161     Derived& operator=(const MatrixBase& other);
00162 
00163     // We cannot inherit here via Base::operator= since it is causing
00164     // trouble with MSVC.
00165 
00166     template <typename OtherDerived>
00167     Derived& operator=(const DenseBase<OtherDerived>& other);
00168 
00169     template <typename OtherDerived>
00170     Derived& operator=(const EigenBase<OtherDerived>& other);
00171 
00172     template<typename OtherDerived>
00173     Derived& operator=(const ReturnByValue<OtherDerived>& other);
00174 
00175 #ifndef EIGEN_PARSED_BY_DOXYGEN
00176     template<typename ProductDerived, typename Lhs, typename Rhs>
00177     Derived& lazyAssign(const ProductBase<ProductDerived, Lhs,Rhs>& other);
00178 #endif // not EIGEN_PARSED_BY_DOXYGEN
00179 
00180     template<typename OtherDerived>
00181     Derived& operator+=(const MatrixBase<OtherDerived>& other);
00182     template<typename OtherDerived>
00183     Derived& operator-=(const MatrixBase<OtherDerived>& other);
00184 
00185     template<typename OtherDerived>
00186     const typename ProductReturnType<Derived,OtherDerived>::Type
00187     operator*(const MatrixBase<OtherDerived> &other) const;
00188 
00189     template<typename OtherDerived>
00190     const typename LazyProductReturnType<Derived,OtherDerived>::Type
00191     lazyProduct(const MatrixBase<OtherDerived> &other) const;
00192 
00193     template<typename OtherDerived>
00194     Derived& operator*=(const EigenBase<OtherDerived>& other);
00195 
00196     template<typename OtherDerived>
00197     void applyOnTheLeft(const EigenBase<OtherDerived>& other);
00198 
00199     template<typename OtherDerived>
00200     void applyOnTheRight(const EigenBase<OtherDerived>& other);
00201 
00202     template<typename DiagonalDerived>
00203     const DiagonalProduct<Derived, DiagonalDerived, OnTheRight>
00204     operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
00205 
00206     template<typename OtherDerived>
00207     typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
00208     dot(const MatrixBase<OtherDerived>& other) const;
00209 
00210     #ifdef EIGEN2_SUPPORT
00211       template<typename OtherDerived>
00212       Scalar eigen2_dot(const MatrixBase<OtherDerived>& other) const;
00213     #endif
00214 
00215     RealScalar squaredNorm() const;
00216     RealScalar norm() const;
00217     RealScalar stableNorm() const;
00218     RealScalar blueNorm() const;
00219     RealScalar hypotNorm() const;
00220     const PlainObject normalized() const;
00221     void normalize();
00222 
00223     const AdjointReturnType adjoint() const;
00224     void adjointInPlace();
00225 
00226     typedef Diagonal<Derived> DiagonalReturnType;
00227     DiagonalReturnType diagonal();
00228     typedef const Diagonal<const Derived> ConstDiagonalReturnType;
00229     const ConstDiagonalReturnType diagonal() const;
00230 
00231     template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
00232     template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };
00233 
00234     template<int Index> typename DiagonalIndexReturnType<Index>::Type diagonal();
00235     template<int Index> typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;
00236 
00237     // Note: The "MatrixBase::" prefixes are added to help MSVC9 to match these declarations with the later implementations.
00238     // On the other hand they confuse MSVC8...
00239     #if (defined _MSC_VER) && (_MSC_VER >= 1500) // 2008 or later
00240     typename MatrixBase::template DiagonalIndexReturnType<Dynamic>::Type diagonal(Index index);
00241     typename MatrixBase::template ConstDiagonalIndexReturnType<Dynamic>::Type diagonal(Index index) const;
00242     #else
00243     typename DiagonalIndexReturnType<Dynamic>::Type diagonal(Index index);
00244     typename ConstDiagonalIndexReturnType<Dynamic>::Type diagonal(Index index) const;
00245     #endif
00246 
00247     #ifdef EIGEN2_SUPPORT
00248     template<unsigned int Mode> typename internal::eigen2_part_return_type<Derived, Mode>::type part();
00249     template<unsigned int Mode> const typename internal::eigen2_part_return_type<Derived, Mode>::type part() const;
00250     
00251     // huuuge hack. make Eigen2's matrix.part<Diagonal>() work in eigen3. Problem: Diagonal is now a class template instead
00252     // of an integer constant. Solution: overload the part() method template wrt template parameters list.
00253     template<template<typename T, int n> class U>
00254     const DiagonalWrapper<ConstDiagonalReturnType> part() const
00255     { return diagonal().asDiagonal(); }
00256     #endif // EIGEN2_SUPPORT
00257 
00258     template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
00259     template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
00260 
00261     template<unsigned int Mode> typename TriangularViewReturnType<Mode>::Type triangularView();
00262     template<unsigned int Mode> typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
00263 
00264     template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
00265     template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
00266 
00267     template<unsigned int UpLo> typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
00268     template<unsigned int UpLo> typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
00269 
00270     const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
00271                                          typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
00272     static const IdentityReturnType Identity();
00273     static const IdentityReturnType Identity(Index rows, Index cols);
00274     static const BasisReturnType Unit(Index size, Index i);
00275     static const BasisReturnType Unit(Index i);
00276     static const BasisReturnType UnitX();
00277     static const BasisReturnType UnitY();
00278     static const BasisReturnType UnitZ();
00279     static const BasisReturnType UnitW();
00280 
00281     const DiagonalWrapper<const Derived> asDiagonal() const;
00282     const PermutationWrapper<const Derived> asPermutation() const;
00283 
00284     Derived& setIdentity();
00285     Derived& setIdentity(Index rows, Index cols);
00286 
00287     bool isIdentity(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00288     bool isDiagonal(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00289 
00290     bool isUpperTriangular(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00291     bool isLowerTriangular(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00292 
00293     template<typename OtherDerived>
00294     bool isOrthogonal(const MatrixBase<OtherDerived>& other,
00295                       RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00296     bool isUnitary(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00297 
00302     template<typename OtherDerived>
00303     inline bool operator==(const MatrixBase<OtherDerived>& other) const
00304     { return cwiseEqual(other).all(); }
00305 
00310     template<typename OtherDerived>
00311     inline bool operator!=(const MatrixBase<OtherDerived>& other) const
00312     { return cwiseNotEqual(other).any(); }
00313 
00314     NoAlias<Derived,Eigen::MatrixBase > noalias();
00315 
00316     inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00317     inline ForceAlignedAccess<Derived> forceAlignedAccess();
00318     template<bool Enable> inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type forceAlignedAccessIf() const;
00319     template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00320 
00321     Scalar trace() const;
00322 
00324 
00325     template<int p> RealScalar lpNorm() const;
00326 
00327     MatrixBase<Derived>& matrix() { return *this; }
00328     const MatrixBase<Derived>& matrix() const { return *this; }
00329 
00332     ArrayWrapper<Derived> array() { return derived(); }
00333     const ArrayWrapper<Derived> array() const { return derived(); }
00334 
00336 
00337     const FullPivLU<PlainObject> fullPivLu() const;
00338     const PartialPivLU<PlainObject> partialPivLu() const;
00339 
00340     #if EIGEN2_SUPPORT_STAGE < STAGE20_RESOLVE_API_CONFLICTS
00341     const LU<PlainObject> lu() const;
00342     #endif
00343 
00344     #ifdef EIGEN2_SUPPORT
00345     const LU<PlainObject> eigen2_lu() const;
00346     #endif
00347 
00348     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00349     const PartialPivLU<PlainObject> lu() const;
00350     #endif
00351     
00352     #ifdef EIGEN2_SUPPORT
00353     template<typename ResultType>
00354     void computeInverse(MatrixBase<ResultType> *result) const {
00355       *result = this->inverse();
00356     }
00357     #endif
00358 
00359     const internal::inverse_impl<Derived> inverse() const;
00360     template<typename ResultType>
00361     void computeInverseAndDetWithCheck(
00362       ResultType& inverse,
00363       typename ResultType::Scalar& determinant,
00364       bool& invertible,
00365       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00366     ) const;
00367     template<typename ResultType>
00368     void computeInverseWithCheck(
00369       ResultType& inverse,
00370       bool& invertible,
00371       const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
00372     ) const;
00373     Scalar determinant() const;
00374 
00376 
00377     const LLT<PlainObject>  llt() const;
00378     const LDLT<PlainObject> ldlt() const;
00379 
00381 
00382     const HouseholderQR<PlainObject> householderQr() const;
00383     const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
00384     const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
00385     
00386     #ifdef EIGEN2_SUPPORT
00387     const QR<PlainObject> qr() const;
00388     #endif
00389 
00390     EigenvaluesReturnType eigenvalues() const;
00391     RealScalar operatorNorm() const;
00392 
00394 
00395     JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
00396 
00397     #ifdef EIGEN2_SUPPORT
00398     SVD<PlainObject> svd() const;
00399     #endif
00400 
00402 
00403     #ifndef EIGEN_PARSED_BY_DOXYGEN
00404 
00405     template<typename OtherDerived> struct cross_product_return_type {
00406       typedef typename internal::scalar_product_traits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
00407       typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
00408     };
00409     #endif // EIGEN_PARSED_BY_DOXYGEN
00410     template<typename OtherDerived>
00411     typename cross_product_return_type<OtherDerived>::type
00412     cross(const MatrixBase<OtherDerived>& other) const;
00413     template<typename OtherDerived>
00414     PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
00415     PlainObject unitOrthogonal(void) const;
00416     Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
00417     
00418     #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
00419     ScalarMultipleReturnType operator*(const UniformScaling<Scalar>& s) const;
00420     // put this as separate enum value to work around possible GCC 4.3 bug (?)
00421     enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1?Vertical:Horizontal };
00422     typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
00423     HomogeneousReturnType homogeneous() const;
00424     #endif
00425     
00426     enum {
00427       SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
00428     };
00429     typedef Block<const Derived,
00430                   internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
00431                   internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
00432     typedef CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>,
00433                 const ConstStartMinusOne > HNormalizedReturnType;
00434 
00435     const HNormalizedReturnType hnormalized() const;
00436 
00438 
00439     void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
00440     template<typename EssentialPart>
00441     void makeHouseholder(EssentialPart& essential,
00442                          Scalar& tau, RealScalar& beta) const;
00443     template<typename EssentialPart>
00444     void applyHouseholderOnTheLeft(const EssentialPart& essential,
00445                                    const Scalar& tau,
00446                                    Scalar* workspace);
00447     template<typename EssentialPart>
00448     void applyHouseholderOnTheRight(const EssentialPart& essential,
00449                                     const Scalar& tau,
00450                                     Scalar* workspace);
00451 
00453 
00454     template<typename OtherScalar>
00455     void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00456     template<typename OtherScalar>
00457     void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
00458 
00460 
00461     typedef typename internal::stem_function<Scalar>::type StemFunction;
00462     const MatrixExponentialReturnValue<Derived> exp() const;
00463     const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
00464     const MatrixFunctionReturnValue<Derived> cosh() const;
00465     const MatrixFunctionReturnValue<Derived> sinh() const;
00466     const MatrixFunctionReturnValue<Derived> cos() const;
00467     const MatrixFunctionReturnValue<Derived> sin() const;
00468 
00469 #ifdef EIGEN2_SUPPORT
00470     template<typename ProductDerived, typename Lhs, typename Rhs>
00471     Derived& operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00472                                       EvalBeforeAssigningBit>& other);
00473 
00474     template<typename ProductDerived, typename Lhs, typename Rhs>
00475     Derived& operator-=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
00476                                       EvalBeforeAssigningBit>& other);
00477 
00480     template<typename OtherDerived>
00481     Derived& lazyAssign(const Flagged<OtherDerived, 0, EvalBeforeAssigningBit>& other)
00482     { return lazyAssign(other._expression()); }
00483 
00484     template<unsigned int Added>
00485     const Flagged<Derived, Added, 0> marked() const;
00486     const Flagged<Derived, 0, EvalBeforeAssigningBit> lazy() const;
00487 
00488     inline const Cwise<Derived> cwise() const;
00489     inline Cwise<Derived> cwise();
00490 
00491     VectorBlock<Derived> start(Index size);
00492     const VectorBlock<const Derived> start(Index size) const;
00493     VectorBlock<Derived> end(Index size);
00494     const VectorBlock<const Derived> end(Index size) const;
00495     template<int Size> VectorBlock<Derived,Size> start();
00496     template<int Size> const VectorBlock<const Derived,Size> start() const;
00497     template<int Size> VectorBlock<Derived,Size> end();
00498     template<int Size> const VectorBlock<const Derived,Size> end() const;
00499 
00500     Minor<Derived> minor(Index row, Index col);
00501     const Minor<Derived> minor(Index row, Index col) const;
00502 #endif
00503 
00504   protected:
00505     MatrixBase() : Base() {}
00506 
00507   private:
00508     explicit MatrixBase(int);
00509     MatrixBase(int,int);
00510     template<typename OtherDerived> explicit MatrixBase(const MatrixBase<OtherDerived>&);
00511   protected:
00512     // mixing arrays and matrices is not legal
00513     template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
00514     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00515     // mixing arrays and matrices is not legal
00516     template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
00517     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00518 };
00519 
00520 #endif // EIGEN_MATRIXBASE_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:06