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