MOAB
4.9.3pre
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2007-2010 Benoit Jacob <[email protected]> 00005 // Copyright (C) 2008-2010 Gael Guennebaud <[email protected]> 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 00055 typedef Eigen::InnerIterator<Derived> InnerIterator; 00056 00057 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00058 00065 typedef typename internal::traits<Derived>::StorageIndex StorageIndex; 00066 00068 typedef typename internal::traits<Derived>::Scalar Scalar; 00069 00073 typedef Scalar value_type; 00074 00075 typedef typename NumTraits<Scalar>::Real RealScalar; 00076 typedef internal::special_scalar_op_base<Derived,Scalar,RealScalar, DenseCoeffsBase<Derived> > Base; 00077 00078 using Base::operator*; 00079 using Base::operator/; 00080 using Base::derived; 00081 using Base::const_cast_derived; 00082 using Base::rows; 00083 using Base::cols; 00084 using Base::size; 00085 using Base::rowIndexByOuterInner; 00086 using Base::colIndexByOuterInner; 00087 using Base::coeff; 00088 using Base::coeffByOuterInner; 00089 using Base::operator(); 00090 using Base::operator[]; 00091 using Base::x; 00092 using Base::y; 00093 using Base::z; 00094 using Base::w; 00095 using Base::stride; 00096 using Base::innerStride; 00097 using Base::outerStride; 00098 using Base::rowStride; 00099 using Base::colStride; 00100 typedef typename Base::CoeffReturnType CoeffReturnType; 00101 00102 enum { 00103 00104 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, 00110 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, 00117 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, 00118 internal::traits<Derived>::ColsAtCompileTime>::ret), 00123 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime, 00134 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime, 00145 MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime, 00146 internal::traits<Derived>::MaxColsAtCompileTime>::ret), 00157 IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1 00158 || internal::traits<Derived>::MaxColsAtCompileTime == 1, 00164 Flags = internal::traits<Derived>::Flags, 00169 IsRowMajor = int(Flags) & RowMajorBit, 00171 InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime) 00172 : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), 00173 00174 InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret, 00175 OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret 00176 }; 00177 00178 typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar; 00179 00180 enum { IsPlainObjectBase = 0 }; 00181 00184 typedef Matrix<typename internal::traits<Derived>::Scalar, 00185 internal::traits<Derived>::RowsAtCompileTime, 00186 internal::traits<Derived>::ColsAtCompileTime, 00187 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), 00188 internal::traits<Derived>::MaxRowsAtCompileTime, 00189 internal::traits<Derived>::MaxColsAtCompileTime 00190 > PlainMatrix; 00191 00194 typedef Array<typename internal::traits<Derived>::Scalar, 00195 internal::traits<Derived>::RowsAtCompileTime, 00196 internal::traits<Derived>::ColsAtCompileTime, 00197 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), 00198 internal::traits<Derived>::MaxRowsAtCompileTime, 00199 internal::traits<Derived>::MaxColsAtCompileTime 00200 > PlainArray; 00201 00208 typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value, 00209 PlainMatrix, PlainArray>::type PlainObject; 00210 00213 EIGEN_DEVICE_FUNC 00214 inline Index nonZeros() const { return size(); } 00215 00221 EIGEN_DEVICE_FUNC 00222 Index outerSize() const 00223 { 00224 return IsVectorAtCompileTime ? 1 00225 : int(IsRowMajor) ? this->rows() : this->cols(); 00226 } 00227 00233 EIGEN_DEVICE_FUNC 00234 Index innerSize() const 00235 { 00236 return IsVectorAtCompileTime ? this->size() 00237 : int(IsRowMajor) ? this->cols() : this->rows(); 00238 } 00239 00244 EIGEN_DEVICE_FUNC 00245 void resize(Index newSize) 00246 { 00247 EIGEN_ONLY_USED_FOR_DEBUG(newSize); 00248 eigen_assert(newSize == this->size() 00249 && "DenseBase::resize() does not actually allow to resize."); 00250 } 00255 EIGEN_DEVICE_FUNC 00256 void resize(Index p_rows, Index p_cols) 00257 { 00258 EIGEN_ONLY_USED_FOR_DEBUG(p_rows); 00259 EIGEN_ONLY_USED_FOR_DEBUG(p_cols); 00260 eigen_assert(p_rows == this->rows() && p_cols == this->cols() 00261 && "DenseBase::resize() does not actually allow to resize."); 00262 } 00263 00264 #ifndef EIGEN_PARSED_BY_DOXYGEN 00265 00266 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType; 00268 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar,false>,PlainObject> SequentialLinSpacedReturnType; 00270 typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar,true>,PlainObject> RandomAccessLinSpacedReturnType; 00272 typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType; 00273 00274 #endif // not EIGEN_PARSED_BY_DOXYGEN 00275 00277 template<typename OtherDerived> 00278 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00279 Derived& operator=(const DenseBase<OtherDerived>& other); 00280 00284 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00285 Derived& operator=(const DenseBase& other); 00286 00287 template<typename OtherDerived> 00288 EIGEN_DEVICE_FUNC 00289 Derived& operator=(const EigenBase<OtherDerived> &other); 00290 00291 template<typename OtherDerived> 00292 EIGEN_DEVICE_FUNC 00293 Derived& operator+=(const EigenBase<OtherDerived> &other); 00294 00295 template<typename OtherDerived> 00296 EIGEN_DEVICE_FUNC 00297 Derived& operator-=(const EigenBase<OtherDerived> &other); 00298 00299 template<typename OtherDerived> 00300 EIGEN_DEVICE_FUNC 00301 Derived& operator=(const ReturnByValue<OtherDerived>& func); 00302 00306 template<typename OtherDerived> 00307 EIGEN_DEVICE_FUNC 00308 Derived& lazyAssign(const DenseBase<OtherDerived>& other); 00309 00310 EIGEN_DEVICE_FUNC 00311 CommaInitializer<Derived> operator<< (const Scalar& s); 00312 00314 template<unsigned int Added,unsigned int Removed> 00315 EIGEN_DEPRECATED 00316 const Derived& flagged() const 00317 { return derived(); } 00318 00319 template<typename OtherDerived> 00320 EIGEN_DEVICE_FUNC 00321 CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other); 00322 00323 typedef Transpose<Derived> TransposeReturnType; 00324 EIGEN_DEVICE_FUNC 00325 TransposeReturnType transpose(); 00326 typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType; 00327 EIGEN_DEVICE_FUNC 00328 ConstTransposeReturnType transpose() const; 00329 EIGEN_DEVICE_FUNC 00330 void transposeInPlace(); 00331 00332 EIGEN_DEVICE_FUNC static const ConstantReturnType 00333 Constant(Index rows, Index cols, const Scalar& value); 00334 EIGEN_DEVICE_FUNC static const ConstantReturnType 00335 Constant(Index size, const Scalar& value); 00336 EIGEN_DEVICE_FUNC static const ConstantReturnType 00337 Constant(const Scalar& value); 00338 00339 EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType 00340 LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high); 00341 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType 00342 LinSpaced(Index size, const Scalar& low, const Scalar& high); 00343 EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType 00344 LinSpaced(Sequential_t, const Scalar& low, const Scalar& high); 00345 EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType 00346 LinSpaced(const Scalar& low, const Scalar& high); 00347 00348 template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC 00349 static const CwiseNullaryOp<CustomNullaryOp, PlainObject> 00350 NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func); 00351 template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC 00352 static const CwiseNullaryOp<CustomNullaryOp, PlainObject> 00353 NullaryExpr(Index size, const CustomNullaryOp& func); 00354 template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC 00355 static const CwiseNullaryOp<CustomNullaryOp, PlainObject> 00356 NullaryExpr(const CustomNullaryOp& func); 00357 00358 EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols); 00359 EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size); 00360 EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(); 00361 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols); 00362 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size); 00363 EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(); 00364 00365 EIGEN_DEVICE_FUNC void fill(const Scalar& value); 00366 EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value); 00367 EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high); 00368 EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high); 00369 EIGEN_DEVICE_FUNC Derived& setZero(); 00370 EIGEN_DEVICE_FUNC Derived& setOnes(); 00371 EIGEN_DEVICE_FUNC Derived& setRandom(); 00372 00373 template<typename OtherDerived> EIGEN_DEVICE_FUNC 00374 bool isApprox(const DenseBase<OtherDerived>& other, 00375 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00376 EIGEN_DEVICE_FUNC 00377 bool isMuchSmallerThan(const RealScalar& other, 00378 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00379 template<typename OtherDerived> EIGEN_DEVICE_FUNC 00380 bool isMuchSmallerThan(const DenseBase<OtherDerived>& other, 00381 const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00382 00383 EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00384 EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00385 EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00386 EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; 00387 00388 inline bool hasNaN() const; 00389 inline bool allFinite() const; 00390 00391 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00392 Derived& operator*=(const Scalar& other); 00393 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00394 Derived& operator/=(const Scalar& other); 00395 00396 typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType; 00404 EIGEN_DEVICE_FUNC 00405 EIGEN_STRONG_INLINE EvalReturnType eval() const 00406 { 00407 // Even though MSVC does not honor strong inlining when the return type 00408 // is a dynamic matrix, we desperately need strong inlining for fixed 00409 // size types on MSVC. 00410 return typename internal::eval<Derived>::type(derived()); 00411 } 00412 00416 template<typename OtherDerived> 00417 EIGEN_DEVICE_FUNC 00418 void swap(const DenseBase<OtherDerived>& other) 00419 { 00420 EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); 00421 eigen_assert(rows()==other.rows() && cols()==other.cols()); 00422 call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>()); 00423 } 00424 00428 template<typename OtherDerived> 00429 EIGEN_DEVICE_FUNC 00430 void swap(PlainObjectBase<OtherDerived>& other) 00431 { 00432 eigen_assert(rows()==other.rows() && cols()==other.cols()); 00433 call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>()); 00434 } 00435 00436 EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const; 00437 EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const; 00438 EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess(); 00439 template<bool Enable> EIGEN_DEVICE_FUNC 00440 inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const; 00441 template<bool Enable> EIGEN_DEVICE_FUNC 00442 inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf(); 00443 00444 EIGEN_DEVICE_FUNC Scalar sum() const; 00445 EIGEN_DEVICE_FUNC Scalar mean() const; 00446 EIGEN_DEVICE_FUNC Scalar trace() const; 00447 00448 EIGEN_DEVICE_FUNC Scalar prod() const; 00449 00450 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const; 00451 EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const; 00452 00453 template<typename IndexType> EIGEN_DEVICE_FUNC 00454 typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const; 00455 template<typename IndexType> EIGEN_DEVICE_FUNC 00456 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const; 00457 template<typename IndexType> EIGEN_DEVICE_FUNC 00458 typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const; 00459 template<typename IndexType> EIGEN_DEVICE_FUNC 00460 typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const; 00461 00462 template<typename BinaryOp> 00463 EIGEN_DEVICE_FUNC 00464 Scalar redux(const BinaryOp& func) const; 00465 00466 template<typename Visitor> 00467 EIGEN_DEVICE_FUNC 00468 void visit(Visitor& func) const; 00469 00470 inline const WithFormat<Derived> format(const IOFormat& fmt) const; 00471 00473 EIGEN_DEVICE_FUNC 00474 CoeffReturnType value() const 00475 { 00476 EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) 00477 eigen_assert(this->rows() == 1 && this->cols() == 1); 00478 return derived().coeff(0,0); 00479 } 00480 00481 bool all() const; 00482 bool any() const; 00483 Index count() const; 00484 00485 typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType; 00486 typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType; 00487 typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType; 00488 typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType; 00489 00497 //Code moved here due to a CUDA compiler bug 00498 EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const { 00499 return ConstRowwiseReturnType(derived()); 00500 } 00501 EIGEN_DEVICE_FUNC RowwiseReturnType rowwise(); 00502 00510 EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const { 00511 return ConstColwiseReturnType(derived()); 00512 } 00513 EIGEN_DEVICE_FUNC ColwiseReturnType colwise(); 00514 00515 typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType; 00516 static const RandomReturnType Random(Index rows, Index cols); 00517 static const RandomReturnType Random(Index size); 00518 static const RandomReturnType Random(); 00519 00520 template<typename ThenDerived,typename ElseDerived> 00521 const Select<Derived,ThenDerived,ElseDerived> 00522 select(const DenseBase<ThenDerived>& thenMatrix, 00523 const DenseBase<ElseDerived>& elseMatrix) const; 00524 00525 template<typename ThenDerived> 00526 inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType> 00527 select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const; 00528 00529 template<typename ElseDerived> 00530 inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived > 00531 select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const; 00532 00533 template<int p> RealScalar lpNorm() const; 00534 00535 template<int RowFactor, int ColFactor> 00536 EIGEN_DEVICE_FUNC 00537 const Replicate<Derived,RowFactor,ColFactor> replicate() const; 00546 //Code moved here due to a CUDA compiler bug 00547 EIGEN_DEVICE_FUNC 00548 const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const 00549 { 00550 return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor); 00551 } 00552 00553 typedef Reverse<Derived, BothDirections> ReverseReturnType; 00554 typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType; 00555 EIGEN_DEVICE_FUNC ReverseReturnType reverse(); 00557 //Code moved here due to a CUDA compiler bug 00558 EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const 00559 { 00560 return ConstReverseReturnType(derived()); 00561 } 00562 EIGEN_DEVICE_FUNC void reverseInPlace(); 00563 00564 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase 00565 # include "../plugins/BlockMethods.h" 00566 # ifdef EIGEN_DENSEBASE_PLUGIN 00567 # include EIGEN_DENSEBASE_PLUGIN 00568 # endif 00569 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS 00570 00571 00572 // disable the use of evalTo for dense objects with a nice compilation error 00573 template<typename Dest> 00574 EIGEN_DEVICE_FUNC 00575 inline void evalTo(Dest& ) const 00576 { 00577 EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS); 00578 } 00579 00580 protected: 00582 EIGEN_DEVICE_FUNC DenseBase() 00583 { 00584 /* Just checks for self-consistency of the flags. 00585 * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down 00586 */ 00587 #ifdef EIGEN_INTERNAL_DEBUGGING 00588 EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor)) 00589 && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))), 00590 INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION) 00591 #endif 00592 } 00593 00594 private: 00595 EIGEN_DEVICE_FUNC explicit DenseBase(int); 00596 EIGEN_DEVICE_FUNC DenseBase(int,int); 00597 template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&); 00598 }; 00599 00600 } // end namespace Eigen 00601 00602 #endif // EIGEN_DENSEBASE_H