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  delete_mat();
25 
26  if(mem_state == 0)
27  {
28  if(n_elem > Cube_prealloc::mem_n_elem)
29  {
30  #if defined(ARMA_USE_TBB_ALLOC)
31  scalable_free((void *)(mem));
32  #else
33  delete [] mem;
34  #endif
35  }
36  }
37 
38  if(arma_config::debug == true)
39  {
40  // try to expose buggy user code that accesses deleted objects
41  access::rw(n_rows) = 0;
42  access::rw(n_cols) = 0;
43  access::rw(n_slices) = 0;
44  access::rw(n_elem) = 0;
45  access::rw(mat_ptrs) = 0;
46  access::rw(mem) = 0;
47  }
48 
50  }
51 
52 
53 
54 template<typename eT>
55 inline
57  : n_rows(0)
58  , n_cols(0)
59  , n_elem_slice(0)
60  , n_slices(0)
61  , n_elem(0)
62  , mem_state(0)
63  , mat_ptrs()
64  , mem()
65  {
67  }
68 
69 
70 
72 template<typename eT>
73 inline
74 Cube<eT>::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
75  : n_rows(in_n_rows)
76  , n_cols(in_n_cols)
77  , n_elem_slice(in_n_rows*in_n_cols)
78  , n_slices(in_n_slices)
79  , n_elem(in_n_rows*in_n_cols*in_n_slices)
80  , mem_state(0)
81  , mat_ptrs()
82  , mem()
83  {
85 
86  init_cold();
87  }
88 
89 
90 
91 template<typename eT>
92 inline
93 void
95  {
96  arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d, n_slices = %d") % n_rows % n_cols % n_slices );
97 
99  (
100  (
101  ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) )
102  ? ( (float(n_rows) * float(n_cols) * float(n_slices)) > float(ARMA_MAX_UWORD) )
103  : false
104  ),
105  "Cube::init(): requested size is too large"
106  );
107 
109  {
111  }
112  else
113  {
114  arma_extra_debug_print("Cube::init(): allocating memory");
115 
116  #if defined(ARMA_USE_TBB_ALLOC)
117  access::rw(mem) = (eT *)scalable_malloc(sizeof(eT)*n_elem);
118  #else
119  access::rw(mem) = new(std::nothrow) eT[n_elem];
120  #endif
121 
122  arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" );
123  }
124 
125 
126  if(n_elem == 0)
127  {
128  access::rw(n_rows) = 0;
129  access::rw(n_cols) = 0;
131  access::rw(n_slices) = 0;
132  }
133  else
134  {
135  create_mat();
136  }
137  }
138 
139 
140 
143 template<typename eT>
144 inline
145 void
146 Cube<eT>::init_warm(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
147  {
148  arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices );
149 
150  if( (n_rows == in_n_rows) && (n_cols == in_n_cols) && (n_slices == in_n_slices) )
151  {
152  return;
153  }
154 
155  const uword t_mem_state = mem_state;
156 
157  bool err_state = false;
158  char* err_msg = 0;
159 
161  (
162  err_state,
163  err_msg,
164  (t_mem_state == 3),
165  "Cube::init(): size is fixed and hence cannot be changed"
166  );
167 
169  (
170  err_state,
171  err_msg,
172  (
173  ( (in_n_rows > 0x0FFF) || (in_n_cols > 0x0FFF) || (in_n_slices > 0xFF) )
174  ? ( (float(in_n_rows) * float(in_n_cols) * float(in_n_slices)) > float(ARMA_MAX_UWORD) )
175  : false
176  ),
177  "Cube::init(): requested size is too large"
178  );
179 
180  arma_debug_check(err_state, err_msg);
181 
182  const uword old_n_elem = n_elem;
183  const uword new_n_elem = in_n_rows * in_n_cols * in_n_slices;
184 
185  if(old_n_elem == new_n_elem)
186  {
187  delete_mat();
188 
189  if(new_n_elem > 0)
190  {
191  access::rw(n_rows) = in_n_rows;
192  access::rw(n_cols) = in_n_cols;
193  access::rw(n_elem_slice) = in_n_rows*in_n_cols;
194  access::rw(n_slices) = in_n_slices;
195 
196  create_mat();
197  }
198  }
199  else
200  {
201  arma_debug_check( (t_mem_state == 2), "Cube::init(): requested size is not compatible with the size of auxiliary memory" );
202 
203  delete_mat();
204 
205  if(t_mem_state == 0)
206  {
208  {
209  arma_extra_debug_print("Cube::init(): freeing memory");
210 
211  #if defined(ARMA_USE_TBB_ALLOC)
212  scalable_free((void *)(mem));
213  #else
214  delete [] mem;
215  #endif
216  }
217  }
218 
219  access::rw(mem_state) = 0;
220 
221  if(new_n_elem <= Cube_prealloc::mem_n_elem)
222  {
224  }
225  else
226  {
227  arma_extra_debug_print("Cube::init(): allocating memory");
228 
229  #if defined(ARMA_USE_TBB_ALLOC)
230  access::rw(mem) = (eT *)scalable_malloc(sizeof(eT)*new_n_elem);
231  #else
232  access::rw(mem) = new(std::nothrow) eT[new_n_elem];
233  #endif
234 
235  arma_check_bad_alloc( (mem == 0), "Cube::init(): out of memory" );
236  }
237 
238  if(new_n_elem > 0)
239  {
240  access::rw(n_rows) = in_n_rows;
241  access::rw(n_cols) = in_n_cols;
242  access::rw(n_elem_slice) = in_n_rows*in_n_cols;
243  access::rw(n_slices) = in_n_slices;
244  access::rw(n_elem) = new_n_elem;
245 
246  create_mat();
247  }
248  }
249 
250 
251  if(new_n_elem == 0)
252  {
253  access::rw(n_rows) = 0;
254  access::rw(n_cols) = 0;
256  access::rw(n_slices) = 0;
257  access::rw(n_elem) = 0;
258  }
259  }
260 
261 
262 
264 template<typename eT>
265 template<typename T1, typename T2>
266 inline
267 void
269  (
270  const BaseCube<typename Cube<eT>::pod_type,T1>& A,
271  const BaseCube<typename Cube<eT>::pod_type,T2>& B
272  )
273  {
275 
276  typedef typename T1::elem_type T;
277  typedef typename ProxyCube<T1>::ea_type ea_type1;
278  typedef typename ProxyCube<T2>::ea_type ea_type2;
279 
280  arma_type_check(( is_complex<eT>::value == false ));
282 
283  arma_type_check(( is_same_type< std::complex<T>, eT >::value == false ));
284 
285  const ProxyCube<T1> X(A.get_ref());
286  const ProxyCube<T2> Y(B.get_ref());
287 
288  arma_assert_same_size(X, Y, "Cube()");
289 
290  init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
291 
292  const uword N = n_elem;
293  eT* out_mem = memptr();
294  ea_type1 PX = X.get_ea();
295  ea_type2 PY = Y.get_ea();
296 
297  for(uword i=0; i<N; ++i)
298  {
299  out_mem[i] = std::complex<T>(PX[i], PY[i]);
300  }
301  }
302 
303 
304 
307 template<typename eT>
308 inline
309 void
311  {
313 
314  if(this != &x)
315  {
316  if( (x.mem_state == 0) && (x.n_elem > Cube_prealloc::mem_n_elem) )
317  {
318  reset();
319 
320  const uword x_n_slices = x.n_slices;
321 
322  access::rw(n_rows) = x.n_rows;
323  access::rw(n_cols) = x.n_cols;
325  access::rw(n_slices) = x_n_slices;
326  access::rw(n_elem) = x.n_elem;
327  access::rw(mem) = x.mem;
328 
329  if(x_n_slices > Cube_prealloc::mat_ptrs_size)
330  {
332  access::rw(x.mat_ptrs) = 0;
333  }
334  else
335  {
336  access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
337 
338  for(uword i=0; i < x_n_slices; ++i)
339  {
340  mat_ptrs[i] = x.mat_ptrs[i];
341  x.mat_ptrs[i] = 0;
342  }
343  }
344 
345  access::rw(x.n_rows) = 0;
346  access::rw(x.n_cols) = 0;
347  access::rw(x.n_elem_slice) = 0;
348  access::rw(x.n_slices) = 0;
349  access::rw(x.n_elem) = 0;
350  access::rw(x.mem) = 0;
351  }
352  else
353  {
354  (*this).operator=(x);
355  }
356  }
357  }
358 
359 
360 
361 template<typename eT>
362 inline
363 void
365  {
367 
368  for(uword slice = 0; slice < n_slices; ++slice)
369  {
370  delete access::rw(mat_ptrs[slice]);
371  }
372 
373  if(mem_state <= 2)
374  {
375  if(n_slices > Cube_prealloc::mat_ptrs_size)
376  {
377  delete [] mat_ptrs;
378  }
379  }
380  }
381 
382 
383 
384 template<typename eT>
385 inline
386 void
388  {
390 
391  if(mem_state <= 2)
392  {
394  {
395  access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
396  }
397  else
398  {
399  access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices];
400 
401  arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" );
402  }
403  }
404 
405  for(uword slice = 0; slice < n_slices; ++slice)
406  {
408  }
409  }
410 
411 
412 
415 template<typename eT>
417 const Cube<eT>&
418 Cube<eT>::operator=(const eT val)
419  {
421 
422  init_warm(1,1,1);
423  access::rw(mem[0]) = val;
424  return *this;
425  }
426 
427 
428 
430 template<typename eT>
432 const Cube<eT>&
433 Cube<eT>::operator+=(const eT val)
434  {
436 
438 
439  return *this;
440  }
441 
442 
443 
445 template<typename eT>
447 const Cube<eT>&
448 Cube<eT>::operator-=(const eT val)
449  {
451 
453 
454  return *this;
455  }
456 
457 
458 
460 template<typename eT>
462 const Cube<eT>&
463 Cube<eT>::operator*=(const eT val)
464  {
466 
468 
469  return *this;
470  }
471 
472 
473 
475 template<typename eT>
477 const Cube<eT>&
478 Cube<eT>::operator/=(const eT val)
479  {
481 
483 
484  return *this;
485  }
486 
487 
488 
490 template<typename eT>
491 inline
493  : n_rows(x.n_rows)
494  , n_cols(x.n_cols)
496  , n_slices(x.n_slices)
497  , n_elem(x.n_elem)
498  , mem_state(0)
499  , mat_ptrs()
500  , mem()
501  {
503  arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x);
504 
505  init_cold();
506 
507  arrayops::copy( memptr(), x.mem, n_elem );
508  }
509 
510 
511 
513 template<typename eT>
514 inline
515 const Cube<eT>&
517  {
518  arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x);
519 
520  if(this != &x)
521  {
522  init_warm(x.n_rows, x.n_cols, x.n_slices);
523 
524  arrayops::copy( memptr(), x.mem, n_elem );
525  }
526 
527  return *this;
528  }
529 
530 
531 
537 
538 template<typename eT>
539 inline
540 Cube<eT>::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem, const bool strict)
541  : n_rows ( aux_n_rows )
542  , n_cols ( aux_n_cols )
543  , n_elem_slice( aux_n_rows*aux_n_cols )
544  , n_slices ( aux_n_slices )
545  , n_elem ( aux_n_rows*aux_n_cols*aux_n_slices )
546  , mem_state ( copy_aux_mem ? 0 : (strict ? 2 : 1) )
547  , mat_ptrs ( 0 )
548  , mem ( copy_aux_mem ? 0 : aux_mem )
549  {
551 
552  if(copy_aux_mem == true)
553  {
554  init_cold();
555 
556  arrayops::copy( memptr(), aux_mem, n_elem );
557  }
558  else
559  {
560  create_mat();
561  }
562  }
563 
564 
565 
568 template<typename eT>
569 inline
570 Cube<eT>::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices)
571  : n_rows(aux_n_rows)
572  , n_cols(aux_n_cols)
573  , n_elem_slice(aux_n_rows*aux_n_cols)
574  , n_slices(aux_n_slices)
575  , n_elem(aux_n_rows*aux_n_cols*aux_n_slices)
576  , mem_state(0)
577  , mat_ptrs()
578  , mem()
579  {
581 
582  init_cold();
583 
584  arrayops::copy( memptr(), aux_mem, n_elem );
585  }
586 
587 
588 
590 template<typename eT>
591 inline
592 const Cube<eT>&
594  {
596 
597  arma_debug_assert_same_size(*this, m, "cube addition");
598 
600 
601  return *this;
602  }
603 
604 
605 
607 template<typename eT>
608 inline
609 const Cube<eT>&
611  {
613 
614  arma_debug_assert_same_size(*this, m, "cube subtraction");
615 
617 
618  return *this;
619  }
620 
621 
622 
624 template<typename eT>
625 inline
626 const Cube<eT>&
628  {
630 
631  arma_debug_assert_same_size(*this, m, "element-wise cube multiplication");
632 
634 
635  return *this;
636  }
637 
638 
639 
641 template<typename eT>
642 inline
643 const Cube<eT>&
645  {
647 
648  arma_debug_assert_same_size(*this, m, "element-wise cube division");
649 
651 
652  return *this;
653  }
654 
655 
656 
658 template<typename eT>
659 template<typename T1, typename T2>
660 inline
662  (
663  const BaseCube<typename Cube<eT>::pod_type,T1>& A,
664  const BaseCube<typename Cube<eT>::pod_type,T2>& B
665  )
666  : n_rows(0)
667  , n_cols(0)
668  , n_elem_slice(0)
669  , n_slices(0)
670  , n_elem(0)
671  , mem_state(0)
672  , mat_ptrs()
673  , mem()
674  {
676 
677  init(A,B);
678  }
679 
680 
681 
683 template<typename eT>
684 inline
686  : n_rows(X.n_rows)
687  , n_cols(X.n_cols)
689  , n_slices(X.n_slices)
690  , n_elem(X.n_elem)
691  , mem_state(0)
692  , mat_ptrs()
693  , mem()
694  {
696 
697  init_cold();
698 
699  subview_cube<eT>::extract(*this, X);
700  }
701 
702 
703 
705 template<typename eT>
706 inline
707 const Cube<eT>&
709  {
711 
712  const bool alias = (this == &(X.m));
713 
714  if(alias == false)
715  {
716  init_warm(X.n_rows, X.n_cols, X.n_slices);
717 
718  subview_cube<eT>::extract(*this, X);
719  }
720  else
721  {
722  Cube<eT> tmp(X);
723 
724  steal_mem(tmp);
725  }
726 
727  return *this;
728  }
729 
730 
731 
733 template<typename eT>
734 inline
735 const Cube<eT>&
737  {
739 
741 
742  return *this;
743  }
744 
745 
746 
748 template<typename eT>
749 inline
750 const Cube<eT>&
752  {
754 
756 
757  return *this;
758  }
759 
760 
761 
763 template<typename eT>
764 inline
765 const Cube<eT>&
767  {
769 
771 
772  return *this;
773  }
774 
775 
776 
778 template<typename eT>
779 inline
780 const Cube<eT>&
782  {
784 
786 
787  return *this;
788  }
789 
790 
791 
793 template<typename eT>
795 Mat<eT>&
796 Cube<eT>::slice(const uword in_slice)
797  {
799 
801  (
802  (in_slice >= n_slices),
803  "Cube::slice(): index out of bounds"
804  );
805 
806  return const_cast< Mat<eT>& >( *(mat_ptrs[in_slice]) );
807  }
808 
809 
810 
812 template<typename eT>
814 const Mat<eT>&
815 Cube<eT>::slice(const uword in_slice) const
816  {
818 
820  (
821  (in_slice >= n_slices),
822  "Cube::slice(): index out of bounds"
823  );
824 
825  return *(mat_ptrs[in_slice]);
826  }
827 
828 
829 
831 template<typename eT>
834 Cube<eT>::slices(const uword in_slice1, const uword in_slice2)
835  {
837 
839  (
840  (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
841  "Cube::slices(): indices out of bounds or incorrectly used"
842  );
843 
844  const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
845 
846  return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
847  }
848 
849 
850 
852 template<typename eT>
854 const subview_cube<eT>
855 Cube<eT>::slices(const uword in_slice1, const uword in_slice2) const
856  {
858 
860  (
861  (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
862  "Cube::rows(): indices out of bounds or incorrectly used"
863  );
864 
865  const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
866 
867  return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
868  }
869 
870 
871 
873 template<typename eT>
876 Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2)
877  {
879 
881  (
882  (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
883  (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
884  "Cube::subcube(): indices out of bounds or incorrectly used"
885  );
886 
887  const uword subcube_n_rows = in_row2 - in_row1 + 1;
888  const uword subcube_n_cols = in_col2 - in_col1 + 1;
889  const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
890 
891  return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
892  }
893 
894 
895 
897 template<typename eT>
899 const subview_cube<eT>
900 Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const
901  {
903 
905  (
906  (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
907  (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
908  "Cube::subcube(): indices out of bounds or incorrectly used"
909  );
910 
911  const uword subcube_n_rows = in_row2 - in_row1 + 1;
912  const uword subcube_n_cols = in_col2 - in_col1 + 1;
913  const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
914 
915  return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
916  }
917 
918 
919 
921 template<typename eT>
922 inline
924 Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span)
925  {
927 
928  const bool row_all = row_span.whole;
929  const bool col_all = col_span.whole;
930  const bool slice_all = slice_span.whole;
931 
932  const uword local_n_rows = n_rows;
933  const uword local_n_cols = n_cols;
934  const uword local_n_slices = n_slices;
935 
936  const uword in_row1 = row_all ? 0 : row_span.a;
937  const uword in_row2 = row_span.b;
938  const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
939 
940  const uword in_col1 = col_all ? 0 : col_span.a;
941  const uword in_col2 = col_span.b;
942  const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
943 
944  const uword in_slice1 = slice_all ? 0 : slice_span.a;
945  const uword in_slice2 = slice_span.b;
946  const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1;
947 
949  (
950  ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
951  ||
952  ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
953  ||
954  ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
955  ,
956  "Cube::subcube(): indices out of bounds or incorrectly used"
957  );
958 
959  return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
960  }
961 
962 
963 
965 template<typename eT>
966 inline
967 const subview_cube<eT>
968 Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span) const
969  {
971 
972  const bool row_all = row_span.whole;
973  const bool col_all = col_span.whole;
974  const bool slice_all = slice_span.whole;
975 
976  const uword local_n_rows = n_rows;
977  const uword local_n_cols = n_cols;
978  const uword local_n_slices = n_slices;
979 
980  const uword in_row1 = row_all ? 0 : row_span.a;
981  const uword in_row2 = row_span.b;
982  const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
983 
984  const uword in_col1 = col_all ? 0 : col_span.a;
985  const uword in_col2 = col_span.b;
986  const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
987 
988  const uword in_slice1 = slice_all ? 0 : slice_span.a;
989  const uword in_slice2 = slice_span.b;
990  const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1;
991 
993  (
994  ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
995  ||
996  ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
997  ||
998  ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
999  ,
1000  "Cube::subcube(): indices out of bounds or incorrectly used"
1001  );
1002 
1003  return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
1004  }
1005 
1006 
1007 
1008 template<typename eT>
1009 inline
1011 Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span)
1012  {
1014 
1015  return (*this).subcube(row_span, col_span, slice_span);
1016  }
1017 
1018 
1019 
1020 template<typename eT>
1021 inline
1022 const subview_cube<eT>
1023 Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span) const
1024  {
1026 
1027  return (*this).subcube(row_span, col_span, slice_span);
1028  }
1029 
1030 
1031 
1033 template<typename eT>
1034 inline
1035 void
1036 Cube<eT>::shed_slice(const uword slice_num)
1037  {
1039 
1040  arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): out of bounds");
1041 
1042  shed_slices(slice_num, slice_num);
1043  }
1044 
1045 
1046 
1048 template<typename eT>
1049 inline
1050 void
1051 Cube<eT>::shed_slices(const uword in_slice1, const uword in_slice2)
1052  {
1054 
1056  (
1057  (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
1058  "Cube::shed_slices(): indices out of bounds or incorrectly used"
1059  );
1060 
1061  const uword n_keep_front = in_slice1;
1062  const uword n_keep_back = n_slices - (in_slice2 + 1);
1063 
1064  Cube<eT> X(n_rows, n_cols, n_keep_front + n_keep_back);
1065 
1066  if(n_keep_front > 0)
1067  {
1068  X.slices( 0, (n_keep_front-1) ) = slices( 0, (in_slice1-1) );
1069  }
1070 
1071  if(n_keep_back > 0)
1072  {
1073  X.slices( n_keep_front, (n_keep_front+n_keep_back-1) ) = slices( (in_slice2+1), (n_slices-1) );
1074  }
1075 
1076  steal_mem(X);
1077  }
1078 
1079 
1080 
1083 template<typename eT>
1084 inline
1085 void
1086 Cube<eT>::insert_slices(const uword slice_num, const uword N, const bool set_to_zero)
1087  {
1089 
1090  const uword t_n_slices = n_slices;
1091 
1092  const uword A_n_slices = slice_num;
1093  const uword B_n_slices = t_n_slices - slice_num;
1094 
1095  // insertion at slice_num == n_slices is in effect an append operation
1096  arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds");
1097 
1098  if(N > 0)
1099  {
1100  Cube<eT> out(n_rows, n_cols, t_n_slices + N);
1101 
1102  if(A_n_slices > 0)
1103  {
1104  out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
1105  }
1106 
1107  if(B_n_slices > 0)
1108  {
1109  out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices-1);
1110  }
1111 
1112  if(set_to_zero == true)
1113  {
1114  //out.slices(slice_num, slice_num + N - 1).zeros();
1115 
1116  for(uword i=slice_num; i < (slice_num + N); ++i)
1117  {
1118  out.slice(i).zeros();
1119  }
1120  }
1121 
1122  steal_mem(out);
1123  }
1124  }
1125 
1126 
1127 
1130 template<typename eT>
1131 template<typename T1>
1132 inline
1133 void
1135  {
1137 
1138  const unwrap_cube<T1> tmp(X.get_ref());
1139  const Cube<eT>& C = tmp.M;
1140 
1141  const uword N = C.n_slices;
1142 
1143  const uword t_n_slices = n_slices;
1144 
1145  const uword A_n_slices = slice_num;
1146  const uword B_n_slices = t_n_slices - slice_num;
1147 
1148  // insertion at slice_num == n_slices is in effect an append operation
1149  arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds");
1150 
1152  (
1153  ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ),
1154  "Cube::insert_slices(): given object has an incompatible dimensions"
1155  );
1156 
1157  if(N > 0)
1158  {
1159  Cube<eT> out(n_rows, n_cols, t_n_slices + N);
1160 
1161  if(A_n_slices > 0)
1162  {
1163  out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
1164  }
1165 
1166  if(B_n_slices > 0)
1167  {
1168  out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices - 1);
1169  }
1170 
1171  out.slices(slice_num, slice_num + N - 1) = C;
1172 
1173  steal_mem(out);
1174  }
1175  }
1176 
1177 
1178 
1180 template<typename eT>
1181 template<typename gen_type>
1182 inline
1184  : n_rows(X.n_rows)
1185  , n_cols(X.n_cols)
1186  , n_elem_slice(X.n_rows*X.n_cols)
1187  , n_slices(X.n_slices)
1188  , n_elem(X.n_rows*X.n_cols*X.n_slices)
1189  , mem_state(0)
1190  , mat_ptrs()
1191  , mem()
1192  {
1194 
1195  init_cold();
1196 
1197  X.apply(*this);
1198  }
1199 
1200 
1201 
1202 template<typename eT>
1203 template<typename gen_type>
1204 inline
1205 const Cube<eT>&
1207  {
1209 
1210  init_warm(X.n_rows, X.n_cols, X.n_slices);
1211 
1212  X.apply(*this);
1213 
1214  return *this;
1215  }
1216 
1217 
1218 
1219 template<typename eT>
1220 template<typename gen_type>
1221 inline
1222 const Cube<eT>&
1224  {
1226 
1227  X.apply_inplace_plus(*this);
1228 
1229  return *this;
1230  }
1231 
1232 
1233 
1234 template<typename eT>
1235 template<typename gen_type>
1236 inline
1237 const Cube<eT>&
1239  {
1241 
1242  X.apply_inplace_minus(*this);
1243 
1244  return *this;
1245  }
1246 
1247 
1248 
1249 template<typename eT>
1250 template<typename gen_type>
1251 inline
1252 const Cube<eT>&
1254  {
1256 
1257  X.apply_inplace_schur(*this);
1258 
1259  return *this;
1260  }
1261 
1262 
1263 
1264 template<typename eT>
1265 template<typename gen_type>
1266 inline
1267 const Cube<eT>&
1269  {
1271 
1272  X.apply_inplace_div(*this);
1273 
1274  return *this;
1275  }
1276 
1277 
1278 
1280 template<typename eT>
1281 template<typename T1, typename op_type>
1282 inline
1284  : n_rows(0)
1285  , n_cols(0)
1286  , n_elem_slice(0)
1287  , n_slices(0)
1288  , n_elem(0)
1289  , mem_state(0)
1290  , mat_ptrs()
1291  , mem()
1292  {
1294 
1296 
1297  op_type::apply(*this, X);
1298  }
1299 
1300 
1301 
1303 template<typename eT>
1304 template<typename T1, typename op_type>
1305 inline
1306 const Cube<eT>&
1308  {
1310 
1312 
1313  op_type::apply(*this, X);
1314 
1315  return *this;
1316  }
1317 
1318 
1319 
1321 template<typename eT>
1322 template<typename T1, typename op_type>
1323 inline
1324 const Cube<eT>&
1326  {
1328 
1330 
1331  const Cube<eT> m(X);
1332 
1333  return (*this).operator+=(m);
1334  }
1335 
1336 
1337 
1339 template<typename eT>
1340 template<typename T1, typename op_type>
1341 inline
1342 const Cube<eT>&
1344  {
1346 
1348 
1349  const Cube<eT> m(X);
1350 
1351  return (*this).operator-=(m);
1352  }
1353 
1354 
1355 
1357 template<typename eT>
1358 template<typename T1, typename op_type>
1359 inline
1360 const Cube<eT>&
1362  {
1364 
1366 
1367  const Cube<eT> m(X);
1368 
1369  return (*this).operator%=(m);
1370  }
1371 
1372 
1373 
1375 template<typename eT>
1376 template<typename T1, typename op_type>
1377 inline
1378 const Cube<eT>&
1380  {
1382 
1384 
1385  const Cube<eT> m(X);
1386 
1387  return (*this).operator/=(m);
1388  }
1389 
1390 
1391 
1393 template<typename eT>
1394 template<typename T1, typename eop_type>
1395 inline
1397  : n_rows(X.get_n_rows())
1398  , n_cols(X.get_n_cols())
1399  , n_elem_slice(X.get_n_elem_slice())
1400  , n_slices(X.get_n_slices())
1401  , n_elem(X.get_n_elem())
1402  , mem_state(0)
1403  , mat_ptrs()
1404  , mem()
1405  {
1407 
1409 
1410  init_cold();
1411 
1412  eop_type::apply(*this, X);
1413  }
1414 
1415 
1416 
1418 template<typename eT>
1419 template<typename T1, typename eop_type>
1420 inline
1421 const Cube<eT>&
1423  {
1425 
1427 
1428  const bool bad_alias = ( X.P.has_subview && X.P.is_alias(*this) );
1429 
1430  if(bad_alias == false)
1431  {
1433 
1434  eop_type::apply(*this, X);
1435  }
1436  else
1437  {
1438  Cube<eT> tmp(X);
1439 
1440  steal_mem(tmp);
1441  }
1442 
1443  return *this;
1444  }
1445 
1446 
1447 
1449 template<typename eT>
1450 template<typename T1, typename eop_type>
1451 inline
1452 const Cube<eT>&
1454  {
1456 
1458 
1459  eop_type::apply_inplace_plus(*this, X);
1460 
1461  return *this;
1462  }
1463 
1464 
1465 
1467 template<typename eT>
1468 template<typename T1, typename eop_type>
1469 inline
1470 const Cube<eT>&
1472  {
1474 
1476 
1477  eop_type::apply_inplace_minus(*this, X);
1478 
1479  return *this;
1480  }
1481 
1482 
1483 
1485 template<typename eT>
1486 template<typename T1, typename eop_type>
1487 inline
1488 const Cube<eT>&
1490  {
1492 
1494 
1495  eop_type::apply_inplace_schur(*this, X);
1496 
1497  return *this;
1498  }
1499 
1500 
1501 
1503 template<typename eT>
1504 template<typename T1, typename eop_type>
1505 inline
1506 const Cube<eT>&
1508  {
1510 
1512 
1513  eop_type::apply_inplace_div(*this, X);
1514 
1515  return *this;
1516  }
1517 
1518 
1519 
1521 template<typename eT>
1522 template<typename T1, typename op_type>
1523 inline
1525  : n_rows(0)
1526  , n_cols(0)
1527  , n_elem_slice(0)
1528  , n_slices(0)
1529  , n_elem(0)
1530  , mem_state(0)
1531  , mat_ptrs()
1532  , mem()
1533  {
1535 
1536  op_type::apply(*this, X);
1537  }
1538 
1539 
1540 
1542 template<typename eT>
1543 template<typename T1, typename op_type>
1544 inline
1545 const Cube<eT>&
1547  {
1549 
1550  op_type::apply(*this, X);
1551 
1552  return *this;
1553  }
1554 
1555 
1556 
1558 template<typename eT>
1559 template<typename T1, typename op_type>
1560 inline
1561 const Cube<eT>&
1563  {
1565 
1566  const Cube<eT> m(X);
1567 
1568  return (*this).operator+=(m);
1569  }
1570 
1571 
1572 
1574 template<typename eT>
1575 template<typename T1, typename op_type>
1576 inline
1577 const Cube<eT>&
1579  {
1581 
1582  const Cube<eT> m(X);
1583 
1584  return (*this).operator-=(m);
1585  }
1586 
1587 
1588 
1590 template<typename eT>
1591 template<typename T1, typename op_type>
1592 inline
1593 const Cube<eT>&
1595  {
1597 
1598  const Cube<eT> m(X);
1599 
1600  return (*this).operator%=(m);
1601  }
1602 
1603 
1604 
1606 template<typename eT>
1607 template<typename T1, typename op_type>
1608 inline
1609 const Cube<eT>&
1611  {
1613 
1614  const Cube<eT> m(X);
1615 
1616  return (*this).operator/=(m);
1617  }
1618 
1619 
1620 
1622 template<typename eT>
1623 template<typename T1, typename T2, typename glue_type>
1624 inline
1626  : n_rows(0)
1627  , n_cols(0)
1628  , n_elem_slice(0)
1629  , n_slices(0)
1630  , n_elem(0)
1631  , mem_state(0)
1632  , mat_ptrs()
1633  , mem()
1634  {
1636  this->operator=(X);
1637  }
1638 
1639 
1640 
1642 template<typename eT>
1643 template<typename T1, typename T2, typename glue_type>
1644 inline
1645 const Cube<eT>&
1647  {
1649 
1652 
1653  glue_type::apply(*this, X);
1654 
1655  return *this;
1656  }
1657 
1658 
1660 template<typename eT>
1661 template<typename T1, typename T2, typename glue_type>
1662 inline
1663 const Cube<eT>&
1665  {
1667 
1670 
1671  const Cube<eT> m(X);
1672 
1673  return (*this).operator+=(m);
1674  }
1675 
1676 
1677 
1679 template<typename eT>
1680 template<typename T1, typename T2, typename glue_type>
1681 inline
1682 const Cube<eT>&
1684  {
1686 
1689 
1690  const Cube<eT> m(X);
1691 
1692  return (*this).operator-=(m);
1693  }
1694 
1695 
1696 
1698 template<typename eT>
1699 template<typename T1, typename T2, typename glue_type>
1700 inline
1701 const Cube<eT>&
1703  {
1705 
1708 
1709  const Cube<eT> m(X);
1710 
1711  return (*this).operator%=(m);
1712  }
1713 
1714 
1715 
1717 template<typename eT>
1718 template<typename T1, typename T2, typename glue_type>
1719 inline
1720 const Cube<eT>&
1722  {
1724 
1727 
1728  const Cube<eT> m(X);
1729 
1730  return (*this).operator/=(m);
1731  }
1732 
1733 
1734 
1736 template<typename eT>
1737 template<typename T1, typename T2, typename eglue_type>
1738 inline
1740  : n_rows(X.get_n_rows())
1741  , n_cols(X.get_n_cols())
1742  , n_elem_slice(X.get_n_elem_slice())
1743  , n_slices(X.get_n_slices())
1744  , n_elem(X.get_n_elem())
1745  , mem_state(0)
1746  , mat_ptrs()
1747  , mem()
1748  {
1750 
1753 
1754  init_cold();
1755 
1756  eglue_type::apply(*this, X);
1757  }
1758 
1759 
1760 
1762 template<typename eT>
1763 template<typename T1, typename T2, typename eglue_type>
1764 inline
1765 const Cube<eT>&
1767  {
1769 
1772 
1773  const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || (X.P2.has_subview && X.P2.is_alias(*this)) );
1774 
1775  if(bad_alias == false)
1776  {
1778 
1779  eglue_type::apply(*this, X);
1780  }
1781  else
1782  {
1783  Cube<eT> tmp(X);
1784 
1785  steal_mem(tmp);
1786  }
1787 
1788  return *this;
1789  }
1790 
1791 
1792 
1794 template<typename eT>
1795 template<typename T1, typename T2, typename eglue_type>
1796 inline
1797 const Cube<eT>&
1799  {
1801 
1804 
1805  eglue_type::apply_inplace_plus(*this, X);
1806 
1807  return *this;
1808  }
1809 
1810 
1811 
1813 template<typename eT>
1814 template<typename T1, typename T2, typename eglue_type>
1815 inline
1816 const Cube<eT>&
1818  {
1820 
1823 
1824  eglue_type::apply_inplace_minus(*this, X);
1825 
1826  return *this;
1827  }
1828 
1829 
1830 
1832 template<typename eT>
1833 template<typename T1, typename T2, typename eglue_type>
1834 inline
1835 const Cube<eT>&
1837  {
1839 
1842 
1843  eglue_type::apply_inplace_schur(*this, X);
1844 
1845  return *this;
1846  }
1847 
1848 
1849 
1851 template<typename eT>
1852 template<typename T1, typename T2, typename eglue_type>
1853 inline
1854 const Cube<eT>&
1856  {
1858 
1861 
1862  eglue_type::apply_inplace_div(*this, X);
1863 
1864  return *this;
1865  }
1866 
1867 
1868 
1870 template<typename eT>
1871 template<typename T1, typename T2, typename glue_type>
1872 inline
1874  : n_rows(0)
1875  , n_cols(0)
1876  , n_elem_slice(0)
1877  , n_slices(0)
1878  , n_elem(0)
1879  , mem_state(0)
1880  , mat_ptrs()
1881  , mem()
1882  {
1884 
1885  glue_type::apply(*this, X);
1886  }
1887 
1888 
1889 
1891 template<typename eT>
1892 template<typename T1, typename T2, typename glue_type>
1893 inline
1894 const Cube<eT>&
1896  {
1898 
1899  glue_type::apply(*this, X);
1900 
1901  return *this;
1902  }
1903 
1904 
1905 
1907 template<typename eT>
1908 template<typename T1, typename T2, typename glue_type>
1909 inline
1910 const Cube<eT>&
1912  {
1914 
1915  const Cube<eT> m(X);
1916 
1917  return (*this).operator+=(m);
1918  }
1919 
1920 
1921 
1923 template<typename eT>
1924 template<typename T1, typename T2, typename glue_type>
1925 inline
1926 const Cube<eT>&
1928  {
1930 
1931  const Cube<eT> m(X);
1932 
1933  return (*this).operator-=(m);
1934  }
1935 
1936 
1937 
1939 template<typename eT>
1940 template<typename T1, typename T2, typename glue_type>
1941 inline
1942 const Cube<eT>&
1944  {
1946 
1947  const Cube<eT> m(X);
1948 
1949  return (*this).operator%=(m);
1950  }
1951 
1952 
1953 
1955 template<typename eT>
1956 template<typename T1, typename T2, typename glue_type>
1957 inline
1958 const Cube<eT>&
1960  {
1962 
1963  const Cube<eT> m(X);
1964 
1965  return (*this).operator/=(m);
1966  }
1967 
1968 
1969 
1971 template<typename eT>
1974 eT&
1976  {
1977  arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
1978  return access::rw(mem[i]);
1979  }
1980 
1981 
1982 
1984 template<typename eT>
1987 eT
1989  {
1990  arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
1991  return mem[i];
1992  }
1993 
1994 
1996 template<typename eT>
1999 eT&
2001  {
2002  return access::rw(mem[i]);
2003  }
2004 
2005 
2006 
2008 template<typename eT>
2011 eT
2013  {
2014  return mem[i];
2015  }
2016 
2017 
2018 
2020 template<typename eT>
2023 eT&
2025  {
2026  return access::rw(mem[i]);
2027  }
2028 
2029 
2030 
2032 template<typename eT>
2035 eT
2036 Cube<eT>::at(const uword i) const
2037  {
2038  return mem[i];
2039  }
2040 
2041 
2042 
2044 template<typename eT>
2047 eT&
2048 Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice)
2049  {
2051  (
2052  (in_row >= n_rows) ||
2053  (in_col >= n_cols) ||
2054  (in_slice >= n_slices)
2055  ,
2056  "Cube::operator(): index out of bounds"
2057  );
2058 
2059  return access::rw(mem[in_slice*n_elem_slice + in_col*n_rows + in_row]);
2060  }
2061 
2062 
2063 
2065 template<typename eT>
2068 eT
2069 Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice) const
2070  {
2072  (
2073  (in_row >= n_rows) ||
2074  (in_col >= n_cols) ||
2075  (in_slice >= n_slices)
2076  ,
2077  "Cube::operator(): index out of bounds"
2078  );
2079 
2080  return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
2081  }
2082 
2083 
2084 
2086 template<typename eT>
2089 eT&
2090 Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice)
2091  {
2092  return access::rw( mem[in_slice*n_elem_slice + in_col*n_rows + in_row] );
2093  }
2094 
2095 
2096 
2098 template<typename eT>
2101 eT
2102 Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) const
2103  {
2104  return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
2105  }
2106 
2107 
2108 
2110 template<typename eT>
2112 const Cube<eT>&
2114  {
2115  Cube_aux::prefix_pp(*this);
2116  return *this;
2117  }
2118 
2119 
2120 
2122 template<typename eT>
2124 void
2126  {
2127  Cube_aux::postfix_pp(*this);
2128  }
2129 
2130 
2131 
2133 template<typename eT>
2135 const Cube<eT>&
2137  {
2138  Cube_aux::prefix_mm(*this);
2139  return *this;
2140  }
2141 
2142 
2143 
2145 template<typename eT>
2147 void
2149  {
2150  Cube_aux::postfix_mm(*this);
2151  }
2152 
2153 
2154 
2156 template<typename eT>
2159 bool
2161  {
2162  return arrayops::is_finite( memptr(), n_elem );
2163  }
2164 
2165 
2166 
2168 template<typename eT>
2171 bool
2173  {
2174  return (n_elem == 0);
2175  }
2176 
2177 
2178 
2180 template<typename eT>
2183 bool
2185  {
2186  return (i < n_elem);
2187  }
2188 
2189 
2190 
2192 template<typename eT>
2195 bool
2196 Cube<eT>::in_range(const span& x) const
2197  {
2199 
2200  if(x.whole == true)
2201  {
2202  return true;
2203  }
2204  else
2205  {
2206  const uword a = x.a;
2207  const uword b = x.b;
2208 
2209  return ( (a <= b) && (b < n_elem) );
2210  }
2211  }
2212 
2213 
2214 
2216 template<typename eT>
2219 bool
2220 Cube<eT>::in_range(const uword in_row, const uword in_col, const uword in_slice) const
2221  {
2222  return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) );
2223  }
2224 
2225 
2226 
2227 template<typename eT>
2228 inline
2230 bool
2231 Cube<eT>::in_range(const span& row_span, const span& col_span, const span& slice_span) const
2232  {
2234 
2235  const uword in_row1 = row_span.a;
2236  const uword in_row2 = row_span.b;
2237 
2238  const uword in_col1 = col_span.a;
2239  const uword in_col2 = col_span.b;
2240 
2241  const uword in_slice1 = slice_span.a;
2242  const uword in_slice2 = slice_span.b;
2243 
2244 
2245  const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) );
2246  const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) );
2247  const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) );
2248 
2249 
2250  return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) );
2251  }
2252 
2253 
2254 
2256 template<typename eT>
2259 eT*
2261  {
2262  return const_cast<eT*>(mem);
2263  }
2264 
2265 
2266 
2268 template<typename eT>
2271 const eT*
2273  {
2274  return mem;
2275  }
2276 
2277 
2278 
2280 template<typename eT>
2283 eT*
2285  {
2286  return const_cast<eT*>( &mem[ slice*n_elem_slice ] );
2287  }
2288 
2289 
2290 
2292 template<typename eT>
2295 const eT*
2297  {
2298  return &mem[ slice*n_elem_slice ];
2299  }
2300 
2301 
2302 
2304 template<typename eT>
2307 eT*
2309  {
2310  return const_cast<eT*>( &mem[ slice*n_elem_slice + col*n_rows] );
2311  }
2312 
2313 
2314 
2316 template<typename eT>
2319 const eT*
2320 Cube<eT>::slice_colptr(const uword slice, const uword col) const
2321  {
2322  return &mem[ slice*n_elem_slice + col*n_rows ];
2323  }
2324 
2325 
2326 
2331 template<typename eT>
2332 inline
2333 void
2334 Cube<eT>::impl_print(const std::string& extra_text) const
2335  {
2337 
2338  if(extra_text.length() != 0)
2339  {
2340  cout << extra_text << '\n';
2341  }
2342 
2343  arma_ostream::print(cout, *this, true);
2344  }
2345 
2346 
2351 template<typename eT>
2352 inline
2353 void
2354 Cube<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
2355  {
2357 
2358  if(extra_text.length() != 0)
2359  {
2360  user_stream << extra_text << '\n';
2361  }
2362 
2363  arma_ostream::print(user_stream, *this, true);
2364  }
2365 
2366 
2367 
2372 template<typename eT>
2373 inline
2374 void
2375 Cube<eT>::impl_raw_print(const std::string& extra_text) const
2376  {
2378 
2379  if(extra_text.length() != 0)
2380  {
2381  cout << extra_text << '\n';
2382  }
2383 
2384  arma_ostream::print(cout, *this, false);
2385  }
2386 
2387 
2388 
2393 template<typename eT>
2394 inline
2395 void
2396 Cube<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
2397  {
2399 
2400  if(extra_text.length() != 0)
2401  {
2402  user_stream << extra_text << '\n';
2403  }
2404 
2405  arma_ostream::print(user_stream, *this, false);
2406  }
2407 
2408 
2409 
2411 template<typename eT>
2412 inline
2413 void
2414 Cube<eT>::set_size(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
2415  {
2417 
2418  init_warm(in_n_rows, in_n_cols, in_n_slices);
2419  }
2420 
2421 
2422 
2424 template<typename eT>
2425 inline
2426 void
2427 Cube<eT>::reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim)
2428  {
2430 
2431  *this = arma::reshape(*this, in_rows, in_cols, in_slices, dim);
2432  }
2433 
2434 
2435 
2437 template<typename eT>
2438 inline
2439 void
2440 Cube<eT>::resize(const uword in_rows, const uword in_cols, const uword in_slices)
2441  {
2443 
2444  *this = arma::resize(*this, in_rows, in_cols, in_slices);
2445  }
2446 
2447 
2448 
2450 template<typename eT>
2451 template<typename eT2>
2452 inline
2453 void
2455  {
2457 
2458  init_warm(m.n_rows, m.n_cols, m.n_slices);
2459  }
2460 
2461 
2462 
2464 template<typename eT>
2465 inline
2466 const Cube<eT>&
2467 Cube<eT>::fill(const eT val)
2468  {
2470 
2471  arrayops::inplace_set( memptr(), val, n_elem );
2472 
2473  return *this;
2474  }
2475 
2476 
2477 
2478 template<typename eT>
2479 inline
2480 const Cube<eT>&
2482  {
2484 
2485  return (*this).fill(eT(0));
2486  }
2487 
2488 
2489 
2490 template<typename eT>
2491 inline
2492 const Cube<eT>&
2493 Cube<eT>::zeros(const uword in_rows, const uword in_cols, const uword in_slices)
2494  {
2496 
2497  set_size(in_rows, in_cols, in_slices);
2498 
2499  return (*this).fill(eT(0));
2500  }
2501 
2502 
2503 
2504 template<typename eT>
2505 inline
2506 const Cube<eT>&
2508  {
2510 
2511  return (*this).fill(eT(1));
2512  }
2513 
2514 
2515 
2516 template<typename eT>
2517 inline
2518 const Cube<eT>&
2519 Cube<eT>::ones(const uword in_rows, const uword in_cols, const uword in_slices)
2520  {
2522 
2523  set_size(in_rows, in_cols, in_slices);
2524 
2525  return (*this).fill(eT(1));
2526  }
2527 
2528 
2529 
2530 template<typename eT>
2531 inline
2532 const Cube<eT>&
2534  {
2536 
2537  const uword N = n_elem;
2538  eT* ptr = memptr();
2539 
2540  uword i,j;
2541 
2542  for(i=0, j=1; j<N; i+=2, j+=2)
2543  {
2544  ptr[i] = eT(eop_aux_randu<eT>());
2545  ptr[j] = eT(eop_aux_randu<eT>());
2546  }
2547 
2548  if(i < N)
2549  {
2550  ptr[i] = eT(eop_aux_randu<eT>());
2551  }
2552 
2553  return *this;
2554  }
2555 
2556 
2557 
2558 template<typename eT>
2559 inline
2560 const Cube<eT>&
2561 Cube<eT>::randu(const uword in_rows, const uword in_cols, const uword in_slices)
2562  {
2564 
2565  set_size(in_rows, in_cols, in_slices);
2566 
2567  return (*this).randu();
2568  }
2569 
2570 
2571 
2572 template<typename eT>
2573 inline
2574 const Cube<eT>&
2576  {
2578 
2579  const uword N = n_elem;
2580  eT* ptr = memptr();
2581 
2582  for(uword i=0; i<N; ++i)
2583  {
2584  ptr[i] = eT(eop_aux_randn<eT>());
2585  }
2586 
2587  return *this;
2588  }
2589 
2590 
2591 
2592 template<typename eT>
2593 inline
2594 const Cube<eT>&
2595 Cube<eT>::randn(const uword in_rows, const uword in_cols, const uword in_slices)
2596  {
2598 
2599  set_size(in_rows, in_cols, in_slices);
2600 
2601  return (*this).randn();
2602  }
2603 
2604 
2605 
2606 template<typename eT>
2607 inline
2608 void
2610  {
2612 
2613  init_warm(0,0,0);
2614  }
2615 
2616 
2617 
2618 template<typename eT>
2619 template<typename T1>
2620 inline
2621 void
2623  {
2625 
2626  Cube_aux::set_real(*this, X);
2627  }
2628 
2629 
2630 
2631 template<typename eT>
2632 template<typename T1>
2633 inline
2634 void
2636  {
2638 
2639  Cube_aux::set_imag(*this, X);
2640  }
2641 
2642 
2643 
2644 template<typename eT>
2645 inline
2647 eT
2649  {
2651 
2652  arma_debug_check( (n_elem == 0), "min(): object has no elements" );
2653 
2654  return op_min::direct_min(memptr(), n_elem);
2655  }
2656 
2657 
2658 
2659 template<typename eT>
2660 inline
2662 eT
2664  {
2666 
2667  arma_debug_check( (n_elem == 0), "max(): object has no elements" );
2668 
2669  return op_max::direct_max(memptr(), n_elem);
2670  }
2671 
2672 
2673 
2674 template<typename eT>
2675 inline
2676 eT
2677 Cube<eT>::min(uword& index_of_min_val) const
2678  {
2680 
2681  arma_debug_check( (n_elem == 0), "min(): object has no elements" );
2682 
2683  return op_min::direct_min(memptr(), n_elem, index_of_min_val);
2684  }
2685 
2686 
2687 
2688 template<typename eT>
2689 inline
2690 eT
2691 Cube<eT>::max(uword& index_of_max_val) const
2692  {
2694 
2695  arma_debug_check( (n_elem == 0), "max(): object has no elements" );
2696 
2697  return op_max::direct_max(memptr(), n_elem, index_of_max_val);
2698  }
2699 
2700 
2701 
2702 template<typename eT>
2703 inline
2704 eT
2705 Cube<eT>::min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const
2706  {
2708 
2709  arma_debug_check( (n_elem == 0), "min(): object has no elements" );
2710 
2711  uword i;
2712 
2713  eT val = op_min::direct_min(memptr(), n_elem, i);
2714 
2715  const uword in_slice = i / n_elem_slice;
2716  const uword offset = in_slice * n_elem_slice;
2717  const uword j = i - offset;
2718 
2719  row_of_min_val = j % n_rows;
2720  col_of_min_val = j / n_rows;
2721  slice_of_min_val = in_slice;
2722 
2723  return val;
2724  }
2725 
2726 
2727 
2728 template<typename eT>
2729 inline
2730 eT
2731 Cube<eT>::max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const
2732  {
2734 
2735  arma_debug_check( (n_elem == 0), "max(): object has no elements" );
2736 
2737  uword i;
2738 
2739  eT val = op_max::direct_max(memptr(), n_elem, i);
2740 
2741  const uword in_slice = i / n_elem_slice;
2742  const uword offset = in_slice * n_elem_slice;
2743  const uword j = i - offset;
2744 
2745  row_of_max_val = j % n_rows;
2746  col_of_max_val = j / n_rows;
2747  slice_of_max_val = in_slice;
2748 
2749  return val;
2750  }
2751 
2752 
2753 
2755 template<typename eT>
2756 inline
2757 bool
2758 Cube<eT>::save(const std::string name, const file_type type, const bool print_status) const
2759  {
2761 
2762  bool save_okay;
2763 
2764  switch(type)
2765  {
2766  case raw_ascii:
2767  save_okay = diskio::save_raw_ascii(*this, name);
2768  break;
2769 
2770  case arma_ascii:
2771  save_okay = diskio::save_arma_ascii(*this, name);
2772  break;
2773 
2774  case raw_binary:
2775  save_okay = diskio::save_raw_binary(*this, name);
2776  break;
2777 
2778  case arma_binary:
2779  save_okay = diskio::save_arma_binary(*this, name);
2780  break;
2781 
2782  case ppm_binary:
2783  save_okay = diskio::save_ppm_binary(*this, name);
2784  break;
2785 
2786  default:
2787  arma_warn(print_status, "Cube::save(): unsupported file type");
2788  save_okay = false;
2789  }
2790 
2791  arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to ", name);
2792 
2793  return save_okay;
2794  }
2795 
2796 
2797 
2799 template<typename eT>
2800 inline
2801 bool
2802 Cube<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
2803  {
2805 
2806  bool save_okay;
2807 
2808  switch(type)
2809  {
2810  case raw_ascii:
2811  save_okay = diskio::save_raw_ascii(*this, os);
2812  break;
2813 
2814  case arma_ascii:
2815  save_okay = diskio::save_arma_ascii(*this, os);
2816  break;
2817 
2818  case raw_binary:
2819  save_okay = diskio::save_raw_binary(*this, os);
2820  break;
2821 
2822  case arma_binary:
2823  save_okay = diskio::save_arma_binary(*this, os);
2824  break;
2825 
2826  case ppm_binary:
2827  save_okay = diskio::save_ppm_binary(*this, os);
2828  break;
2829 
2830  default:
2831  arma_warn(print_status, "Cube::save(): unsupported file type");
2832  save_okay = false;
2833  }
2834 
2835  arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to given stream");
2836 
2837  return save_okay;
2838  }
2839 
2840 
2841 
2843 template<typename eT>
2844 inline
2845 bool
2846 Cube<eT>::load(const std::string name, const file_type type, const bool print_status)
2847  {
2849 
2850  bool load_okay;
2851  std::string err_msg;
2852 
2853  switch(type)
2854  {
2855  case auto_detect:
2856  load_okay = diskio::load_auto_detect(*this, name, err_msg);
2857  break;
2858 
2859  case raw_ascii:
2860  load_okay = diskio::load_raw_ascii(*this, name, err_msg);
2861  break;
2862 
2863  case arma_ascii:
2864  load_okay = diskio::load_arma_ascii(*this, name, err_msg);
2865  break;
2866 
2867  case raw_binary:
2868  load_okay = diskio::load_raw_binary(*this, name, err_msg);
2869  break;
2870 
2871  case arma_binary:
2872  load_okay = diskio::load_arma_binary(*this, name, err_msg);
2873  break;
2874 
2875  case ppm_binary:
2876  load_okay = diskio::load_ppm_binary(*this, name, err_msg);
2877  break;
2878 
2879  default:
2880  arma_warn(print_status, "Cube::load(): unsupported file type");
2881  load_okay = false;
2882  }
2883 
2884  if( (print_status == true) && (load_okay == false) )
2885  {
2886  if(err_msg.length() > 0)
2887  {
2888  arma_warn(true, "Cube::load(): ", err_msg, name);
2889  }
2890  else
2891  {
2892  arma_warn(true, "Cube::load(): couldn't read ", name);
2893  }
2894  }
2895 
2896  if(load_okay == false)
2897  {
2898  (*this).reset();
2899  }
2900 
2901  return load_okay;
2902  }
2903 
2904 
2905 
2907 template<typename eT>
2908 inline
2909 bool
2910 Cube<eT>::load(std::istream& is, const file_type type, const bool print_status)
2911  {
2913 
2914  bool load_okay;
2915  std::string err_msg;
2916 
2917  switch(type)
2918  {
2919  case auto_detect:
2920  load_okay = diskio::load_auto_detect(*this, is, err_msg);
2921  break;
2922 
2923  case raw_ascii:
2924  load_okay = diskio::load_raw_ascii(*this, is, err_msg);
2925  break;
2926 
2927  case arma_ascii:
2928  load_okay = diskio::load_arma_ascii(*this, is, err_msg);
2929  break;
2930 
2931  case raw_binary:
2932  load_okay = diskio::load_raw_binary(*this, is, err_msg);
2933  break;
2934 
2935  case arma_binary:
2936  load_okay = diskio::load_arma_binary(*this, is, err_msg);
2937  break;
2938 
2939  case ppm_binary:
2940  load_okay = diskio::load_ppm_binary(*this, is, err_msg);
2941  break;
2942 
2943  default:
2944  arma_warn(print_status, "Cube::load(): unsupported file type");
2945  load_okay = false;
2946  }
2947 
2948 
2949  if( (print_status == true) && (load_okay == false) )
2950  {
2951  if(err_msg.length() > 0)
2952  {
2953  arma_warn(true, "Cube::load(): ", err_msg, "the given stream");
2954  }
2955  else
2956  {
2957  arma_warn(true, "Cube::load(): couldn't load from the given stream");
2958  }
2959  }
2960 
2961  if(load_okay == false)
2962  {
2963  (*this).reset();
2964  }
2965 
2966  return load_okay;
2967  }
2968 
2969 
2970 
2972 template<typename eT>
2973 inline
2974 bool
2975 Cube<eT>::quiet_save(const std::string name, const file_type type) const
2976  {
2978 
2979  return (*this).save(name, type, false);
2980  }
2981 
2982 
2983 
2985 template<typename eT>
2986 inline
2987 bool
2988 Cube<eT>::quiet_save(std::ostream& os, const file_type type) const
2989  {
2991 
2992  return (*this).save(os, type, false);
2993  }
2994 
2995 
2996 
2998 template<typename eT>
2999 inline
3000 bool
3001 Cube<eT>::quiet_load(const std::string name, const file_type type)
3002  {
3004 
3005  return (*this).load(name, type, false);
3006  }
3007 
3008 
3009 
3011 template<typename eT>
3012 inline
3013 bool
3014 Cube<eT>::quiet_load(std::istream& is, const file_type type)
3015  {
3017 
3018  return (*this).load(is, type, false);
3019  }
3020 
3021 
3022 
3023 template<typename eT>
3024 inline
3025 typename Cube<eT>::iterator
3027  {
3029 
3030  return memptr();
3031  }
3032 
3033 
3034 
3035 template<typename eT>
3036 inline
3037 typename Cube<eT>::const_iterator
3039  {
3041 
3042  return memptr();
3043  }
3044 
3045 
3046 
3047 template<typename eT>
3048 inline
3049 typename Cube<eT>::iterator
3051  {
3053 
3054  return memptr() + n_elem;
3055  }
3056 
3057 
3058 
3059 template<typename eT>
3060 inline
3061 typename Cube<eT>::const_iterator
3063  {
3065 
3066  return memptr() + n_elem;
3067  }
3068 
3069 
3070 
3071 template<typename eT>
3072 inline
3073 typename Cube<eT>::slice_iterator
3075  {
3077 
3078  arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
3079 
3080  return slice_memptr(slice_num);
3081  }
3082 
3083 
3084 
3085 template<typename eT>
3086 inline
3088 Cube<eT>::begin_slice(const uword slice_num) const
3089  {
3091 
3092  arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
3093 
3094  return slice_memptr(slice_num);
3095  }
3096 
3097 
3098 
3099 template<typename eT>
3100 inline
3101 typename Cube<eT>::slice_iterator
3102 Cube<eT>::end_slice(const uword slice_num)
3103  {
3105 
3106  arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
3107 
3108  return slice_memptr(slice_num) + n_elem_slice;
3109  }
3110 
3111 
3112 
3113 template<typename eT>
3114 inline
3116 Cube<eT>::end_slice(const uword slice_num) const
3117  {
3119 
3120  arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
3121 
3122  return slice_memptr(slice_num) + n_elem_slice;
3123  }
3124 
3125 
3126 
3127 template<typename eT>
3128 template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
3130 void
3132  {
3134 
3135  if(fixed_n_elem > 0)
3136  {
3137  access::rw(Cube<eT>::n_rows) = fixed_n_rows;
3138  access::rw(Cube<eT>::n_cols) = fixed_n_cols;
3139  access::rw(Cube<eT>::n_elem_slice) = fixed_n_rows * fixed_n_cols;
3140  access::rw(Cube<eT>::n_slices) = fixed_n_slices;
3141  access::rw(Cube<eT>::n_elem) = fixed_n_elem;
3143  access::rw(Cube<eT>::mat_ptrs) = const_cast< const Mat<eT>** >( \
3144  (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local );
3145  access::rw(Cube<eT>::mem) = (fixed_n_elem > Cube_prealloc::mem_n_elem) ? mem_local_extra : mem_local;
3146 
3147  create_mat();
3148  }
3149  else
3150  {
3159  }
3160  }
3161 
3162 
3163 
3165 template<typename eT>
3167 void
3169  {
3170  eT* memptr = x.memptr();
3171  const uword n_elem = x.n_elem;
3172 
3173  uword i,j;
3174 
3175  for(i=0, j=1; j<n_elem; i+=2, j+=2)
3176  {
3177  ++(memptr[i]);
3178  ++(memptr[j]);
3179  }
3180 
3181  if(i < n_elem)
3182  {
3183  ++(memptr[i]);
3184  }
3185  }
3186 
3187 
3188 
3190 template<typename T>
3192 void
3193 Cube_aux::prefix_pp(Cube< std::complex<T> >& x)
3194  {
3195  x += T(1);
3196  }
3197 
3198 
3199 
3201 template<typename eT>
3203 void
3205  {
3206  eT* memptr = x.memptr();
3207  const uword n_elem = x.n_elem;
3208 
3209  uword i,j;
3210 
3211  for(i=0, j=1; j<n_elem; i+=2, j+=2)
3212  {
3213  (memptr[i])++;
3214  (memptr[j])++;
3215  }
3216 
3217  if(i < n_elem)
3218  {
3219  (memptr[i])++;
3220  }
3221  }
3222 
3223 
3224 
3226 template<typename T>
3228 void
3229 Cube_aux::postfix_pp(Cube< std::complex<T> >& x)
3230  {
3231  x += T(1);
3232  }
3233 
3234 
3235 
3237 template<typename eT>
3239 void
3241  {
3242  eT* memptr = x.memptr();
3243  const uword n_elem = x.n_elem;
3244 
3245  uword i,j;
3246 
3247  for(i=0, j=1; j<n_elem; i+=2, j+=2)
3248  {
3249  --(memptr[i]);
3250  --(memptr[j]);
3251  }
3252 
3253  if(i < n_elem)
3254  {
3255  --(memptr[i]);
3256  }
3257  }
3258 
3259 
3260 
3262 template<typename T>
3264 void
3265 Cube_aux::prefix_mm(Cube< std::complex<T> >& x)
3266  {
3267  x -= T(1);
3268  }
3269 
3270 
3271 
3273 template<typename eT>
3275 void
3277  {
3278  eT* memptr = x.memptr();
3279  const uword n_elem = x.n_elem;
3280 
3281  uword i,j;
3282 
3283  for(i=0, j=1; j<n_elem; i+=2, j+=2)
3284  {
3285  (memptr[i])--;
3286  (memptr[j])--;
3287  }
3288 
3289  if(i < n_elem)
3290  {
3291  (memptr[i])--;
3292  }
3293  }
3294 
3295 
3296 
3298 template<typename T>
3300 void
3301 Cube_aux::postfix_mm(Cube< std::complex<T> >& x)
3302  {
3303  x -= T(1);
3304  }
3305 
3306 
3307 
3308 template<typename eT, typename T1>
3309 inline
3310 void
3312  {
3314 
3315  const unwrap_cube<T1> tmp(X.get_ref());
3316  const Cube<eT>& A = tmp.M;
3317 
3318  arma_debug_assert_same_size( out, A, "Cube::set_real()" );
3319 
3320  out = A;
3321  }
3322 
3323 
3324 
3325 template<typename eT, typename T1>
3326 inline
3327 void
3329  {
3331  }
3332 
3333 
3334 
3335 template<typename T, typename T1>
3336 inline
3337 void
3338 Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
3339  {
3341 
3342  typedef typename std::complex<T> eT;
3343  typedef typename ProxyCube<T1>::ea_type ea_type;
3344 
3345  const ProxyCube<T1> A(X.get_ref());
3346 
3348  (
3349  out.n_rows, out.n_cols, out.n_slices,
3350  A.get_n_rows(), A.get_n_cols(), A.get_n_slices(),
3351  "Cube::set_real()"
3352  );
3353 
3354  const uword n_elem = out.n_elem;
3355  eT* out_mem = out.memptr();
3356  ea_type PA = A.get_ea();
3357 
3358  for(uword i=0; i<n_elem; ++i)
3359  {
3360  //out_mem[i].real() = PA[i];
3361  out_mem[i] = std::complex<T>( PA[i], out_mem[i].imag() );
3362  }
3363  }
3364 
3365 
3366 
3367 template<typename T, typename T1>
3368 inline
3369 void
3370 Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
3371  {
3373 
3374  typedef typename std::complex<T> eT;
3375  typedef typename ProxyCube<T1>::ea_type ea_type;
3376 
3377  const ProxyCube<T1> A(X.get_ref());
3378 
3380  (
3381  out.n_rows, out.n_cols, out.n_slices,
3382  A.get_n_rows(), A.get_n_cols(), A.get_n_slices(),
3383  "Cube::set_imag()"
3384  );
3385 
3386  const uword n_elem = out.n_elem;
3387  eT* out_mem = out.memptr();
3388  ea_type PA = A.get_ea();
3389 
3390  for(uword i=0; i<n_elem; ++i)
3391  {
3392  //out_mem[i].imag() = PA[i];
3393  out_mem[i] = std::complex<T>( out_mem[i].real(), PA[i] );
3394  }
3395  }
3396 
3397 
3398 
3399 #ifdef ARMA_EXTRA_CUBE_MEAT
3400  #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT)
3401 #endif
3402 
3403 
3404 
Portable Pixel Map (colour image), used by the field and cube classes.
support class for generator functions (eg. zeros, randu, randn, ...)
static bool save_raw_binary(const Mat< eT > &x, const std::string &final_name)
Save a matrix as raw binary (no header)
uword b
Definition: span.hpp:40
static arma_inline void prefix_mm(Cube< eT > &x)
prefix –
Definition: Cube_meat.hpp:3240
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 uword get_n_cols() const
arma_inline arma_warn_unused eT * slice_memptr(const uword slice)
returns a pointer to array of eTs used by the specified slice in the cube
Definition: Cube_meat.hpp:2284
const Cube & zeros()
Definition: Cube_meat.hpp:2481
arma_inline subview_cube< eT > slices(const uword in_slice1, const uword in_slice2)
creation of subview_cube (subcube comprised of specified slices)
Definition: Cube_meat.hpp:834
slice_iterator end_slice(const uword slice_num)
Definition: Cube_meat.hpp:3102
void set_imag(const BaseCube< pod_type, T1 > &X)
static void minus_inplace(Cube< eT > &out, const subview_cube &in)
cube X -= Y.subcube(...)
bool whole
Definition: span.hpp:41
static bool load_arma_binary(Mat< eT > &x, const std::string &name, std::string &err_msg)
arma_hot static arma_inline void copy(eT *dest, const eT *src, const uword n_elem)
void delete_mat()
Definition: Cube_meat.hpp:364
arma_aligned const uword n_cols
arma_inline subview_cube< eT > subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2)
creation of subview_cube (generic subcube)
Definition: Cube_meat.hpp:876
iterator end()
Definition: Cube_meat.hpp:3050
arma_warn_unused eT min() const
Definition: Cube_meat.hpp:2648
void shed_slices(const uword in_slice1, const uword in_slice2)
remove specified slices
Definition: Cube_meat.hpp:1051
arma_inline const Cube & operator++()
prefix ++
Definition: Cube_meat.hpp:2113
static arma_hot void inplace_minus(eT *dest, const eT *src, const uword n_elem)
const uword mem_state
Definition: Cube_bones.hpp:42
static arma_inline void postfix_mm(Cube< eT > &x)
postfix –
Definition: Cube_meat.hpp:3276
void arma_hot arma_check_bad_alloc(const bool state, const T1 &x)
Definition: debug.hpp:368
arma_inline uword get_n_slices() const
subview_cube< eT > operator()(const span &row_span, const span &col_span, const span &slice_span)
Definition: Cube_meat.hpp:1011
void impl_print(const std::string &extra_text) const
Definition: Cube_meat.hpp:2334
static arma_hot void inplace_mul(eT *dest, const eT *src, const uword n_elem)
#define arma_debug_set_error
Definition: debug.hpp:1085
Definition: span.hpp:35
arma_inline arma_warn_unused bool is_finite() const
returns true if all of the elements are finite
Definition: Cube_meat.hpp:2160
arma_aligned const Mat< eT > **const mat_ptrs
pointer to an array containing pointers to Mat instances (one for each slice)
Definition: Cube_bones.hpp:50
void set_size(const uword in_rows, const uword in_cols, const uword in_slices)
change the cube to have user specified dimensions (data is not preserved)
Definition: Cube_meat.hpp:2414
static eT direct_min(const eT *const X, const uword N)
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
void init_cold()
Definition: Cube_meat.hpp:94
static arma_inline void postfix_pp(Cube< eT > &x)
postfix ++
Definition: Cube_meat.hpp:3204
static arma_inline void prefix_pp(Cube< eT > &x)
prefix ++
Definition: Cube_meat.hpp:3168
static void extract(Cube< eT > &out, const subview_cube &in)
cube X = Y.subcube(...)
arma_aligned const uword n_slices
arma_inline uword get_n_slices() const
arma_inline const Cube & operator-=(const eT val)
In-place subtraction of a scalar from all elements of the cube.
Definition: Cube_meat.hpp:448
void arma_hot arma_assert_same_size(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:459
#define arma_extra_debug_print
Definition: debug.hpp:1118
void steal_mem(Cube &X)
Definition: Cube_meat.hpp:310
arma_inline arma_warn_unused bool in_range(const uword i) const
returns true if the given index is currently in range
Definition: Cube_meat.hpp:2184
void resize(const uword in_rows, const uword in_cols, const uword in_slices)
change the cube to have user specified dimensions (data is preserved)
Definition: Cube_meat.hpp:2440
arma_aligned Mat< eT > * mat_ptrs_local[Cube_prealloc::mat_ptrs_size]
Definition: Cube_bones.hpp:54
~Cube()
Definition: Cube_meat.hpp:20
u32 uword
Definition: typedef.hpp:85
void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim=0)
change the cube to have user specified dimensions (data is preserved)
Definition: Cube_meat.hpp:2427
const uword n_slices
static arma_hot void inplace_plus(eT *dest, const eT *src, const uword n_elem)
#define arma_type_check(condition)
bool save(const std::string name, const file_type type=arma_binary, const bool print_status=true) const
save the cube to a file
Definition: Cube_meat.hpp:2758
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the cube
Definition: Cube_meat.hpp:2260
eT * iterator
Definition: Cube_bones.hpp:264
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
void set_real(const BaseCube< pod_type, T1 > &X)
static bool save_ppm_binary(const Cube< T1 > &x, const std::string &final_name)
static void plus_inplace(Cube< eT > &out, const subview_cube &in)
cube X += Y.subcube(...)
const Op< T1, op_reshape > reshape(const Base< typename T1::elem_type, T1 > &X, const uword in_n_rows, const uword in_n_cols, const uword dim=0)
Definition: fn_reshape.hpp:22
const Cube & randu()
Definition: Cube_meat.hpp:2533
static bool load_ppm_binary(Cube< T1 > &x, const std::string &final_name, std::string &err_msg)
static void print(std::ostream &o, const Mat< eT > &m, const bool modify)
Print a matrix to the specified stream.
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
iterator begin()
Definition: Cube_meat.hpp:3026
static arma_hot void inplace_div(eT *dest, const eT *src, const uword n_elem)
static bool load_raw_binary(Mat< eT > &x, const std::string &name, std::string &err_msg)
file_type
static void set_real(Cube< eT > &out, const BaseCube< eT, T1 > &X)
Definition: Cube_meat.hpp:3311
uword a
Definition: span.hpp:39
static const uword mat_ptrs_size
Definition: Cube_bones.hpp:21
arma_inline arma_warn_unused eT & operator[](const uword i)
linear element accessor (treats the cube as a vector); no bounds check.
Definition: Cube_meat.hpp:2000
void insert_slices(const uword slice_num, const uword N, const bool set_to_zero=true)
Definition: Cube_meat.hpp:1086
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
arma_inline uword get_n_rows() const
arma_inline uword get_n_cols() const
static const uword mem_n_elem
Definition: Cube_bones.hpp:22
Dense cube class.
Definition: Cube_bones.hpp:30
#define arma_extra_debug_sigprint_this
Definition: debug.hpp:1117
void init(const BaseCube< pod_type, T1 > &A, const BaseCube< pod_type, T2 > &B)
Armadillo binary format, with information about matrix type and size.
static bool load_auto_detect(Mat< eT > &x, const std::string &name, std::string &err_msg)
Try to load a matrix by automatically determining its type.
void impl_raw_print(const std::string &extra_text) const
Definition: Cube_meat.hpp:2375
arma_inline const Cube & operator+=(const eT val)
In-place addition of a scalar to all elements of the cube.
Definition: Cube_meat.hpp:433
static bool save_raw_ascii(const Mat< eT > &x, const std::string &final_name)
void reset()
Definition: Cube_meat.hpp:2609
arma_aligned const eT *const mem
pointer to the memory used by the cube (memory is read-only)
Definition: Cube_bones.hpp:51
static bool load_raw_ascii(Mat< eT > &x, const std::string &name, std::string &err_msg)
Cube()
Definition: Cube_meat.hpp:56
const Cube & fill(const eT val)
fill the cube with the specified value
Definition: Cube_meat.hpp:2467
void init_warm(const uword in_rows, const uword in_cols, const uword in_slices)
Definition: Cube_meat.hpp:146
arma_warn_unused eT max() const
Definition: Cube_meat.hpp:2663
arma_inline const Cube & operator*=(const eT val)
In-place multiplication of all elements of the cube with a scalar.
Definition: Cube_meat.hpp:463
void apply_inplace_minus(Cube< eT > &out) const
const Cube & randn()
Definition: Cube_meat.hpp:2575
static void schur_inplace(Cube< eT > &out, const subview_cube &in)
cube X %= Y.subcube(...)
arma_aligned const ProxyCube< T1 > P
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
arma_inline uword get_n_rows() const
void apply_inplace_plus(Cube< eT > &out) const
arma_inline const Cube & operator--()
prefix –
Definition: Cube_meat.hpp:2136
void shed_slice(const uword slice_num)
remove specified slice
Definition: Cube_meat.hpp:1036
arma_inline arma_warn_unused bool is_empty() const
returns true if the cube has no elements
Definition: Cube_meat.hpp:2172
Analog of the Op class, intended for cubes.
Analog of the Base class, intended for cubes.
arma_aligned const ProxyCube< T2 > P2
#define arma_warn_unused
void copy_size(const Cube< eT2 > &m)
change the cube (without preserving data) to have the same dimensions as the given cube ...
Definition: Cube_meat.hpp:2454
void apply_inplace_schur(Cube< eT > &out) const
ASCII format (text), without any other information.
static eT direct_max(const eT *const X, const uword N)
raw binary format, without any other information.
bool quiet_load(const std::string name, const file_type type=auto_detect)
load a cube from a file, without printing any error messages
Definition: Cube_meat.hpp:3001
void arma_cold arma_warn(const bool state, const T1 &x)
print a message to the warn stream
Definition: debug.hpp:298
static bool load_arma_ascii(Mat< eT > &x, const std::string &name, std::string &err_msg)
static bool save_arma_ascii(const Mat< eT > &x, const std::string &final_name)
const Cube & ones()
Definition: Cube_meat.hpp:2507
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
bool load(const std::string name, const file_type type=auto_detect, const bool print_status=true)
load a cube from a file
Definition: Cube_meat.hpp:2846
static void set_imag(Cube< eT > &out, const BaseCube< eT, T1 > &X)
Definition: Cube_meat.hpp:3328
eT * slice_iterator
Definition: Cube_bones.hpp:267
void apply(Cube< eT > &out) const
Dense matrix class.
#define arma_inline
#define ARMA_MAX_UWORD
Definition: typedef.hpp:91
const eT * const_iterator
Definition: Cube_bones.hpp:265
const uword n_cols
arma_inline const derived & get_ref() const
arma_aligned eT mem_local[Cube_prealloc::mem_n_elem]
Definition: Cube_bones.hpp:55
const eT * const_slice_iterator
Definition: Cube_bones.hpp:268
arma_inline const Cube & operator/=(const eT val)
In-place division of all elements of the cube with a scalar.
Definition: Cube_meat.hpp:478
bool quiet_save(const std::string name, const file_type type=arma_binary) const
save the cube to a file, without printing any error messages
Definition: Cube_meat.hpp:2975
static const bool debug
Definition: arma_config.hpp:63
const uword n_rows
arma_hot static arma_pure bool is_finite(const eT *src, const uword n_elem)
arma_aligned const ProxyCube< T1 > P1
arma_aligned const uword n_rows
static void div_inplace(Cube< eT > &out, const subview_cube &in)
cube X /= Y.subcube(...)
const Cube & operator%=(const Cube &m)
in-place element-wise cube multiplication
Definition: Cube_meat.hpp:627
void create_mat()
Definition: Cube_meat.hpp:387
Armadillo ASCII format (text), with information about matrix type and size.
void apply_inplace_div(Cube< eT > &out) const
arma_aligned const Cube< eT > & m
arma_inline const Cube & operator=(const eT val)
Definition: Cube_meat.hpp:418
analog of the Glue class, intended for Cube objects
Automatically detect the file type (file must be one of the following types)
static bool save_arma_binary(const Mat< eT > &x, const std::string &final_name)
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
slice_iterator begin_slice(const uword slice_num)
Definition: Cube_meat.hpp:3074
get_pod_type< eT >::result pod_type
if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std:...
Definition: Cube_bones.hpp:35
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
const Op< T1, op_resize > resize(const Base< typename T1::elem_type, T1 > &X, const uword in_n_rows, const uword in_n_cols)
Definition: fn_resize.hpp:22


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