DenseBase.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) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008-2010 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_DENSEBASE_H
00012 #define EIGEN_DENSEBASE_H
00013 
00014 namespace Eigen {
00015 
00016 namespace internal {
00017   
00018 // The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
00019 // This dummy function simply aims at checking that at compile time.
00020 static inline void check_DenseIndex_is_signed() {
00021   EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); 
00022 }
00023 
00024 } // end namespace internal
00025   
00041 template<typename Derived> class DenseBase
00042 #ifndef EIGEN_PARSED_BY_DOXYGEN
00043   : public internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00044                                      typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>
00045 #else
00046   : public DenseCoeffsBase<Derived>
00047 #endif // not EIGEN_PARSED_BY_DOXYGEN
00048 {
00049   public:
00050     using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00051                 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
00052 
00053     class InnerIterator;
00054 
00055     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00056 
00061     typedef typename internal::traits<Derived>::Index Index; 
00062 
00063     typedef typename internal::traits<Derived>::Scalar Scalar;
00064     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00065     typedef typename NumTraits<Scalar>::Real RealScalar;
00066 
00067     typedef DenseCoeffsBase<Derived> Base;
00068     using Base::derived;
00069     using Base::const_cast_derived;
00070     using Base::rows;
00071     using Base::cols;
00072     using Base::size;
00073     using Base::rowIndexByOuterInner;
00074     using Base::colIndexByOuterInner;
00075     using Base::coeff;
00076     using Base::coeffByOuterInner;
00077     using Base::packet;
00078     using Base::packetByOuterInner;
00079     using Base::writePacket;
00080     using Base::writePacketByOuterInner;
00081     using Base::coeffRef;
00082     using Base::coeffRefByOuterInner;
00083     using Base::copyCoeff;
00084     using Base::copyCoeffByOuterInner;
00085     using Base::copyPacket;
00086     using Base::copyPacketByOuterInner;
00087     using Base::operator();
00088     using Base::operator[];
00089     using Base::x;
00090     using Base::y;
00091     using Base::z;
00092     using Base::w;
00093     using Base::stride;
00094     using Base::innerStride;
00095     using Base::outerStride;
00096     using Base::rowStride;
00097     using Base::colStride;
00098     typedef typename Base::CoeffReturnType CoeffReturnType;
00099 
00100     enum {
00101 
00102       RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00108       ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00115       SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
00116                                                    internal::traits<Derived>::ColsAtCompileTime>::ret),
00121       MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
00132       MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
00143       MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
00144                                                       internal::traits<Derived>::MaxColsAtCompileTime>::ret),
00155       IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
00156                            || internal::traits<Derived>::MaxColsAtCompileTime == 1,
00162       Flags = internal::traits<Derived>::Flags,
00167       IsRowMajor = int(Flags) & RowMajorBit, 
00169       InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
00170                              : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
00171 
00172       CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
00177       InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
00178       OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
00179     };
00180 
00181     enum { ThisConstantIsPrivateInPlainObjectBase };
00182 
00185     inline Index nonZeros() const { return size(); }
00196     Index outerSize() const
00197     {
00198       return IsVectorAtCompileTime ? 1
00199            : int(IsRowMajor) ? this->rows() : this->cols();
00200     }
00201 
00207     Index innerSize() const
00208     {
00209       return IsVectorAtCompileTime ? this->size()
00210            : int(IsRowMajor) ? this->cols() : this->rows();
00211     }
00212 
00217     void resize(Index newSize)
00218     {
00219       EIGEN_ONLY_USED_FOR_DEBUG(newSize);
00220       eigen_assert(newSize == this->size()
00221                 && "DenseBase::resize() does not actually allow to resize.");
00222     }
00227     void resize(Index nbRows, Index nbCols)
00228     {
00229       EIGEN_ONLY_USED_FOR_DEBUG(nbRows);
00230       EIGEN_ONLY_USED_FOR_DEBUG(nbCols);
00231       eigen_assert(nbRows == this->rows() && nbCols == this->cols()
00232                 && "DenseBase::resize() does not actually allow to resize.");
00233     }
00234 
00235 #ifndef EIGEN_PARSED_BY_DOXYGEN
00236 
00238     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00240     typedef CwiseNullaryOp<internal::linspaced_op<Scalar,false>,Derived> SequentialLinSpacedReturnType;
00242     typedef CwiseNullaryOp<internal::linspaced_op<Scalar,true>,Derived> RandomAccessLinSpacedReturnType;
00244     typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
00245 
00246 #endif // not EIGEN_PARSED_BY_DOXYGEN
00247 
00249     template<typename OtherDerived>
00250     Derived& operator=(const DenseBase<OtherDerived>& other);
00251 
00255     Derived& operator=(const DenseBase& other);
00256 
00257     template<typename OtherDerived>
00258     Derived& operator=(const EigenBase<OtherDerived> &other);
00259 
00260     template<typename OtherDerived>
00261     Derived& operator+=(const EigenBase<OtherDerived> &other);
00262 
00263     template<typename OtherDerived>
00264     Derived& operator-=(const EigenBase<OtherDerived> &other);
00265 
00266     template<typename OtherDerived>
00267     Derived& operator=(const ReturnByValue<OtherDerived>& func);
00268 
00269 #ifndef EIGEN_PARSED_BY_DOXYGEN
00270 
00271     template<typename OtherDerived>
00272     Derived& lazyAssign(const DenseBase<OtherDerived>& other);
00273 #endif // not EIGEN_PARSED_BY_DOXYGEN
00274 
00275     CommaInitializer<Derived> operator<< (const Scalar& s);
00276 
00277     template<unsigned int Added,unsigned int Removed>
00278     const Flagged<Derived, Added, Removed> flagged() const;
00279 
00280     template<typename OtherDerived>
00281     CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
00282 
00283     Eigen::Transpose<Derived> transpose();
00284         typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
00285     ConstTransposeReturnType transpose() const;
00286     void transposeInPlace();
00287 #ifndef EIGEN_NO_DEBUG
00288   protected:
00289     template<typename OtherDerived>
00290     void checkTransposeAliasing(const OtherDerived& other) const;
00291   public:
00292 #endif
00293 
00294 
00295     static const ConstantReturnType
00296     Constant(Index rows, Index cols, const Scalar& value);
00297     static const ConstantReturnType
00298     Constant(Index size, const Scalar& value);
00299     static const ConstantReturnType
00300     Constant(const Scalar& value);
00301 
00302     static const SequentialLinSpacedReturnType
00303     LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
00304     static const RandomAccessLinSpacedReturnType
00305     LinSpaced(Index size, const Scalar& low, const Scalar& high);
00306     static const SequentialLinSpacedReturnType
00307     LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
00308     static const RandomAccessLinSpacedReturnType
00309     LinSpaced(const Scalar& low, const Scalar& high);
00310 
00311     template<typename CustomNullaryOp>
00312     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00313     NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
00314     template<typename CustomNullaryOp>
00315     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00316     NullaryExpr(Index size, const CustomNullaryOp& func);
00317     template<typename CustomNullaryOp>
00318     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00319     NullaryExpr(const CustomNullaryOp& func);
00320 
00321     static const ConstantReturnType Zero(Index rows, Index cols);
00322     static const ConstantReturnType Zero(Index size);
00323     static const ConstantReturnType Zero();
00324     static const ConstantReturnType Ones(Index rows, Index cols);
00325     static const ConstantReturnType Ones(Index size);
00326     static const ConstantReturnType Ones();
00327 
00328     void fill(const Scalar& value);
00329     Derived& setConstant(const Scalar& value);
00330     Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
00331     Derived& setLinSpaced(const Scalar& low, const Scalar& high);
00332     Derived& setZero();
00333     Derived& setOnes();
00334     Derived& setRandom();
00335 
00336     template<typename OtherDerived>
00337     bool isApprox(const DenseBase<OtherDerived>& other,
00338                   const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00339     bool isMuchSmallerThan(const RealScalar& other,
00340                            const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00341     template<typename OtherDerived>
00342     bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
00343                            const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00344 
00345     bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00346     bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00347     bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00348     bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
00349     
00350     inline bool hasNaN() const;
00351     inline bool allFinite() const;
00352 
00353     inline Derived& operator*=(const Scalar& other);
00354     inline Derived& operator/=(const Scalar& other);
00355 
00356     typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
00362     EIGEN_STRONG_INLINE EvalReturnType eval() const
00363     {
00364       // Even though MSVC does not honor strong inlining when the return type
00365       // is a dynamic matrix, we desperately need strong inlining for fixed
00366       // size types on MSVC.
00367       return typename internal::eval<Derived>::type(derived());
00368     }
00369 
00373     template<typename OtherDerived>
00374     void swap(const DenseBase<OtherDerived>& other,
00375               int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
00376     {
00377       SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00378     }
00379 
00383     template<typename OtherDerived>
00384     void swap(PlainObjectBase<OtherDerived>& other)
00385     {
00386       SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00387     }
00388 
00389 
00390     inline const NestByValue<Derived> nestByValue() const;
00391     inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00392     inline ForceAlignedAccess<Derived> forceAlignedAccess();
00393     template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
00394     template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00395 
00396     Scalar sum() const;
00397     Scalar mean() const;
00398     Scalar trace() const;
00399 
00400     Scalar prod() const;
00401 
00402     typename internal::traits<Derived>::Scalar minCoeff() const;
00403     typename internal::traits<Derived>::Scalar maxCoeff() const;
00404 
00405     template<typename IndexType>
00406     typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
00407     template<typename IndexType>
00408     typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
00409     template<typename IndexType>
00410     typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
00411     template<typename IndexType>
00412     typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
00413 
00414     template<typename BinaryOp>
00415     typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type
00416     redux(const BinaryOp& func) const;
00417 
00418     template<typename Visitor>
00419     void visit(Visitor& func) const;
00420 
00421     inline const WithFormat<Derived> format(const IOFormat& fmt) const;
00422 
00424     CoeffReturnType value() const
00425     {
00426       EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
00427       eigen_assert(this->rows() == 1 && this->cols() == 1);
00428       return derived().coeff(0,0);
00429     }
00430 
00431     bool all(void) const;
00432     bool any(void) const;
00433     Index count() const;
00434 
00435     typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
00436     typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
00437     typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
00438     typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
00439 
00440     ConstRowwiseReturnType rowwise() const;
00441     RowwiseReturnType rowwise();
00442     ConstColwiseReturnType colwise() const;
00443     ColwiseReturnType colwise();
00444 
00445     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols);
00446     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size);
00447     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
00448 
00449     template<typename ThenDerived,typename ElseDerived>
00450     const Select<Derived,ThenDerived,ElseDerived>
00451     select(const DenseBase<ThenDerived>& thenMatrix,
00452            const DenseBase<ElseDerived>& elseMatrix) const;
00453 
00454     template<typename ThenDerived>
00455     inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
00456     select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
00457 
00458     template<typename ElseDerived>
00459     inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
00460     select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
00461 
00462     template<int p> RealScalar lpNorm() const;
00463 
00464     template<int RowFactor, int ColFactor>
00465     const Replicate<Derived,RowFactor,ColFactor> replicate() const;
00466     const Replicate<Derived,Dynamic,Dynamic> replicate(Index rowFacor,Index colFactor) const;
00467 
00468     typedef Reverse<Derived, BothDirections> ReverseReturnType;
00469     typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
00470     ReverseReturnType reverse();
00471     ConstReverseReturnType reverse() const;
00472     void reverseInPlace();
00473 
00474 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
00475 #   include "../plugins/BlockMethods.h"
00476 #   ifdef EIGEN_DENSEBASE_PLUGIN
00477 #     include EIGEN_DENSEBASE_PLUGIN
00478 #   endif
00479 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00480 
00481 #ifdef EIGEN2_SUPPORT
00482 
00483     Block<Derived> corner(CornerType type, Index cRows, Index cCols);
00484     const Block<Derived> corner(CornerType type, Index cRows, Index cCols) const;
00485     template<int CRows, int CCols>
00486     Block<Derived, CRows, CCols> corner(CornerType type);
00487     template<int CRows, int CCols>
00488     const Block<Derived, CRows, CCols> corner(CornerType type) const;
00489 
00490 #endif // EIGEN2_SUPPORT
00491 
00492 
00493     // disable the use of evalTo for dense objects with a nice compilation error
00494     template<typename Dest> inline void evalTo(Dest& ) const
00495     {
00496       EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
00497     }
00498 
00499   protected:
00501     DenseBase()
00502     {
00503       /* Just checks for self-consistency of the flags.
00504        * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down
00505        */
00506 #ifdef EIGEN_INTERNAL_DEBUGGING
00507       EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
00508                         && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
00509                           INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
00510 #endif
00511     }
00512 
00513   private:
00514     explicit DenseBase(int);
00515     DenseBase(int,int);
00516     template<typename OtherDerived> explicit DenseBase(const DenseBase<OtherDerived>&);
00517 };
00518 
00519 } // end namespace Eigen
00520 
00521 #endif // EIGEN_DENSEBASE_H


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