ArrayCwiseUnaryOps.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. typedef CwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> AbsReturnType;
  2. typedef CwiseUnaryOp<internal::scalar_arg_op<Scalar>, const Derived> ArgReturnType;
  3. typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> Abs2ReturnType;
  4. typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> SqrtReturnType;
  5. typedef CwiseUnaryOp<internal::scalar_rsqrt_op<Scalar>, const Derived> RsqrtReturnType;
  6. typedef CwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> SignReturnType;
  7. typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> InverseReturnType;
  8. typedef CwiseUnaryOp<internal::scalar_boolean_not_op<Scalar>, const Derived> BooleanNotReturnType;
  9. typedef CwiseUnaryOp<internal::scalar_exp_op<Scalar>, const Derived> ExpReturnType;
  10. typedef CwiseUnaryOp<internal::scalar_log_op<Scalar>, const Derived> LogReturnType;
  11. typedef CwiseUnaryOp<internal::scalar_log1p_op<Scalar>, const Derived> Log1pReturnType;
  12. typedef CwiseUnaryOp<internal::scalar_log10_op<Scalar>, const Derived> Log10ReturnType;
  13. typedef CwiseUnaryOp<internal::scalar_cos_op<Scalar>, const Derived> CosReturnType;
  14. typedef CwiseUnaryOp<internal::scalar_sin_op<Scalar>, const Derived> SinReturnType;
  15. typedef CwiseUnaryOp<internal::scalar_tan_op<Scalar>, const Derived> TanReturnType;
  16. typedef CwiseUnaryOp<internal::scalar_acos_op<Scalar>, const Derived> AcosReturnType;
  17. typedef CwiseUnaryOp<internal::scalar_asin_op<Scalar>, const Derived> AsinReturnType;
  18. typedef CwiseUnaryOp<internal::scalar_atan_op<Scalar>, const Derived> AtanReturnType;
  19. typedef CwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> TanhReturnType;
  20. typedef CwiseUnaryOp<internal::scalar_sinh_op<Scalar>, const Derived> SinhReturnType;
  21. typedef CwiseUnaryOp<internal::scalar_cosh_op<Scalar>, const Derived> CoshReturnType;
  22. typedef CwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> SquareReturnType;
  23. typedef CwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> CubeReturnType;
  24. typedef CwiseUnaryOp<internal::scalar_round_op<Scalar>, const Derived> RoundReturnType;
  25. typedef CwiseUnaryOp<internal::scalar_floor_op<Scalar>, const Derived> FloorReturnType;
  26. typedef CwiseUnaryOp<internal::scalar_ceil_op<Scalar>, const Derived> CeilReturnType;
  27. typedef CwiseUnaryOp<internal::scalar_isnan_op<Scalar>, const Derived> IsNaNReturnType;
  28. typedef CwiseUnaryOp<internal::scalar_isinf_op<Scalar>, const Derived> IsInfReturnType;
  29. typedef CwiseUnaryOp<internal::scalar_isfinite_op<Scalar>, const Derived> IsFiniteReturnType;
  30. /** \returns an expression of the coefficient-wise absolute value of \c *this
  31. *
  32. * Example: \include Cwise_abs.cpp
  33. * Output: \verbinclude Cwise_abs.out
  34. *
  35. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs">Math functions</a>, abs2()
  36. */
  37. EIGEN_DEVICE_FUNC
  38. EIGEN_STRONG_INLINE const AbsReturnType
  39. abs() const
  40. {
  41. return AbsReturnType(derived());
  42. }
  43. /** \returns an expression of the coefficient-wise phase angle of \c *this
  44. *
  45. * Example: \include Cwise_arg.cpp
  46. * Output: \verbinclude Cwise_arg.out
  47. *
  48. * \sa abs()
  49. */
  50. EIGEN_DEVICE_FUNC
  51. EIGEN_STRONG_INLINE const ArgReturnType
  52. arg() const
  53. {
  54. return ArgReturnType(derived());
  55. }
  56. /** \returns an expression of the coefficient-wise squared absolute value of \c *this
  57. *
  58. * Example: \include Cwise_abs2.cpp
  59. * Output: \verbinclude Cwise_abs2.out
  60. *
  61. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs2">Math functions</a>, abs(), square()
  62. */
  63. EIGEN_DEVICE_FUNC
  64. EIGEN_STRONG_INLINE const Abs2ReturnType
  65. abs2() const
  66. {
  67. return Abs2ReturnType(derived());
  68. }
  69. /** \returns an expression of the coefficient-wise exponential of *this.
  70. *
  71. * This function computes the coefficient-wise exponential. The function MatrixBase::exp() in the
  72. * unsupported module MatrixFunctions computes the matrix exponential.
  73. *
  74. * Example: \include Cwise_exp.cpp
  75. * Output: \verbinclude Cwise_exp.out
  76. *
  77. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_exp">Math functions</a>, pow(), log(), sin(), cos()
  78. */
  79. EIGEN_DEVICE_FUNC
  80. inline const ExpReturnType
  81. exp() const
  82. {
  83. return ExpReturnType(derived());
  84. }
  85. /** \returns an expression of the coefficient-wise logarithm of *this.
  86. *
  87. * This function computes the coefficient-wise logarithm. The function MatrixBase::log() in the
  88. * unsupported module MatrixFunctions computes the matrix logarithm.
  89. *
  90. * Example: \include Cwise_log.cpp
  91. * Output: \verbinclude Cwise_log.out
  92. *
  93. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log">Math functions</a>, exp()
  94. */
  95. EIGEN_DEVICE_FUNC
  96. inline const LogReturnType
  97. log() const
  98. {
  99. return LogReturnType(derived());
  100. }
  101. /** \returns an expression of the coefficient-wise logarithm of 1 plus \c *this.
  102. *
  103. * In exact arithmetic, \c x.log() is equivalent to \c (x+1).log(),
  104. * however, with finite precision, this function is much more accurate when \c x is close to zero.
  105. *
  106. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log1p">Math functions</a>, log()
  107. */
  108. EIGEN_DEVICE_FUNC
  109. inline const Log1pReturnType
  110. log1p() const
  111. {
  112. return Log1pReturnType(derived());
  113. }
  114. /** \returns an expression of the coefficient-wise base-10 logarithm of *this.
  115. *
  116. * This function computes the coefficient-wise base-10 logarithm.
  117. *
  118. * Example: \include Cwise_log10.cpp
  119. * Output: \verbinclude Cwise_log10.out
  120. *
  121. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log10">Math functions</a>, log()
  122. */
  123. EIGEN_DEVICE_FUNC
  124. inline const Log10ReturnType
  125. log10() const
  126. {
  127. return Log10ReturnType(derived());
  128. }
  129. /** \returns an expression of the coefficient-wise square root of *this.
  130. *
  131. * This function computes the coefficient-wise square root. The function MatrixBase::sqrt() in the
  132. * unsupported module MatrixFunctions computes the matrix square root.
  133. *
  134. * Example: \include Cwise_sqrt.cpp
  135. * Output: \verbinclude Cwise_sqrt.out
  136. *
  137. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sqrt">Math functions</a>, pow(), square()
  138. */
  139. EIGEN_DEVICE_FUNC
  140. inline const SqrtReturnType
  141. sqrt() const
  142. {
  143. return SqrtReturnType(derived());
  144. }
  145. /** \returns an expression of the coefficient-wise inverse square root of *this.
  146. *
  147. * This function computes the coefficient-wise inverse square root.
  148. *
  149. * Example: \include Cwise_sqrt.cpp
  150. * Output: \verbinclude Cwise_sqrt.out
  151. *
  152. * \sa pow(), square()
  153. */
  154. EIGEN_DEVICE_FUNC
  155. inline const RsqrtReturnType
  156. rsqrt() const
  157. {
  158. return RsqrtReturnType(derived());
  159. }
  160. /** \returns an expression of the coefficient-wise signum of *this.
  161. *
  162. * This function computes the coefficient-wise signum.
  163. *
  164. * Example: \include Cwise_sign.cpp
  165. * Output: \verbinclude Cwise_sign.out
  166. *
  167. * \sa pow(), square()
  168. */
  169. EIGEN_DEVICE_FUNC
  170. inline const SignReturnType
  171. sign() const
  172. {
  173. return SignReturnType(derived());
  174. }
  175. /** \returns an expression of the coefficient-wise cosine of *this.
  176. *
  177. * This function computes the coefficient-wise cosine. The function MatrixBase::cos() in the
  178. * unsupported module MatrixFunctions computes the matrix cosine.
  179. *
  180. * Example: \include Cwise_cos.cpp
  181. * Output: \verbinclude Cwise_cos.out
  182. *
  183. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cos">Math functions</a>, sin(), acos()
  184. */
  185. EIGEN_DEVICE_FUNC
  186. inline const CosReturnType
  187. cos() const
  188. {
  189. return CosReturnType(derived());
  190. }
  191. /** \returns an expression of the coefficient-wise sine of *this.
  192. *
  193. * This function computes the coefficient-wise sine. The function MatrixBase::sin() in the
  194. * unsupported module MatrixFunctions computes the matrix sine.
  195. *
  196. * Example: \include Cwise_sin.cpp
  197. * Output: \verbinclude Cwise_sin.out
  198. *
  199. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sin">Math functions</a>, cos(), asin()
  200. */
  201. EIGEN_DEVICE_FUNC
  202. inline const SinReturnType
  203. sin() const
  204. {
  205. return SinReturnType(derived());
  206. }
  207. /** \returns an expression of the coefficient-wise tan of *this.
  208. *
  209. * Example: \include Cwise_tan.cpp
  210. * Output: \verbinclude Cwise_tan.out
  211. *
  212. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tan">Math functions</a>, cos(), sin()
  213. */
  214. EIGEN_DEVICE_FUNC
  215. inline const TanReturnType
  216. tan() const
  217. {
  218. return TanReturnType(derived());
  219. }
  220. /** \returns an expression of the coefficient-wise arc tan of *this.
  221. *
  222. * Example: \include Cwise_atan.cpp
  223. * Output: \verbinclude Cwise_atan.out
  224. *
  225. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atan">Math functions</a>, tan(), asin(), acos()
  226. */
  227. EIGEN_DEVICE_FUNC
  228. inline const AtanReturnType
  229. atan() const
  230. {
  231. return AtanReturnType(derived());
  232. }
  233. /** \returns an expression of the coefficient-wise arc cosine of *this.
  234. *
  235. * Example: \include Cwise_acos.cpp
  236. * Output: \verbinclude Cwise_acos.out
  237. *
  238. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acos">Math functions</a>, cos(), asin()
  239. */
  240. EIGEN_DEVICE_FUNC
  241. inline const AcosReturnType
  242. acos() const
  243. {
  244. return AcosReturnType(derived());
  245. }
  246. /** \returns an expression of the coefficient-wise arc sine of *this.
  247. *
  248. * Example: \include Cwise_asin.cpp
  249. * Output: \verbinclude Cwise_asin.out
  250. *
  251. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asin">Math functions</a>, sin(), acos()
  252. */
  253. EIGEN_DEVICE_FUNC
  254. inline const AsinReturnType
  255. asin() const
  256. {
  257. return AsinReturnType(derived());
  258. }
  259. /** \returns an expression of the coefficient-wise hyperbolic tan of *this.
  260. *
  261. * Example: \include Cwise_tanh.cpp
  262. * Output: \verbinclude Cwise_tanh.out
  263. *
  264. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tanh">Math functions</a>, tan(), sinh(), cosh()
  265. */
  266. EIGEN_DEVICE_FUNC
  267. inline const TanhReturnType
  268. tanh() const
  269. {
  270. return TanhReturnType(derived());
  271. }
  272. /** \returns an expression of the coefficient-wise hyperbolic sin of *this.
  273. *
  274. * Example: \include Cwise_sinh.cpp
  275. * Output: \verbinclude Cwise_sinh.out
  276. *
  277. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sinh">Math functions</a>, sin(), tanh(), cosh()
  278. */
  279. EIGEN_DEVICE_FUNC
  280. inline const SinhReturnType
  281. sinh() const
  282. {
  283. return SinhReturnType(derived());
  284. }
  285. /** \returns an expression of the coefficient-wise hyperbolic cos of *this.
  286. *
  287. * Example: \include Cwise_cosh.cpp
  288. * Output: \verbinclude Cwise_cosh.out
  289. *
  290. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cosh">Math functions</a>, tan(), sinh(), cosh()
  291. */
  292. EIGEN_DEVICE_FUNC
  293. inline const CoshReturnType
  294. cosh() const
  295. {
  296. return CoshReturnType(derived());
  297. }
  298. /** \returns an expression of the coefficient-wise inverse of *this.
  299. *
  300. * Example: \include Cwise_inverse.cpp
  301. * Output: \verbinclude Cwise_inverse.out
  302. *
  303. * \sa operator/(), operator*()
  304. */
  305. EIGEN_DEVICE_FUNC
  306. inline const InverseReturnType
  307. inverse() const
  308. {
  309. return InverseReturnType(derived());
  310. }
  311. /** \returns an expression of the coefficient-wise square of *this.
  312. *
  313. * Example: \include Cwise_square.cpp
  314. * Output: \verbinclude Cwise_square.out
  315. *
  316. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_squareE">Math functions</a>, abs2(), cube(), pow()
  317. */
  318. EIGEN_DEVICE_FUNC
  319. inline const SquareReturnType
  320. square() const
  321. {
  322. return SquareReturnType(derived());
  323. }
  324. /** \returns an expression of the coefficient-wise cube of *this.
  325. *
  326. * Example: \include Cwise_cube.cpp
  327. * Output: \verbinclude Cwise_cube.out
  328. *
  329. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cube">Math functions</a>, square(), pow()
  330. */
  331. EIGEN_DEVICE_FUNC
  332. inline const CubeReturnType
  333. cube() const
  334. {
  335. return CubeReturnType(derived());
  336. }
  337. /** \returns an expression of the coefficient-wise round of *this.
  338. *
  339. * Example: \include Cwise_round.cpp
  340. * Output: \verbinclude Cwise_round.out
  341. *
  342. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_round">Math functions</a>, ceil(), floor()
  343. */
  344. EIGEN_DEVICE_FUNC
  345. inline const RoundReturnType
  346. round() const
  347. {
  348. return RoundReturnType(derived());
  349. }
  350. /** \returns an expression of the coefficient-wise floor of *this.
  351. *
  352. * Example: \include Cwise_floor.cpp
  353. * Output: \verbinclude Cwise_floor.out
  354. *
  355. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_floor">Math functions</a>, ceil(), round()
  356. */
  357. EIGEN_DEVICE_FUNC
  358. inline const FloorReturnType
  359. floor() const
  360. {
  361. return FloorReturnType(derived());
  362. }
  363. /** \returns an expression of the coefficient-wise ceil of *this.
  364. *
  365. * Example: \include Cwise_ceil.cpp
  366. * Output: \verbinclude Cwise_ceil.out
  367. *
  368. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ceil">Math functions</a>, floor(), round()
  369. */
  370. EIGEN_DEVICE_FUNC
  371. inline const CeilReturnType
  372. ceil() const
  373. {
  374. return CeilReturnType(derived());
  375. }
  376. /** \returns an expression of the coefficient-wise isnan of *this.
  377. *
  378. * Example: \include Cwise_isNaN.cpp
  379. * Output: \verbinclude Cwise_isNaN.out
  380. *
  381. * \sa isfinite(), isinf()
  382. */
  383. EIGEN_DEVICE_FUNC
  384. inline const IsNaNReturnType
  385. isNaN() const
  386. {
  387. return IsNaNReturnType(derived());
  388. }
  389. /** \returns an expression of the coefficient-wise isinf of *this.
  390. *
  391. * Example: \include Cwise_isInf.cpp
  392. * Output: \verbinclude Cwise_isInf.out
  393. *
  394. * \sa isnan(), isfinite()
  395. */
  396. EIGEN_DEVICE_FUNC
  397. inline const IsInfReturnType
  398. isInf() const
  399. {
  400. return IsInfReturnType(derived());
  401. }
  402. /** \returns an expression of the coefficient-wise isfinite of *this.
  403. *
  404. * Example: \include Cwise_isFinite.cpp
  405. * Output: \verbinclude Cwise_isFinite.out
  406. *
  407. * \sa isnan(), isinf()
  408. */
  409. EIGEN_DEVICE_FUNC
  410. inline const IsFiniteReturnType
  411. isFinite() const
  412. {
  413. return IsFiniteReturnType(derived());
  414. }
  415. /** \returns an expression of the coefficient-wise ! operator of *this
  416. *
  417. * \warning this operator is for expression of bool only.
  418. *
  419. * Example: \include Cwise_boolean_not.cpp
  420. * Output: \verbinclude Cwise_boolean_not.out
  421. *
  422. * \sa operator!=()
  423. */
  424. EIGEN_DEVICE_FUNC
  425. inline const BooleanNotReturnType
  426. operator!() const
  427. {
  428. EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value),
  429. THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
  430. return BooleanNotReturnType(derived());
  431. }
  432. // --- SpecialFunctions module ---
  433. typedef CwiseUnaryOp<internal::scalar_lgamma_op<Scalar>, const Derived> LgammaReturnType;
  434. typedef CwiseUnaryOp<internal::scalar_digamma_op<Scalar>, const Derived> DigammaReturnType;
  435. typedef CwiseUnaryOp<internal::scalar_erf_op<Scalar>, const Derived> ErfReturnType;
  436. typedef CwiseUnaryOp<internal::scalar_erfc_op<Scalar>, const Derived> ErfcReturnType;
  437. /** \cpp11 \returns an expression of the coefficient-wise ln(|gamma(*this)|).
  438. *
  439. * \specialfunctions_module
  440. *
  441. * Example: \include Cwise_lgamma.cpp
  442. * Output: \verbinclude Cwise_lgamma.out
  443. *
  444. * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
  445. * or float/double in non c++11 mode, the user has to provide implementations of lgamma(T) for any scalar
  446. * type T to be supported.
  447. *
  448. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_lgamma">Math functions</a>, digamma()
  449. */
  450. EIGEN_DEVICE_FUNC
  451. inline const LgammaReturnType
  452. lgamma() const
  453. {
  454. return LgammaReturnType(derived());
  455. }
  456. /** \returns an expression of the coefficient-wise digamma (psi, derivative of lgamma).
  457. *
  458. * \specialfunctions_module
  459. *
  460. * \note This function supports only float and double scalar types. To support other scalar types,
  461. * the user has to provide implementations of digamma(T) for any scalar
  462. * type T to be supported.
  463. *
  464. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_digamma">Math functions</a>, Eigen::digamma(), Eigen::polygamma(), lgamma()
  465. */
  466. EIGEN_DEVICE_FUNC
  467. inline const DigammaReturnType
  468. digamma() const
  469. {
  470. return DigammaReturnType(derived());
  471. }
  472. /** \cpp11 \returns an expression of the coefficient-wise Gauss error
  473. * function of *this.
  474. *
  475. * \specialfunctions_module
  476. *
  477. * Example: \include Cwise_erf.cpp
  478. * Output: \verbinclude Cwise_erf.out
  479. *
  480. * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
  481. * or float/double in non c++11 mode, the user has to provide implementations of erf(T) for any scalar
  482. * type T to be supported.
  483. *
  484. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erf">Math functions</a>, erfc()
  485. */
  486. EIGEN_DEVICE_FUNC
  487. inline const ErfReturnType
  488. erf() const
  489. {
  490. return ErfReturnType(derived());
  491. }
  492. /** \cpp11 \returns an expression of the coefficient-wise Complementary error
  493. * function of *this.
  494. *
  495. * \specialfunctions_module
  496. *
  497. * Example: \include Cwise_erfc.cpp
  498. * Output: \verbinclude Cwise_erfc.out
  499. *
  500. * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
  501. * or float/double in non c++11 mode, the user has to provide implementations of erfc(T) for any scalar
  502. * type T to be supported.
  503. *
  504. * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erfc">Math functions</a>, erf()
  505. */
  506. EIGEN_DEVICE_FUNC
  507. inline const ErfcReturnType
  508. erfc() const
  509. {
  510. return ErfcReturnType(derived());
  511. }