DenseBase.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
  6. //
  7. // This Source Code Form is subject to the terms of the Mozilla
  8. // Public License v. 2.0. If a copy of the MPL was not distributed
  9. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  10. #ifndef EIGEN_DENSEBASE_H
  11. #define EIGEN_DENSEBASE_H
  12. namespace Eigen {
  13. namespace internal {
  14. // The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
  15. // This dummy function simply aims at checking that at compile time.
  16. static inline void check_DenseIndex_is_signed() {
  17. EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE);
  18. }
  19. } // end namespace internal
  20. /** \class DenseBase
  21. * \ingroup Core_Module
  22. *
  23. * \brief Base class for all dense matrices, vectors, and arrays
  24. *
  25. * This class is the base that is inherited by all dense objects (matrix, vector, arrays,
  26. * and related expression types). The common Eigen API for dense objects is contained in this class.
  27. *
  28. * \tparam Derived is the derived type, e.g., a matrix type or an expression.
  29. *
  30. * This class can be extended with the help of the plugin mechanism described on the page
  31. * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN.
  32. *
  33. * \sa \blank \ref TopicClassHierarchy
  34. */
  35. template<typename Derived> class DenseBase
  36. #ifndef EIGEN_PARSED_BY_DOXYGEN
  37. : public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>
  38. #else
  39. : public DenseCoeffsBase<Derived,DirectWriteAccessors>
  40. #endif // not EIGEN_PARSED_BY_DOXYGEN
  41. {
  42. public:
  43. /** Inner iterator type to iterate over the coefficients of a row or column.
  44. * \sa class InnerIterator
  45. */
  46. typedef Eigen::InnerIterator<Derived> InnerIterator;
  47. typedef typename internal::traits<Derived>::StorageKind StorageKind;
  48. /**
  49. * \brief The type used to store indices
  50. * \details This typedef is relevant for types that store multiple indices such as
  51. * PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index
  52. * \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase.
  53. */
  54. typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
  55. /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. */
  56. typedef typename internal::traits<Derived>::Scalar Scalar;
  57. /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc.
  58. *
  59. * It is an alias for the Scalar type */
  60. typedef Scalar value_type;
  61. typedef typename NumTraits<Scalar>::Real RealScalar;
  62. typedef DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value> Base;
  63. using Base::derived;
  64. using Base::const_cast_derived;
  65. using Base::rows;
  66. using Base::cols;
  67. using Base::size;
  68. using Base::rowIndexByOuterInner;
  69. using Base::colIndexByOuterInner;
  70. using Base::coeff;
  71. using Base::coeffByOuterInner;
  72. using Base::operator();
  73. using Base::operator[];
  74. using Base::x;
  75. using Base::y;
  76. using Base::z;
  77. using Base::w;
  78. using Base::stride;
  79. using Base::innerStride;
  80. using Base::outerStride;
  81. using Base::rowStride;
  82. using Base::colStride;
  83. typedef typename Base::CoeffReturnType CoeffReturnType;
  84. enum {
  85. RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
  86. /**< The number of rows at compile-time. This is just a copy of the value provided
  87. * by the \a Derived type. If a value is not known at compile-time,
  88. * it is set to the \a Dynamic constant.
  89. * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
  90. ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
  91. /**< The number of columns at compile-time. This is just a copy of the value provided
  92. * by the \a Derived type. If a value is not known at compile-time,
  93. * it is set to the \a Dynamic constant.
  94. * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
  95. SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
  96. internal::traits<Derived>::ColsAtCompileTime>::ret),
  97. /**< This is equal to the number of coefficients, i.e. the number of
  98. * rows times the number of columns, or to \a Dynamic if this is not
  99. * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
  100. MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
  101. /**< This value is equal to the maximum possible number of rows that this expression
  102. * might have. If this expression might have an arbitrarily high number of rows,
  103. * this value is set to \a Dynamic.
  104. *
  105. * This value is useful to know when evaluating an expression, in order to determine
  106. * whether it is possible to avoid doing a dynamic memory allocation.
  107. *
  108. * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
  109. */
  110. MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
  111. /**< This value is equal to the maximum possible number of columns that this expression
  112. * might have. If this expression might have an arbitrarily high number of columns,
  113. * this value is set to \a Dynamic.
  114. *
  115. * This value is useful to know when evaluating an expression, in order to determine
  116. * whether it is possible to avoid doing a dynamic memory allocation.
  117. *
  118. * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
  119. */
  120. MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
  121. internal::traits<Derived>::MaxColsAtCompileTime>::ret),
  122. /**< This value is equal to the maximum possible number of coefficients that this expression
  123. * might have. If this expression might have an arbitrarily high number of coefficients,
  124. * this value is set to \a Dynamic.
  125. *
  126. * This value is useful to know when evaluating an expression, in order to determine
  127. * whether it is possible to avoid doing a dynamic memory allocation.
  128. *
  129. * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
  130. */
  131. IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
  132. || internal::traits<Derived>::MaxColsAtCompileTime == 1,
  133. /**< This is set to true if either the number of rows or the number of
  134. * columns is known at compile-time to be equal to 1. Indeed, in that case,
  135. * we are dealing with a column-vector (if there is only one column) or with
  136. * a row-vector (if there is only one row). */
  137. Flags = internal::traits<Derived>::Flags,
  138. /**< This stores expression \ref flags flags which may or may not be inherited by new expressions
  139. * constructed from this one. See the \ref flags "list of flags".
  140. */
  141. IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */
  142. InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
  143. : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
  144. InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
  145. OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
  146. };
  147. typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar;
  148. enum { IsPlainObjectBase = 0 };
  149. /** The plain matrix type corresponding to this expression.
  150. * \sa PlainObject */
  151. typedef Matrix<typename internal::traits<Derived>::Scalar,
  152. internal::traits<Derived>::RowsAtCompileTime,
  153. internal::traits<Derived>::ColsAtCompileTime,
  154. AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
  155. internal::traits<Derived>::MaxRowsAtCompileTime,
  156. internal::traits<Derived>::MaxColsAtCompileTime
  157. > PlainMatrix;
  158. /** The plain array type corresponding to this expression.
  159. * \sa PlainObject */
  160. typedef Array<typename internal::traits<Derived>::Scalar,
  161. internal::traits<Derived>::RowsAtCompileTime,
  162. internal::traits<Derived>::ColsAtCompileTime,
  163. AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
  164. internal::traits<Derived>::MaxRowsAtCompileTime,
  165. internal::traits<Derived>::MaxColsAtCompileTime
  166. > PlainArray;
  167. /** \brief The plain matrix or array type corresponding to this expression.
  168. *
  169. * This is not necessarily exactly the return type of eval(). In the case of plain matrices,
  170. * the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed
  171. * that the return type of eval() is either PlainObject or const PlainObject&.
  172. */
  173. typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value,
  174. PlainMatrix, PlainArray>::type PlainObject;
  175. /** \returns the number of nonzero coefficients which is in practice the number
  176. * of stored coefficients. */
  177. EIGEN_DEVICE_FUNC
  178. inline Index nonZeros() const { return size(); }
  179. /** \returns the outer size.
  180. *
  181. * \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension
  182. * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a
  183. * column-major matrix, and the number of rows for a row-major matrix. */
  184. EIGEN_DEVICE_FUNC
  185. Index outerSize() const
  186. {
  187. return IsVectorAtCompileTime ? 1
  188. : int(IsRowMajor) ? this->rows() : this->cols();
  189. }
  190. /** \returns the inner size.
  191. *
  192. * \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension
  193. * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a
  194. * column-major matrix, and the number of columns for a row-major matrix. */
  195. EIGEN_DEVICE_FUNC
  196. Index innerSize() const
  197. {
  198. return IsVectorAtCompileTime ? this->size()
  199. : int(IsRowMajor) ? this->cols() : this->rows();
  200. }
  201. /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
  202. * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
  203. * nothing else.
  204. */
  205. EIGEN_DEVICE_FUNC
  206. void resize(Index newSize)
  207. {
  208. EIGEN_ONLY_USED_FOR_DEBUG(newSize);
  209. eigen_assert(newSize == this->size()
  210. && "DenseBase::resize() does not actually allow to resize.");
  211. }
  212. /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
  213. * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
  214. * nothing else.
  215. */
  216. EIGEN_DEVICE_FUNC
  217. void resize(Index rows, Index cols)
  218. {
  219. EIGEN_ONLY_USED_FOR_DEBUG(rows);
  220. EIGEN_ONLY_USED_FOR_DEBUG(cols);
  221. eigen_assert(rows == this->rows() && cols == this->cols()
  222. && "DenseBase::resize() does not actually allow to resize.");
  223. }
  224. #ifndef EIGEN_PARSED_BY_DOXYGEN
  225. /** \internal Represents a matrix with all coefficients equal to one another*/
  226. typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
  227. /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */
  228. typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar>,PlainObject> SequentialLinSpacedReturnType;
  229. /** \internal Represents a vector with linearly spaced coefficients that allows random access. */
  230. typedef CwiseNullaryOp<internal::linspaced_op<Scalar,PacketScalar>,PlainObject> RandomAccessLinSpacedReturnType;
  231. /** \internal the return type of MatrixBase::eigenvalues() */
  232. typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
  233. #endif // not EIGEN_PARSED_BY_DOXYGEN
  234. /** Copies \a other into *this. \returns a reference to *this. */
  235. template<typename OtherDerived>
  236. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  237. Derived& operator=(const DenseBase<OtherDerived>& other);
  238. /** Special case of the template operator=, in order to prevent the compiler
  239. * from generating a default operator= (issue hit with g++ 4.1)
  240. */
  241. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  242. Derived& operator=(const DenseBase& other);
  243. template<typename OtherDerived>
  244. EIGEN_DEVICE_FUNC
  245. Derived& operator=(const EigenBase<OtherDerived> &other);
  246. template<typename OtherDerived>
  247. EIGEN_DEVICE_FUNC
  248. Derived& operator+=(const EigenBase<OtherDerived> &other);
  249. template<typename OtherDerived>
  250. EIGEN_DEVICE_FUNC
  251. Derived& operator-=(const EigenBase<OtherDerived> &other);
  252. template<typename OtherDerived>
  253. EIGEN_DEVICE_FUNC
  254. Derived& operator=(const ReturnByValue<OtherDerived>& func);
  255. /** \internal
  256. * Copies \a other into *this without evaluating other. \returns a reference to *this.
  257. * \deprecated */
  258. template<typename OtherDerived>
  259. EIGEN_DEVICE_FUNC
  260. Derived& lazyAssign(const DenseBase<OtherDerived>& other);
  261. EIGEN_DEVICE_FUNC
  262. CommaInitializer<Derived> operator<< (const Scalar& s);
  263. /** \deprecated it now returns \c *this */
  264. template<unsigned int Added,unsigned int Removed>
  265. EIGEN_DEPRECATED
  266. const Derived& flagged() const
  267. { return derived(); }
  268. template<typename OtherDerived>
  269. EIGEN_DEVICE_FUNC
  270. CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
  271. typedef Transpose<Derived> TransposeReturnType;
  272. EIGEN_DEVICE_FUNC
  273. TransposeReturnType transpose();
  274. typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
  275. EIGEN_DEVICE_FUNC
  276. ConstTransposeReturnType transpose() const;
  277. EIGEN_DEVICE_FUNC
  278. void transposeInPlace();
  279. EIGEN_DEVICE_FUNC static const ConstantReturnType
  280. Constant(Index rows, Index cols, const Scalar& value);
  281. EIGEN_DEVICE_FUNC static const ConstantReturnType
  282. Constant(Index size, const Scalar& value);
  283. EIGEN_DEVICE_FUNC static const ConstantReturnType
  284. Constant(const Scalar& value);
  285. EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType
  286. LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
  287. EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
  288. LinSpaced(Index size, const Scalar& low, const Scalar& high);
  289. EIGEN_DEVICE_FUNC static const SequentialLinSpacedReturnType
  290. LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
  291. EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
  292. LinSpaced(const Scalar& low, const Scalar& high);
  293. template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
  294. static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
  295. NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
  296. template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
  297. static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
  298. NullaryExpr(Index size, const CustomNullaryOp& func);
  299. template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
  300. static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
  301. NullaryExpr(const CustomNullaryOp& func);
  302. EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols);
  303. EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size);
  304. EIGEN_DEVICE_FUNC static const ConstantReturnType Zero();
  305. EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols);
  306. EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size);
  307. EIGEN_DEVICE_FUNC static const ConstantReturnType Ones();
  308. EIGEN_DEVICE_FUNC void fill(const Scalar& value);
  309. EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
  310. EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
  311. EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
  312. EIGEN_DEVICE_FUNC Derived& setZero();
  313. EIGEN_DEVICE_FUNC Derived& setOnes();
  314. EIGEN_DEVICE_FUNC Derived& setRandom();
  315. template<typename OtherDerived> EIGEN_DEVICE_FUNC
  316. bool isApprox(const DenseBase<OtherDerived>& other,
  317. const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  318. EIGEN_DEVICE_FUNC
  319. bool isMuchSmallerThan(const RealScalar& other,
  320. const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  321. template<typename OtherDerived> EIGEN_DEVICE_FUNC
  322. bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
  323. const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  324. EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  325. EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  326. EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  327. EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  328. inline bool hasNaN() const;
  329. inline bool allFinite() const;
  330. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  331. Derived& operator*=(const Scalar& other);
  332. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  333. Derived& operator/=(const Scalar& other);
  334. typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
  335. /** \returns the matrix or vector obtained by evaluating this expression.
  336. *
  337. * Notice that in the case of a plain matrix or vector (not an expression) this function just returns
  338. * a const reference, in order to avoid a useless copy.
  339. *
  340. * \warning Be carefull with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page \endlink.
  341. */
  342. EIGEN_DEVICE_FUNC
  343. EIGEN_STRONG_INLINE EvalReturnType eval() const
  344. {
  345. // Even though MSVC does not honor strong inlining when the return type
  346. // is a dynamic matrix, we desperately need strong inlining for fixed
  347. // size types on MSVC.
  348. return typename internal::eval<Derived>::type(derived());
  349. }
  350. /** swaps *this with the expression \a other.
  351. *
  352. */
  353. template<typename OtherDerived>
  354. EIGEN_DEVICE_FUNC
  355. void swap(const DenseBase<OtherDerived>& other)
  356. {
  357. EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
  358. eigen_assert(rows()==other.rows() && cols()==other.cols());
  359. call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
  360. }
  361. /** swaps *this with the matrix or array \a other.
  362. *
  363. */
  364. template<typename OtherDerived>
  365. EIGEN_DEVICE_FUNC
  366. void swap(PlainObjectBase<OtherDerived>& other)
  367. {
  368. eigen_assert(rows()==other.rows() && cols()==other.cols());
  369. call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
  370. }
  371. EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const;
  372. EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
  373. EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess();
  374. template<bool Enable> EIGEN_DEVICE_FUNC
  375. inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
  376. template<bool Enable> EIGEN_DEVICE_FUNC
  377. inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
  378. EIGEN_DEVICE_FUNC Scalar sum() const;
  379. EIGEN_DEVICE_FUNC Scalar mean() const;
  380. EIGEN_DEVICE_FUNC Scalar trace() const;
  381. EIGEN_DEVICE_FUNC Scalar prod() const;
  382. EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const;
  383. EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const;
  384. template<typename IndexType> EIGEN_DEVICE_FUNC
  385. typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
  386. template<typename IndexType> EIGEN_DEVICE_FUNC
  387. typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
  388. template<typename IndexType> EIGEN_DEVICE_FUNC
  389. typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
  390. template<typename IndexType> EIGEN_DEVICE_FUNC
  391. typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
  392. template<typename BinaryOp>
  393. EIGEN_DEVICE_FUNC
  394. Scalar redux(const BinaryOp& func) const;
  395. template<typename Visitor>
  396. EIGEN_DEVICE_FUNC
  397. void visit(Visitor& func) const;
  398. /** \returns a WithFormat proxy object allowing to print a matrix the with given
  399. * format \a fmt.
  400. *
  401. * See class IOFormat for some examples.
  402. *
  403. * \sa class IOFormat, class WithFormat
  404. */
  405. inline const WithFormat<Derived> format(const IOFormat& fmt) const
  406. {
  407. return WithFormat<Derived>(derived(), fmt);
  408. }
  409. /** \returns the unique coefficient of a 1x1 expression */
  410. EIGEN_DEVICE_FUNC
  411. CoeffReturnType value() const
  412. {
  413. EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
  414. eigen_assert(this->rows() == 1 && this->cols() == 1);
  415. return derived().coeff(0,0);
  416. }
  417. EIGEN_DEVICE_FUNC bool all() const;
  418. EIGEN_DEVICE_FUNC bool any() const;
  419. EIGEN_DEVICE_FUNC Index count() const;
  420. typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
  421. typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
  422. typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
  423. typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
  424. /** \returns a VectorwiseOp wrapper of *this providing additional partial reduction operations
  425. *
  426. * Example: \include MatrixBase_rowwise.cpp
  427. * Output: \verbinclude MatrixBase_rowwise.out
  428. *
  429. * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
  430. */
  431. //Code moved here due to a CUDA compiler bug
  432. EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const {
  433. return ConstRowwiseReturnType(derived());
  434. }
  435. EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
  436. /** \returns a VectorwiseOp wrapper of *this providing additional partial reduction operations
  437. *
  438. * Example: \include MatrixBase_colwise.cpp
  439. * Output: \verbinclude MatrixBase_colwise.out
  440. *
  441. * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
  442. */
  443. EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const {
  444. return ConstColwiseReturnType(derived());
  445. }
  446. EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
  447. typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType;
  448. static const RandomReturnType Random(Index rows, Index cols);
  449. static const RandomReturnType Random(Index size);
  450. static const RandomReturnType Random();
  451. template<typename ThenDerived,typename ElseDerived>
  452. const Select<Derived,ThenDerived,ElseDerived>
  453. select(const DenseBase<ThenDerived>& thenMatrix,
  454. const DenseBase<ElseDerived>& elseMatrix) const;
  455. template<typename ThenDerived>
  456. inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
  457. select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
  458. template<typename ElseDerived>
  459. inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
  460. select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
  461. template<int p> RealScalar lpNorm() const;
  462. template<int RowFactor, int ColFactor>
  463. EIGEN_DEVICE_FUNC
  464. const Replicate<Derived,RowFactor,ColFactor> replicate() const;
  465. /**
  466. * \return an expression of the replication of \c *this
  467. *
  468. * Example: \include MatrixBase_replicate_int_int.cpp
  469. * Output: \verbinclude MatrixBase_replicate_int_int.out
  470. *
  471. * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), class Replicate
  472. */
  473. //Code moved here due to a CUDA compiler bug
  474. EIGEN_DEVICE_FUNC
  475. const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const
  476. {
  477. return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
  478. }
  479. typedef Reverse<Derived, BothDirections> ReverseReturnType;
  480. typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
  481. EIGEN_DEVICE_FUNC ReverseReturnType reverse();
  482. /** This is the const version of reverse(). */
  483. //Code moved here due to a CUDA compiler bug
  484. EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const
  485. {
  486. return ConstReverseReturnType(derived());
  487. }
  488. EIGEN_DEVICE_FUNC void reverseInPlace();
  489. #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
  490. #define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
  491. #define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
  492. # include "../plugins/BlockMethods.h"
  493. # ifdef EIGEN_DENSEBASE_PLUGIN
  494. # include EIGEN_DENSEBASE_PLUGIN
  495. # endif
  496. #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
  497. #undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
  498. #undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
  499. // disable the use of evalTo for dense objects with a nice compilation error
  500. template<typename Dest>
  501. EIGEN_DEVICE_FUNC
  502. inline void evalTo(Dest& ) const
  503. {
  504. EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
  505. }
  506. protected:
  507. EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
  508. /** Default constructor. Do nothing. */
  509. EIGEN_DEVICE_FUNC DenseBase()
  510. {
  511. /* Just checks for self-consistency of the flags.
  512. * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
  513. */
  514. #ifdef EIGEN_INTERNAL_DEBUGGING
  515. EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
  516. && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
  517. INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
  518. #endif
  519. }
  520. private:
  521. EIGEN_DEVICE_FUNC explicit DenseBase(int);
  522. EIGEN_DEVICE_FUNC DenseBase(int,int);
  523. template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
  524. };
  525. } // end namespace Eigen
  526. #endif // EIGEN_DENSEBASE_H