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