00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 typedef typename internal::traits<Derived>::Index Index;
00060 typedef typename internal::traits<Derived>::Scalar Scalar;
00061 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00062 typedef typename NumTraits<Scalar>::Real RealScalar;
00063
00064 typedef DenseCoeffsBase<Derived> Base;
00065 using Base::derived;
00066 using Base::const_cast_derived;
00067 using Base::rows;
00068 using Base::cols;
00069 using Base::size;
00070 using Base::rowIndexByOuterInner;
00071 using Base::colIndexByOuterInner;
00072 using Base::coeff;
00073 using Base::coeffByOuterInner;
00074 using Base::packet;
00075 using Base::packetByOuterInner;
00076 using Base::writePacket;
00077 using Base::writePacketByOuterInner;
00078 using Base::coeffRef;
00079 using Base::coeffRefByOuterInner;
00080 using Base::copyCoeff;
00081 using Base::copyCoeffByOuterInner;
00082 using Base::copyPacket;
00083 using Base::copyPacketByOuterInner;
00084 using Base::operator();
00085 using Base::operator[];
00086 using Base::x;
00087 using Base::y;
00088 using Base::z;
00089 using Base::w;
00090 using Base::stride;
00091 using Base::innerStride;
00092 using Base::outerStride;
00093 using Base::rowStride;
00094 using Base::colStride;
00095 typedef typename Base::CoeffReturnType CoeffReturnType;
00096
00097 enum {
00098
00099 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00105 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00112 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
00113 internal::traits<Derived>::ColsAtCompileTime>::ret),
00118 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
00129 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
00140 MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
00141 internal::traits<Derived>::MaxColsAtCompileTime>::ret),
00152 IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
00153 || internal::traits<Derived>::MaxColsAtCompileTime == 1,
00159 Flags = internal::traits<Derived>::Flags,
00164 IsRowMajor = int(Flags) & RowMajorBit,
00166 InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? SizeAtCompileTime
00167 : int(IsRowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
00168
00169 CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
00174 InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
00175 OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
00176 };
00177
00178 enum { ThisConstantIsPrivateInPlainObjectBase };
00179
00182 inline Index nonZeros() const { return size(); }
00193 Index outerSize() const
00194 {
00195 return IsVectorAtCompileTime ? 1
00196 : int(IsRowMajor) ? this->rows() : this->cols();
00197 }
00198
00204 Index innerSize() const
00205 {
00206 return IsVectorAtCompileTime ? this->size()
00207 : int(IsRowMajor) ? this->cols() : this->rows();
00208 }
00209
00214 void resize(Index size)
00215 {
00216 EIGEN_ONLY_USED_FOR_DEBUG(size);
00217 eigen_assert(size == this->size()
00218 && "DenseBase::resize() does not actually allow to resize.");
00219 }
00224 void resize(Index rows, Index cols)
00225 {
00226 EIGEN_ONLY_USED_FOR_DEBUG(rows);
00227 EIGEN_ONLY_USED_FOR_DEBUG(cols);
00228 eigen_assert(rows == this->rows() && cols == this->cols()
00229 && "DenseBase::resize() does not actually allow to resize.");
00230 }
00231
00232 #ifndef EIGEN_PARSED_BY_DOXYGEN
00233
00235 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00237 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,false>,Derived> SequentialLinSpacedReturnType;
00239 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,true>,Derived> RandomAccessLinSpacedReturnType;
00241 typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
00242
00243 #endif // not EIGEN_PARSED_BY_DOXYGEN
00244
00246 template<typename OtherDerived>
00247 Derived& operator=(const DenseBase<OtherDerived>& other);
00248
00252 Derived& operator=(const DenseBase& other);
00253
00254 template<typename OtherDerived>
00255 Derived& operator=(const EigenBase<OtherDerived> &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 ReturnByValue<OtherDerived>& func);
00265
00266 #ifndef EIGEN_PARSED_BY_DOXYGEN
00267
00268 template<typename OtherDerived>
00269 Derived& lazyAssign(const DenseBase<OtherDerived>& other);
00270 #endif // not EIGEN_PARSED_BY_DOXYGEN
00271
00272 CommaInitializer<Derived> operator<< (const Scalar& s);
00273
00274 template<unsigned int Added,unsigned int Removed>
00275 const Flagged<Derived, Added, Removed> flagged() const;
00276
00277 template<typename OtherDerived>
00278 CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
00279
00280 Eigen::Transpose<Derived> transpose();
00281 typedef const Transpose<const Derived> ConstTransposeReturnType;
00282 ConstTransposeReturnType transpose() const;
00283 void transposeInPlace();
00284 #ifndef EIGEN_NO_DEBUG
00285 protected:
00286 template<typename OtherDerived>
00287 void checkTransposeAliasing(const OtherDerived& other) const;
00288 public:
00289 #endif
00290
00291 typedef VectorBlock<Derived> SegmentReturnType;
00292 typedef const VectorBlock<const Derived> ConstSegmentReturnType;
00293 template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; };
00294 template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; };
00295
00296
00297 SegmentReturnType segment(Index start, Index size);
00298 typename DenseBase::ConstSegmentReturnType segment(Index start, Index size) const;
00299
00300 SegmentReturnType head(Index size);
00301 typename DenseBase::ConstSegmentReturnType head(Index size) const;
00302
00303 SegmentReturnType tail(Index size);
00304 typename DenseBase::ConstSegmentReturnType tail(Index size) const;
00305
00306 template<int Size> typename FixedSegmentReturnType<Size>::Type head();
00307 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type head() const;
00308
00309 template<int Size> typename FixedSegmentReturnType<Size>::Type tail();
00310 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type tail() const;
00311
00312 template<int Size> typename FixedSegmentReturnType<Size>::Type segment(Index start);
00313 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type segment(Index start) const;
00314
00315 static const ConstantReturnType
00316 Constant(Index rows, Index cols, const Scalar& value);
00317 static const ConstantReturnType
00318 Constant(Index size, const Scalar& value);
00319 static const ConstantReturnType
00320 Constant(const Scalar& value);
00321
00322 static const SequentialLinSpacedReturnType
00323 LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
00324 static const RandomAccessLinSpacedReturnType
00325 LinSpaced(Index size, const Scalar& low, const Scalar& high);
00326 static const SequentialLinSpacedReturnType
00327 LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
00328 static const RandomAccessLinSpacedReturnType
00329 LinSpaced(const Scalar& low, const Scalar& high);
00330
00331 template<typename CustomNullaryOp>
00332 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00333 NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
00334 template<typename CustomNullaryOp>
00335 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00336 NullaryExpr(Index size, const CustomNullaryOp& func);
00337 template<typename CustomNullaryOp>
00338 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00339 NullaryExpr(const CustomNullaryOp& func);
00340
00341 static const ConstantReturnType Zero(Index rows, Index cols);
00342 static const ConstantReturnType Zero(Index size);
00343 static const ConstantReturnType Zero();
00344 static const ConstantReturnType Ones(Index rows, Index cols);
00345 static const ConstantReturnType Ones(Index size);
00346 static const ConstantReturnType Ones();
00347
00348 void fill(const Scalar& value);
00349 Derived& setConstant(const Scalar& value);
00350 Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
00351 Derived& setLinSpaced(const Scalar& low, const Scalar& high);
00352 Derived& setZero();
00353 Derived& setOnes();
00354 Derived& setRandom();
00355
00356 template<typename OtherDerived>
00357 bool isApprox(const DenseBase<OtherDerived>& other,
00358 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00359 bool isMuchSmallerThan(const RealScalar& other,
00360 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00361 template<typename OtherDerived>
00362 bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
00363 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00364
00365 bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00366 bool isConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00367 bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00368 bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00369
00370 inline Derived& operator*=(const Scalar& other);
00371 inline Derived& operator/=(const Scalar& other);
00372
00378 EIGEN_STRONG_INLINE const typename internal::eval<Derived>::type eval() const
00379 {
00380
00381
00382
00383 return typename internal::eval<Derived>::type(derived());
00384 }
00385
00389 template<typename OtherDerived>
00390 void swap(const DenseBase<OtherDerived>& other,
00391 int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
00392 {
00393 SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00394 }
00395
00399 template<typename OtherDerived>
00400 void swap(PlainObjectBase<OtherDerived>& other)
00401 {
00402 SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00403 }
00404
00405
00406 inline const NestByValue<Derived> nestByValue() const;
00407 inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00408 inline ForceAlignedAccess<Derived> forceAlignedAccess();
00409 template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
00410 template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00411
00412 Scalar sum() const;
00413 Scalar mean() const;
00414 Scalar trace() const;
00415
00416 Scalar prod() const;
00417
00418 typename internal::traits<Derived>::Scalar minCoeff() const;
00419 typename internal::traits<Derived>::Scalar maxCoeff() const;
00420
00421 template<typename IndexType>
00422 typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
00423 template<typename IndexType>
00424 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
00425 template<typename IndexType>
00426 typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
00427 template<typename IndexType>
00428 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
00429
00430 template<typename BinaryOp>
00431 typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type
00432 redux(const BinaryOp& func) const;
00433
00434 template<typename Visitor>
00435 void visit(Visitor& func) const;
00436
00437 inline const WithFormat<Derived> format(const IOFormat& fmt) const;
00438
00440 CoeffReturnType value() const
00441 {
00442 EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
00443 eigen_assert(this->rows() == 1 && this->cols() == 1);
00444 return derived().coeff(0,0);
00445 }
00446
00448
00449 bool all(void) const;
00450 bool any(void) const;
00451 Index count() const;
00452
00453 typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
00454 typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
00455 typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
00456 typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
00457
00458 ConstRowwiseReturnType rowwise() const;
00459 RowwiseReturnType rowwise();
00460 ConstColwiseReturnType colwise() const;
00461 ColwiseReturnType colwise();
00462
00463 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols);
00464 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size);
00465 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
00466
00467 template<typename ThenDerived,typename ElseDerived>
00468 const Select<Derived,ThenDerived,ElseDerived>
00469 select(const DenseBase<ThenDerived>& thenMatrix,
00470 const DenseBase<ElseDerived>& elseMatrix) const;
00471
00472 template<typename ThenDerived>
00473 inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
00474 select(const DenseBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
00475
00476 template<typename ElseDerived>
00477 inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
00478 select(typename ElseDerived::Scalar thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
00479
00480 template<int p> RealScalar lpNorm() const;
00481
00482 template<int RowFactor, int ColFactor>
00483 const Replicate<Derived,RowFactor,ColFactor> replicate() const;
00484 const Replicate<Derived,Dynamic,Dynamic> replicate(Index rowFacor,Index colFactor) const;
00485
00486 typedef Reverse<Derived, BothDirections> ReverseReturnType;
00487 typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
00488 ReverseReturnType reverse();
00489 ConstReverseReturnType reverse() const;
00490 void reverseInPlace();
00491
00492 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
00493 # include "../plugins/BlockMethods.h"
00494 # ifdef EIGEN_DENSEBASE_PLUGIN
00495 # include EIGEN_DENSEBASE_PLUGIN
00496 # endif
00497 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00498
00499 #ifdef EIGEN2_SUPPORT
00500
00501 Block<Derived> corner(CornerType type, Index cRows, Index cCols);
00502 const Block<Derived> corner(CornerType type, Index cRows, Index cCols) const;
00503 template<int CRows, int CCols>
00504 Block<Derived, CRows, CCols> corner(CornerType type);
00505 template<int CRows, int CCols>
00506 const Block<Derived, CRows, CCols> corner(CornerType type) const;
00507
00508 #endif // EIGEN2_SUPPORT
00509
00510
00511
00512 template<typename Dest> inline void evalTo(Dest& ) const
00513 {
00514 EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
00515 }
00516
00517 protected:
00519 DenseBase()
00520 {
00521
00522
00523
00524 #ifdef EIGEN_INTERNAL_DEBUGGING
00525 EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
00526 && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
00527 INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
00528 #endif
00529 }
00530
00531 private:
00532 explicit DenseBase(int);
00533 DenseBase(int,int);
00534 template<typename OtherDerived> explicit DenseBase(const DenseBase<OtherDerived>&);
00535 };
00536
00537 #endif // EIGEN_DENSEBASE_H