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 
00031 template<typename Derived> class DenseBase
00032 #ifndef EIGEN_PARSED_BY_DOXYGEN
00033   : public internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00034                                      typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>
00035 #else
00036   : public DenseCoeffsBase<Derived>
00037 #endif // not EIGEN_PARSED_BY_DOXYGEN
00038 {
00039   public:
00040     using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00041                 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
00042 
00043     class InnerIterator;
00044 
00045     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00046 
00051     typedef typename internal::traits<Derived>::Index Index; 
00052 
00053     typedef typename internal::traits<Derived>::Scalar Scalar;
00054     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00055     typedef typename NumTraits<Scalar>::Real RealScalar;
00056 
00057     typedef DenseCoeffsBase<Derived> Base;
00058     using Base::derived;
00059     using Base::const_cast_derived;
00060     using Base::rows;
00061     using Base::cols;
00062     using Base::size;
00063     using Base::rowIndexByOuterInner;
00064     using Base::colIndexByOuterInner;
00065     using Base::coeff;
00066     using Base::coeffByOuterInner;
00067     using Base::packet;
00068     using Base::packetByOuterInner;
00069     using Base::writePacket;
00070     using Base::writePacketByOuterInner;
00071     using Base::coeffRef;
00072     using Base::coeffRefByOuterInner;
00073     using Base::copyCoeff;
00074     using Base::copyCoeffByOuterInner;
00075     using Base::copyPacket;
00076     using Base::copyPacketByOuterInner;
00077     using Base::operator();
00078     using Base::operator[];
00079     using Base::x;
00080     using Base::y;
00081     using Base::z;
00082     using Base::w;
00083     using Base::stride;
00084     using Base::innerStride;
00085     using Base::outerStride;
00086     using Base::rowStride;
00087     using Base::colStride;
00088     typedef typename Base::CoeffReturnType CoeffReturnType;
00089 
00090     enum {
00091 
00092       RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00098       ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00105       SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
00106                                                    internal::traits<Derived>::ColsAtCompileTime>::ret),
00111       MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
00122       MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
00133       MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
00134                                                       internal::traits<Derived>::MaxColsAtCompileTime>::ret),
00145       IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
00146                            || internal::traits<Derived>::MaxColsAtCompileTime == 1,
00152       Flags = internal::traits<Derived>::Flags,
00157       IsRowMajor = int(Flags) & RowMajorBit, 
00159       InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
00160                              : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
00161 
00162       CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
00167       InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
00168       OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
00169     };
00170 
00171     enum { ThisConstantIsPrivateInPlainObjectBase };
00172 
00175     inline Index nonZeros() const { return size(); }
00186     Index outerSize() const
00187     {
00188       return IsVectorAtCompileTime ? 1
00189            : int(IsRowMajor) ? this->rows() : this->cols();
00190     }
00191 
00197     Index innerSize() const
00198     {
00199       return IsVectorAtCompileTime ? this->size()
00200            : int(IsRowMajor) ? this->cols() : this->rows();
00201     }
00202 
00207     void resize(Index size)
00208     {
00209       EIGEN_ONLY_USED_FOR_DEBUG(size);
00210       eigen_assert(size == this->size()
00211                 && "DenseBase::resize() does not actually allow to resize.");
00212     }
00217     void resize(Index rows, Index cols)
00218     {
00219       EIGEN_ONLY_USED_FOR_DEBUG(rows);
00220       EIGEN_ONLY_USED_FOR_DEBUG(cols);
00221       eigen_assert(rows == this->rows() && cols == this->cols()
00222                 && "DenseBase::resize() does not actually allow to resize.");
00223     }
00224 
00225 #ifndef EIGEN_PARSED_BY_DOXYGEN
00226 
00228     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00230     typedef CwiseNullaryOp<internal::linspaced_op<Scalar,false>,Derived> SequentialLinSpacedReturnType;
00232     typedef CwiseNullaryOp<internal::linspaced_op<Scalar,true>,Derived> RandomAccessLinSpacedReturnType;
00234     typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
00235 
00236 #endif // not EIGEN_PARSED_BY_DOXYGEN
00237 
00239     template<typename OtherDerived>
00240     Derived& operator=(const DenseBase<OtherDerived>& other);
00241 
00245     Derived& operator=(const DenseBase& other);
00246 
00247     template<typename OtherDerived>
00248     Derived& operator=(const EigenBase<OtherDerived> &other);
00249 
00250     template<typename OtherDerived>
00251     Derived& operator+=(const EigenBase<OtherDerived> &other);
00252 
00253     template<typename OtherDerived>
00254     Derived& operator-=(const EigenBase<OtherDerived> &other);
00255 
00256     template<typename OtherDerived>
00257     Derived& operator=(const ReturnByValue<OtherDerived>& func);
00258 
00259 #ifndef EIGEN_PARSED_BY_DOXYGEN
00260 
00261     template<typename OtherDerived>
00262     Derived& lazyAssign(const DenseBase<OtherDerived>& other);
00263 #endif // not EIGEN_PARSED_BY_DOXYGEN
00264 
00265     CommaInitializer<Derived> operator<< (const Scalar& s);
00266 
00267     template<unsigned int Added,unsigned int Removed>
00268     const Flagged<Derived, Added, Removed> flagged() const;
00269 
00270     template<typename OtherDerived>
00271     CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
00272 
00273     Eigen::Transpose<Derived> transpose();
00274     typedef const Transpose<const Derived> ConstTransposeReturnType;
00275     ConstTransposeReturnType transpose() const;
00276     void transposeInPlace();
00277 #ifndef EIGEN_NO_DEBUG
00278   protected:
00279     template<typename OtherDerived>
00280     void checkTransposeAliasing(const OtherDerived& other) const;
00281   public:
00282 #endif
00283 
00284     typedef VectorBlock<Derived> SegmentReturnType;
00285     typedef const VectorBlock<const Derived> ConstSegmentReturnType;
00286     template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; };
00287     template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; };
00288     
00289     // Note: The "DenseBase::" prefixes are added to help MSVC9 to match these declarations with the later implementations.
00290     SegmentReturnType segment(Index start, Index size);
00291     typename DenseBase::ConstSegmentReturnType segment(Index start, Index size) const;
00292 
00293     SegmentReturnType head(Index size);
00294     typename DenseBase::ConstSegmentReturnType head(Index size) const;
00295 
00296     SegmentReturnType tail(Index size);
00297     typename DenseBase::ConstSegmentReturnType tail(Index size) const;
00298 
00299     template<int Size> typename FixedSegmentReturnType<Size>::Type head();
00300     template<int Size> typename ConstFixedSegmentReturnType<Size>::Type head() const;
00301 
00302     template<int Size> typename FixedSegmentReturnType<Size>::Type tail();
00303     template<int Size> typename ConstFixedSegmentReturnType<Size>::Type tail() const;
00304 
00305     template<int Size> typename FixedSegmentReturnType<Size>::Type segment(Index start);
00306     template<int Size> typename ConstFixedSegmentReturnType<Size>::Type segment(Index start) const;
00307 
00308     static const ConstantReturnType
00309     Constant(Index rows, Index cols, const Scalar& value);
00310     static const ConstantReturnType
00311     Constant(Index size, const Scalar& value);
00312     static const ConstantReturnType
00313     Constant(const Scalar& value);
00314 
00315     static const SequentialLinSpacedReturnType
00316     LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
00317     static const RandomAccessLinSpacedReturnType
00318     LinSpaced(Index size, const Scalar& low, const Scalar& high);
00319     static const SequentialLinSpacedReturnType
00320     LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
00321     static const RandomAccessLinSpacedReturnType
00322     LinSpaced(const Scalar& low, const Scalar& high);
00323 
00324     template<typename CustomNullaryOp>
00325     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00326     NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
00327     template<typename CustomNullaryOp>
00328     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00329     NullaryExpr(Index size, const CustomNullaryOp& func);
00330     template<typename CustomNullaryOp>
00331     static const CwiseNullaryOp<CustomNullaryOp, Derived>
00332     NullaryExpr(const CustomNullaryOp& func);
00333 
00334     static const ConstantReturnType Zero(Index rows, Index cols);
00335     static const ConstantReturnType Zero(Index size);
00336     static const ConstantReturnType Zero();
00337     static const ConstantReturnType Ones(Index rows, Index cols);
00338     static const ConstantReturnType Ones(Index size);
00339     static const ConstantReturnType Ones();
00340 
00341     void fill(const Scalar& value);
00342     Derived& setConstant(const Scalar& value);
00343     Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
00344     Derived& setLinSpaced(const Scalar& low, const Scalar& high);
00345     Derived& setZero();
00346     Derived& setOnes();
00347     Derived& setRandom();
00348 
00349     template<typename OtherDerived>
00350     bool isApprox(const DenseBase<OtherDerived>& other,
00351                   RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00352     bool isMuchSmallerThan(const RealScalar& other,
00353                            RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00354     template<typename OtherDerived>
00355     bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
00356                            RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00357 
00358     bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00359     bool isConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00360     bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00361     bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00362 
00363     inline Derived& operator*=(const Scalar& other);
00364     inline Derived& operator/=(const Scalar& other);
00365 
00366     typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
00372     EIGEN_STRONG_INLINE EvalReturnType eval() const
00373     {
00374       // Even though MSVC does not honor strong inlining when the return type
00375       // is a dynamic matrix, we desperately need strong inlining for fixed
00376       // size types on MSVC.
00377       return typename internal::eval<Derived>::type(derived());
00378     }
00379 
00383     template<typename OtherDerived>
00384     void swap(const DenseBase<OtherDerived>& other,
00385               int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
00386     {
00387       SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00388     }
00389 
00393     template<typename OtherDerived>
00394     void swap(PlainObjectBase<OtherDerived>& other)
00395     {
00396       SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00397     }
00398 
00399 
00400     inline const NestByValue<Derived> nestByValue() const;
00401     inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00402     inline ForceAlignedAccess<Derived> forceAlignedAccess();
00403     template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
00404     template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00405 
00406     Scalar sum() const;
00407     Scalar mean() const;
00408     Scalar trace() const;
00409 
00410     Scalar prod() const;
00411 
00412     typename internal::traits<Derived>::Scalar minCoeff() const;
00413     typename internal::traits<Derived>::Scalar maxCoeff() const;
00414 
00415     template<typename IndexType>
00416     typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
00417     template<typename IndexType>
00418     typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
00419     template<typename IndexType>
00420     typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
00421     template<typename IndexType>
00422     typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
00423 
00424     template<typename BinaryOp>
00425     typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type
00426     redux(const BinaryOp& func) const;
00427 
00428     template<typename Visitor>
00429     void visit(Visitor& func) const;
00430 
00431     inline const WithFormat<Derived> format(const IOFormat& fmt) const;
00432 
00434     CoeffReturnType value() const
00435     {
00436       EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
00437       eigen_assert(this->rows() == 1 && this->cols() == 1);
00438       return derived().coeff(0,0);
00439     }
00440 
00442 
00443     bool all(void) const;
00444     bool any(void) const;
00445     Index count() const;
00446 
00447     typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
00448     typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
00449     typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
00450     typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
00451 
00452     ConstRowwiseReturnType rowwise() const;
00453     RowwiseReturnType rowwise();
00454     ConstColwiseReturnType colwise() const;
00455     ColwiseReturnType colwise();
00456 
00457     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols);
00458     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size);
00459     static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
00460 
00461     template<typename ThenDerived,typename ElseDerived>
00462     const Select<Derived,ThenDerived,ElseDerived>
00463     select(const DenseBase<ThenDerived>& thenMatrix,
00464            const DenseBase<ElseDerived>& elseMatrix) const;
00465 
00466     template<typename ThenDerived>
00467     inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
00468     select(const DenseBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
00469 
00470     template<typename ElseDerived>
00471     inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
00472     select(typename ElseDerived::Scalar thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
00473 
00474     template<int p> RealScalar lpNorm() const;
00475 
00476     template<int RowFactor, int ColFactor>
00477     const Replicate<Derived,RowFactor,ColFactor> replicate() const;
00478     const Replicate<Derived,Dynamic,Dynamic> replicate(Index rowFacor,Index colFactor) const;
00479 
00480     typedef Reverse<Derived, BothDirections> ReverseReturnType;
00481     typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
00482     ReverseReturnType reverse();
00483     ConstReverseReturnType reverse() const;
00484     void reverseInPlace();
00485 
00486 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
00487 #   include "../plugins/BlockMethods.h"
00488 #   ifdef EIGEN_DENSEBASE_PLUGIN
00489 #     include EIGEN_DENSEBASE_PLUGIN
00490 #   endif
00491 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00492 
00493 #ifdef EIGEN2_SUPPORT
00494 
00495     Block<Derived> corner(CornerType type, Index cRows, Index cCols);
00496     const Block<Derived> corner(CornerType type, Index cRows, Index cCols) const;
00497     template<int CRows, int CCols>
00498     Block<Derived, CRows, CCols> corner(CornerType type);
00499     template<int CRows, int CCols>
00500     const Block<Derived, CRows, CCols> corner(CornerType type) const;
00501 
00502 #endif // EIGEN2_SUPPORT
00503 
00504 
00505     // disable the use of evalTo for dense objects with a nice compilation error
00506     template<typename Dest> inline void evalTo(Dest& ) const
00507     {
00508       EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
00509     }
00510 
00511   protected:
00513     DenseBase()
00514     {
00515       /* Just checks for self-consistency of the flags.
00516        * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down
00517        */
00518 #ifdef EIGEN_INTERNAL_DEBUGGING
00519       EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
00520                         && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
00521                           INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
00522 #endif
00523     }
00524 
00525   private:
00526     explicit DenseBase(int);
00527     DenseBase(int,int);
00528     template<typename OtherDerived> explicit DenseBase(const DenseBase<OtherDerived>&);
00529 };
00530 
00531 } // end namespace Eigen
00532 
00533 #endif // EIGEN_DENSEBASE_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:22