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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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 typedef typename internal::traits<Derived>::Index Index;
00057 typedef typename internal::traits<Derived>::Scalar Scalar;
00058 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00059 typedef typename NumTraits<Scalar>::Real RealScalar;
00060
00061 typedef DenseCoeffsBase<Derived> Base;
00062 using Base::derived;
00063 using Base::const_cast_derived;
00064 using Base::rows;
00065 using Base::cols;
00066 using Base::size;
00067 using Base::rowIndexByOuterInner;
00068 using Base::colIndexByOuterInner;
00069 using Base::coeff;
00070 using Base::coeffByOuterInner;
00071 using Base::packet;
00072 using Base::packetByOuterInner;
00073 using Base::writePacket;
00074 using Base::writePacketByOuterInner;
00075 using Base::coeffRef;
00076 using Base::coeffRefByOuterInner;
00077 using Base::copyCoeff;
00078 using Base::copyCoeffByOuterInner;
00079 using Base::copyPacket;
00080 using Base::copyPacketByOuterInner;
00081 using Base::operator();
00082 using Base::operator[];
00083 using Base::x;
00084 using Base::y;
00085 using Base::z;
00086 using Base::w;
00087 using Base::stride;
00088 using Base::innerStride;
00089 using Base::outerStride;
00090 using Base::rowStride;
00091 using Base::colStride;
00092 typedef typename Base::CoeffReturnType CoeffReturnType;
00093
00094 enum {
00095
00096 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00097
00098
00099
00100
00101
00102 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00103
00104
00105
00106
00107
00108
00109 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
00110 internal::traits<Derived>::ColsAtCompileTime>::ret),
00111
00112
00113
00114
00115 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
00138 internal::traits<Derived>::MaxColsAtCompileTime>::ret),
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
00150 || internal::traits<Derived>::MaxColsAtCompileTime == 1,
00151
00152
00153
00154
00155
00156 Flags = internal::traits<Derived>::Flags,
00157
00158
00159
00160
00161 IsRowMajor = int(Flags) & RowMajorBit,
00162
00163 InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? SizeAtCompileTime
00164 : int(IsRowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
00165
00166 CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
00167
00168
00169
00170
00171 InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
00172 OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
00173 };
00174
00175 enum { ThisConstantIsPrivateInPlainObjectBase };
00176
00177
00178
00179 inline Index nonZeros() const { return size(); }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 Index outerSize() const
00191 {
00192 return IsVectorAtCompileTime ? 1
00193 : int(IsRowMajor) ? this->rows() : this->cols();
00194 }
00195
00196
00197
00198
00199
00200
00201 Index innerSize() const
00202 {
00203 return IsVectorAtCompileTime ? this->size()
00204 : int(IsRowMajor) ? this->cols() : this->rows();
00205 }
00206
00207
00208
00209
00210
00211 void resize(Index size)
00212 {
00213 EIGEN_ONLY_USED_FOR_DEBUG(size);
00214 eigen_assert(size == this->size()
00215 && "DenseBase::resize() does not actually allow to resize.");
00216 }
00217
00218
00219
00220
00221 void resize(Index rows, Index cols)
00222 {
00223 EIGEN_ONLY_USED_FOR_DEBUG(rows);
00224 EIGEN_ONLY_USED_FOR_DEBUG(cols);
00225 eigen_assert(rows == this->rows() && cols == this->cols()
00226 && "DenseBase::resize() does not actually allow to resize.");
00227 }
00228
00229 #ifndef EIGEN_PARSED_BY_DOXYGEN
00230
00231
00232 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00233
00234 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,false>,Derived> SequentialLinSpacedReturnType;
00235
00236 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,true>,Derived> RandomAccessLinSpacedReturnType;
00237
00238 typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
00239
00240 #endif // not EIGEN_PARSED_BY_DOXYGEN
00241
00242
00243 template<typename OtherDerived>
00244 Derived& operator=(const DenseBase<OtherDerived>& other);
00245
00246
00247
00248
00249 Derived& operator=(const DenseBase& other);
00250
00251 template<typename OtherDerived>
00252 Derived& operator=(const EigenBase<OtherDerived> &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 ReturnByValue<OtherDerived>& func);
00262
00263 #ifndef EIGEN_PARSED_BY_DOXYGEN
00264
00265 template<typename OtherDerived>
00266 Derived& lazyAssign(const DenseBase<OtherDerived>& other);
00267 #endif // not EIGEN_PARSED_BY_DOXYGEN
00268
00269 CommaInitializer<Derived> operator<< (const Scalar& s);
00270
00271 template<unsigned int Added,unsigned int Removed>
00272 const Flagged<Derived, Added, Removed> flagged() const;
00273
00274 template<typename OtherDerived>
00275 CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
00276
00277 Eigen::Transpose<Derived> transpose();
00278 typedef const Transpose<const Derived> ConstTransposeReturnType;
00279 ConstTransposeReturnType transpose() const;
00280 void transposeInPlace();
00281 #ifndef EIGEN_NO_DEBUG
00282 protected:
00283 template<typename OtherDerived>
00284 void checkTransposeAliasing(const OtherDerived& other) const;
00285 public:
00286 #endif
00287
00288 typedef VectorBlock<Derived> SegmentReturnType;
00289 typedef const VectorBlock<const Derived> ConstSegmentReturnType;
00290 template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; };
00291 template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; };
00292
00293
00294 SegmentReturnType segment(Index start, Index size);
00295 typename DenseBase::ConstSegmentReturnType segment(Index start, Index size) const;
00296
00297 SegmentReturnType head(Index size);
00298 typename DenseBase::ConstSegmentReturnType head(Index size) const;
00299
00300 SegmentReturnType tail(Index size);
00301 typename DenseBase::ConstSegmentReturnType tail(Index size) const;
00302
00303 template<int Size> typename FixedSegmentReturnType<Size>::Type head();
00304 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type head() const;
00305
00306 template<int Size> typename FixedSegmentReturnType<Size>::Type tail();
00307 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type tail() const;
00308
00309 template<int Size> typename FixedSegmentReturnType<Size>::Type segment(Index start);
00310 template<int Size> typename ConstFixedSegmentReturnType<Size>::Type segment(Index start) const;
00311
00312 static const ConstantReturnType
00313 Constant(Index rows, Index cols, const Scalar& value);
00314 static const ConstantReturnType
00315 Constant(Index size, const Scalar& value);
00316 static const ConstantReturnType
00317 Constant(const Scalar& value);
00318
00319 static const SequentialLinSpacedReturnType
00320 LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
00321 static const RandomAccessLinSpacedReturnType
00322 LinSpaced(Index size, const Scalar& low, const Scalar& high);
00323 static const SequentialLinSpacedReturnType
00324 LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
00325 static const RandomAccessLinSpacedReturnType
00326 LinSpaced(const Scalar& low, const Scalar& high);
00327
00328 template<typename CustomNullaryOp>
00329 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00330 NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
00331 template<typename CustomNullaryOp>
00332 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00333 NullaryExpr(Index size, const CustomNullaryOp& func);
00334 template<typename CustomNullaryOp>
00335 static const CwiseNullaryOp<CustomNullaryOp, Derived>
00336 NullaryExpr(const CustomNullaryOp& func);
00337
00338 static const ConstantReturnType Zero(Index rows, Index cols);
00339 static const ConstantReturnType Zero(Index size);
00340 static const ConstantReturnType Zero();
00341 static const ConstantReturnType Ones(Index rows, Index cols);
00342 static const ConstantReturnType Ones(Index size);
00343 static const ConstantReturnType Ones();
00344
00345 void fill(const Scalar& value);
00346 Derived& setConstant(const Scalar& value);
00347 Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
00348 Derived& setLinSpaced(const Scalar& low, const Scalar& high);
00349 Derived& setZero();
00350 Derived& setOnes();
00351 Derived& setRandom();
00352
00353 template<typename OtherDerived>
00354 bool isApprox(const DenseBase<OtherDerived>& other,
00355 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00356 bool isMuchSmallerThan(const RealScalar& other,
00357 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00358 template<typename OtherDerived>
00359 bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
00360 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00361
00362 bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00363 bool isConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00364 bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00365 bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
00366
00367 inline Derived& operator*=(const Scalar& other);
00368 inline Derived& operator/=(const Scalar& other);
00369
00370
00371
00372
00373
00374
00375 EIGEN_STRONG_INLINE const typename internal::eval<Derived>::type eval() const
00376 {
00377
00378
00379
00380 return typename internal::eval<Derived>::type(derived());
00381 }
00382
00383
00384
00385
00386 template<typename OtherDerived>
00387 void swap(const DenseBase<OtherDerived>& other,
00388 int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
00389 {
00390 SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00391 }
00392
00393
00394
00395
00396 template<typename OtherDerived>
00397 void swap(PlainObjectBase<OtherDerived>& other)
00398 {
00399 SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
00400 }
00401
00402
00403 inline const NestByValue<Derived> nestByValue() const;
00404 inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
00405 inline ForceAlignedAccess<Derived> forceAlignedAccess();
00406 template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
00407 template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
00408
00409 Scalar sum() const;
00410 Scalar mean() const;
00411 Scalar trace() const;
00412
00413 Scalar prod() const;
00414
00415 typename internal::traits<Derived>::Scalar minCoeff() const;
00416 typename internal::traits<Derived>::Scalar maxCoeff() const;
00417
00418 typename internal::traits<Derived>::Scalar minCoeff(Index* row, Index* col) const;
00419 typename internal::traits<Derived>::Scalar maxCoeff(Index* row, Index* col) const;
00420
00421 typename internal::traits<Derived>::Scalar minCoeff(Index* index) const;
00422 typename internal::traits<Derived>::Scalar maxCoeff(Index* 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
00433
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
00441
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
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:
00512
00513 DenseBase()
00514 {
00515
00516
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 #endif // EIGEN_DENSEBASE_H