MatrixBase.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. // Copyright (C) 2008 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_MATRIXBASE_H
  11. #define EIGEN_MATRIXBASE_H
  12. namespace Eigen {
  13. /** \class MatrixBase
  14. * \ingroup Core_Module
  15. *
  16. * \brief Base class for all dense matrices, vectors, and expressions
  17. *
  18. * This class is the base that is inherited by all matrix, vector, and related expression
  19. * types. Most of the Eigen API is contained in this class, and its base classes. Other important
  20. * classes for the Eigen API are Matrix, and VectorwiseOp.
  21. *
  22. * Note that some methods are defined in other modules such as the \ref LU_Module LU module
  23. * for all functions related to matrix inversions.
  24. *
  25. * \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc.
  26. *
  27. * When writing a function taking Eigen objects as argument, if you want your function
  28. * to take as argument any matrix, vector, or expression, just let it take a
  29. * MatrixBase argument. As an example, here is a function printFirstRow which, given
  30. * a matrix, vector, or expression \a x, prints the first row of \a x.
  31. *
  32. * \code
  33. template<typename Derived>
  34. void printFirstRow(const Eigen::MatrixBase<Derived>& x)
  35. {
  36. cout << x.row(0) << endl;
  37. }
  38. * \endcode
  39. *
  40. * This class can be extended with the help of the plugin mechanism described on the page
  41. * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN.
  42. *
  43. * \sa \blank \ref TopicClassHierarchy
  44. */
  45. template<typename Derived> class MatrixBase
  46. : public DenseBase<Derived>
  47. {
  48. public:
  49. #ifndef EIGEN_PARSED_BY_DOXYGEN
  50. typedef MatrixBase StorageBaseType;
  51. typedef typename internal::traits<Derived>::StorageKind StorageKind;
  52. typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
  53. typedef typename internal::traits<Derived>::Scalar Scalar;
  54. typedef typename internal::packet_traits<Scalar>::type PacketScalar;
  55. typedef typename NumTraits<Scalar>::Real RealScalar;
  56. typedef DenseBase<Derived> Base;
  57. using Base::RowsAtCompileTime;
  58. using Base::ColsAtCompileTime;
  59. using Base::SizeAtCompileTime;
  60. using Base::MaxRowsAtCompileTime;
  61. using Base::MaxColsAtCompileTime;
  62. using Base::MaxSizeAtCompileTime;
  63. using Base::IsVectorAtCompileTime;
  64. using Base::Flags;
  65. using Base::derived;
  66. using Base::const_cast_derived;
  67. using Base::rows;
  68. using Base::cols;
  69. using Base::size;
  70. using Base::coeff;
  71. using Base::coeffRef;
  72. using Base::lazyAssign;
  73. using Base::eval;
  74. using Base::operator-;
  75. using Base::operator+=;
  76. using Base::operator-=;
  77. using Base::operator*=;
  78. using Base::operator/=;
  79. typedef typename Base::CoeffReturnType CoeffReturnType;
  80. typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
  81. typedef typename Base::RowXpr RowXpr;
  82. typedef typename Base::ColXpr ColXpr;
  83. #endif // not EIGEN_PARSED_BY_DOXYGEN
  84. #ifndef EIGEN_PARSED_BY_DOXYGEN
  85. /** type of the equivalent square matrix */
  86. typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
  87. EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
  88. #endif // not EIGEN_PARSED_BY_DOXYGEN
  89. /** \returns the size of the main diagonal, which is min(rows(),cols()).
  90. * \sa rows(), cols(), SizeAtCompileTime. */
  91. EIGEN_DEVICE_FUNC
  92. inline Index diagonalSize() const { return (numext::mini)(rows(),cols()); }
  93. typedef typename Base::PlainObject PlainObject;
  94. #ifndef EIGEN_PARSED_BY_DOXYGEN
  95. /** \internal Represents a matrix with all coefficients equal to one another*/
  96. typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
  97. /** \internal the return type of MatrixBase::adjoint() */
  98. typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
  99. CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
  100. ConstTransposeReturnType
  101. >::type AdjointReturnType;
  102. /** \internal Return type of eigenvalues() */
  103. typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
  104. /** \internal the return type of identity */
  105. typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,PlainObject> IdentityReturnType;
  106. /** \internal the return type of unit vectors */
  107. typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
  108. internal::traits<Derived>::RowsAtCompileTime,
  109. internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
  110. #endif // not EIGEN_PARSED_BY_DOXYGEN
  111. #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
  112. #define EIGEN_DOC_UNARY_ADDONS(X,Y)
  113. # include "../plugins/CommonCwiseBinaryOps.h"
  114. # include "../plugins/MatrixCwiseUnaryOps.h"
  115. # include "../plugins/MatrixCwiseBinaryOps.h"
  116. # ifdef EIGEN_MATRIXBASE_PLUGIN
  117. # include EIGEN_MATRIXBASE_PLUGIN
  118. # endif
  119. #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
  120. #undef EIGEN_DOC_UNARY_ADDONS
  121. /** Special case of the template operator=, in order to prevent the compiler
  122. * from generating a default operator= (issue hit with g++ 4.1)
  123. */
  124. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  125. Derived& operator=(const MatrixBase& other);
  126. // We cannot inherit here via Base::operator= since it is causing
  127. // trouble with MSVC.
  128. template <typename OtherDerived>
  129. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  130. Derived& operator=(const DenseBase<OtherDerived>& other);
  131. template <typename OtherDerived>
  132. EIGEN_DEVICE_FUNC
  133. Derived& operator=(const EigenBase<OtherDerived>& other);
  134. template<typename OtherDerived>
  135. EIGEN_DEVICE_FUNC
  136. Derived& operator=(const ReturnByValue<OtherDerived>& other);
  137. template<typename OtherDerived>
  138. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  139. Derived& operator+=(const MatrixBase<OtherDerived>& other);
  140. template<typename OtherDerived>
  141. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
  142. Derived& operator-=(const MatrixBase<OtherDerived>& other);
  143. template<typename OtherDerived>
  144. EIGEN_DEVICE_FUNC
  145. const Product<Derived,OtherDerived>
  146. operator*(const MatrixBase<OtherDerived> &other) const;
  147. template<typename OtherDerived>
  148. EIGEN_DEVICE_FUNC
  149. const Product<Derived,OtherDerived,LazyProduct>
  150. lazyProduct(const MatrixBase<OtherDerived> &other) const;
  151. template<typename OtherDerived>
  152. Derived& operator*=(const EigenBase<OtherDerived>& other);
  153. template<typename OtherDerived>
  154. void applyOnTheLeft(const EigenBase<OtherDerived>& other);
  155. template<typename OtherDerived>
  156. void applyOnTheRight(const EigenBase<OtherDerived>& other);
  157. template<typename DiagonalDerived>
  158. EIGEN_DEVICE_FUNC
  159. const Product<Derived, DiagonalDerived, LazyProduct>
  160. operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
  161. template<typename OtherDerived>
  162. EIGEN_DEVICE_FUNC
  163. typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
  164. dot(const MatrixBase<OtherDerived>& other) const;
  165. EIGEN_DEVICE_FUNC RealScalar squaredNorm() const;
  166. EIGEN_DEVICE_FUNC RealScalar norm() const;
  167. RealScalar stableNorm() const;
  168. RealScalar blueNorm() const;
  169. RealScalar hypotNorm() const;
  170. EIGEN_DEVICE_FUNC const PlainObject normalized() const;
  171. EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const;
  172. EIGEN_DEVICE_FUNC void normalize();
  173. EIGEN_DEVICE_FUNC void stableNormalize();
  174. EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const;
  175. EIGEN_DEVICE_FUNC void adjointInPlace();
  176. typedef Diagonal<Derived> DiagonalReturnType;
  177. EIGEN_DEVICE_FUNC
  178. DiagonalReturnType diagonal();
  179. typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType;
  180. EIGEN_DEVICE_FUNC
  181. ConstDiagonalReturnType diagonal() const;
  182. template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
  183. template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };
  184. template<int Index>
  185. EIGEN_DEVICE_FUNC
  186. typename DiagonalIndexReturnType<Index>::Type diagonal();
  187. template<int Index>
  188. EIGEN_DEVICE_FUNC
  189. typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;
  190. typedef Diagonal<Derived,DynamicIndex> DiagonalDynamicIndexReturnType;
  191. typedef typename internal::add_const<Diagonal<const Derived,DynamicIndex> >::type ConstDiagonalDynamicIndexReturnType;
  192. EIGEN_DEVICE_FUNC
  193. DiagonalDynamicIndexReturnType diagonal(Index index);
  194. EIGEN_DEVICE_FUNC
  195. ConstDiagonalDynamicIndexReturnType diagonal(Index index) const;
  196. template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
  197. template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
  198. template<unsigned int Mode>
  199. EIGEN_DEVICE_FUNC
  200. typename TriangularViewReturnType<Mode>::Type triangularView();
  201. template<unsigned int Mode>
  202. EIGEN_DEVICE_FUNC
  203. typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
  204. template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
  205. template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
  206. template<unsigned int UpLo>
  207. EIGEN_DEVICE_FUNC
  208. typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
  209. template<unsigned int UpLo>
  210. EIGEN_DEVICE_FUNC
  211. typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
  212. const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
  213. const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
  214. EIGEN_DEVICE_FUNC static const IdentityReturnType Identity();
  215. EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols);
  216. EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i);
  217. EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i);
  218. EIGEN_DEVICE_FUNC static const BasisReturnType UnitX();
  219. EIGEN_DEVICE_FUNC static const BasisReturnType UnitY();
  220. EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ();
  221. EIGEN_DEVICE_FUNC static const BasisReturnType UnitW();
  222. EIGEN_DEVICE_FUNC
  223. const DiagonalWrapper<const Derived> asDiagonal() const;
  224. const PermutationWrapper<const Derived> asPermutation() const;
  225. EIGEN_DEVICE_FUNC
  226. Derived& setIdentity();
  227. EIGEN_DEVICE_FUNC
  228. Derived& setIdentity(Index rows, Index cols);
  229. EIGEN_DEVICE_FUNC Derived& setUnit(Index i);
  230. EIGEN_DEVICE_FUNC Derived& setUnit(Index newSize, Index i);
  231. bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  232. bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  233. bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  234. bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  235. template<typename OtherDerived>
  236. bool isOrthogonal(const MatrixBase<OtherDerived>& other,
  237. const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  238. bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
  239. /** \returns true if each coefficients of \c *this and \a other are all exactly equal.
  240. * \warning When using floating point scalar values you probably should rather use a
  241. * fuzzy comparison such as isApprox()
  242. * \sa isApprox(), operator!= */
  243. template<typename OtherDerived>
  244. EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const
  245. { return cwiseEqual(other).all(); }
  246. /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other.
  247. * \warning When using floating point scalar values you probably should rather use a
  248. * fuzzy comparison such as isApprox()
  249. * \sa isApprox(), operator== */
  250. template<typename OtherDerived>
  251. EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const
  252. { return cwiseNotEqual(other).any(); }
  253. NoAlias<Derived,Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias();
  254. // TODO forceAlignedAccess is temporarily disabled
  255. // Need to find a nicer workaround.
  256. inline const Derived& forceAlignedAccess() const { return derived(); }
  257. inline Derived& forceAlignedAccess() { return derived(); }
  258. template<bool Enable> inline const Derived& forceAlignedAccessIf() const { return derived(); }
  259. template<bool Enable> inline Derived& forceAlignedAccessIf() { return derived(); }
  260. EIGEN_DEVICE_FUNC Scalar trace() const;
  261. template<int p> EIGEN_DEVICE_FUNC RealScalar lpNorm() const;
  262. EIGEN_DEVICE_FUNC MatrixBase<Derived>& matrix() { return *this; }
  263. EIGEN_DEVICE_FUNC const MatrixBase<Derived>& matrix() const { return *this; }
  264. /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix
  265. * \sa ArrayBase::matrix() */
  266. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); }
  267. /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix
  268. * \sa ArrayBase::matrix() */
  269. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); }
  270. /////////// LU module ///////////
  271. inline const FullPivLU<PlainObject> fullPivLu() const;
  272. inline const PartialPivLU<PlainObject> partialPivLu() const;
  273. inline const PartialPivLU<PlainObject> lu() const;
  274. EIGEN_DEVICE_FUNC
  275. inline const Inverse<Derived> inverse() const;
  276. template<typename ResultType>
  277. inline void computeInverseAndDetWithCheck(
  278. ResultType& inverse,
  279. typename ResultType::Scalar& determinant,
  280. bool& invertible,
  281. const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
  282. ) const;
  283. template<typename ResultType>
  284. inline void computeInverseWithCheck(
  285. ResultType& inverse,
  286. bool& invertible,
  287. const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
  288. ) const;
  289. EIGEN_DEVICE_FUNC
  290. Scalar determinant() const;
  291. /////////// Cholesky module ///////////
  292. inline const LLT<PlainObject> llt() const;
  293. inline const LDLT<PlainObject> ldlt() const;
  294. /////////// QR module ///////////
  295. inline const HouseholderQR<PlainObject> householderQr() const;
  296. inline const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
  297. inline const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
  298. inline const CompleteOrthogonalDecomposition<PlainObject> completeOrthogonalDecomposition() const;
  299. /////////// Eigenvalues module ///////////
  300. inline EigenvaluesReturnType eigenvalues() const;
  301. inline RealScalar operatorNorm() const;
  302. /////////// SVD module ///////////
  303. inline JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
  304. inline BDCSVD<PlainObject> bdcSvd(unsigned int computationOptions = 0) const;
  305. /////////// Geometry module ///////////
  306. #ifndef EIGEN_PARSED_BY_DOXYGEN
  307. /// \internal helper struct to form the return type of the cross product
  308. template<typename OtherDerived> struct cross_product_return_type {
  309. typedef typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
  310. typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
  311. };
  312. #endif // EIGEN_PARSED_BY_DOXYGEN
  313. template<typename OtherDerived>
  314. EIGEN_DEVICE_FUNC
  315. #ifndef EIGEN_PARSED_BY_DOXYGEN
  316. inline typename cross_product_return_type<OtherDerived>::type
  317. #else
  318. inline PlainObject
  319. #endif
  320. cross(const MatrixBase<OtherDerived>& other) const;
  321. template<typename OtherDerived>
  322. EIGEN_DEVICE_FUNC
  323. inline PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
  324. EIGEN_DEVICE_FUNC
  325. inline PlainObject unitOrthogonal(void) const;
  326. EIGEN_DEVICE_FUNC
  327. inline Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
  328. // put this as separate enum value to work around possible GCC 4.3 bug (?)
  329. enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1&&RowsAtCompileTime==1 ? ((internal::traits<Derived>::Flags&RowMajorBit)==RowMajorBit ? Horizontal : Vertical)
  330. : ColsAtCompileTime==1 ? Vertical : Horizontal };
  331. typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
  332. EIGEN_DEVICE_FUNC
  333. inline HomogeneousReturnType homogeneous() const;
  334. enum {
  335. SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
  336. };
  337. typedef Block<const Derived,
  338. internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
  339. internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
  340. typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne,Scalar,quotient) HNormalizedReturnType;
  341. EIGEN_DEVICE_FUNC
  342. inline const HNormalizedReturnType hnormalized() const;
  343. ////////// Householder module ///////////
  344. EIGEN_DEVICE_FUNC
  345. void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
  346. template<typename EssentialPart>
  347. EIGEN_DEVICE_FUNC
  348. void makeHouseholder(EssentialPart& essential,
  349. Scalar& tau, RealScalar& beta) const;
  350. template<typename EssentialPart>
  351. EIGEN_DEVICE_FUNC
  352. void applyHouseholderOnTheLeft(const EssentialPart& essential,
  353. const Scalar& tau,
  354. Scalar* workspace);
  355. template<typename EssentialPart>
  356. EIGEN_DEVICE_FUNC
  357. void applyHouseholderOnTheRight(const EssentialPart& essential,
  358. const Scalar& tau,
  359. Scalar* workspace);
  360. ///////// Jacobi module /////////
  361. template<typename OtherScalar>
  362. EIGEN_DEVICE_FUNC
  363. void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
  364. template<typename OtherScalar>
  365. EIGEN_DEVICE_FUNC
  366. void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
  367. ///////// SparseCore module /////////
  368. template<typename OtherDerived>
  369. EIGEN_STRONG_INLINE const typename SparseMatrixBase<OtherDerived>::template CwiseProductDenseReturnType<Derived>::Type
  370. cwiseProduct(const SparseMatrixBase<OtherDerived> &other) const
  371. {
  372. return other.cwiseProduct(derived());
  373. }
  374. ///////// MatrixFunctions module /////////
  375. typedef typename internal::stem_function<Scalar>::type StemFunction;
  376. #define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \
  377. /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
  378. const ReturnType<Derived> Name() const;
  379. #define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \
  380. /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
  381. const ReturnType<Derived> Name(Argument) const;
  382. EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential)
  383. /** \brief Helper function for the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>.*/
  384. const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
  385. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
  386. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
  387. #if EIGEN_HAS_CXX11_MATH
  388. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine)
  389. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine)
  390. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine)
  391. #endif
  392. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
  393. EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
  394. EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
  395. EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm)
  396. EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p)
  397. EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)
  398. protected:
  399. EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase)
  400. EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase)
  401. private:
  402. EIGEN_DEVICE_FUNC explicit MatrixBase(int);
  403. EIGEN_DEVICE_FUNC MatrixBase(int,int);
  404. template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase<OtherDerived>&);
  405. protected:
  406. // mixing arrays and matrices is not legal
  407. template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
  408. {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
  409. // mixing arrays and matrices is not legal
  410. template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
  411. {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
  412. };
  413. /***************************************************************************
  414. * Implementation of matrix base methods
  415. ***************************************************************************/
  416. /** replaces \c *this by \c *this * \a other.
  417. *
  418. * \returns a reference to \c *this
  419. *
  420. * Example: \include MatrixBase_applyOnTheRight.cpp
  421. * Output: \verbinclude MatrixBase_applyOnTheRight.out
  422. */
  423. template<typename Derived>
  424. template<typename OtherDerived>
  425. inline Derived&
  426. MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
  427. {
  428. other.derived().applyThisOnTheRight(derived());
  429. return derived();
  430. }
  431. /** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=().
  432. *
  433. * Example: \include MatrixBase_applyOnTheRight.cpp
  434. * Output: \verbinclude MatrixBase_applyOnTheRight.out
  435. */
  436. template<typename Derived>
  437. template<typename OtherDerived>
  438. inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
  439. {
  440. other.derived().applyThisOnTheRight(derived());
  441. }
  442. /** replaces \c *this by \a other * \c *this.
  443. *
  444. * Example: \include MatrixBase_applyOnTheLeft.cpp
  445. * Output: \verbinclude MatrixBase_applyOnTheLeft.out
  446. */
  447. template<typename Derived>
  448. template<typename OtherDerived>
  449. inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
  450. {
  451. other.derived().applyThisOnTheLeft(derived());
  452. }
  453. } // end namespace Eigen
  454. #endif // EIGEN_MATRIXBASE_H