eglue_core_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-2011 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 
16 
17 
18 
19 class eglue_plus : public eglue_core<eglue_plus>
20  {
21  public:
22 
23  inline static const char* text() { return "addition"; }
24  };
25 
26 
27 
28 class eglue_minus : public eglue_core<eglue_minus>
29  {
30  public:
31 
32  inline static const char* text() { return "subtraction"; }
33  };
34 
35 
36 
37 class eglue_div : public eglue_core<eglue_div>
38  {
39  public:
40 
41  inline static const char* text() { return "element-wise division"; }
42  };
43 
44 
45 
46 class eglue_schur : public eglue_core<eglue_schur>
47  {
48  public:
49 
50  inline static const char* text() { return "element-wise multiplication"; }
51  };
52 
53 
54 
55 #undef arma_applier_1
56 #undef arma_applier_2
57 #undef arma_applier_3
58 #undef operatorA
59 #undef operatorB
60 
61 #define arma_applier_1(operatorA, operatorB) \
62  {\
63  uword i,j;\
64  \
65  for(i=0, j=1; j<n_elem; i+=2, j+=2)\
66  {\
67  eT tmp_i = P1[i];\
68  eT tmp_j = P1[j];\
69  \
70  tmp_i operatorB##= P2[i];\
71  tmp_j operatorB##= P2[j];\
72  \
73  out_mem[i] operatorA tmp_i;\
74  out_mem[j] operatorA tmp_j;\
75  }\
76  \
77  if(i < n_elem)\
78  {\
79  out_mem[i] operatorA P1[i] operatorB P2[i];\
80  }\
81  }
82 
83 
84 
85 #define arma_applier_2(operatorA, operatorB) \
86  {\
87  uword count = 0;\
88  \
89  for(uword col=0; col<n_cols; ++col)\
90  {\
91  uword i,j;\
92  \
93  for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\
94  {\
95  eT tmp_i = P1.at(i,col);\
96  eT tmp_j = P1.at(j,col);\
97  \
98  tmp_i operatorB##= P2.at(i,col);\
99  tmp_j operatorB##= P2.at(j,col);\
100  \
101  out_mem[count ] operatorA tmp_i;\
102  out_mem[count+1] operatorA tmp_j;\
103  }\
104  \
105  if(i < n_rows)\
106  {\
107  out_mem[count] operatorA P1.at(i,col) operatorB P2.at(i,col);\
108  ++count;\
109  }\
110  }\
111  }
112 
113 
114 
115 #define arma_applier_3(operatorA, operatorB) \
116  {\
117  uword count = 0;\
118  \
119  for(uword slice=0; slice<n_slices; ++slice)\
120  {\
121  for(uword col=0; col<n_cols; ++col)\
122  {\
123  uword i,j;\
124  \
125  for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\
126  {\
127  eT tmp_i = P1.at(i,col,slice);\
128  eT tmp_j = P1.at(j,col,slice);\
129  \
130  tmp_i operatorB##= P2.at(i,col,slice);\
131  tmp_j operatorB##= P2.at(j,col,slice);\
132  \
133  out_mem[count ] operatorA tmp_i;\
134  out_mem[count+1] operatorA tmp_j;\
135  }\
136  \
137  if(i < n_rows)\
138  {\
139  out_mem[count] operatorA P1.at(i,col,slice) operatorB P2.at(i,col,slice);\
140  ++count;\
141  }\
142  }\
143  }\
144  }
145 
146 
147 
148 //
149 // matrices
150 
151 
152 
153 template<typename eglue_type>
154 template<typename T1, typename T2>
155 arma_hot
156 inline
157 void
159  {
161 
162  typedef typename T1::elem_type eT;
163 
164  const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
165 
166  // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
167  // size setting and alias checking is done by either the Mat contructor or operator=()
168 
169  eT* out_mem = out.memptr();
170 
171  if(prefer_at_accessor == false)
172  {
173  const uword n_elem = out.n_elem;
174 
175  typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
176  typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
177 
182  }
183  else
184  {
185  const uword n_rows = out.n_rows;
186  const uword n_cols = out.n_cols;
187 
188  const Proxy<T1>& P1 = x.P1;
189  const Proxy<T2>& P2 = x.P2;
190 
195  }
196  }
197 
198 
199 
200 template<typename eglue_type>
201 template<typename T1, typename T2>
202 arma_hot
203 inline
204 void
206  {
208 
209  arma_debug_assert_same_size(out, x.P1, "addition");
210 
211  typedef typename T1::elem_type eT;
212 
213  eT* out_mem = out.memptr();
214 
215  const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
216 
217  if(prefer_at_accessor == false)
218  {
219  const uword n_elem = out.n_elem;
220 
221  typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
222  typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
223 
228  }
229  else
230  {
231  const uword n_rows = out.n_rows;
232  const uword n_cols = out.n_cols;
233 
234  const Proxy<T1>& P1 = x.P1;
235  const Proxy<T2>& P2 = x.P2;
236 
241  }
242  }
243 
244 
245 
246 template<typename eglue_type>
247 template<typename T1, typename T2>
248 arma_hot
249 inline
250 void
252  {
254 
255  arma_debug_assert_same_size(out, x.P1, "subtraction");
256 
257  typedef typename T1::elem_type eT;
258 
259  eT* out_mem = out.memptr();
260 
261  const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
262 
263  if(prefer_at_accessor == false)
264  {
265  const uword n_elem = out.n_elem;
266 
267  typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
268  typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
269 
274  }
275  else
276  {
277  const uword n_rows = out.n_rows;
278  const uword n_cols = out.n_cols;
279 
280  const Proxy<T1>& P1 = x.P1;
281  const Proxy<T2>& P2 = x.P2;
282 
287  }
288  }
289 
290 
291 
292 template<typename eglue_type>
293 template<typename T1, typename T2>
294 arma_hot
295 inline
296 void
298  {
300 
301  arma_debug_assert_same_size(out, x.P1, "element-wise multiplication");
302 
303  typedef typename T1::elem_type eT;
304 
305  eT* out_mem = out.memptr();
306 
307  const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
308 
309  if(prefer_at_accessor == false)
310  {
311  const uword n_elem = out.n_elem;
312 
313  typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
314  typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
315 
320  }
321  else
322  {
323  const uword n_rows = out.n_rows;
324  const uword n_cols = out.n_cols;
325 
326  const Proxy<T1>& P1 = x.P1;
327  const Proxy<T2>& P2 = x.P2;
328 
333  }
334  }
335 
336 
337 
338 template<typename eglue_type>
339 template<typename T1, typename T2>
340 arma_hot
341 inline
342 void
344  {
346 
347  arma_debug_assert_same_size(out, x.P1, "element-wise division");
348 
349  typedef typename T1::elem_type eT;
350 
351  eT* out_mem = out.memptr();
352 
353  const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
354 
355  if(prefer_at_accessor == false)
356  {
357  const uword n_elem = out.n_elem;
358 
359  typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
360  typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
361 
366  }
367  else
368  {
369  const uword n_rows = out.n_rows;
370  const uword n_cols = out.n_cols;
371 
372  const Proxy<T1>& P1 = x.P1;
373  const Proxy<T2>& P2 = x.P2;
374 
379  }
380  }
381 
382 
383 
384 //
385 // cubes
386 
387 
388 
389 template<typename eglue_type>
390 template<typename T1, typename T2>
391 arma_hot
392 inline
393 void
395  {
397 
398  typedef typename T1::elem_type eT;
399 
400  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
401 
402  // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing;
403  // size setting and alias checking is done by either the Cube contructor or operator=()
404 
405 
406  eT* out_mem = out.memptr();
407 
408  if(prefer_at_accessor == false)
409  {
410  const uword n_elem = out.n_elem;
411 
412  typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
413  typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
414 
419  }
420  else
421  {
422  const uword n_rows = x.get_n_rows();
423  const uword n_cols = x.get_n_cols();
424  const uword n_slices = x.get_n_slices();
425 
426  const ProxyCube<T1>& P1 = x.P1;
427  const ProxyCube<T2>& P2 = x.P2;
428 
433  }
434  }
435 
436 
437 
438 template<typename eglue_type>
439 template<typename T1, typename T2>
440 arma_hot
441 inline
442 void
444  {
446 
447  const uword n_rows = x.get_n_rows();
448  const uword n_cols = x.get_n_cols();
449  const uword n_slices = x.get_n_slices();
450 
451  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
452 
453  typedef typename T1::elem_type eT;
454 
455  eT* out_mem = out.memptr();
456 
457  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
458 
459  if(prefer_at_accessor == false)
460  {
461  const uword n_elem = out.n_elem;
462 
463  typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
464  typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
465 
470  }
471  else
472  {
473  const ProxyCube<T1>& P1 = x.P1;
474  const ProxyCube<T2>& P2 = x.P2;
475 
480  }
481  }
482 
483 
484 
485 template<typename eglue_type>
486 template<typename T1, typename T2>
487 arma_hot
488 inline
489 void
491  {
493 
494  const uword n_rows = x.get_n_rows();
495  const uword n_cols = x.get_n_cols();
496  const uword n_slices = x.get_n_slices();
497 
498  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
499 
500  typedef typename T1::elem_type eT;
501 
502  eT* out_mem = out.memptr();
503 
504  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
505 
506  if(prefer_at_accessor == false)
507  {
508  const uword n_elem = out.n_elem;
509 
510  typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
511  typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
512 
517  }
518  else
519  {
520  const ProxyCube<T1>& P1 = x.P1;
521  const ProxyCube<T2>& P2 = x.P2;
522 
527  }
528  }
529 
530 
531 
532 template<typename eglue_type>
533 template<typename T1, typename T2>
534 arma_hot
535 inline
536 void
538  {
540 
541  const uword n_rows = x.get_n_rows();
542  const uword n_cols = x.get_n_cols();
543  const uword n_slices = x.get_n_slices();
544 
545  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
546 
547  typedef typename T1::elem_type eT;
548 
549  eT* out_mem = out.memptr();
550 
551  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
552 
553  if(prefer_at_accessor == false)
554  {
555  const uword n_elem = out.n_elem;
556 
557  typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
558  typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
559 
564  }
565  else
566  {
567  const ProxyCube<T1>& P1 = x.P1;
568  const ProxyCube<T2>& P2 = x.P2;
569 
574  }
575  }
576 
577 
578 
579 template<typename eglue_type>
580 template<typename T1, typename T2>
581 arma_hot
582 inline
583 void
585  {
587 
588  const uword n_rows = x.get_n_rows();
589  const uword n_cols = x.get_n_cols();
590  const uword n_slices = x.get_n_slices();
591 
592  arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
593 
594  typedef typename T1::elem_type eT;
595 
596  eT* out_mem = out.memptr();
597 
598  const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
599 
600  if(prefer_at_accessor == false)
601  {
602  const uword n_elem = out.n_elem;
603 
604  typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
605  typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
606 
611  }
612  else
613  {
614  const ProxyCube<T1>& P1 = x.P1;
615  const ProxyCube<T2>& P2 = x.P2;
616 
621  }
622  }
623 
624 
625 
626 #undef arma_applier_1
627 #undef arma_applier_2
628 #undef arma_applier_3
629 
630 
631 
#define arma_applier_3(operatorA, operatorB)
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 const Proxy< T2 > P2
Definition: eGlue_bones.hpp:30
static const char * text()
arma_inline uword get_n_slices() const
static const char * text()
static arma_hot void apply_inplace_minus(Mat< typename T1::elem_type > &out, const eGlue< T1, T2, eglue_type > &x)
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
static const char * text()
#define arma_applier_2(operatorA, operatorB)
static arma_hot void apply(Mat< typename T1::elem_type > &out, const eGlue< T1, T2, eglue_type > &x)
u32 uword
Definition: typedef.hpp:85
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the cube
Definition: Cube_meat.hpp:2260
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
arma_inline uword get_n_rows() const
arma_inline uword get_n_cols() const
Dense cube class.
Definition: Cube_bones.hpp:30
static arma_hot void apply_inplace_plus(Mat< typename T1::elem_type > &out, const eGlue< T1, T2, eglue_type > &x)
arma_aligned const Proxy< T1 > P1
Definition: eGlue_bones.hpp:29
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
arma_aligned const ProxyCube< T2 > P2
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
Dense matrix class.
arma_aligned const ProxyCube< T1 > P1
#define arma_applier_1(operatorA, operatorB)
static arma_hot void apply_inplace_div(Mat< typename T1::elem_type > &out, const eGlue< T1, T2, eglue_type > &x)
#define arma_hot
static arma_hot void apply_inplace_schur(Mat< typename T1::elem_type > &out, const eGlue< T1, T2, eglue_type > &x)
const uword n_slices
number of slices in the cube (read-only)
Definition: Cube_bones.hpp:40
static const char * text()
const uword n_rows
number of rows in each slice (read-only)
Definition: Cube_bones.hpp:37


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