glue_relational_meat.hpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 glue_relational
  16. //! @{
  17. #undef operator_rel
  18. #undef operator_str
  19. #undef arma_applier_mat
  20. #undef arma_applier_cube
  21. #define arma_applier_mat(operator_rel, operator_str) \
  22. {\
  23. const Proxy<T1> P1(X.A);\
  24. const Proxy<T2> P2(X.B);\
  25. \
  26. arma_debug_assert_same_size(P1, P2, operator_str);\
  27. \
  28. const bool bad_alias = (Proxy<T1>::has_subview && P1.is_alias(out)) || (Proxy<T2>::has_subview && P2.is_alias(out));\
  29. \
  30. if(bad_alias == false)\
  31. {\
  32. \
  33. const uword n_rows = P1.get_n_rows();\
  34. const uword n_cols = P1.get_n_cols();\
  35. \
  36. out.set_size(n_rows, n_cols);\
  37. \
  38. uword* out_mem = out.memptr();\
  39. \
  40. const bool use_at = (Proxy<T1>::use_at || Proxy<T2>::use_at);\
  41. \
  42. if(use_at == false)\
  43. {\
  44. typename Proxy<T1>::ea_type A = P1.get_ea();\
  45. typename Proxy<T2>::ea_type B = P2.get_ea();\
  46. \
  47. const uword n_elem = out.n_elem;\
  48. \
  49. for(uword i=0; i<n_elem; ++i)\
  50. {\
  51. out_mem[i] = (A[i] operator_rel B[i]) ? uword(1) : uword(0);\
  52. }\
  53. }\
  54. else\
  55. {\
  56. if(n_rows == 1)\
  57. {\
  58. for(uword count=0; count < n_cols; ++count)\
  59. {\
  60. out_mem[count] = (P1.at(0,count) operator_rel P2.at(0,count)) ? uword(1) : uword(0);\
  61. }\
  62. }\
  63. else\
  64. {\
  65. for(uword col=0; col<n_cols; ++col)\
  66. for(uword row=0; row<n_rows; ++row)\
  67. {\
  68. *out_mem = (P1.at(row,col) operator_rel P2.at(row,col)) ? uword(1) : uword(0);\
  69. out_mem++;\
  70. }\
  71. }\
  72. }\
  73. }\
  74. else\
  75. {\
  76. const unwrap_check<typename Proxy<T1>::stored_type> tmp1(P1.Q, P1.is_alias(out));\
  77. const unwrap_check<typename Proxy<T2>::stored_type> tmp2(P2.Q, P2.is_alias(out));\
  78. \
  79. out = (tmp1.M) operator_rel (tmp2.M);\
  80. }\
  81. }
  82. #define arma_applier_cube(operator_rel, operator_str) \
  83. {\
  84. const ProxyCube<T1> P1(X.A);\
  85. const ProxyCube<T2> P2(X.B);\
  86. \
  87. arma_debug_assert_same_size(P1, P2, operator_str);\
  88. \
  89. const bool bad_alias = (ProxyCube<T1>::has_subview && P1.is_alias(out)) || (ProxyCube<T2>::has_subview && P2.is_alias(out));\
  90. \
  91. if(bad_alias == false)\
  92. {\
  93. \
  94. const uword n_rows = P1.get_n_rows();\
  95. const uword n_cols = P1.get_n_cols();\
  96. const uword n_slices = P1.get_n_slices();\
  97. \
  98. out.set_size(n_rows, n_cols, n_slices);\
  99. \
  100. uword* out_mem = out.memptr();\
  101. \
  102. const bool use_at = (ProxyCube<T1>::use_at || ProxyCube<T2>::use_at);\
  103. \
  104. if(use_at == false)\
  105. {\
  106. typename ProxyCube<T1>::ea_type A = P1.get_ea();\
  107. typename ProxyCube<T2>::ea_type B = P2.get_ea();\
  108. \
  109. const uword n_elem = out.n_elem;\
  110. \
  111. for(uword i=0; i<n_elem; ++i)\
  112. {\
  113. out_mem[i] = (A[i] operator_rel B[i]) ? uword(1) : uword(0);\
  114. }\
  115. }\
  116. else\
  117. {\
  118. for(uword slice = 0; slice < n_slices; ++slice)\
  119. for(uword col = 0; col < n_cols; ++col )\
  120. for(uword row = 0; row < n_rows; ++row )\
  121. {\
  122. *out_mem = (P1.at(row,col,slice) operator_rel P2.at(row,col,slice)) ? uword(1) : uword(0);\
  123. out_mem++;\
  124. }\
  125. }\
  126. }\
  127. else\
  128. {\
  129. const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp1(P1.Q);\
  130. const unwrap_cube<typename ProxyCube<T2>::stored_type> tmp2(P2.Q);\
  131. \
  132. out = (tmp1.M) operator_rel (tmp2.M);\
  133. }\
  134. }
  135. template<typename T1, typename T2>
  136. inline
  137. void
  138. glue_rel_lt::apply
  139. (
  140. Mat <uword>& out,
  141. const mtGlue<uword, T1, T2, glue_rel_lt>& X
  142. )
  143. {
  144. arma_extra_debug_sigprint();
  145. arma_applier_mat(<, "operator<");
  146. }
  147. template<typename T1, typename T2>
  148. inline
  149. void
  150. glue_rel_gt::apply
  151. (
  152. Mat <uword>& out,
  153. const mtGlue<uword, T1, T2, glue_rel_gt>& X
  154. )
  155. {
  156. arma_extra_debug_sigprint();
  157. arma_applier_mat(>, "operator>");
  158. }
  159. template<typename T1, typename T2>
  160. inline
  161. void
  162. glue_rel_lteq::apply
  163. (
  164. Mat <uword>& out,
  165. const mtGlue<uword, T1, T2, glue_rel_lteq>& X
  166. )
  167. {
  168. arma_extra_debug_sigprint();
  169. arma_applier_mat(<=, "operator<=");
  170. }
  171. template<typename T1, typename T2>
  172. inline
  173. void
  174. glue_rel_gteq::apply
  175. (
  176. Mat <uword>& out,
  177. const mtGlue<uword, T1, T2, glue_rel_gteq>& X
  178. )
  179. {
  180. arma_extra_debug_sigprint();
  181. arma_applier_mat(>=, "operator>=");
  182. }
  183. template<typename T1, typename T2>
  184. inline
  185. void
  186. glue_rel_eq::apply
  187. (
  188. Mat <uword>& out,
  189. const mtGlue<uword, T1, T2, glue_rel_eq>& X
  190. )
  191. {
  192. arma_extra_debug_sigprint();
  193. arma_applier_mat(==, "operator==");
  194. }
  195. template<typename T1, typename T2>
  196. inline
  197. void
  198. glue_rel_noteq::apply
  199. (
  200. Mat <uword>& out,
  201. const mtGlue<uword, T1, T2, glue_rel_noteq>& X
  202. )
  203. {
  204. arma_extra_debug_sigprint();
  205. arma_applier_mat(!=, "operator!=");
  206. }
  207. template<typename T1, typename T2>
  208. inline
  209. void
  210. glue_rel_and::apply
  211. (
  212. Mat <uword>& out,
  213. const mtGlue<uword, T1, T2, glue_rel_and>& X
  214. )
  215. {
  216. arma_extra_debug_sigprint();
  217. arma_applier_mat(&&, "operator&&");
  218. }
  219. template<typename T1, typename T2>
  220. inline
  221. void
  222. glue_rel_or::apply
  223. (
  224. Mat <uword>& out,
  225. const mtGlue<uword, T1, T2, glue_rel_or>& X
  226. )
  227. {
  228. arma_extra_debug_sigprint();
  229. arma_applier_mat(||, "operator||");
  230. }
  231. //
  232. //
  233. //
  234. template<typename T1, typename T2>
  235. inline
  236. void
  237. glue_rel_lt::apply
  238. (
  239. Cube <uword>& out,
  240. const mtGlueCube<uword, T1, T2, glue_rel_lt>& X
  241. )
  242. {
  243. arma_extra_debug_sigprint();
  244. arma_applier_cube(<, "operator<");
  245. }
  246. template<typename T1, typename T2>
  247. inline
  248. void
  249. glue_rel_gt::apply
  250. (
  251. Cube <uword>& out,
  252. const mtGlueCube<uword, T1, T2, glue_rel_gt>& X
  253. )
  254. {
  255. arma_extra_debug_sigprint();
  256. arma_applier_cube(>, "operator>");
  257. }
  258. template<typename T1, typename T2>
  259. inline
  260. void
  261. glue_rel_lteq::apply
  262. (
  263. Cube <uword>& out,
  264. const mtGlueCube<uword, T1, T2, glue_rel_lteq>& X
  265. )
  266. {
  267. arma_extra_debug_sigprint();
  268. arma_applier_cube(<=, "operator<=");
  269. }
  270. template<typename T1, typename T2>
  271. inline
  272. void
  273. glue_rel_gteq::apply
  274. (
  275. Cube <uword>& out,
  276. const mtGlueCube<uword, T1, T2, glue_rel_gteq>& X
  277. )
  278. {
  279. arma_extra_debug_sigprint();
  280. arma_applier_cube(>=, "operator>=");
  281. }
  282. template<typename T1, typename T2>
  283. inline
  284. void
  285. glue_rel_eq::apply
  286. (
  287. Cube <uword>& out,
  288. const mtGlueCube<uword, T1, T2, glue_rel_eq>& X
  289. )
  290. {
  291. arma_extra_debug_sigprint();
  292. arma_applier_cube(==, "operator==");
  293. }
  294. template<typename T1, typename T2>
  295. inline
  296. void
  297. glue_rel_noteq::apply
  298. (
  299. Cube <uword>& out,
  300. const mtGlueCube<uword, T1, T2, glue_rel_noteq>& X
  301. )
  302. {
  303. arma_extra_debug_sigprint();
  304. arma_applier_cube(!=, "operator!=");
  305. }
  306. template<typename T1, typename T2>
  307. inline
  308. void
  309. glue_rel_and::apply
  310. (
  311. Cube <uword>& out,
  312. const mtGlueCube<uword, T1, T2, glue_rel_and>& X
  313. )
  314. {
  315. arma_extra_debug_sigprint();
  316. arma_applier_cube(&&, "operator&&");
  317. }
  318. template<typename T1, typename T2>
  319. inline
  320. void
  321. glue_rel_or::apply
  322. (
  323. Cube <uword>& out,
  324. const mtGlueCube<uword, T1, T2, glue_rel_or>& X
  325. )
  326. {
  327. arma_extra_debug_sigprint();
  328. arma_applier_cube(||, "operator||");
  329. }
  330. #undef arma_applier_mat
  331. #undef arma_applier_cube
  332. //! @}