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


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:37