fn_trig.hpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_trig
  16. //! @{
  17. // single argument trigonometric functions:
  18. // cos family: cos, acos, cosh, acosh
  19. // sin family: sin, asin, sinh, asinh
  20. // tan family: tan, atan, tanh, atanh
  21. //
  22. // misc functions:
  23. // sinc
  24. //
  25. // dual argument trigonometric functions:
  26. // atan2
  27. // hypot
  28. //
  29. // cos
  30. template<typename T1>
  31. arma_warn_unused
  32. arma_inline
  33. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_cos> >::result
  34. cos(const T1& A)
  35. {
  36. arma_extra_debug_sigprint();
  37. return eOp<T1, eop_cos>(A);
  38. }
  39. template<typename T1>
  40. arma_warn_unused
  41. arma_inline
  42. const eOpCube<T1, eop_cos>
  43. cos(const BaseCube<typename T1::elem_type,T1>& A)
  44. {
  45. arma_extra_debug_sigprint();
  46. return eOpCube<T1, eop_cos>(A.get_ref());
  47. }
  48. //
  49. // acos
  50. template<typename T1>
  51. arma_warn_unused
  52. arma_inline
  53. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_acos> >::result
  54. acos(const T1& A)
  55. {
  56. arma_extra_debug_sigprint();
  57. return eOp<T1, eop_acos>(A);
  58. }
  59. template<typename T1>
  60. arma_warn_unused
  61. arma_inline
  62. const eOpCube<T1, eop_acos>
  63. acos(const BaseCube<typename T1::elem_type,T1>& A)
  64. {
  65. arma_extra_debug_sigprint();
  66. return eOpCube<T1, eop_acos>(A.get_ref());
  67. }
  68. //
  69. // cosh
  70. template<typename T1>
  71. arma_warn_unused
  72. arma_inline
  73. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_cosh> >::result
  74. cosh(const T1& A)
  75. {
  76. arma_extra_debug_sigprint();
  77. return eOp<T1, eop_cosh>(A);
  78. }
  79. template<typename T1>
  80. arma_warn_unused
  81. arma_inline
  82. const eOpCube<T1, eop_cosh>
  83. cosh(const BaseCube<typename T1::elem_type,T1>& A)
  84. {
  85. arma_extra_debug_sigprint();
  86. return eOpCube<T1, eop_cosh>(A.get_ref());
  87. }
  88. //
  89. // acosh
  90. template<typename T1>
  91. arma_warn_unused
  92. arma_inline
  93. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_acosh> >::result
  94. acosh(const T1& A)
  95. {
  96. arma_extra_debug_sigprint();
  97. return eOp<T1, eop_acosh>(A);
  98. }
  99. template<typename T1>
  100. arma_warn_unused
  101. arma_inline
  102. const eOpCube<T1, eop_acosh>
  103. acosh(const BaseCube<typename T1::elem_type,T1>& A)
  104. {
  105. arma_extra_debug_sigprint();
  106. return eOpCube<T1, eop_acosh>(A.get_ref());
  107. }
  108. //
  109. // sin
  110. template<typename T1>
  111. arma_warn_unused
  112. arma_inline
  113. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_sin> >::result
  114. sin(const T1& A)
  115. {
  116. arma_extra_debug_sigprint();
  117. return eOp<T1, eop_sin>(A);
  118. }
  119. template<typename T1>
  120. arma_warn_unused
  121. arma_inline
  122. const eOpCube<T1, eop_sin>
  123. sin(const BaseCube<typename T1::elem_type,T1>& A)
  124. {
  125. arma_extra_debug_sigprint();
  126. return eOpCube<T1, eop_sin>(A.get_ref());
  127. }
  128. //
  129. // asin
  130. template<typename T1>
  131. arma_warn_unused
  132. arma_inline
  133. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_asin> >::result
  134. asin(const T1& A)
  135. {
  136. arma_extra_debug_sigprint();
  137. return eOp<T1, eop_asin>(A);
  138. }
  139. template<typename T1>
  140. arma_warn_unused
  141. arma_inline
  142. const eOpCube<T1, eop_asin>
  143. asin(const BaseCube<typename T1::elem_type,T1>& A)
  144. {
  145. arma_extra_debug_sigprint();
  146. return eOpCube<T1, eop_asin>(A.get_ref());
  147. }
  148. //
  149. // sinh
  150. template<typename T1>
  151. arma_warn_unused
  152. arma_inline
  153. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_sinh> >::result
  154. sinh(const T1& A)
  155. {
  156. arma_extra_debug_sigprint();
  157. return eOp<T1, eop_sinh>(A);
  158. }
  159. template<typename T1>
  160. arma_warn_unused
  161. arma_inline
  162. const eOpCube<T1, eop_sinh>
  163. sinh(const BaseCube<typename T1::elem_type,T1>& A)
  164. {
  165. arma_extra_debug_sigprint();
  166. return eOpCube<T1, eop_sinh>(A.get_ref());
  167. }
  168. //
  169. // asinh
  170. template<typename T1>
  171. arma_warn_unused
  172. arma_inline
  173. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_asinh> >::result
  174. asinh(const T1& A)
  175. {
  176. arma_extra_debug_sigprint();
  177. return eOp<T1, eop_asinh>(A);
  178. }
  179. template<typename T1>
  180. arma_warn_unused
  181. arma_inline
  182. const eOpCube<T1, eop_asinh>
  183. asinh(const BaseCube<typename T1::elem_type,T1>& A)
  184. {
  185. arma_extra_debug_sigprint();
  186. return eOpCube<T1, eop_asinh>(A.get_ref());
  187. }
  188. //
  189. // tan
  190. template<typename T1>
  191. arma_warn_unused
  192. arma_inline
  193. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_tan> >::result
  194. tan(const T1& A)
  195. {
  196. arma_extra_debug_sigprint();
  197. return eOp<T1, eop_tan>(A);
  198. }
  199. template<typename T1>
  200. arma_warn_unused
  201. arma_inline
  202. const eOpCube<T1, eop_tan>
  203. tan(const BaseCube<typename T1::elem_type,T1>& A)
  204. {
  205. arma_extra_debug_sigprint();
  206. return eOpCube<T1, eop_tan>(A.get_ref());
  207. }
  208. //
  209. // atan
  210. template<typename T1>
  211. arma_warn_unused
  212. arma_inline
  213. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_atan> >::result
  214. atan(const T1& A)
  215. {
  216. arma_extra_debug_sigprint();
  217. return eOp<T1, eop_atan>(A);
  218. }
  219. template<typename T1>
  220. arma_warn_unused
  221. arma_inline
  222. const eOpCube<T1, eop_atan>
  223. atan(const BaseCube<typename T1::elem_type,T1>& A)
  224. {
  225. arma_extra_debug_sigprint();
  226. return eOpCube<T1, eop_atan>(A.get_ref());
  227. }
  228. //
  229. // tanh
  230. template<typename T1>
  231. arma_warn_unused
  232. arma_inline
  233. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_tanh> >::result
  234. tanh(const T1& A)
  235. {
  236. arma_extra_debug_sigprint();
  237. return eOp<T1, eop_tanh>(A);
  238. }
  239. template<typename T1>
  240. arma_warn_unused
  241. arma_inline
  242. const eOpCube<T1, eop_tanh>
  243. tanh(const BaseCube<typename T1::elem_type,T1>& A)
  244. {
  245. arma_extra_debug_sigprint();
  246. return eOpCube<T1, eop_tanh>(A.get_ref());
  247. }
  248. //
  249. // atanh
  250. template<typename T1>
  251. arma_warn_unused
  252. arma_inline
  253. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_atanh> >::result
  254. atanh(const T1& A)
  255. {
  256. arma_extra_debug_sigprint();
  257. return eOp<T1, eop_atanh>(A);
  258. }
  259. template<typename T1>
  260. arma_warn_unused
  261. arma_inline
  262. const eOpCube<T1, eop_atanh>
  263. atanh(const BaseCube<typename T1::elem_type,T1>& A)
  264. {
  265. arma_extra_debug_sigprint();
  266. return eOpCube<T1, eop_atanh>(A.get_ref());
  267. }
  268. //
  269. // sinc
  270. template<typename T>
  271. arma_warn_unused
  272. arma_inline
  273. typename arma_scalar_only<T>::result
  274. sinc(const T x)
  275. {
  276. return arma_sinc(x);
  277. }
  278. template<typename T1>
  279. arma_warn_unused
  280. arma_inline
  281. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_sinc> >::result
  282. sinc(const T1& A)
  283. {
  284. arma_extra_debug_sigprint();
  285. return eOp<T1, eop_sinc>(A);
  286. }
  287. template<typename T1>
  288. arma_warn_unused
  289. arma_inline
  290. const eOpCube<T1, eop_sinc>
  291. sinc(const BaseCube<typename T1::elem_type,T1>& A)
  292. {
  293. arma_extra_debug_sigprint();
  294. return eOpCube<T1, eop_sinc>(A.get_ref());
  295. }
  296. //
  297. // atan2
  298. template<typename T1, typename T2>
  299. arma_warn_unused
  300. arma_inline
  301. typename
  302. enable_if2
  303. <
  304. (is_arma_type<T1>::value && is_arma_type<T2>::value && is_real<typename T1::elem_type>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
  305. const Glue<T1, T2, glue_atan2>
  306. >::result
  307. atan2(const T1& Y, const T2& X)
  308. {
  309. arma_extra_debug_sigprint();
  310. return Glue<T1, T2, glue_atan2>(Y, X);
  311. }
  312. template<typename T1, typename T2>
  313. arma_warn_unused
  314. arma_inline
  315. typename enable_if2< is_real<typename T1::elem_type>::value, const GlueCube<T1, T2, glue_atan2> >::result
  316. atan2(const BaseCube<typename T1::elem_type,T1>& Y, const BaseCube<typename T1::elem_type,T2>& X)
  317. {
  318. arma_extra_debug_sigprint();
  319. return GlueCube<T1, T2, glue_atan2>(Y.get_ref(), X.get_ref());
  320. }
  321. //
  322. // hypot
  323. template<typename T1, typename T2>
  324. arma_warn_unused
  325. arma_inline
  326. typename
  327. enable_if2
  328. <
  329. (is_arma_type<T1>::value && is_arma_type<T2>::value && is_real<typename T1::elem_type>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
  330. const Glue<T1, T2, glue_hypot>
  331. >::result
  332. hypot(const T1& X, const T2& Y)
  333. {
  334. arma_extra_debug_sigprint();
  335. return Glue<T1, T2, glue_hypot>(X, Y);
  336. }
  337. template<typename T1, typename T2>
  338. arma_warn_unused
  339. arma_inline
  340. typename enable_if2< is_real<typename T1::elem_type>::value, const GlueCube<T1, T2, glue_hypot> >::result
  341. hypot(const BaseCube<typename T1::elem_type,T1>& X, const BaseCube<typename T1::elem_type,T2>& Y)
  342. {
  343. arma_extra_debug_sigprint();
  344. return GlueCube<T1, T2, glue_hypot>(X.get_ref(), Y.get_ref());
  345. }
  346. //! @}