![]() |
Eigen
3.2.8
|
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 DenseCoeffsBase<Derived> > 00046 #else 00047 : public DenseCoeffsBase<Derived> 00048 #endif // not EIGEN_PARSED_BY_DOXYGEN 00049 { 00050 public: 00051 00052 class InnerIterator; 00053 00054 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00055 00060 typedef typename internal::traits<Derived>::Index Index; 00061 00062 typedef typename internal::traits<Derived>::Scalar Scalar; 00063 typedef typename internal::packet_traits<Scalar>::type PacketScalar; 00064 typedef typename NumTraits<Scalar>::Real RealScalar; 00065 typedef internal::special_scalar_op_base<Derived,Scalar,RealScalar, DenseCoeffsBase<Derived> > Base; 00066 00067 using Base::operator*; 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(); } 00186 00192 Index outerSize() const 00193 { 00194 return IsVectorAtCompileTime ? 1 00195 : int(IsRowMajor) ? this->rows() : this->cols(); 00196 } 00197 00203 Index innerSize() const 00204 { 00205 return IsVectorAtCompileTime ? this->size() 00206 : int(IsRowMajor) ? this->cols() : this->rows(); 00207 } 00208 00213 void resize(Index newSize) 00214 { 00215 EIGEN_ONLY_USED_FOR_DEBUG(newSize); 00216 eigen_assert(newSize == this->size() 00217 && "DenseBase::resize() does not actually allow to resize."); 00218 } 00223 void resize(Index nbRows, Index nbCols) 00224 { 00225 EIGEN_ONLY_USED_FOR_DEBUG(nbRows); 00226 EIGEN_ONLY_USED_FOR_DEBUG(nbCols); 00227 eigen_assert(nbRows == this->rows() && nbCols == this->cols() 00228 && "DenseBase::resize() does not actually allow to resize."); 00229 } 00230 00231 #ifndef EIGEN_PARSED_BY_DOXYGEN 00232 00234 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType; 00236 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,false>,Derived> SequentialLinSpacedReturnType; 00238 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,true>,Derived> RandomAccessLinSpacedReturnType; 00240 typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType; 00241 00242 #endif // not EIGEN_PARSED_BY_DOXYGEN 00243 00245 template<typename OtherDerived> 00246 Derived& operator=(const DenseBase<OtherDerived>& other); 00247 00251 Derived& operator=(const DenseBase& other); 00252 00253 template<typename OtherDerived> 00254 Derived& operator=(const EigenBase<OtherDerived> &other); 00255 00256 template<typename OtherDerived> 00257 Derived& operator+=(const EigenBase<OtherDerived> &other); 00258 00259 template<typename OtherDerived> 00260 Derived& operator-=(const EigenBase<OtherDerived> &other); 00261 00262 template<typename OtherDerived> 00263 Derived& operator=(const ReturnByValue<OtherDerived>& func); 00264 00266 template<typename OtherDerived> 00267 Derived& lazyAssign(const DenseBase<OtherDerived>& other); 00268 00270 template<typename OtherDerived> 00271 Derived& lazyAssign(const ReturnByValue<OtherDerived>& other); 00272 00273 CommaInitializer<Derived> operator<< (const Scalar& s); 00274 00275 template<unsigned int Added,unsigned int Removed> 00276 const Flagged<Derived, Added, Removed> flagged() const; 00277 00278 template<typename OtherDerived> 00279 CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other); 00280 00281 Eigen::Transpose<Derived> transpose(); 00282 typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; 00283 ConstTransposeReturnType transpose() const; 00284 void transposeInPlace(); 00285 #ifndef EIGEN_NO_DEBUG 00286 protected: 00287 template<typename OtherDerived> 00288 void checkTransposeAliasing(const OtherDerived& other) const; 00289 public: 00290 #endif 00291 00292 00293 static const ConstantReturnType 00294 Constant(Index rows, Index cols, const Scalar& value); 00295 static const ConstantReturnType 00296 Constant(Index size, const Scalar& value); 00297 static const ConstantReturnType 00298 Constant(const Scalar& value); 00299 00300 static const SequentialLinSpacedReturnType 00301 LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high); 00302 static const RandomAccessLinSpacedReturnType 00303 LinSpaced(Index size, const Scalar& low, const Scalar& high); 00304 static const SequentialLinSpacedReturnType 00305 LinSpaced(Sequential_t, const Scalar& low, const Scalar& high); 00306 static const RandomAccessLinSpacedReturnType 00307 LinSpaced(const Scalar& low, const Scalar& high); 00308 00309 template<typename CustomNullaryOp> 00310 static const CwiseNullaryOp<CustomNullaryOp, Derived> 00311 NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func); 00312 template<typename CustomNullaryOp> 00313 static const CwiseNullaryOp<CustomNullaryOp, Derived> 00314 NullaryExpr(Index size, const CustomNullaryOp& func); 00315 template<typename CustomNullaryOp> 00316 static const CwiseNullaryOp<CustomNullaryOp, Derived> 00317 NullaryExpr(const CustomNullaryOp& func); 00318 00319 static const ConstantReturnType Zero(Index rows, Index cols); 00320 static const ConstantReturnType Zero(Index size); 00321 static const ConstantReturnType Zero(); 00322 static const ConstantReturnType Ones(Index rows, Index cols); 00323 static const ConstantReturnType Ones(Index size); 00324 static const ConstantReturnType Ones(); 00325 00326 void fill(const Scalar& value); 00327 Derived& setConstant(const Scalar& value); 00328 Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high); 00329 Derived& setLinSpaced(const Scalar& low, const Scalar& high); 00330 Derived& setZero(); 00331 Derived& setOnes(); 00332 Derived& setRandom(); 00333 00334 template<typename OtherDerived> 00335 bool isApprox(const DenseBase<OtherDerived>& other, 00336 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00337 bool isMuchSmallerThan(const RealScalar& other, 00338 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00339 template<typename OtherDerived> 00340 bool isMuchSmallerThan(const DenseBase<OtherDerived>& other, 00341 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00342 00343 bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00344 bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00345 bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00346 bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00347 00348 inline bool hasNaN() const; 00349 inline bool allFinite() const; 00350 00351 inline Derived& operator*=(const Scalar& other); 00352 inline Derived& operator/=(const Scalar& other); 00353 00354 typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType; 00360 EIGEN_STRONG_INLINE EvalReturnType eval() const 00361 { 00362 // Even though MSVC does not honor strong inlining when the return type 00363 // is a dynamic matrix, we desperately need strong inlining for fixed 00364 // size types on MSVC. 00365 return typename internal::eval<Derived>::type(derived()); 00366 } 00367 00371 template<typename OtherDerived> 00372 void swap(const DenseBase<OtherDerived>& other, 00373 int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase) 00374 { 00375 SwapWrapper<Derived>(derived()).lazyAssign(other.derived()); 00376 } 00377 00381 template<typename OtherDerived> 00382 void swap(PlainObjectBase<OtherDerived>& other) 00383 { 00384 SwapWrapper<Derived>(derived()).lazyAssign(other.derived()); 00385 } 00386 00387 00388 inline const NestByValue<Derived> nestByValue() const; 00389 inline const ForceAlignedAccess<Derived> forceAlignedAccess() const; 00390 inline ForceAlignedAccess<Derived> forceAlignedAccess(); 00391 template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const; 00392 template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf(); 00393 00394 Scalar sum() const; 00395 Scalar mean() const; 00396 Scalar trace() const; 00397 00398 Scalar prod() const; 00399 00400 typename internal::traits<Derived>::Scalar minCoeff() const; 00401 typename internal::traits<Derived>::Scalar maxCoeff() const; 00402 00403 template<typename IndexType> 00404 typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const; 00405 template<typename IndexType> 00406 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const; 00407 template<typename IndexType> 00408 typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const; 00409 template<typename IndexType> 00410 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const; 00411 00412 template<typename BinaryOp> 00413 typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type 00414 redux(const BinaryOp& func) const; 00415 00416 template<typename Visitor> 00417 void visit(Visitor& func) const; 00418 00419 inline const WithFormat<Derived> format(const IOFormat& fmt) const; 00420 00422 CoeffReturnType value() const 00423 { 00424 EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) 00425 eigen_assert(this->rows() == 1 && this->cols() == 1); 00426 return derived().coeff(0,0); 00427 } 00428 00429 bool all(void) const; 00430 bool any(void) const; 00431 Index count() const; 00432 00433 typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType; 00434 typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType; 00435 typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType; 00436 typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType; 00437 00438 ConstRowwiseReturnType rowwise() const; 00439 RowwiseReturnType rowwise(); 00440 ConstColwiseReturnType colwise() const; 00441 ColwiseReturnType colwise(); 00442 00443 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols); 00444 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size); 00445 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(); 00446 00447 template<typename ThenDerived,typename ElseDerived> 00448 const Select<Derived,ThenDerived,ElseDerived> 00449 select(const DenseBase<ThenDerived>& thenMatrix, 00450 const DenseBase<ElseDerived>& elseMatrix) const; 00451 00452 template<typename ThenDerived> 00453 inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType> 00454 select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const; 00455 00456 template<typename ElseDerived> 00457 inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived > 00458 select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const; 00459 00460 template<int p> RealScalar lpNorm() const; 00461 00462 template<int RowFactor, int ColFactor> 00463 inline const Replicate<Derived,RowFactor,ColFactor> replicate() const; 00464 00465 typedef Replicate<Derived,Dynamic,Dynamic> ReplicateReturnType; 00466 inline const ReplicateReturnType 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