source: mmcs/armadillo_bits/op_relational_meat.hpp @ 8ad4484

matrices
Last change on this file since 8ad4484 was 9dd61b1, checked in by rboet <rboet@…>, 9 years ago

Avance del proyecto 60%

  • Property mode set to 100644
File size: 9.6 KB
Line 
1// Copyright (C) 2009-2012 Conrad Sanderson
2// Copyright (C) 2009-2012 NICTA (www.nicta.com.au)
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9//! \addtogroup op_relational
10//! @{
11
12
13#undef operator_rel
14
15#undef arma_applier_mat_pre
16#undef arma_applier_mat_post
17
18#undef arma_applier_cube_pre
19#undef arma_applier_cube_post
20
21
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>::prefer_at_accessor == 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
80
81
82#define arma_applier_mat_post(operator_rel) \
83  {\
84  typedef typename T1::elem_type      eT;\
85  typedef typename Proxy<T1>::ea_type ea_type;\
86  \
87  const eT val = X.aux;\
88  \
89  const Proxy<T1> P(X.m);\
90  \
91  const uword n_rows = P.get_n_rows();\
92  const uword n_cols = P.get_n_cols();\
93  \
94  const bool bad_alias = ( Proxy<T1>::has_subview && P.is_alias(out) );\
95  \
96  if(bad_alias == false)\
97    {\
98    out.set_size(n_rows, n_cols);\
99    \
100    uword* out_mem = out.memptr();\
101    \
102    if(Proxy<T1>::prefer_at_accessor == false)\
103      {\
104            ea_type PA     = P.get_ea();\
105      const uword   n_elem = out.n_elem;\
106      \
107      for(uword i=0; i<n_elem; ++i)\
108        {\
109        out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\
110        }\
111      }\
112    else\
113      {\
114      if(n_rows == 1)\
115        {\
116        for(uword count=0; count < n_cols; ++count)\
117          {\
118          out_mem[count] = (P.at(0,count) operator_rel val) ? uword(1) : uword(0);\
119          }\
120        }\
121      else\
122        {\
123        for(uword col=0; col < n_cols; ++col)\
124        for(uword row=0; row < n_rows; ++row)\
125          {\
126          *out_mem = (P.at(row,col) operator_rel val) ? uword(1) : uword(0);\
127          out_mem++;\
128          }\
129        }\
130      }\
131    }\
132  else\
133    {\
134    const Mat<eT> tmp(P.Q);\
135    \
136    out = (tmp) operator_rel (val);\
137    }\
138  }
139
140
141
142#define arma_applier_cube_pre(operator_rel) \
143  {\
144  typedef typename T1::elem_type          eT;\
145  typedef typename ProxyCube<T1>::ea_type ea_type;\
146  \
147  const eT val = X.aux;\
148  \
149  const ProxyCube<T1> P(X.m);\
150  \
151  const uword n_rows   = P.get_n_rows();\
152  const uword n_cols   = P.get_n_cols();\
153  const uword n_slices = P.get_n_slices();\
154  \
155  const bool bad_alias = ( ProxyCube<T1>::has_subview && P.is_alias(out) );\
156  \
157  if(bad_alias == false)\
158    {\
159    out.set_size(n_rows, n_cols, n_slices);\
160    \
161    uword* out_mem = out.memptr();\
162    \
163    if(ProxyCube<T1>::prefer_at_accessor == false)\
164      {\
165            ea_type PA     = P.get_ea();\
166      const uword   n_elem = out.n_elem;\
167      \
168      for(uword i=0; i<n_elem; ++i)\
169        {\
170        out_mem[i] = (val operator_rel PA[i]) ? uword(1) : uword(0);\
171        }\
172      }\
173    else\
174      {\
175      for(uword slice=0; slice < n_slices; ++slice)\
176      for(uword col=0;   col   < n_cols;   ++col  )\
177      for(uword row=0;   row   < n_rows;   ++row  )\
178        {\
179        *out_mem = (val operator_rel P.at(row,col,slice)) ? uword(1) : uword(0);\
180        out_mem++;\
181        }\
182      }\
183    }\
184  else\
185    {\
186    const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
187    \
188    out = (val) operator_rel (tmp.M);\
189    }\
190  }
191
192
193
194#define arma_applier_cube_post(operator_rel) \
195  {\
196  typedef typename T1::elem_type          eT;\
197  typedef typename ProxyCube<T1>::ea_type ea_type;\
198  \
199  const eT val = X.aux;\
200  \
201  const ProxyCube<T1> P(X.m);\
202  \
203  const uword n_rows   = P.get_n_rows();\
204  const uword n_cols   = P.get_n_cols();\
205  const uword n_slices = P.get_n_slices();\
206  \
207  const bool bad_alias = ( ProxyCube<T1>::has_subview && P.is_alias(out) );\
208  \
209  if(bad_alias == false)\
210    {\
211    out.set_size(n_rows, n_cols, n_slices);\
212    \
213    uword* out_mem = out.memptr();\
214    \
215    if(ProxyCube<T1>::prefer_at_accessor == false)\
216      {\
217            ea_type PA     = P.get_ea();\
218      const uword   n_elem = out.n_elem;\
219      \
220      for(uword i=0; i<n_elem; ++i)\
221        {\
222        out_mem[i] = (PA[i] operator_rel val) ? uword(1) : uword(0);\
223        }\
224      }\
225    else\
226      {\
227      for(uword slice=0; slice < n_slices; ++slice)\
228      for(uword col=0;   col   < n_cols;   ++col  )\
229      for(uword row=0;   row   < n_rows;   ++row  )\
230        {\
231        *out_mem = (P.at(row,col,slice) operator_rel val) ? uword(1) : uword(0);\
232        out_mem++;\
233        }\
234      }\
235    }\
236  else\
237    {\
238    const unwrap_cube<typename ProxyCube<T1>::stored_type> tmp(P.Q);\
239    \
240    out = (tmp.M) operator_rel (val);\
241    }\
242  }
243
244
245
246template<typename T1>
247inline
248void
249op_rel_lt_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lt_pre>& X)
250  {
251  arma_extra_debug_sigprint();
252 
253  arma_applier_mat_pre( < );
254  }
255
256
257
258template<typename T1>
259inline
260void
261op_rel_gt_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gt_pre>& X)
262  {
263  arma_extra_debug_sigprint();
264 
265  arma_applier_mat_pre( > );
266  }
267
268
269
270template<typename T1>
271inline
272void
273op_rel_lteq_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lteq_pre>& X)
274  {
275  arma_extra_debug_sigprint();
276 
277  arma_applier_mat_pre( <= );
278  }
279
280
281
282template<typename T1>
283inline
284void
285op_rel_gteq_pre::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gteq_pre>& X)
286  {
287  arma_extra_debug_sigprint();
288 
289  arma_applier_mat_pre( >= );
290  }
291
292
293
294template<typename T1>
295inline
296void
297op_rel_lt_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lt_post>& X)
298  {
299  arma_extra_debug_sigprint();
300 
301  arma_applier_mat_post( < );
302  }
303
304
305
306template<typename T1>
307inline
308void
309op_rel_gt_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gt_post>& X)
310  {
311  arma_extra_debug_sigprint();
312 
313  arma_applier_mat_post( > );
314  }
315
316
317
318template<typename T1>
319inline
320void
321op_rel_lteq_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_lteq_post>& X)
322  {
323  arma_extra_debug_sigprint();
324 
325  arma_applier_mat_post( <= );
326  }
327
328
329
330template<typename T1>
331inline
332void
333op_rel_gteq_post::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_gteq_post>& X)
334  {
335  arma_extra_debug_sigprint();
336 
337  arma_applier_mat_post( >= );
338  }
339
340
341
342template<typename T1>
343inline
344void
345op_rel_eq::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_eq>& X)
346  {
347  arma_extra_debug_sigprint();
348 
349  arma_applier_mat_post( == );
350  }
351
352
353
354template<typename T1>
355inline
356void
357op_rel_noteq::apply(Mat<uword>& out, const mtOp<uword, T1, op_rel_noteq>& X)
358  {
359  arma_extra_debug_sigprint();
360 
361  arma_applier_mat_post( != );
362  }
363
364
365
366//
367//
368//
369
370
371
372template<typename T1>
373inline
374void
375op_rel_lt_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lt_pre>& X)
376  {
377  arma_extra_debug_sigprint();
378 
379  arma_applier_cube_pre( < );
380  }
381
382
383
384template<typename T1>
385inline
386void
387op_rel_gt_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gt_pre>& X)
388  {
389  arma_extra_debug_sigprint();
390 
391  arma_applier_cube_pre( > );
392  }
393
394
395
396template<typename T1>
397inline
398void
399op_rel_lteq_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lteq_pre>& X)
400  {
401  arma_extra_debug_sigprint();
402 
403  arma_applier_cube_pre( <= );
404  }
405
406
407
408template<typename T1>
409inline
410void
411op_rel_gteq_pre::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gteq_pre>& X)
412  {
413  arma_extra_debug_sigprint();
414 
415  arma_applier_cube_pre( >= );
416  }
417
418
419
420template<typename T1>
421inline
422void
423op_rel_lt_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lt_post>& X)
424  {
425  arma_extra_debug_sigprint();
426 
427  arma_applier_cube_post( < );
428  }
429
430
431
432template<typename T1>
433inline
434void
435op_rel_gt_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gt_post>& X)
436  {
437  arma_extra_debug_sigprint();
438 
439  arma_applier_cube_post( > );
440  }
441
442
443
444template<typename T1>
445inline
446void
447op_rel_lteq_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_lteq_post>& X)
448  {
449  arma_extra_debug_sigprint();
450 
451  arma_applier_cube_post( <= );
452  }
453
454
455
456template<typename T1>
457inline
458void
459op_rel_gteq_post::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_gteq_post>& X)
460  {
461  arma_extra_debug_sigprint();
462 
463  arma_applier_cube_post( >= );
464  }
465
466
467
468template<typename T1>
469inline
470void
471op_rel_eq::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_eq>& X)
472  {
473  arma_extra_debug_sigprint();
474 
475  arma_applier_cube_post( == );
476  }
477
478
479
480template<typename T1>
481inline
482void
483op_rel_noteq::apply(Cube<uword>& out, const mtOpCube<uword, T1, op_rel_noteq>& X)
484  {
485  arma_extra_debug_sigprint();
486 
487  arma_applier_cube_post( != );
488  }
489
490
491
492#undef arma_applier_mat_pre
493#undef arma_applier_mat_post
494
495#undef arma_applier_cube_pre
496#undef arma_applier_cube_post
497
498
499
500//! @}
Note: See TracBrowser for help on using the repository browser.