op_find_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010 Conrad Sanderson
3 // Copyright (C) 2010 Dimitrios Bouzas
4 //
5 // This file is part of the Armadillo C++ library.
6 // It is provided without any warranty of fitness
7 // for any purpose. You can redistribute this file
8 // and/or modify it under the terms of the GNU
9 // Lesser General Public License (LGPL) as published
10 // by the Free Software Foundation, either version 3
11 // of the License or (at your option) any later version.
12 // (see http://www.opensource.org/licenses for more info)
13 
14 
15 
18 
19 
20 
21 template<typename T1>
22 inline
23 uword
25  (
26  Mat<uword>& indices,
28  )
29  {
31 
32  typedef typename T1::elem_type eT;
33  typedef typename Proxy<T1>::ea_type ea_type;
34 
35  const Proxy<T1> A(X.get_ref());
36 
37  ea_type PA = A.get_ea();
38  const uword n_elem = A.get_n_elem();
39 
40  indices.set_size(n_elem, 1);
41 
42  uword* indices_mem = indices.memptr();
43  uword n_nz = 0;
44 
45  for(uword i=0; i<n_elem; ++i)
46  {
47  if(PA[i] != eT(0))
48  {
49  indices_mem[n_nz] = i;
50  ++n_nz;
51  }
52  }
53 
54  return n_nz;
55  }
56 
57 
58 
59 template<typename T1, typename op_type>
60 inline
61 uword
63  (
64  Mat<uword>& indices,
65  const mtOp<uword, T1, op_type>& X,
66  const typename arma_op_rel_only<op_type>::result junk1,
68  )
69  {
71  arma_ignore(junk1);
72  arma_ignore(junk2);
73 
74  typedef typename T1::elem_type eT;
75  typedef typename Proxy<T1>::ea_type ea_type;
76 
77  const eT val = X.aux;
78 
79  const Proxy<T1> A(X.m);
80 
81  ea_type PA = A.get_ea();
82  const uword n_elem = A.get_n_elem();
83 
84  indices.set_size(n_elem, 1);
85 
86  uword* indices_mem = indices.memptr();
87  uword n_nz = 0;
88 
89  for(uword i=0; i<n_elem; ++i)
90  {
91  const eT tmp = PA[i];
92 
93  bool not_zero;
94 
95  if(is_same_type<op_type, op_rel_lt_pre >::value == true) { not_zero = (val < tmp); }
96  else if(is_same_type<op_type, op_rel_lt_post >::value == true) { not_zero = (tmp < val); }
97  else if(is_same_type<op_type, op_rel_gt_pre >::value == true) { not_zero = (val > tmp); }
98  else if(is_same_type<op_type, op_rel_gt_post >::value == true) { not_zero = (tmp > val); }
99  else if(is_same_type<op_type, op_rel_lteq_pre >::value == true) { not_zero = (val <= tmp); }
100  else if(is_same_type<op_type, op_rel_lteq_post>::value == true) { not_zero = (tmp <= val); }
101  else if(is_same_type<op_type, op_rel_gteq_pre >::value == true) { not_zero = (val >= tmp); }
102  else if(is_same_type<op_type, op_rel_gteq_post>::value == true) { not_zero = (tmp >= val); }
103  else if(is_same_type<op_type, op_rel_eq >::value == true) { not_zero = (tmp == val); }
104  else if(is_same_type<op_type, op_rel_noteq >::value == true) { not_zero = (tmp != val); }
105  else not_zero = false;
106 
107  if(not_zero == true)
108  {
109  indices_mem[n_nz] = i;
110  ++n_nz;
111  }
112  }
113 
114  return n_nz;
115  }
116 
117 
118 
119 template<typename T1, typename op_type>
120 inline
121 uword
123  (
124  Mat<uword>& indices,
125  const mtOp<uword, T1, op_type>& X,
126  const typename arma_op_rel_only<op_type>::result junk1,
128  )
129  {
131  arma_ignore(junk1);
132  arma_ignore(junk2);
133 
134  typedef typename T1::elem_type eT;
135  typedef typename Proxy<T1>::ea_type ea_type;
136 
137  const eT val = X.aux;
138 
139  const Proxy<T1> A(X.m);
140 
141  ea_type PA = A.get_ea();
142  const uword n_elem = A.get_n_elem();
143 
144  indices.set_size(n_elem, 1);
145 
146  uword* indices_mem = indices.memptr();
147  uword n_nz = 0;
148 
149  for(uword i=0; i<n_elem; ++i)
150  {
151  const eT tmp = PA[i];
152 
153  bool not_zero;
154 
155  if(is_same_type<op_type, op_rel_eq >::value == true) { not_zero = (tmp == val); }
156  else if(is_same_type<op_type, op_rel_noteq>::value == true) { not_zero = (tmp != val); }
157  else not_zero = false;
158 
159  if(not_zero == true)
160  {
161  indices_mem[n_nz] = i;
162  ++n_nz;
163  }
164  }
165 
166  return n_nz;
167  }
168 
169 
170 
171 template<typename T1, typename T2, typename glue_type>
172 inline
173 uword
175  (
176  Mat<uword>& indices,
178  const typename arma_glue_rel_only<glue_type>::result junk1,
179  const typename arma_not_cx<typename T1::elem_type>::result junk2,
181  )
182  {
184  arma_ignore(junk1);
185  arma_ignore(junk2);
186  arma_ignore(junk3);
187 
188  typedef typename T1::elem_type eT1;
189  typedef typename T2::elem_type eT2;
190 
191  typedef typename Proxy<T1>::ea_type ea_type1;
192  typedef typename Proxy<T2>::ea_type ea_type2;
193 
194  const Proxy<T1> A(X.A);
195  const Proxy<T2> B(X.B);
196 
197  arma_debug_assert_same_size(A, B, "relational operator");
198 
199  ea_type1 PA = A.get_ea();
200  ea_type2 PB = B.get_ea();
201  const uword n_elem = B.get_n_elem();
202 
203  indices.set_size(n_elem, 1);
204 
205  uword* indices_mem = indices.memptr();
206  uword n_nz = 0;
207 
208  for(uword i=0; i<n_elem; ++i)
209  {
210  const eT1 tmp1 = PA[i];
211  const eT2 tmp2 = PB[i];
212 
213  bool not_zero;
214 
215  if(is_same_type<glue_type, glue_rel_lt >::value == true) { not_zero = (tmp1 < tmp2); }
216  else if(is_same_type<glue_type, glue_rel_gt >::value == true) { not_zero = (tmp1 > tmp2); }
217  else if(is_same_type<glue_type, glue_rel_lteq >::value == true) { not_zero = (tmp1 <= tmp2); }
218  else if(is_same_type<glue_type, glue_rel_gteq >::value == true) { not_zero = (tmp1 >= tmp2); }
219  else if(is_same_type<glue_type, glue_rel_eq >::value == true) { not_zero = (tmp1 == tmp2); }
220  else if(is_same_type<glue_type, glue_rel_noteq >::value == true) { not_zero = (tmp1 != tmp2); }
221  else not_zero = false;
222 
223  if(not_zero == true)
224  {
225  indices_mem[n_nz] = i;
226  ++n_nz;
227  }
228  }
229 
230  return n_nz;
231  }
232 
233 
234 
235 template<typename T1, typename T2, typename glue_type>
236 inline
237 uword
239  (
240  Mat<uword>& indices,
242  const typename arma_glue_rel_only<glue_type>::result junk1,
245  )
246  {
248  arma_ignore(junk1);
249  arma_ignore(junk2);
250  arma_ignore(junk3);
251 
252  typedef typename Proxy<T1>::ea_type ea_type1;
253  typedef typename Proxy<T2>::ea_type ea_type2;
254 
255  const Proxy<T1> A(X.A);
256  const Proxy<T2> B(X.B);
257 
258  arma_debug_assert_same_size(A, B, "relational operator");
259 
260  ea_type1 PA = A.get_ea();
261  ea_type2 PB = B.get_ea();
262  const uword n_elem = B.get_n_elem();
263 
264  indices.set_size(n_elem, 1);
265 
266  uword* indices_mem = indices.memptr();
267  uword n_nz = 0;
268 
269  for(uword i=0; i<n_elem; ++i)
270  {
271  bool not_zero;
272 
273  if(is_same_type<glue_type, glue_rel_eq >::value == true) { not_zero = (PA[i] == PB[i]); }
274  else if(is_same_type<glue_type, glue_rel_noteq >::value == true) { not_zero = (PA[i] != PB[i]); }
275  else not_zero = false;
276 
277  if(not_zero == true)
278  {
279  indices_mem[n_nz] = i;
280  ++n_nz;
281  }
282  }
283 
284  return n_nz;
285  }
286 
287 
288 
289 template<typename T1>
290 inline
291 void
293  {
295 
296  const uword k = X.aux_uword_a;
297  const uword type = X.aux_uword_b;
298 
299  Mat<uword> indices;
300  const uword n_nz = op_find::helper(indices, X.m);
301 
302  if(n_nz > 0)
303  {
304  if(type == 0) // "first"
305  {
306  out = (k > 0 && k <= n_nz) ? indices.rows(0, k-1 ) : indices.rows(0, n_nz-1);
307  }
308  else // "last"
309  {
310  out = (k > 0 && k <= n_nz) ? indices.rows(n_nz-k, n_nz-1) : indices.rows(0, n_nz-1);
311  }
312  }
313  else
314  {
315  out.reset();
316  }
317  }
318 
319 
320 
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
arma_aligned uword aux_uword_b
storage of auxiliary data, uword format
Definition: mtOp_bones.hpp:43
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: mtOp_bones.hpp:39
arma_aligned const T1 & A
first operand
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
static uword helper(Mat< uword > &indices, const Base< typename T1::elem_type, T1 > &X)
arma_aligned const T2 & B
second operand
arma_aligned in_eT aux
storage of auxiliary data, using the element type as used by T1
Definition: mtOp_bones.hpp:40
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
static void apply(Mat< uword > &out, const mtOp< uword, T1, op_find > &X)
arma_inline subview< eT > rows(const uword in_row1, const uword in_row2)
creation of subview (submatrix comprised of specified row vectors)
Definition: Mat_meat.hpp:2008
u32 uword
Definition: typedef.hpp:85
#define arma_ignore(variable)
void reset()
Definition: Mat_meat.hpp:4553
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Dense matrix class.
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: mtOp_bones.hpp:42


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:58