Cube_bones.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 
20  {
21  static const uword mat_ptrs_size = 4;
22  static const uword mem_n_elem = 64;
23  };
24 
25 
26 
28 
29 template<typename eT>
30 class Cube : public BaseCube< eT, Cube<eT> >
31  {
32  public:
33 
34  typedef eT elem_type;
36 
37  const uword n_rows;
38  const uword n_cols;
40  const uword n_slices;
41  const uword n_elem;
43 
44  // mem_state = 0: normal cube that can be resized;
45  // mem_state = 1: use auxiliary memory until change in the number of elements is requested;
46  // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed;
47  // mem_state = 3: fixed size (e.g. via template based size specification).
48 
49 
50  arma_aligned const Mat<eT>** const mat_ptrs;
51  arma_aligned const eT* const mem;
52 
53  protected:
56 
57 
58  public:
59 
60  inline ~Cube();
61  inline Cube();
62 
63  inline Cube(const uword in_rows, const uword in_cols, const uword in_slices);
64 
65  inline Cube( eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem = true, const bool strict = true);
66  inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices);
67 
68  arma_inline const Cube& operator=(const eT val);
69  arma_inline const Cube& operator+=(const eT val);
70  arma_inline const Cube& operator-=(const eT val);
71  arma_inline const Cube& operator*=(const eT val);
72  arma_inline const Cube& operator/=(const eT val);
73 
74  inline Cube(const Cube& m);
75  inline const Cube& operator=(const Cube& m);
76  inline const Cube& operator+=(const Cube& m);
77  inline const Cube& operator-=(const Cube& m);
78  inline const Cube& operator%=(const Cube& m);
79  inline const Cube& operator/=(const Cube& m);
80 
81  template<typename T1, typename T2>
82  inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
83 
84  inline Cube(const subview_cube<eT>& X);
85  inline const Cube& operator=(const subview_cube<eT>& X);
86  inline const Cube& operator+=(const subview_cube<eT>& X);
87  inline const Cube& operator-=(const subview_cube<eT>& X);
88  inline const Cube& operator%=(const subview_cube<eT>& X);
89  inline const Cube& operator/=(const subview_cube<eT>& X);
90 
91  arma_inline Mat<eT>& slice(const uword in_slice);
92  arma_inline const Mat<eT>& slice(const uword in_slice) const;
93 
94  arma_inline subview_cube<eT> slices(const uword in_slice1, const uword in_slice2);
95  arma_inline const subview_cube<eT> slices(const uword in_slice1, const uword in_slice2) const;
96 
97  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);
98  arma_inline const 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) const;
99 
100  inline subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span);
101  inline const subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span) const;
102 
103  inline subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span);
104  inline const subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span) const;
105 
106 
107  inline void shed_slice(const uword slice_num);
108 
109  inline void shed_slices(const uword in_slice1, const uword in_slice2);
110 
111  inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true);
112 
113  template<typename T1>
114  inline void insert_slices(const uword row_num, const BaseCube<eT,T1>& X);
115 
116 
117  template<typename gen_type> inline Cube(const GenCube<eT, gen_type>& X);
118  template<typename gen_type> inline const Cube& operator=(const GenCube<eT, gen_type>& X);
119  template<typename gen_type> inline const Cube& operator+=(const GenCube<eT, gen_type>& X);
120  template<typename gen_type> inline const Cube& operator-=(const GenCube<eT, gen_type>& X);
121  template<typename gen_type> inline const Cube& operator%=(const GenCube<eT, gen_type>& X);
122  template<typename gen_type> inline const Cube& operator/=(const GenCube<eT, gen_type>& X);
123 
124  template<typename T1, typename op_type> inline Cube(const OpCube<T1, op_type>& X);
125  template<typename T1, typename op_type> inline const Cube& operator=(const OpCube<T1, op_type>& X);
126  template<typename T1, typename op_type> inline const Cube& operator+=(const OpCube<T1, op_type>& X);
127  template<typename T1, typename op_type> inline const Cube& operator-=(const OpCube<T1, op_type>& X);
128  template<typename T1, typename op_type> inline const Cube& operator%=(const OpCube<T1, op_type>& X);
129  template<typename T1, typename op_type> inline const Cube& operator/=(const OpCube<T1, op_type>& X);
130 
131  template<typename T1, typename eop_type> inline Cube(const eOpCube<T1, eop_type>& X);
132  template<typename T1, typename eop_type> inline const Cube& operator=(const eOpCube<T1, eop_type>& X);
133  template<typename T1, typename eop_type> inline const Cube& operator+=(const eOpCube<T1, eop_type>& X);
134  template<typename T1, typename eop_type> inline const Cube& operator-=(const eOpCube<T1, eop_type>& X);
135  template<typename T1, typename eop_type> inline const Cube& operator%=(const eOpCube<T1, eop_type>& X);
136  template<typename T1, typename eop_type> inline const Cube& operator/=(const eOpCube<T1, eop_type>& X);
137 
138  template<typename T1, typename op_type> inline Cube(const mtOpCube<eT, T1, op_type>& X);
139  template<typename T1, typename op_type> inline const Cube& operator=(const mtOpCube<eT, T1, op_type>& X);
140  template<typename T1, typename op_type> inline const Cube& operator+=(const mtOpCube<eT, T1, op_type>& X);
141  template<typename T1, typename op_type> inline const Cube& operator-=(const mtOpCube<eT, T1, op_type>& X);
142  template<typename T1, typename op_type> inline const Cube& operator%=(const mtOpCube<eT, T1, op_type>& X);
143  template<typename T1, typename op_type> inline const Cube& operator/=(const mtOpCube<eT, T1, op_type>& X);
144 
145  template<typename T1, typename T2, typename glue_type> inline Cube(const GlueCube<T1, T2, glue_type>& X);
146  template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const GlueCube<T1, T2, glue_type>& X);
147  template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const GlueCube<T1, T2, glue_type>& X);
148  template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const GlueCube<T1, T2, glue_type>& X);
149  template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const GlueCube<T1, T2, glue_type>& X);
150  template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const GlueCube<T1, T2, glue_type>& X);
151 
152  template<typename T1, typename T2, typename eglue_type> inline Cube(const eGlueCube<T1, T2, eglue_type>& X);
153  template<typename T1, typename T2, typename eglue_type> inline const Cube& operator=(const eGlueCube<T1, T2, eglue_type>& X);
154  template<typename T1, typename T2, typename eglue_type> inline const Cube& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
155  template<typename T1, typename T2, typename eglue_type> inline const Cube& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
156  template<typename T1, typename T2, typename eglue_type> inline const Cube& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
157  template<typename T1, typename T2, typename eglue_type> inline const Cube& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
158 
159  template<typename T1, typename T2, typename glue_type> inline Cube(const mtGlueCube<eT, T1, T2, glue_type>& X);
160  template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const mtGlueCube<eT, T1, T2, glue_type>& X);
161  template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X);
162  template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X);
163  template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X);
164  template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X);
165 
166 
167  arma_inline arma_warn_unused eT& operator[] (const uword i);
168  arma_inline arma_warn_unused eT operator[] (const uword i) const;
169 
170  arma_inline arma_warn_unused eT& at(const uword i);
171  arma_inline arma_warn_unused eT at(const uword i) const;
172 
173  arma_inline arma_warn_unused eT& operator() (const uword i);
174  arma_inline arma_warn_unused eT operator() (const uword i) const;
175 
176  arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice);
177  arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col, const uword in_slice) const;
178 
179  arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice);
180  arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col, const uword in_slice) const;
181 
182  arma_inline const Cube& operator++();
183  arma_inline void operator++(int);
184 
185  arma_inline const Cube& operator--();
186  arma_inline void operator--(int);
187 
189  arma_inline arma_warn_unused bool is_empty() const;
190 
191  arma_inline arma_warn_unused bool in_range(const uword i) const;
192  arma_inline arma_warn_unused bool in_range(const span& x) const;
193 
194  arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const;
195  inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const;
196 
197  arma_inline arma_warn_unused eT* memptr();
198  arma_inline arma_warn_unused const eT* memptr() const;
199 
200  arma_inline arma_warn_unused eT* slice_memptr(const uword slice);
201  arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const;
202 
203  arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col);
204  arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const;
205 
206  inline void impl_print(const std::string& extra_text) const;
207  inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
208 
209  inline void impl_raw_print(const std::string& extra_text) const;
210  inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
211 
212  inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices);
213  inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim = 0);
214  inline void resize(const uword in_rows, const uword in_cols, const uword in_slices);
215 
216  template<typename eT2> inline void copy_size(const Cube<eT2>& m);
217 
218  inline const Cube& fill(const eT val);
219 
220  inline const Cube& zeros();
221  inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices);
222 
223  inline const Cube& ones();
224  inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices);
225 
226  inline const Cube& randu();
227  inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices);
228 
229  inline const Cube& randn();
230  inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices);
231 
232  inline void reset();
233 
234 
235  template<typename T1> inline void set_real(const BaseCube<pod_type,T1>& X);
236  template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X);
237 
238 
239  inline arma_warn_unused eT min() const;
240  inline arma_warn_unused eT max() const;
241 
242  inline eT min(uword& index_of_min_val) const;
243  inline eT max(uword& index_of_max_val) const;
244 
245  inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const;
246  inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const;
247 
248 
249  inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
250  inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
251 
252  inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true);
253  inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true);
254 
255  inline bool quiet_save(const std::string name, const file_type type = arma_binary) const;
256  inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
257 
258  inline bool quiet_load(const std::string name, const file_type type = auto_detect);
259  inline bool quiet_load( std::istream& is, const file_type type = auto_detect);
260 
261 
262  // iterators
263 
264  typedef eT* iterator;
265  typedef const eT* const_iterator;
266 
267  typedef eT* slice_iterator;
268  typedef const eT* const_slice_iterator;
269 
270  inline iterator begin();
271  inline const_iterator begin() const;
272 
273  inline iterator end();
274  inline const_iterator end() const;
275 
276  inline slice_iterator begin_slice(const uword slice_num);
277  inline const_slice_iterator begin_slice(const uword slice_num) const;
278 
279  inline slice_iterator end_slice(const uword slice_num);
280  inline const_slice_iterator end_slice(const uword slice_num) const;
281 
282 
283  template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
284  class fixed : public Cube<eT>
285  {
286  private:
287 
288  static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices;
289 
290  arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
291  arma_aligned eT mem_local_extra [ (fixed_n_elem > Cube_prealloc::mem_n_elem) ? fixed_n_elem : 1 ];
292 
293  arma_inline void mem_setup();
294 
295 
296  public:
297 
298  inline fixed() { mem_setup(); }
299 
300  inline const Cube& operator=(const eT val) { mem_setup(); Cube<eT>::operator=(val); return *this; }
301 
302  template<typename T1>
303  inline fixed(const BaseCube<eT,T1>& A) { mem_setup(); Cube<eT>::operator=(A.get_ref()); }
304 
305  template<typename T1>
306  inline const Cube& operator=(const BaseCube<eT,T1>& A) { Cube<eT>::operator=(A.get_ref()); return *this; }
307 
308  template<typename T1, typename T2>
309  inline explicit fixed(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B) { mem_setup(); Cube<eT>::init(A,B); }
310  };
311 
312 
313  protected:
314 
315  inline void init_cold();
316  inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices);
317 
318  template<typename T1, typename T2>
319  inline void init(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
320 
321  inline void steal_mem(Cube& X);
322 
323  inline void delete_mat();
324  inline void create_mat();
325 
326  friend class glue_join;
327  friend class op_reshape;
328  friend class op_resize;
329 
330 
331  public:
332 
333  #ifdef ARMA_EXTRA_CUBE_PROTO
334  #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO)
335  #endif
336  };
337 
338 
339 
340 class Cube_aux
341  {
342  public:
343 
344  template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
345  template<typename T> arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
346 
347  template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x);
348  template<typename T> arma_inline static void postfix_pp(Cube< std::complex<T> >& x);
349 
350  template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
351  template<typename T> arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
352 
353  template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
354  template<typename T> arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
355 
356  template<typename eT, typename T1> inline static void set_real(Cube<eT>& out, const BaseCube<eT,T1>& X);
357  template<typename eT, typename T1> inline static void set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X);
358 
359  template<typename T, typename T1> inline static void set_real(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
360  template<typename T, typename T1> inline static void set_imag(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
361  };
362 
363 
364 
fixed(const BaseCube< pod_type, T1 > &A, const BaseCube< pod_type, T2 > &B)
Definition: Cube_bones.hpp:309
support class for generator functions (eg. zeros, randu, randn, ...)
const Cube & operator=(const eT val)
Definition: Cube_bones.hpp:300
eT elem_type
the type of elements stored in the cube
Definition: Cube_bones.hpp:34
double randu()
Definition: fn_randu.hpp:20
const uword mem_state
Definition: Cube_bones.hpp:42
Definition: span.hpp:35
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
arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only< eT >::result *junk=0)
Definition: fn_misc.hpp:132
arma_inline const Op< T1, op_max > max(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed &#39;maximum values&#39; operation. The dimension, along which the maxima are found, is set via &#39;dim&#39;. For dim = 0, the maximum value of each column is found (i.e. searches by traversing across rows). For dim = 1, the maximum value of each row is found (i.e. searches by traversing across columns). The default is dim = 0.
Definition: fn_max.hpp:28
double randn()
Definition: fn_randn.hpp:20
arma_inline const Op< T1, op_min > min(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed &#39;minimum values&#39; operation. The dimension, along which the minima are found, is set via &#39;dim&#39;. For dim = 0, the minimum value of each column is found (i.e. searches by traversing across rows). For dim = 1, the minimum value of each row is found (i.e. searches by traversing across columns). The default is dim = 0.
Definition: fn_min.hpp:27
u32 uword
Definition: typedef.hpp:85
eT * iterator
Definition: Cube_bones.hpp:264
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
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 & operator=(const BaseCube< eT, T1 > &A)
Definition: Cube_bones.hpp:306
file_type
static const uword mat_ptrs_size
Definition: Cube_bones.hpp:21
static const uword mem_n_elem
Definition: Cube_bones.hpp:22
Dense cube class.
Definition: Cube_bones.hpp:30
void init(const BaseCube< pod_type, T1 > &A, const BaseCube< pod_type, T2 > &B)
Armadillo binary format, with information about matrix type and size.
arma_aligned const eT *const mem
pointer to the memory used by the cube (memory is read-only)
Definition: Cube_bones.hpp:51
#define arma_aligned
arma_inline const Gen< vec::elem_type, gen_ones_full > ones(const uword n_elem)
Definition: fn_ones.hpp:21
Analog of the Op class, intended for cubes.
Analog of the Base class, intended for cubes.
#define arma_warn_unused
fixed(const BaseCube< eT, T1 > &A)
Definition: Cube_bones.hpp:303
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
eT * slice_iterator
Definition: Cube_bones.hpp:267
Dense matrix class.
#define arma_inline
const eT * const_iterator
Definition: Cube_bones.hpp:265
arma_inline const derived & get_ref() const
const eT * const_slice_iterator
Definition: Cube_bones.hpp:268
arma_inline const Gen< vec::elem_type, gen_zeros > zeros(const uword n_elem)
Generate a vector with all elements set to zero.
Definition: fn_zeros.hpp:21
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)
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
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
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