subview_cube_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-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 template<typename eT>
19 inline
21  {
23  }
24 
25 
26 
27 template<typename eT>
30  (
31  const Cube<eT>& in_m,
32  const uword in_row1,
33  const uword in_col1,
34  const uword in_slice1,
35  const uword in_n_rows,
36  const uword in_n_cols,
37  const uword in_n_slices
38  )
39  : m (in_m)
40  , m_ptr (0)
41  , aux_row1 (in_row1)
42  , aux_col1 (in_col1)
43  , aux_slice1 (in_slice1)
44  , n_rows (in_n_rows)
45  , n_cols (in_n_cols)
46  , n_elem_slice(in_n_rows * in_n_cols)
47  , n_slices (in_n_slices)
48  , n_elem (n_elem_slice * in_n_slices)
49  {
51  }
52 
53 
54 
55 template<typename eT>
58  (
59  Cube<eT>& in_m,
60  const uword in_row1,
61  const uword in_col1,
62  const uword in_slice1,
63  const uword in_n_rows,
64  const uword in_n_cols,
65  const uword in_n_slices
66  )
67  : m (in_m)
68  , m_ptr (&in_m)
69  , aux_row1 (in_row1)
70  , aux_col1 (in_col1)
71  , aux_slice1 (in_slice1)
72  , n_rows (in_n_rows)
73  , n_cols (in_n_cols)
74  , n_elem_slice(in_n_rows * in_n_cols)
75  , n_slices (in_n_slices)
76  , n_elem (n_elem_slice * in_n_slices)
77  {
79  }
80 
81 
82 
83 template<typename eT>
84 inline
85 void
87  {
89 
90  const uword local_n_rows = n_rows;
91  const uword local_n_cols = n_cols;
92  const uword local_n_slices = n_slices;
93 
94  for(uword slice = 0; slice < local_n_slices; ++slice)
95  {
96  for(uword col = 0; col < local_n_cols; ++col)
97  {
98  arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows );
99  }
100  }
101  }
102 
103 
104 
105 template<typename eT>
106 inline
107 void
109  {
111 
112  const uword local_n_rows = n_rows;
113  const uword local_n_cols = n_cols;
114  const uword local_n_slices = n_slices;
115 
116  for(uword slice = 0; slice < local_n_slices; ++slice)
117  {
118  for(uword col = 0; col < local_n_cols; ++col)
119  {
120  arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows );
121  }
122  }
123  }
124 
125 
126 
127 template<typename eT>
128 inline
129 void
131  {
133 
134  const uword local_n_rows = n_rows;
135  const uword local_n_cols = n_cols;
136  const uword local_n_slices = n_slices;
137 
138  for(uword slice = 0; slice < local_n_slices; ++slice)
139  {
140  for(uword col = 0; col < local_n_cols; ++col)
141  {
142  arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows );
143  }
144  }
145  }
146 
147 
148 
149 template<typename eT>
150 inline
151 void
153  {
155 
156  const uword local_n_rows = n_rows;
157  const uword local_n_cols = n_cols;
158  const uword local_n_slices = n_slices;
159 
160  for(uword slice = 0; slice < local_n_slices; ++slice)
161  {
162  for(uword col = 0; col < local_n_cols; ++col)
163  {
164  arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows );
165  }
166  }
167  }
168 
169 
170 
171 template<typename eT>
172 template<typename T1>
173 inline
174 void
176  {
178 
179  const unwrap_cube<T1> tmp(in.get_ref());
180 
181  const Cube<eT>& x = tmp.M;
182  subview_cube<eT>& t = *this;
183 
184  arma_debug_assert_same_size(t, x, "copy into subcube");
185 
186  const uword t_n_rows = t.n_rows;
187  const uword t_n_cols = t.n_cols;
188  const uword t_n_slices = t.n_slices;
189 
190  for(uword slice = 0; slice < t_n_slices; ++slice)
191  {
192  for(uword col = 0; col < t_n_cols; ++col)
193  {
194  arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
195  }
196  }
197  }
198 
199 
200 
201 template<typename eT>
202 template<typename T1>
203 inline
204 void
206  {
208 
209  const unwrap_cube<T1> tmp(in.get_ref());
210 
211  const Cube<eT>& x = tmp.M;
212  subview_cube<eT>& t = *this;
213 
214  arma_debug_assert_same_size(t, x, "addition");
215 
216  const uword t_n_rows = t.n_rows;
217  const uword t_n_cols = t.n_cols;
218  const uword t_n_slices = t.n_slices;
219 
220  for(uword slice = 0; slice < t_n_slices; ++slice)
221  {
222  for(uword col = 0; col < t_n_cols; ++col)
223  {
224  arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
225  }
226  }
227  }
228 
229 
230 
231 template<typename eT>
232 template<typename T1>
233 inline
234 void
236  {
238 
239  const unwrap_cube<T1> tmp(in.get_ref());
240 
241  const Cube<eT>& x = tmp.M;
242  subview_cube<eT>& t = *this;
243 
244  arma_debug_assert_same_size(t, x, "subtraction");
245 
246  const uword t_n_rows = t.n_rows;
247  const uword t_n_cols = t.n_cols;
248  const uword t_n_slices = t.n_slices;
249 
250  for(uword slice = 0; slice < t_n_slices; ++slice)
251  {
252  for(uword col = 0; col < t_n_cols; ++col)
253  {
254  arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
255  }
256  }
257  }
258 
259 
260 
261 template<typename eT>
262 template<typename T1>
263 inline
264 void
266  {
268 
269  const unwrap_cube<T1> tmp(in.get_ref());
270 
271  const Cube<eT>& x = tmp.M;
272  subview_cube<eT>& t = *this;
273 
274  arma_debug_assert_same_size(t, x, "element-wise multiplication");
275 
276  const uword t_n_rows = t.n_rows;
277  const uword t_n_cols = t.n_cols;
278  const uword t_n_slices = t.n_slices;
279 
280  for(uword slice = 0; slice < t_n_slices; ++slice)
281  {
282  for(uword col = 0; col < t_n_cols; ++col)
283  {
284  arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
285  }
286  }
287  }
288 
289 
290 
291 template<typename eT>
292 template<typename T1>
293 inline
294 void
296  {
298 
299  const unwrap_cube<T1> tmp(in.get_ref());
300 
301  const Cube<eT>& x = tmp.M;
302  subview_cube<eT>& t = *this;
303 
304  arma_debug_assert_same_size(t, x, "element-wise division");
305 
306  const uword t_n_rows = t.n_rows;
307  const uword t_n_cols = t.n_cols;
308  const uword t_n_slices = t.n_slices;
309 
310  for(uword slice = 0; slice < t_n_slices; ++slice)
311  {
312  for(uword col = 0; col < t_n_cols; ++col)
313  {
314  arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
315  }
316  }
317  }
318 
319 
320 
322 template<typename eT>
323 inline
324 void
326  {
328 
329  const bool overlap = check_overlap(x_in);
330 
331  Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
332  const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0;
333  const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
334 
335  subview_cube<eT>& t = *this;
336 
337  arma_debug_assert_same_size(t, x, "copy into subcube");
338 
339  const uword t_n_rows = t.n_rows;
340  const uword t_n_cols = t.n_cols;
341  const uword t_n_slices = t.n_slices;
342 
343  for(uword slice = 0; slice < t_n_slices; ++slice)
344  {
345  for(uword col = 0; col < t_n_cols; ++col)
346  {
347  arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
348  }
349  }
350 
351  if(overlap)
352  {
353  delete tmp_subview_cube;
354  delete tmp_cube;
355  }
356 
357  }
358 
359 
360 
361 template<typename eT>
362 inline
363 void
365  {
367 
368  const bool overlap = check_overlap(x_in);
369 
370  Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
371  const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0;
372  const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
373 
374  subview_cube<eT>& t = *this;
375 
376  arma_debug_assert_same_size(t, x, "addition");
377 
378  const uword t_n_rows = t.n_rows;
379  const uword t_n_cols = t.n_cols;
380  const uword t_n_slices = t.n_slices;
381 
382  for(uword slice = 0; slice < t_n_slices; ++slice)
383  {
384  for(uword col = 0; col < t_n_cols; ++col)
385  {
386  arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
387  }
388  }
389 
390  if(overlap)
391  {
392  delete tmp_subview_cube;
393  delete tmp_cube;
394  }
395 
396  }
397 
398 
399 
400 template<typename eT>
401 inline
402 void
404  {
406 
407  const bool overlap = check_overlap(x_in);
408 
409  Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
410  const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0;
411  const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
412 
413  subview_cube<eT>& t = *this;
414 
415  arma_debug_assert_same_size(t, x, "subtraction");
416 
417  const uword t_n_rows = t.n_rows;
418  const uword t_n_cols = t.n_cols;
419  const uword t_n_slices = t.n_slices;
420 
421  for(uword slice = 0; slice < t_n_slices; ++slice)
422  {
423  for(uword col = 0; col < t_n_cols; ++col)
424  {
425  arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
426  }
427  }
428 
429  if(overlap)
430  {
431  delete tmp_subview_cube;
432  delete tmp_cube;
433  }
434 
435  }
436 
437 
438 
439 template<typename eT>
440 inline
441 void
443  {
445 
446  const bool overlap = check_overlap(x_in);
447 
448  Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
449  const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0;
450  const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
451 
452  subview_cube<eT>& t = *this;
453 
454  arma_debug_assert_same_size(t, x, "element-wise multiplication");
455 
456  const uword t_n_rows = t.n_rows;
457  const uword t_n_cols = t.n_cols;
458  const uword t_n_slices = t.n_slices;
459 
460  for(uword slice = 0; slice < t_n_slices; ++slice)
461  {
462  for(uword col = 0; col < t_n_cols; ++col)
463  {
464  arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
465  }
466  }
467 
468  if(overlap)
469  {
470  delete tmp_subview_cube;
471  delete tmp_cube;
472  }
473 
474  }
475 
476 
477 
478 template<typename eT>
479 inline
480 void
482  {
484 
485  const bool overlap = check_overlap(x_in);
486 
487  Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0;
488  const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0;
489  const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in;
490 
491  subview_cube<eT>& t = *this;
492 
493  arma_debug_assert_same_size(t, x, "element-wise division");
494 
495  const uword t_n_rows = t.n_rows;
496  const uword t_n_cols = t.n_cols;
497  const uword t_n_slices = t.n_slices;
498 
499  for(uword slice = 0; slice < t_n_slices; ++slice)
500  {
501  for(uword col = 0; col < t_n_cols; ++col)
502  {
503  arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows );
504  }
505  }
506 
507  if(overlap)
508  {
509  delete tmp_subview_cube;
510  delete tmp_cube;
511  }
512 
513  }
514 
515 
516 
517 template<typename eT>
518 template<typename T1>
519 inline
520 void
522  {
524 
525  const unwrap<T1> tmp(in.get_ref());
526 
527  const Mat<eT>& x = tmp.M;
528  subview_cube<eT>& t = *this;
529 
530  const uword t_n_rows = t.n_rows;
531  const uword t_n_cols = t.n_cols;
532  const uword t_n_slices = t.n_slices;
533 
534  const uword x_n_rows = x.n_rows;
535  const uword x_n_cols = x.n_cols;
536 
537  if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) )
538  {
539  // interpret the matrix as a cube with one slice
540 
541  for(uword col = 0; col < t_n_cols; ++col)
542  {
543  arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows );
544  }
545  }
546  else
547  if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) )
548  {
549  for(uword i=0; i < t_n_slices; ++i)
550  {
551  arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows );
552  }
553  }
554  else
555  if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) )
556  {
557  Cube<eT>& Q = *(t.m_ptr);
558 
559  const uword t_aux_row1 = t.aux_row1;
560  const uword t_aux_col1 = t.aux_col1;
561  const uword t_aux_slice1 = t.aux_slice1;
562 
563  for(uword slice=0; slice < t_n_slices; ++slice)
564  {
565  const uword mod_slice = t_aux_slice1 + slice;
566 
567  const eT* x_colptr = x.colptr(slice);
568 
569  uword i,j;
570  for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
571  {
572  const eT tmp_i = x_colptr[i];
573  const eT tmp_j = x_colptr[j];
574 
575  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = tmp_i;
576  Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) = tmp_j;
577  }
578 
579  if(i < t_n_cols)
580  {
581  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = x_colptr[i];
582  }
583  }
584  }
585  else
586  {
587  if(arma_config::debug == true)
588  {
589  arma_stop( arma_incompat_size_string(t, x, "copy into subcube") );
590  }
591  }
592  }
593 
594 
595 
596 template<typename eT>
597 template<typename T1>
598 inline
599 void
601  {
603 
604  const unwrap<T1> tmp(in.get_ref());
605 
606  const Mat<eT>& x = tmp.M;
607  subview_cube<eT>& t = *this;
608 
609  const uword t_n_rows = t.n_rows;
610  const uword t_n_cols = t.n_cols;
611  const uword t_n_slices = t.n_slices;
612 
613  const uword x_n_rows = x.n_rows;
614  const uword x_n_cols = x.n_cols;
615 
616  if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) )
617  {
618  for(uword col = 0; col < t_n_cols; ++col)
619  {
620  arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_rows );
621  }
622  }
623  else
624  if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) )
625  {
626  for(uword i=0; i < t_n_slices; ++i)
627  {
628  arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows );
629  }
630  }
631  else
632  if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) )
633  {
634  Cube<eT>& Q = *(t.m_ptr);
635 
636  const uword t_aux_row1 = t.aux_row1;
637  const uword t_aux_col1 = t.aux_col1;
638  const uword t_aux_slice1 = t.aux_slice1;
639 
640  for(uword slice=0; slice < t_n_slices; ++slice)
641  {
642  const uword mod_slice = t_aux_slice1 + slice;
643 
644  const eT* x_colptr = x.colptr(slice);
645 
646  uword i,j;
647  for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
648  {
649  const eT tmp_i = x_colptr[i];
650  const eT tmp_j = x_colptr[j];
651 
652  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += tmp_i;
653  Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) += tmp_j;
654  }
655 
656  if(i < t_n_cols)
657  {
658  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += x_colptr[i];
659  }
660  }
661  }
662  else
663  {
664  if(arma_config::debug == true)
665  {
666  arma_stop( arma_incompat_size_string(t, x, "addition") );
667  }
668  }
669  }
670 
671 
672 
673 template<typename eT>
674 template<typename T1>
675 inline
676 void
678  {
680 
681  const unwrap<T1> tmp(in.get_ref());
682 
683  const Mat<eT>& x = tmp.M;
684  subview_cube<eT>& t = *this;
685 
686  const uword t_n_rows = t.n_rows;
687  const uword t_n_cols = t.n_cols;
688  const uword t_n_slices = t.n_slices;
689 
690  const uword x_n_rows = x.n_rows;
691  const uword x_n_cols = x.n_cols;
692 
693  if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) )
694  {
695  for(uword col = 0; col < t_n_cols; ++col)
696  {
697  arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_rows );
698  }
699  }
700  else
701  if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) )
702  {
703  for(uword i=0; i < t_n_slices; ++i)
704  {
705  arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows );
706  }
707  }
708  else
709  if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) )
710  {
711  Cube<eT>& Q = *(t.m_ptr);
712 
713  const uword t_aux_row1 = t.aux_row1;
714  const uword t_aux_col1 = t.aux_col1;
715  const uword t_aux_slice1 = t.aux_slice1;
716 
717  for(uword slice=0; slice < t_n_slices; ++slice)
718  {
719  const uword mod_slice = t_aux_slice1 + slice;
720 
721  const eT* x_colptr = x.colptr(slice);
722 
723  uword i,j;
724  for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
725  {
726  const eT tmp_i = x_colptr[i];
727  const eT tmp_j = x_colptr[j];
728 
729  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= tmp_i;
730  Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) -= tmp_j;
731  }
732 
733  if(i < t_n_cols)
734  {
735  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= x_colptr[i];
736  }
737  }
738  }
739  else
740  {
741  if(arma_config::debug == true)
742  {
743  arma_stop( arma_incompat_size_string(t, x, "subtraction") );
744  }
745  }
746  }
747 
748 
749 
750 template<typename eT>
751 template<typename T1>
752 inline
753 void
755  {
757 
758  const unwrap<T1> tmp(in.get_ref());
759 
760  const Mat<eT>& x = tmp.M;
761  subview_cube<eT>& t = *this;
762 
763  const uword t_n_rows = t.n_rows;
764  const uword t_n_cols = t.n_cols;
765  const uword t_n_slices = t.n_slices;
766 
767  const uword x_n_rows = x.n_rows;
768  const uword x_n_cols = x.n_cols;
769 
770  if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) )
771  {
772  for(uword col = 0; col < t_n_cols; ++col)
773  {
774  arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_rows );
775  }
776  }
777  else
778  if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) )
779  {
780  for(uword i=0; i < t_n_slices; ++i)
781  {
782  arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows );
783  }
784  }
785  else
786  if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) )
787  {
788  Cube<eT>& Q = *(t.m_ptr);
789 
790  const uword t_aux_row1 = t.aux_row1;
791  const uword t_aux_col1 = t.aux_col1;
792  const uword t_aux_slice1 = t.aux_slice1;
793 
794  for(uword slice=0; slice < t_n_slices; ++slice)
795  {
796  const uword mod_slice = t_aux_slice1 + slice;
797 
798  const eT* x_colptr = x.colptr(slice);
799 
800  uword i,j;
801  for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
802  {
803  const eT tmp_i = x_colptr[i];
804  const eT tmp_j = x_colptr[j];
805 
806  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= tmp_i;
807  Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) *= tmp_j;
808  }
809 
810  if(i < t_n_cols)
811  {
812  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= x_colptr[i];
813  }
814  }
815  }
816  else
817  {
818  if(arma_config::debug == true)
819  {
820  arma_stop( arma_incompat_size_string(t, x, "element-wise multiplication") );
821  }
822  }
823  }
824 
825 
826 
827 template<typename eT>
828 template<typename T1>
829 inline
830 void
832  {
834 
835  const unwrap<T1> tmp(in.get_ref());
836 
837  const Mat<eT>& x = tmp.M;
838  subview_cube<eT>& t = *this;
839 
840  const uword t_n_rows = t.n_rows;
841  const uword t_n_cols = t.n_cols;
842  const uword t_n_slices = t.n_slices;
843 
844  const uword x_n_rows = x.n_rows;
845  const uword x_n_cols = x.n_cols;
846 
847  if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) )
848  {
849  for(uword col = 0; col < t_n_cols; ++col)
850  {
851  arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_rows );
852  }
853  }
854  else
855  if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) )
856  {
857  for(uword i=0; i < t_n_slices; ++i)
858  {
859  arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows );
860  }
861  }
862  else
863  if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) )
864  {
865  Cube<eT>& Q = *(t.m_ptr);
866 
867  const uword t_aux_row1 = t.aux_row1;
868  const uword t_aux_col1 = t.aux_col1;
869  const uword t_aux_slice1 = t.aux_slice1;
870 
871  for(uword slice=0; slice < t_n_slices; ++slice)
872  {
873  const uword mod_slice = t_aux_slice1 + slice;
874 
875  const eT* x_colptr = x.colptr(slice);
876 
877  uword i,j;
878  for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
879  {
880  const eT tmp_i = x_colptr[i];
881  const eT tmp_j = x_colptr[j];
882 
883  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= tmp_i;
884  Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) /= tmp_j;
885  }
886 
887  if(i < t_n_cols)
888  {
889  Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= x_colptr[i];
890  }
891  }
892  }
893  else
894  {
895  if(arma_config::debug == true)
896  {
897  arma_stop( arma_incompat_size_string(t, x, "element-wise division") );
898  }
899  }
900  }
901 
902 
903 
904 template<typename eT>
905 inline
906 void
908  {
910 
911  const uword local_n_rows = n_rows;
912  const uword local_n_cols = n_cols;
913  const uword local_n_slices = n_slices;
914 
915  for(uword slice = 0; slice < local_n_slices; ++slice)
916  {
917  for(uword col = 0; col < local_n_cols; ++col)
918  {
919  arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows );
920  }
921  }
922 
923  }
924 
925 
926 
927 template<typename eT>
928 inline
929 void
931  {
933 
934  fill(eT(0));
935  }
936 
937 
938 
939 template<typename eT>
940 inline
941 void
943  {
945 
946  fill(eT(1));
947  }
948 
949 
950 
951 template<typename eT>
952 inline
953 eT&
955  {
956  const uword in_slice = i / n_elem_slice;
957  const uword offset = in_slice * n_elem_slice;
958  const uword j = i - offset;
959 
960  const uword in_col = j / n_rows;
961  const uword in_row = j % n_rows;
962 
963  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
964  return access::rw( (*m_ptr).mem[index] );
965  }
966 
967 
968 
969 template<typename eT>
970 inline
971 eT
973  {
974  const uword in_slice = i / n_elem_slice;
975  const uword offset = in_slice * n_elem_slice;
976  const uword j = i - offset;
977 
978  const uword in_col = j / n_rows;
979  const uword in_row = j % n_rows;
980 
981  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
982  return m.mem[index];
983  }
984 
985 
986 
987 template<typename eT>
988 inline
989 eT&
991  {
992  arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds");
993 
994  const uword in_slice = i / n_elem_slice;
995  const uword offset = in_slice * n_elem_slice;
996  const uword j = i - offset;
997 
998  const uword in_col = j / n_rows;
999  const uword in_row = j % n_rows;
1000 
1001  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1002  return access::rw( (*m_ptr).mem[index] );
1003  }
1004 
1005 
1006 
1007 template<typename eT>
1008 inline
1009 eT
1011  {
1012  arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds");
1013 
1014  const uword in_slice = i / n_elem_slice;
1015  const uword offset = in_slice * n_elem_slice;
1016  const uword j = i - offset;
1017 
1018  const uword in_col = j / n_rows;
1019  const uword in_row = j % n_rows;
1020 
1021  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1022  return m.mem[index];
1023  }
1024 
1025 
1026 
1027 template<typename eT>
1029 eT&
1030 subview_cube<eT>::operator()(const uword in_row, const uword in_col, const uword in_slice)
1031  {
1032  arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds");
1033 
1034  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1035  return access::rw( (*m_ptr).mem[index] );
1036  }
1037 
1038 
1039 
1040 template<typename eT>
1042 eT
1043 subview_cube<eT>::operator()(const uword in_row, const uword in_col, const uword in_slice) const
1044  {
1045  arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds");
1046 
1047  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1048  return m.mem[index];
1049  }
1050 
1051 
1052 
1053 template<typename eT>
1055 eT&
1056 subview_cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice)
1057  {
1058  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1059  return access::rw( (*m_ptr).mem[index] );
1060  }
1061 
1062 
1063 
1064 template<typename eT>
1066 eT
1067 subview_cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) const
1068  {
1069  const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
1070  return m.mem[index];
1071  }
1072 
1073 
1074 
1075 template<typename eT>
1077 eT*
1078 subview_cube<eT>::slice_colptr(const uword in_slice, const uword in_col)
1079  {
1080  return & access::rw((*m_ptr).mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]);
1081  }
1082 
1083 
1084 
1085 template<typename eT>
1087 const eT*
1088 subview_cube<eT>::slice_colptr(const uword in_slice, const uword in_col) const
1089  {
1090  return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ];
1091  }
1092 
1093 
1094 
1095 template<typename eT>
1096 inline
1097 bool
1099  {
1100  const subview_cube<eT>& t = *this;
1101 
1102  if(&t.m != &x.m)
1103  {
1104  return false;
1105  }
1106  else
1107  {
1108  if( (t.n_elem == 0) || (x.n_elem == 0) )
1109  {
1110  return false;
1111  }
1112  else
1113  {
1114  const uword t_row_start = t.aux_row1;
1115  const uword t_row_end_p1 = t_row_start + t.n_rows;
1116 
1117  const uword t_col_start = t.aux_col1;
1118  const uword t_col_end_p1 = t_col_start + t.n_cols;
1119 
1120  const uword t_slice_start = t.aux_slice1;
1121  const uword t_slice_end_p1 = t_slice_start + t.n_slices;
1122 
1123 
1124  const uword x_row_start = x.aux_row1;
1125  const uword x_row_end_p1 = x_row_start + x.n_rows;
1126 
1127  const uword x_col_start = x.aux_col1;
1128  const uword x_col_end_p1 = x_col_start + x.n_cols;
1129 
1130  const uword x_slice_start = x.aux_slice1;
1131  const uword x_slice_end_p1 = x_slice_start + x.n_slices;
1132 
1133 
1134  const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) );
1135  const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) );
1136  const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) );
1137 
1138  return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) );
1139  }
1140  }
1141  }
1142 
1143 
1144 
1145 template<typename eT>
1146 inline
1147 bool
1149  {
1150  const subview_cube<eT>& t = *this;
1151 
1152  const uword t_aux_slice1 = t.aux_slice1;
1153  const uword t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices;
1154 
1155  for(uword slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice)
1156  {
1157  const Mat<eT>& y = *(t.m.mat_ptrs[slice]);
1158 
1159  if( x.memptr() == y.memptr() )
1160  {
1161  return true;
1162  }
1163  }
1164 
1165  return false;
1166  }
1167 
1168 
1169 
1171 template<typename eT>
1172 inline
1173 void
1175  {
1177 
1178  // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing;
1179  // size setting and alias checking is done by either the Cube contructor or operator=()
1180 
1181  const uword n_rows = in.n_rows;
1182  const uword n_cols = in.n_cols;
1183  const uword n_slices = in.n_slices;
1184 
1185  arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n_cols % in.m.n_slices);
1186 
1187 
1188  for(uword slice = 0; slice < n_slices; ++slice)
1189  {
1190  for(uword col = 0; col < n_cols; ++col)
1191  {
1192  arrayops::copy( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows );
1193  }
1194  }
1195  }
1196 
1197 
1198 
1200 template<typename eT>
1201 inline
1202 void
1204  {
1206 
1207  arma_debug_assert_same_size(out, in, "addition");
1208 
1209  const uword n_rows = out.n_rows;
1210  const uword n_cols = out.n_cols;
1211  const uword n_slices = out.n_slices;
1212 
1213  for(uword slice = 0; slice<n_slices; ++slice)
1214  {
1215  for(uword col = 0; col<n_cols; ++col)
1216  {
1218  }
1219  }
1220  }
1221 
1222 
1223 
1225 template<typename eT>
1226 inline
1227 void
1229  {
1231 
1232  arma_debug_assert_same_size(out, in, "subtraction");
1233 
1234  const uword n_rows = out.n_rows;
1235  const uword n_cols = out.n_cols;
1236  const uword n_slices = out.n_slices;
1237 
1238  for(uword slice = 0; slice<n_slices; ++slice)
1239  {
1240  for(uword col = 0; col<n_cols; ++col)
1241  {
1243  }
1244  }
1245  }
1246 
1247 
1248 
1250 template<typename eT>
1251 inline
1252 void
1254  {
1256 
1257  arma_debug_assert_same_size(out, in, "element-wise multiplication");
1258 
1259  const uword n_rows = out.n_rows;
1260  const uword n_cols = out.n_cols;
1261  const uword n_slices = out.n_slices;
1262 
1263  for(uword slice = 0; slice<n_slices; ++slice)
1264  {
1265  for(uword col = 0; col<n_cols; ++col)
1266  {
1268  }
1269  }
1270  }
1271 
1272 
1273 
1275 template<typename eT>
1276 inline
1277 void
1279  {
1281 
1282  arma_debug_assert_same_size(out, in, "element-wise division");
1283 
1284  const uword n_rows = out.n_rows;
1285  const uword n_cols = out.n_cols;
1286  const uword n_slices = out.n_slices;
1287 
1288  for(uword slice = 0; slice<n_slices; ++slice)
1289  {
1290  for(uword col = 0; col<n_cols; ++col)
1291  {
1293  }
1294  }
1295  }
1296 
1297 
1298 
1300 template<typename eT>
1301 inline
1302 void
1304  {
1306 
1307  arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false);
1308 
1309  const uword in_n_rows = in.n_rows;
1310  const uword in_n_cols = in.n_cols;
1311  const uword in_n_slices = in.n_slices;
1312 
1313  const uword out_vec_state = out.vec_state;
1314 
1315  if(in_n_slices == 1)
1316  {
1317  out.set_size(in_n_rows, in_n_cols);
1318 
1319  for(uword col=0; col < in_n_cols; ++col)
1320  {
1321  arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
1322  }
1323  }
1324  else
1325  {
1326  if(out_vec_state == 0)
1327  {
1328  if(in_n_cols == 1)
1329  {
1330  out.set_size(in_n_rows, in_n_slices);
1331 
1332  for(uword i=0; i < in_n_slices; ++i)
1333  {
1334  arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
1335  }
1336  }
1337  else
1338  if(in_n_rows == 1)
1339  {
1340  const Cube<eT>& Q = in.m;
1341 
1342  const uword in_aux_row1 = in.aux_row1;
1343  const uword in_aux_col1 = in.aux_col1;
1344  const uword in_aux_slice1 = in.aux_slice1;
1345 
1346  out.set_size(in_n_cols, in_n_slices);
1347 
1348  for(uword slice=0; slice < in_n_slices; ++slice)
1349  {
1350  const uword mod_slice = in_aux_slice1 + slice;
1351 
1352  eT* out_colptr = out.colptr(slice);
1353 
1354  uword i,j;
1355  for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
1356  {
1357  const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1358  const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice);
1359 
1360  out_colptr[i] = tmp_i;
1361  out_colptr[j] = tmp_j;
1362  }
1363 
1364  if(i < in_n_cols)
1365  {
1366  out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1367  }
1368  }
1369  }
1370  }
1371  else
1372  {
1373  out.set_size(in_n_slices);
1374 
1375  eT* out_mem = out.memptr();
1376 
1377  const Cube<eT>& Q = in.m;
1378 
1379  const uword in_aux_row1 = in.aux_row1;
1380  const uword in_aux_col1 = in.aux_col1;
1381  const uword in_aux_slice1 = in.aux_slice1;
1382 
1383  for(uword i=0; i<in_n_slices; ++i)
1384  {
1385  out_mem[i] = Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i);
1386  }
1387  }
1388  }
1389  }
1390 
1391 
1392 
1394 template<typename eT>
1395 inline
1396 void
1398  {
1400 
1401  arma_debug_assert_cube_as_mat(out, in, "addition", true);
1402 
1403  const uword in_n_rows = in.n_rows;
1404  const uword in_n_cols = in.n_cols;
1405  const uword in_n_slices = in.n_slices;
1406 
1407  const uword out_n_rows = out.n_rows;
1408  const uword out_n_cols = out.n_cols;
1409  const uword out_vec_state = out.vec_state;
1410 
1411  if(in_n_slices == 1)
1412  {
1413  for(uword col=0; col < in_n_cols; ++col)
1414  {
1415  arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
1416  }
1417  }
1418  else
1419  {
1420  if(out_vec_state == 0)
1421  {
1422  if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
1423  {
1424  for(uword i=0; i < in_n_slices; ++i)
1425  {
1426  arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
1427  }
1428  }
1429  else
1430  if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
1431  {
1432  const Cube<eT>& Q = in.m;
1433 
1434  const uword in_aux_row1 = in.aux_row1;
1435  const uword in_aux_col1 = in.aux_col1;
1436  const uword in_aux_slice1 = in.aux_slice1;
1437 
1438  for(uword slice=0; slice < in_n_slices; ++slice)
1439  {
1440  const uword mod_slice = in_aux_slice1 + slice;
1441 
1442  eT* out_colptr = out.colptr(slice);
1443 
1444  uword i,j;
1445  for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
1446  {
1447  const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1448  const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice);
1449 
1450  out_colptr[i] += tmp_i;
1451  out_colptr[j] += tmp_j;
1452  }
1453 
1454  if(i < in_n_cols)
1455  {
1456  out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1457  }
1458  }
1459  }
1460  }
1461  else
1462  {
1463  eT* out_mem = out.memptr();
1464 
1465  const Cube<eT>& Q = in.m;
1466 
1467  const uword in_aux_row1 = in.aux_row1;
1468  const uword in_aux_col1 = in.aux_col1;
1469  const uword in_aux_slice1 = in.aux_slice1;
1470 
1471  for(uword i=0; i<in_n_slices; ++i)
1472  {
1473  out_mem[i] += Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i);
1474  }
1475  }
1476  }
1477  }
1478 
1479 
1480 
1482 template<typename eT>
1483 inline
1484 void
1486  {
1488 
1489  arma_debug_assert_cube_as_mat(out, in, "subtraction", true);
1490 
1491  const uword in_n_rows = in.n_rows;
1492  const uword in_n_cols = in.n_cols;
1493  const uword in_n_slices = in.n_slices;
1494 
1495  const uword out_n_rows = out.n_rows;
1496  const uword out_n_cols = out.n_cols;
1497  const uword out_vec_state = out.vec_state;
1498 
1499  if(in_n_slices == 1)
1500  {
1501  for(uword col=0; col < in_n_cols; ++col)
1502  {
1503  arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
1504  }
1505  }
1506  else
1507  {
1508  if(out_vec_state == 0)
1509  {
1510  if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
1511  {
1512  for(uword i=0; i < in_n_slices; ++i)
1513  {
1514  arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
1515  }
1516  }
1517  else
1518  if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
1519  {
1520  const Cube<eT>& Q = in.m;
1521 
1522  const uword in_aux_row1 = in.aux_row1;
1523  const uword in_aux_col1 = in.aux_col1;
1524  const uword in_aux_slice1 = in.aux_slice1;
1525 
1526  for(uword slice=0; slice < in_n_slices; ++slice)
1527  {
1528  const uword mod_slice = in_aux_slice1 + slice;
1529 
1530  eT* out_colptr = out.colptr(slice);
1531 
1532  uword i,j;
1533  for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
1534  {
1535  const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1536  const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice);
1537 
1538  out_colptr[i] -= tmp_i;
1539  out_colptr[j] -= tmp_j;
1540  }
1541 
1542  if(i < in_n_cols)
1543  {
1544  out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1545  }
1546  }
1547  }
1548  }
1549  else
1550  {
1551  eT* out_mem = out.memptr();
1552 
1553  const Cube<eT>& Q = in.m;
1554 
1555  const uword in_aux_row1 = in.aux_row1;
1556  const uword in_aux_col1 = in.aux_col1;
1557  const uword in_aux_slice1 = in.aux_slice1;
1558 
1559  for(uword i=0; i<in_n_slices; ++i)
1560  {
1561  out_mem[i] -= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i);
1562  }
1563  }
1564  }
1565  }
1566 
1567 
1568 
1570 template<typename eT>
1571 inline
1572 void
1574  {
1576 
1577  arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true);
1578 
1579  const uword in_n_rows = in.n_rows;
1580  const uword in_n_cols = in.n_cols;
1581  const uword in_n_slices = in.n_slices;
1582 
1583  const uword out_n_rows = out.n_rows;
1584  const uword out_n_cols = out.n_cols;
1585  const uword out_vec_state = out.vec_state;
1586 
1587  if(in_n_slices == 1)
1588  {
1589  for(uword col=0; col < in_n_cols; ++col)
1590  {
1591  arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
1592  }
1593  }
1594  else
1595  {
1596  if(out_vec_state == 0)
1597  {
1598  if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
1599  {
1600  for(uword i=0; i < in_n_slices; ++i)
1601  {
1602  arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
1603  }
1604  }
1605  else
1606  if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
1607  {
1608  const Cube<eT>& Q = in.m;
1609 
1610  const uword in_aux_row1 = in.aux_row1;
1611  const uword in_aux_col1 = in.aux_col1;
1612  const uword in_aux_slice1 = in.aux_slice1;
1613 
1614  for(uword slice=0; slice < in_n_slices; ++slice)
1615  {
1616  const uword mod_slice = in_aux_slice1 + slice;
1617 
1618  eT* out_colptr = out.colptr(slice);
1619 
1620  uword i,j;
1621  for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
1622  {
1623  const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1624  const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice);
1625 
1626  out_colptr[i] *= tmp_i;
1627  out_colptr[j] *= tmp_j;
1628  }
1629 
1630  if(i < in_n_cols)
1631  {
1632  out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1633  }
1634  }
1635  }
1636  }
1637  else
1638  {
1639  eT* out_mem = out.memptr();
1640 
1641  const Cube<eT>& Q = in.m;
1642 
1643  const uword in_aux_row1 = in.aux_row1;
1644  const uword in_aux_col1 = in.aux_col1;
1645  const uword in_aux_slice1 = in.aux_slice1;
1646 
1647  for(uword i=0; i<in_n_slices; ++i)
1648  {
1649  out_mem[i] *= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i);
1650  }
1651  }
1652  }
1653  }
1654 
1655 
1656 
1658 template<typename eT>
1659 inline
1660 void
1662  {
1664 
1665  arma_debug_assert_cube_as_mat(out, in, "element-wise division", true);
1666 
1667  const uword in_n_rows = in.n_rows;
1668  const uword in_n_cols = in.n_cols;
1669  const uword in_n_slices = in.n_slices;
1670 
1671  const uword out_n_rows = out.n_rows;
1672  const uword out_n_cols = out.n_cols;
1673  const uword out_vec_state = out.vec_state;
1674 
1675  if(in_n_slices == 1)
1676  {
1677  for(uword col=0; col < in_n_cols; ++col)
1678  {
1679  arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows );
1680  }
1681  }
1682  else
1683  {
1684  if(out_vec_state == 0)
1685  {
1686  if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
1687  {
1688  for(uword i=0; i < in_n_slices; ++i)
1689  {
1690  arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
1691  }
1692  }
1693  else
1694  if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
1695  {
1696  const Cube<eT>& Q = in.m;
1697 
1698  const uword in_aux_row1 = in.aux_row1;
1699  const uword in_aux_col1 = in.aux_col1;
1700  const uword in_aux_slice1 = in.aux_slice1;
1701 
1702  for(uword slice=0; slice < in_n_slices; ++slice)
1703  {
1704  const uword mod_slice = in_aux_slice1 + slice;
1705 
1706  eT* out_colptr = out.colptr(slice);
1707 
1708  uword i,j;
1709  for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
1710  {
1711  const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1712  const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice);
1713 
1714  out_colptr[i] /= tmp_i;
1715  out_colptr[j] /= tmp_j;
1716  }
1717 
1718  if(i < in_n_cols)
1719  {
1720  out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice);
1721  }
1722  }
1723  }
1724  }
1725  else
1726  {
1727  eT* out_mem = out.memptr();
1728 
1729  const Cube<eT>& Q = in.m;
1730 
1731  const uword in_aux_row1 = in.aux_row1;
1732  const uword in_aux_col1 = in.aux_col1;
1733  const uword in_aux_slice1 = in.aux_slice1;
1734 
1735  for(uword i=0; i<in_n_slices; ++i)
1736  {
1737  out_mem[i] /= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i);
1738  }
1739  }
1740  }
1741  }
1742 
1743 
1744 
arma_inline arma_warn_unused eT * slice_colptr(const uword in_slice, const uword in_col)
returns a pointer to array of eTs used by the specified slice in the cube
Definition: Cube_meat.hpp:2308
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
#define arma_debug_assert_cube_as_mat
Definition: debug.hpp:1088
void operator%=(const BaseCube< eT, T1 > &x)
void operator+=(const eT val)
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
static void minus_inplace(Cube< eT > &out, const subview_cube &in)
cube X -= Y.subcube(...)
arma_hot static arma_inline void copy(eT *dest, const eT *src, const uword n_elem)
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
static arma_hot void inplace_minus(eT *dest, const eT *src, const uword n_elem)
static arma_hot void inplace_mul(eT *dest, const eT *src, const uword n_elem)
void operator*=(const eT val)
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
void operator/=(const eT val)
const uword n_elem
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
static void extract(Cube< eT > &out, const subview_cube &in)
cube X = Y.subcube(...)
bool check_overlap(const subview_cube &x) const
#define arma_extra_debug_print
Definition: debug.hpp:1118
arma_inline eT & at(const uword in_row, const uword in_col, const uword in_slice)
arma_inline arma_warn_unused eT * colptr(const uword in_col)
returns a pointer to array of eTs for a specified column; no bounds check
Definition: Mat_meat.hpp:4000
u32 uword
Definition: typedef.hpp:85
const uword aux_slice1
const uword n_slices
static arma_hot void inplace_plus(eT *dest, const eT *src, const uword n_elem)
void operator=(const BaseCube< eT, T1 > &x)
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
eT & operator()(const uword i)
static void plus_inplace(Cube< eT > &out, const subview_cube &in)
cube X += Y.subcube(...)
static arma_inline T1 & rw(const T1 &x)
internal function to allow modification of data declared as read-only
Definition: access.hpp:23
#define arma_debug_check
Definition: debug.hpp:1084
static arma_hot void inplace_div(eT *dest, const eT *src, const uword n_elem)
static arma_hot void inplace_set(eT *dest, const eT val, const uword n_elem)
arma_inline Mat< eT > & slice(const uword in_slice)
provide the reference to the matrix representing a single slice
Definition: Cube_meat.hpp:796
std::string arma_cold arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char *x)
Definition: debug.hpp:403
Dense cube class.
Definition: Cube_bones.hpp:30
void arma_cold arma_stop(const T1 &x)
print a message to get_stream_err1() and/or throw a logic_error exception
Definition: debug.hpp:98
const uword aux_col1
void operator-=(const eT val)
const Cube & fill(const eT val)
fill the cube with the specified value
Definition: Cube_meat.hpp:2467
static void schur_inplace(Cube< eT > &out, const subview_cube &in)
cube X %= Y.subcube(...)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
Analog of the Base class, intended for cubes.
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
arma_aligned Cube< eT > * m_ptr
Dense matrix class.
#define arma_inline
const uword n_cols
arma_inline const derived & get_ref() const
static const bool debug
Definition: arma_config.hpp:63
const uword n_rows
eT & operator[](const uword i)
static void div_inplace(Cube< eT > &out, const subview_cube &in)
cube X /= Y.subcube(...)
const uhword vec_state
0: matrix layout; 1: column vector layout; 2: row vector layout
Definition: Mat_bones.hpp:32
void fill(const eT val)
arma_inline eT * slice_colptr(const uword in_slice, const uword in_col)
arma_aligned const Cube< eT > & m
const uword aux_row1
const uword n_slices
number of slices in the cube (read-only)
Definition: Cube_bones.hpp:40
const uword n_elem_slice
DEPRECATED: do not use this member variable – it will be removed in version 3.0. ...
Definition: Cube_bones.hpp:39
const uword n_rows
number of rows in each slice (read-only)
Definition: Cube_bones.hpp:37
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the cube as a vector); no bounds check.
Definition: Cube_meat.hpp:2024


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