op_relational_meat.hpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 op_relational
  16. //! @{
  17. #undef operator_rel
  18. #undef arma_applier_mat_pre
  19. #undef arma_applier_mat_post
  20. #undef arma_applier_cube_pre
  21. #undef arma_applier_cube_post
  22. #define arma_applier_mat_pre(operator_rel) \
  23. {\
  24. typedef typename T1::elem_type eT;\
  25. typedef typename Proxy<T1>::ea_type ea_type;\
  26. \
  27. const eT val = X.aux;\
  28. \
  29. const Proxy<T1> P(X.m);\
  30. \
  31. const uword n_rows = P.get_n_rows();\
  32. const uword n_cols = P.get_n_cols();\
  33. \
  34. const bool bad_alias = ( Proxy<T1>::has_subview && P.is_alias(out) );\
  35. \
  36. if(bad_alias == false)\
  37. {\
  38. out.set_size(n_rows, n_cols);\
  39. \
  40. uword* out_mem = out.memptr();\
  41. \
  42. if(Proxy<T1>::use_at == false)\
  43. {\
  44. ea_type PA = P.get_ea();\
  45. const uword n_elem = out.n_elem;\
  46. \
  47. for(uword i=0; i<n_elem; ++i)\
  48. {\
  49. out_mem[i] = (val operator_rel PA[i]) ? uword(1) : uword(0);\
  50. }\
  51. }\
  52. else\
  53. {\
  54. if(n_rows == 1)\
  55. {\
  56. for(uword count=0; count < n_cols; ++count)\
  57. {\
  58. out_mem[count] = (val operator_rel P.at(0,count)) ? uword(1) : uword(0);\
  59. }\
  60. }\
  61. else\
  62. {\
  63. for(uword col=0; col < n_cols; ++col)\
  64. for(uword row=0; row < n_rows; ++row)\
  65. {\
  66. *out_mem = (val operator_rel P.at(row,col)) ? uword(1) : uword(0);\
  67. out_mem++;\
  68. }\
  69. }\
  70. }\
  71. }\
  72. else\
  73. {\
  74. const Mat<eT> tmp(P.Q);\
  75. \
  76. out = (val) operator_rel (tmp);\
  77. }\
  78. }
  79. #define arma_applier_mat_post(operator_rel) \
  80. {\
  81. typedef typename T1::elem_type eT;\
  82. typedef typename Proxy<T1>::ea_type ea_type;\
  83. \
  84. const eT val = X.aux;\
  85. \
  86. const Proxy<T1> P(X.m);\
  87. \
  88. const uword n_rows = P.get_n_rows();\
  89. const uword n_cols = P.get_n_cols();\
  90. \
  91. const bool bad_alias = ( Proxy<T1>::has_subview && P.is_alias(out) );\
  92. \
  93. if(bad_alias == false)\
  94. {\
  95. out.set_size(n_rows, n_cols);\
  96. \
  97. uword* out_mem = out.memptr();\
  98. \
  99. if(Proxy<T1>::use_at == false)\
  100. {\
  101. ea_type PA = P.get_ea();\
  102. const uword n_elem = out.n_elem;\
  103. \
  104. for(uword i=0; i<n_elem; ++i)\
  105. {\
  106. out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\
  107. }\
  108. }\
  109. else\
  110. {\
  111. if(n_rows == 1)\
  112. {\
  113. for(uword count=0; count < n_cols; ++count)\
  114. {\
  115. out_mem[count] = (P.at(0,count) operator_rel val) ? uword(1) : uword(0);\
  116. }\
  117. }\
  118. else\
  119. {\
  120. for(uword col=0; col < n_cols; ++col)\
  121. for(uword row=0; row < n_rows; ++row)\
  122. {\
  123. *out_mem = (P.at(row,col) operator_rel val) ? uword(1) : uword(0);\
  124. out_mem++;\
  125. }\
  126. }\
  127. }\
  128. }\
  129. else\
  130. {\
  131. const Mat<eT> tmp(P.Q);\
  132. \
  133. out = (tmp) operator_rel (val);\
  134. }\
  135. }
  136. #define arma_applier_cube_pre(operator_rel) \
  137. {\
  138. typedef typename T1::elem_type eT;\
  139. typedef typename ProxyCube<T1>::ea_type ea_type;\
  140. \
  141. const eT val = X.aux;\
  142. \
  143. const ProxyCube<T1> P(X.m);\
  144. \
  145. const uword n_rows = P.get_n_rows();\
  146. const uword n_cols = P.get_n_cols();\
  147. const uword n_slices = P.get_n_slices();\
  148. \
  149. const bool bad_alias = ( ProxyCube<T1>::has_subview && P.is_alias(out) );\
  150. \
  151. if(bad_alias == false)\
  152. {\
  153. out.set_size(n_rows, n_cols, n_slices);\
  154. \
  155. uword* out_mem = out.memptr();\
  156. \
  157. if(ProxyCube<T1>::use_at == false)\
  158. {\
  159. ea_type PA = P.get_ea();\
  160. const uword n_elem = out.n_elem;\
  161. \
  162. for(uword i=0; i<n_elem; ++i)\
  163. {\
  164. out_mem[i] = (val operator_rel PA[i]) ? uword(1) : uword(0);\
  165. }\
  166. }\
  167. else\
  168. {\
  169. for(uword slice=0; slice < n_slices; ++slice)\
  170. for(uword col=0; col < n_cols; ++col )\
  171. for(uword row=0; row < n_rows; ++row )\
  172. {\
  173. *out_mem = (val operator_rel P.at(row,col,slice)) ? uword(1) : uword(0);\
  174. out_mem++;\
  175. }\
  176. }\
  177. }\
  178. else\
  179. {\
  180. const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
  181. \
  182. out = (val) operator_rel (tmp.M);\
  183. }\
  184. }
  185. #define arma_applier_cube_post(operator_rel) \
  186. {\
  187. typedef typename T1::elem_type eT;\
  188. typedef typename ProxyCube<T1>::ea_type ea_type;\
  189. \
  190. const eT val = X.aux;\
  191. \
  192. const ProxyCube<T1> P(X.m);\
  193. \
  194. const uword n_rows = P.get_n_rows();\
  195. const uword n_cols = P.get_n_cols();\
  196. const uword n_slices = P.get_n_slices();\
  197. \
  198. const bool bad_alias = ( ProxyCube<T1>::has_subview && P.is_alias(out) );\
  199. \
  200. if(bad_alias == false)\
  201. {\
  202. out.set_size(n_rows, n_cols, n_slices);\
  203. \
  204. uword* out_mem = out.memptr();\
  205. \
  206. if(ProxyCube<T1>::use_at == false)\
  207. {\
  208. ea_type PA = P.get_ea();\
  209. const uword n_elem = out.n_elem;\
  210. \
  211. for(uword i=0; i<n_elem; ++i)\
  212. {\
  213. out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\
  214. }\
  215. }\
  216. else\
  217. {\
  218. for(uword slice=0; slice < n_slices; ++slice)\
  219. for(uword col=0; col < n_cols; ++col )\
  220. for(uword row=0; row < n_rows; ++row )\
  221. {\
  222. *out_mem = (P.at(row,col,slice) operator_rel val) ? uword(1) : uword(0);\
  223. out_mem++;\
  224. }\
  225. }\
  226. }\
  227. else\
  228. {\
  229. const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
  230. \
  231. out = (tmp.M) operator_rel (val);\
  232. }\
  233. }
  234. template<typename T1>
  235. inline
  236. void
  237. op_rel_lt_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lt_pre>& X)
  238. {
  239. arma_extra_debug_sigprint();
  240. arma_applier_mat_pre( < );
  241. }
  242. template<typename T1>
  243. inline
  244. void
  245. op_rel_gt_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gt_pre>& X)
  246. {
  247. arma_extra_debug_sigprint();
  248. arma_applier_mat_pre( > );
  249. }
  250. template<typename T1>
  251. inline
  252. void
  253. op_rel_lteq_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lteq_pre>& X)
  254. {
  255. arma_extra_debug_sigprint();
  256. arma_applier_mat_pre( <= );
  257. }
  258. template<typename T1>
  259. inline
  260. void
  261. op_rel_gteq_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gteq_pre>& X)
  262. {
  263. arma_extra_debug_sigprint();
  264. arma_applier_mat_pre( >= );
  265. }
  266. template<typename T1>
  267. inline
  268. void
  269. op_rel_lt_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lt_post>& X)
  270. {
  271. arma_extra_debug_sigprint();
  272. arma_applier_mat_post( < );
  273. }
  274. template<typename T1>
  275. inline
  276. void
  277. op_rel_gt_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gt_post>& X)
  278. {
  279. arma_extra_debug_sigprint();
  280. arma_applier_mat_post( > );
  281. }
  282. template<typename T1>
  283. inline
  284. void
  285. op_rel_lteq_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lteq_post>& X)
  286. {
  287. arma_extra_debug_sigprint();
  288. arma_applier_mat_post( <= );
  289. }
  290. template<typename T1>
  291. inline
  292. void
  293. op_rel_gteq_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gteq_post>& X)
  294. {
  295. arma_extra_debug_sigprint();
  296. arma_applier_mat_post( >= );
  297. }
  298. template<typename T1>
  299. inline
  300. void
  301. op_rel_eq::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_eq>& X)
  302. {
  303. arma_extra_debug_sigprint();
  304. arma_applier_mat_post( == );
  305. }
  306. template<typename T1>
  307. inline
  308. void
  309. op_rel_noteq::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_noteq>& X)
  310. {
  311. arma_extra_debug_sigprint();
  312. arma_applier_mat_post( != );
  313. }
  314. //
  315. //
  316. //
  317. template<typename T1>
  318. inline
  319. void
  320. op_rel_lt_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lt_pre>& X)
  321. {
  322. arma_extra_debug_sigprint();
  323. arma_applier_cube_pre( < );
  324. }
  325. template<typename T1>
  326. inline
  327. void
  328. op_rel_gt_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gt_pre>& X)
  329. {
  330. arma_extra_debug_sigprint();
  331. arma_applier_cube_pre( > );
  332. }
  333. template<typename T1>
  334. inline
  335. void
  336. op_rel_lteq_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lteq_pre>& X)
  337. {
  338. arma_extra_debug_sigprint();
  339. arma_applier_cube_pre( <= );
  340. }
  341. template<typename T1>
  342. inline
  343. void
  344. op_rel_gteq_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gteq_pre>& X)
  345. {
  346. arma_extra_debug_sigprint();
  347. arma_applier_cube_pre( >= );
  348. }
  349. template<typename T1>
  350. inline
  351. void
  352. op_rel_lt_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lt_post>& X)
  353. {
  354. arma_extra_debug_sigprint();
  355. arma_applier_cube_post( < );
  356. }
  357. template<typename T1>
  358. inline
  359. void
  360. op_rel_gt_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gt_post>& X)
  361. {
  362. arma_extra_debug_sigprint();
  363. arma_applier_cube_post( > );
  364. }
  365. template<typename T1>
  366. inline
  367. void
  368. op_rel_lteq_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lteq_post>& X)
  369. {
  370. arma_extra_debug_sigprint();
  371. arma_applier_cube_post( <= );
  372. }
  373. template<typename T1>
  374. inline
  375. void
  376. op_rel_gteq_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gteq_post>& X)
  377. {
  378. arma_extra_debug_sigprint();
  379. arma_applier_cube_post( >= );
  380. }
  381. template<typename T1>
  382. inline
  383. void
  384. op_rel_eq::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_eq>& X)
  385. {
  386. arma_extra_debug_sigprint();
  387. arma_applier_cube_post( == );
  388. }
  389. template<typename T1>
  390. inline
  391. void
  392. op_rel_noteq::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_noteq>& X)
  393. {
  394. arma_extra_debug_sigprint();
  395. arma_applier_cube_post( != );
  396. }
  397. #undef arma_applier_mat_pre
  398. #undef arma_applier_mat_post
  399. #undef arma_applier_cube_pre
  400. #undef arma_applier_cube_post
  401. //! @}