comparison armadillo-2.4.4/include/armadillo_bits/Proxy.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) 2010-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-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 Proxy
15 //! @{
16
17
18
19 template<typename T1>
20 class Proxy
21 {
22 public:
23 inline Proxy(const T1& A)
24 {
25 arma_type_check(( is_arma_type<T1>::value == false ));
26 }
27 };
28
29
30
31 // ea_type is the "element accessor" type,
32 // which can provide access to elements via operator[]
33
34 template<typename eT>
35 class Proxy< Mat<eT> >
36 {
37 public:
38
39 typedef eT elem_type;
40 typedef typename get_pod_type<elem_type>::result pod_type;
41 typedef Mat<eT> stored_type;
42 typedef const eT* ea_type;
43
44 static const bool prefer_at_accessor = false;
45 static const bool has_subview = false;
46
47 arma_aligned const Mat<eT>& Q;
48
49 inline explicit Proxy(const Mat<eT>& A)
50 : Q(A)
51 {
52 arma_extra_debug_sigprint();
53 }
54
55 arma_inline uword get_n_rows() const { return Q.n_rows; }
56 arma_inline uword get_n_cols() const { return Q.n_cols; }
57 arma_inline uword get_n_elem() const { return Q.n_elem; }
58
59 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
60 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
61
62 arma_inline ea_type get_ea() const { return Q.memptr(); }
63
64 template<typename eT2>
65 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
66 };
67
68
69
70 template<typename eT>
71 class Proxy< Col<eT> >
72 {
73 public:
74
75 typedef eT elem_type;
76 typedef typename get_pod_type<elem_type>::result pod_type;
77 typedef Col<eT> stored_type;
78 typedef const eT* ea_type;
79
80 static const bool prefer_at_accessor = false;
81 static const bool has_subview = false;
82
83 arma_aligned const Col<eT>& Q;
84
85 inline explicit Proxy(const Col<eT>& A)
86 : Q(A)
87 {
88 arma_extra_debug_sigprint();
89 }
90
91 arma_inline uword get_n_rows() const { return Q.n_rows; }
92 arma_inline uword get_n_cols() const { return 1; }
93 arma_inline uword get_n_elem() const { return Q.n_elem; }
94
95 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
96 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
97
98 arma_inline ea_type get_ea() const { return Q.memptr(); }
99
100 template<typename eT2>
101 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
102 };
103
104
105
106 template<typename eT>
107 class Proxy< Row<eT> >
108 {
109 public:
110
111 typedef eT elem_type;
112 typedef typename get_pod_type<elem_type>::result pod_type;
113 typedef Row<eT> stored_type;
114 typedef const eT* ea_type;
115
116 static const bool prefer_at_accessor = false;
117 static const bool has_subview = false;
118
119 arma_aligned const Row<eT>& Q;
120
121 inline explicit Proxy(const Row<eT>& A)
122 : Q(A)
123 {
124 arma_extra_debug_sigprint();
125 }
126
127 arma_inline uword get_n_rows() const { return 1; }
128 arma_inline uword get_n_cols() const { return Q.n_cols; }
129 arma_inline uword get_n_elem() const { return Q.n_elem; }
130
131 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
132 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
133
134 arma_inline ea_type get_ea() const { return Q.memptr(); }
135
136 template<typename eT2>
137 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
138 };
139
140
141
142 template<typename eT, typename gen_type>
143 class Proxy< Gen<eT, gen_type > >
144 {
145 public:
146
147 typedef eT elem_type;
148 typedef typename get_pod_type<elem_type>::result pod_type;
149 typedef Gen<eT, gen_type> stored_type;
150 typedef const Gen<eT, gen_type>& ea_type;
151
152 static const bool prefer_at_accessor = Gen<eT, gen_type>::prefer_at_accessor;
153 static const bool has_subview = false;
154
155 arma_aligned const Gen<eT, gen_type>& Q;
156
157 inline explicit Proxy(const Gen<eT, gen_type>& A)
158 : Q(A)
159 {
160 arma_extra_debug_sigprint();
161 }
162
163 arma_inline uword get_n_rows() const { return Q.n_rows; }
164 arma_inline uword get_n_cols() const { return Q.n_cols; }
165 arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols; }
166
167 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
168 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
169
170 arma_inline ea_type get_ea() const { return Q; }
171
172 template<typename eT2>
173 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
174 };
175
176
177
178 template<typename T1, typename op_type>
179 class Proxy< Op<T1, op_type> >
180 {
181 public:
182
183 typedef typename T1::elem_type elem_type;
184 typedef typename get_pod_type<elem_type>::result pod_type;
185 typedef Mat<elem_type> stored_type;
186 typedef const elem_type* ea_type;
187
188 static const bool prefer_at_accessor = false;
189 static const bool has_subview = false;
190
191 arma_aligned const Mat<elem_type> Q;
192
193 inline explicit Proxy(const Op<T1, op_type>& A)
194 : Q(A)
195 {
196 arma_extra_debug_sigprint();
197 }
198
199 arma_inline uword get_n_rows() const { return Q.n_rows; }
200 arma_inline uword get_n_cols() const { return Q.n_cols; }
201 arma_inline uword get_n_elem() const { return Q.n_elem; }
202
203 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
204 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
205
206 arma_inline ea_type get_ea() const { return Q.memptr(); }
207
208 template<typename eT2>
209 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
210 };
211
212
213
214 template<typename T1, typename T2, typename glue_type>
215 class Proxy< Glue<T1, T2, glue_type> >
216 {
217 public:
218
219 typedef typename T1::elem_type elem_type;
220 typedef typename get_pod_type<elem_type>::result pod_type;
221 typedef Mat<elem_type> stored_type;
222 typedef const elem_type* ea_type;
223
224 static const bool prefer_at_accessor = false;
225 static const bool has_subview = false;
226
227 arma_aligned const Mat<elem_type> Q;
228
229 inline explicit Proxy(const Glue<T1, T2, glue_type>& A)
230 : Q(A)
231 {
232 arma_extra_debug_sigprint();
233 }
234
235 arma_inline uword get_n_rows() const { return Q.n_rows; }
236 arma_inline uword get_n_cols() const { return Q.n_cols; }
237 arma_inline uword get_n_elem() const { return Q.n_elem; }
238
239 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
240 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
241
242 arma_inline ea_type get_ea() const { return Q.memptr(); }
243
244 template<typename eT2>
245 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
246 };
247
248
249
250 template<typename eT>
251 class Proxy< subview<eT> >
252 {
253 public:
254
255 typedef eT elem_type;
256 typedef typename get_pod_type<elem_type>::result pod_type;
257 typedef subview<eT> stored_type;
258 typedef const subview<eT>& ea_type;
259
260 static const bool prefer_at_accessor = true;
261 static const bool has_subview = true;
262
263 arma_aligned const subview<eT>& Q;
264
265 inline explicit Proxy(const subview<eT>& A)
266 : Q(A)
267 {
268 arma_extra_debug_sigprint();
269 }
270
271 arma_inline uword get_n_rows() const { return Q.n_rows; }
272 arma_inline uword get_n_cols() const { return Q.n_cols; }
273 arma_inline uword get_n_elem() const { return Q.n_elem; }
274
275 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
276 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
277
278 arma_inline ea_type get_ea() const { return Q; }
279
280 template<typename eT2>
281 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); }
282 };
283
284
285
286 template<typename eT, typename T1>
287 class Proxy< subview_elem1<eT,T1> >
288 {
289 public:
290
291 typedef eT elem_type;
292 typedef typename get_pod_type<elem_type>::result pod_type;
293 typedef Mat<eT> stored_type;
294 typedef const eT* ea_type;
295
296 static const bool prefer_at_accessor = false;
297 static const bool has_subview = false;
298
299 arma_aligned const Mat<eT> Q;
300
301 inline explicit Proxy(const subview_elem1<eT,T1>& A)
302 : Q(A)
303 {
304 arma_extra_debug_sigprint();
305 }
306
307 arma_inline uword get_n_rows() const { return Q.n_rows; }
308 arma_inline uword get_n_cols() const { return 1; }
309 arma_inline uword get_n_elem() const { return Q.n_elem; }
310
311 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
312 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
313
314 arma_inline ea_type get_ea() const { return Q.memptr(); }
315
316 template<typename eT2>
317 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
318 };
319
320
321
322 template<typename eT>
323 class Proxy< diagview<eT> >
324 {
325 public:
326
327 typedef eT elem_type;
328 typedef typename get_pod_type<elem_type>::result pod_type;
329 typedef diagview<eT> stored_type;
330 typedef const diagview<eT>& ea_type;
331
332 static const bool prefer_at_accessor = false;
333 static const bool has_subview = true;
334
335 arma_aligned const diagview<eT>& Q;
336
337 inline explicit Proxy(const diagview<eT>& A)
338 : Q(A)
339 {
340 arma_extra_debug_sigprint();
341 }
342
343 arma_inline uword get_n_rows() const { return Q.n_rows; }
344 arma_inline uword get_n_cols() const { return 1; }
345 arma_inline uword get_n_elem() const { return Q.n_elem; }
346
347 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
348 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
349
350 arma_inline ea_type get_ea() const { return Q; }
351
352 template<typename eT2>
353 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); }
354 };
355
356
357
358
359 template<typename T1, typename eop_type>
360 class Proxy< eOp<T1, eop_type > >
361 {
362 public:
363
364 typedef typename T1::elem_type elem_type;
365 typedef typename get_pod_type<elem_type>::result pod_type;
366 typedef eOp<T1, eop_type> stored_type;
367 typedef const eOp<T1, eop_type>& ea_type;
368
369 static const bool prefer_at_accessor = eOp<T1, eop_type>::prefer_at_accessor;
370 static const bool has_subview = eOp<T1, eop_type>::has_subview;
371
372 arma_aligned const eOp<T1, eop_type>& Q;
373
374 inline explicit Proxy(const eOp<T1, eop_type>& A)
375 : Q(A)
376 {
377 arma_extra_debug_sigprint();
378 }
379
380 arma_inline uword get_n_rows() const { return Q.get_n_rows(); }
381 arma_inline uword get_n_cols() const { return Q.get_n_cols(); }
382 arma_inline uword get_n_elem() const { return Q.get_n_elem(); }
383
384 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
385 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
386
387 arma_inline ea_type get_ea() const { return Q; }
388
389 template<typename eT2>
390 arma_inline bool is_alias(const Mat<eT2>& X) const { return Q.P.is_alias(X); }
391 };
392
393
394
395 template<typename T1, typename T2, typename eglue_type>
396 class Proxy< eGlue<T1, T2, eglue_type > >
397 {
398 public:
399
400 typedef typename T1::elem_type elem_type;
401 typedef typename get_pod_type<elem_type>::result pod_type;
402 typedef eGlue<T1, T2, eglue_type> stored_type;
403 typedef const eGlue<T1, T2, eglue_type>& ea_type;
404
405 static const bool prefer_at_accessor = eGlue<T1, T2, eglue_type>::prefer_at_accessor;
406 static const bool has_subview = eGlue<T1, T2, eglue_type>::has_subview;
407
408 arma_aligned const eGlue<T1, T2, eglue_type>& Q;
409
410 inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A)
411 : Q(A)
412 {
413 arma_extra_debug_sigprint();
414 }
415
416 arma_inline uword get_n_rows() const { return Q.get_n_rows(); }
417 arma_inline uword get_n_cols() const { return Q.get_n_cols(); }
418 arma_inline uword get_n_elem() const { return Q.get_n_elem(); }
419
420 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
421 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
422
423 arma_inline ea_type get_ea() const { return Q; }
424
425 template<typename eT2>
426 arma_inline bool is_alias(const Mat<eT2>& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); }
427 };
428
429
430
431 template<typename out_eT, typename T1, typename op_type>
432 class Proxy< mtOp<out_eT, T1, op_type> >
433 {
434 public:
435
436 typedef out_eT elem_type;
437 typedef typename get_pod_type<out_eT>::result pod_type;
438 typedef Mat<out_eT> stored_type;
439 typedef const elem_type* ea_type;
440
441 static const bool prefer_at_accessor = false;
442 static const bool has_subview = false;
443
444 arma_aligned const Mat<out_eT> Q;
445
446 inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A)
447 : Q(A)
448 {
449 arma_extra_debug_sigprint();
450 }
451
452 arma_inline uword get_n_rows() const { return Q.n_rows; }
453 arma_inline uword get_n_cols() const { return Q.n_cols; }
454 arma_inline uword get_n_elem() const { return Q.n_elem; }
455
456 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
457 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); }
458
459 arma_inline ea_type get_ea() const { return Q.memptr(); }
460
461 template<typename eT2>
462 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
463 };
464
465
466
467 template<typename out_eT, typename T1, typename T2, typename glue_type>
468 class Proxy< mtGlue<out_eT, T1, T2, glue_type > >
469 {
470 public:
471
472 typedef out_eT elem_type;
473 typedef typename get_pod_type<out_eT>::result pod_type;
474 typedef Mat<out_eT> stored_type;
475 typedef const elem_type* ea_type;
476
477 static const bool prefer_at_accessor = false;
478 static const bool has_subview = false;
479
480 arma_aligned const Mat<out_eT> Q;
481
482 inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A)
483 : Q(A)
484 {
485 arma_extra_debug_sigprint();
486 }
487
488 arma_inline uword get_n_rows() const { return Q.n_rows; }
489 arma_inline uword get_n_cols() const { return Q.n_cols; }
490 arma_inline uword get_n_elem() const { return Q.n_elem; }
491
492 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
493 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); }
494
495 arma_inline ea_type get_ea() const { return Q.memptr(); }
496
497 template<typename eT2>
498 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
499 };
500
501
502
503 //! @}