00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00016
00017
00018
00019 struct Cube_prealloc
00020 {
00021 static const uword mat_ptrs_size = 4;
00022 static const uword mem_n_elem = 64;
00023 };
00024
00025
00026
00028
00029 template<typename eT>
00030 class Cube : public BaseCube< eT, Cube<eT> >
00031 {
00032 public:
00033
00034 typedef eT elem_type;
00035 typedef typename get_pod_type<eT>::result pod_type;
00036
00037 const uword n_rows;
00038 const uword n_cols;
00039 const uword n_elem_slice;
00040 const uword n_slices;
00041 const uword n_elem;
00042 const uword mem_state;
00043
00044
00045
00046
00047
00048
00049
00050 arma_aligned const Mat<eT>** const mat_ptrs;
00051 arma_aligned const eT* const mem;
00052
00053 protected:
00054 arma_aligned Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ];
00055 arma_aligned eT mem_local[ Cube_prealloc::mem_n_elem ];
00056
00057
00058 public:
00059
00060 inline ~Cube();
00061 inline Cube();
00062
00063 inline Cube(const uword in_rows, const uword in_cols, const uword in_slices);
00064
00065 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);
00066 inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices);
00067
00068 arma_inline const Cube& operator=(const eT val);
00069 arma_inline const Cube& operator+=(const eT val);
00070 arma_inline const Cube& operator-=(const eT val);
00071 arma_inline const Cube& operator*=(const eT val);
00072 arma_inline const Cube& operator/=(const eT val);
00073
00074 inline Cube(const Cube& m);
00075 inline const Cube& operator=(const Cube& m);
00076 inline const Cube& operator+=(const Cube& m);
00077 inline const Cube& operator-=(const Cube& m);
00078 inline const Cube& operator%=(const Cube& m);
00079 inline const Cube& operator/=(const Cube& m);
00080
00081 template<typename T1, typename T2>
00082 inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
00083
00084 inline Cube(const subview_cube<eT>& X);
00085 inline const Cube& operator=(const subview_cube<eT>& X);
00086 inline const Cube& operator+=(const subview_cube<eT>& X);
00087 inline const Cube& operator-=(const subview_cube<eT>& X);
00088 inline const Cube& operator%=(const subview_cube<eT>& X);
00089 inline const Cube& operator/=(const subview_cube<eT>& X);
00090
00091 arma_inline Mat<eT>& slice(const uword in_slice);
00092 arma_inline const Mat<eT>& slice(const uword in_slice) const;
00093
00094 arma_inline subview_cube<eT> slices(const uword in_slice1, const uword in_slice2);
00095 arma_inline const subview_cube<eT> slices(const uword in_slice1, const uword in_slice2) const;
00096
00097 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);
00098 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;
00099
00100 inline subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span);
00101 inline const subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span) const;
00102
00103 inline subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span);
00104 inline const subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span) const;
00105
00106
00107 inline void shed_slice(const uword slice_num);
00108
00109 inline void shed_slices(const uword in_slice1, const uword in_slice2);
00110
00111 inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true);
00112
00113 template<typename T1>
00114 inline void insert_slices(const uword row_num, const BaseCube<eT,T1>& X);
00115
00116
00117 template<typename gen_type> inline Cube(const GenCube<eT, gen_type>& X);
00118 template<typename gen_type> inline const Cube& operator=(const GenCube<eT, gen_type>& X);
00119 template<typename gen_type> inline const Cube& operator+=(const GenCube<eT, gen_type>& X);
00120 template<typename gen_type> inline const Cube& operator-=(const GenCube<eT, gen_type>& X);
00121 template<typename gen_type> inline const Cube& operator%=(const GenCube<eT, gen_type>& X);
00122 template<typename gen_type> inline const Cube& operator/=(const GenCube<eT, gen_type>& X);
00123
00124 template<typename T1, typename op_type> inline Cube(const OpCube<T1, op_type>& X);
00125 template<typename T1, typename op_type> inline const Cube& operator=(const OpCube<T1, op_type>& X);
00126 template<typename T1, typename op_type> inline const Cube& operator+=(const OpCube<T1, op_type>& X);
00127 template<typename T1, typename op_type> inline const Cube& operator-=(const OpCube<T1, op_type>& X);
00128 template<typename T1, typename op_type> inline const Cube& operator%=(const OpCube<T1, op_type>& X);
00129 template<typename T1, typename op_type> inline const Cube& operator/=(const OpCube<T1, op_type>& X);
00130
00131 template<typename T1, typename eop_type> inline Cube(const eOpCube<T1, eop_type>& X);
00132 template<typename T1, typename eop_type> inline const Cube& operator=(const eOpCube<T1, eop_type>& X);
00133 template<typename T1, typename eop_type> inline const Cube& operator+=(const eOpCube<T1, eop_type>& X);
00134 template<typename T1, typename eop_type> inline const Cube& operator-=(const eOpCube<T1, eop_type>& X);
00135 template<typename T1, typename eop_type> inline const Cube& operator%=(const eOpCube<T1, eop_type>& X);
00136 template<typename T1, typename eop_type> inline const Cube& operator/=(const eOpCube<T1, eop_type>& X);
00137
00138 template<typename T1, typename op_type> inline Cube(const mtOpCube<eT, T1, op_type>& X);
00139 template<typename T1, typename op_type> inline const Cube& operator=(const mtOpCube<eT, T1, op_type>& X);
00140 template<typename T1, typename op_type> inline const Cube& operator+=(const mtOpCube<eT, T1, op_type>& X);
00141 template<typename T1, typename op_type> inline const Cube& operator-=(const mtOpCube<eT, T1, op_type>& X);
00142 template<typename T1, typename op_type> inline const Cube& operator%=(const mtOpCube<eT, T1, op_type>& X);
00143 template<typename T1, typename op_type> inline const Cube& operator/=(const mtOpCube<eT, T1, op_type>& X);
00144
00145 template<typename T1, typename T2, typename glue_type> inline Cube(const GlueCube<T1, T2, glue_type>& X);
00146 template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const GlueCube<T1, T2, glue_type>& X);
00147 template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const GlueCube<T1, T2, glue_type>& X);
00148 template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const GlueCube<T1, T2, glue_type>& X);
00149 template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const GlueCube<T1, T2, glue_type>& X);
00150 template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const GlueCube<T1, T2, glue_type>& X);
00151
00152 template<typename T1, typename T2, typename eglue_type> inline Cube(const eGlueCube<T1, T2, eglue_type>& X);
00153 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator=(const eGlueCube<T1, T2, eglue_type>& X);
00154 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
00155 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
00156 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
00157 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
00158
00159 template<typename T1, typename T2, typename glue_type> inline Cube(const mtGlueCube<eT, T1, T2, glue_type>& X);
00160 template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const mtGlueCube<eT, T1, T2, glue_type>& X);
00161 template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X);
00162 template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X);
00163 template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X);
00164 template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X);
00165
00166
00167 arma_inline arma_warn_unused eT& operator[] (const uword i);
00168 arma_inline arma_warn_unused eT operator[] (const uword i) const;
00169
00170 arma_inline arma_warn_unused eT& at(const uword i);
00171 arma_inline arma_warn_unused eT at(const uword i) const;
00172
00173 arma_inline arma_warn_unused eT& operator() (const uword i);
00174 arma_inline arma_warn_unused eT operator() (const uword i) const;
00175
00176 arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice);
00177 arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col, const uword in_slice) const;
00178
00179 arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice);
00180 arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col, const uword in_slice) const;
00181
00182 arma_inline const Cube& operator++();
00183 arma_inline void operator++(int);
00184
00185 arma_inline const Cube& operator--();
00186 arma_inline void operator--(int);
00187
00188 arma_inline arma_warn_unused bool is_finite() const;
00189 arma_inline arma_warn_unused bool is_empty() const;
00190
00191 arma_inline arma_warn_unused bool in_range(const uword i) const;
00192 arma_inline arma_warn_unused bool in_range(const span& x) const;
00193
00194 arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const;
00195 inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const;
00196
00197 arma_inline arma_warn_unused eT* memptr();
00198 arma_inline arma_warn_unused const eT* memptr() const;
00199
00200 arma_inline arma_warn_unused eT* slice_memptr(const uword slice);
00201 arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const;
00202
00203 arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col);
00204 arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const;
00205
00206 inline void impl_print(const std::string& extra_text) const;
00207 inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
00208
00209 inline void impl_raw_print(const std::string& extra_text) const;
00210 inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
00211
00212 inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices);
00213 inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim = 0);
00214 inline void resize(const uword in_rows, const uword in_cols, const uword in_slices);
00215
00216 template<typename eT2> inline void copy_size(const Cube<eT2>& m);
00217
00218 inline const Cube& fill(const eT val);
00219
00220 inline const Cube& zeros();
00221 inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices);
00222
00223 inline const Cube& ones();
00224 inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices);
00225
00226 inline const Cube& randu();
00227 inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices);
00228
00229 inline const Cube& randn();
00230 inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices);
00231
00232 inline void reset();
00233
00234
00235 template<typename T1> inline void set_real(const BaseCube<pod_type,T1>& X);
00236 template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X);
00237
00238
00239 inline arma_warn_unused eT min() const;
00240 inline arma_warn_unused eT max() const;
00241
00242 inline eT min(uword& index_of_min_val) const;
00243 inline eT max(uword& index_of_max_val) const;
00244
00245 inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const;
00246 inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const;
00247
00248
00249 inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
00250 inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
00251
00252 inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true);
00253 inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true);
00254
00255 inline bool quiet_save(const std::string name, const file_type type = arma_binary) const;
00256 inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
00257
00258 inline bool quiet_load(const std::string name, const file_type type = auto_detect);
00259 inline bool quiet_load( std::istream& is, const file_type type = auto_detect);
00260
00261
00262
00263
00264 typedef eT* iterator;
00265 typedef const eT* const_iterator;
00266
00267 typedef eT* slice_iterator;
00268 typedef const eT* const_slice_iterator;
00269
00270 inline iterator begin();
00271 inline const_iterator begin() const;
00272
00273 inline iterator end();
00274 inline const_iterator end() const;
00275
00276 inline slice_iterator begin_slice(const uword slice_num);
00277 inline const_slice_iterator begin_slice(const uword slice_num) const;
00278
00279 inline slice_iterator end_slice(const uword slice_num);
00280 inline const_slice_iterator end_slice(const uword slice_num) const;
00281
00282
00283 template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
00284 class fixed : public Cube<eT>
00285 {
00286 private:
00287
00288 static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices;
00289
00290 arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
00291 arma_aligned eT mem_local_extra [ (fixed_n_elem > Cube_prealloc::mem_n_elem) ? fixed_n_elem : 1 ];
00292
00293 arma_inline void mem_setup();
00294
00295
00296 public:
00297
00298 inline fixed() { mem_setup(); }
00299
00300 inline const Cube& operator=(const eT val) { mem_setup(); Cube<eT>::operator=(val); return *this; }
00301
00302 template<typename T1>
00303 inline fixed(const BaseCube<eT,T1>& A) { mem_setup(); Cube<eT>::operator=(A.get_ref()); }
00304
00305 template<typename T1>
00306 inline const Cube& operator=(const BaseCube<eT,T1>& A) { Cube<eT>::operator=(A.get_ref()); return *this; }
00307
00308 template<typename T1, typename T2>
00309 inline explicit fixed(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B) { mem_setup(); Cube<eT>::init(A,B); }
00310 };
00311
00312
00313 protected:
00314
00315 inline void init_cold();
00316 inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices);
00317
00318 template<typename T1, typename T2>
00319 inline void init(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
00320
00321 inline void steal_mem(Cube& X);
00322
00323 inline void delete_mat();
00324 inline void create_mat();
00325
00326 friend class glue_join;
00327 friend class op_reshape;
00328 friend class op_resize;
00329
00330
00331 public:
00332
00333 #ifdef ARMA_EXTRA_CUBE_PROTO
00334 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO)
00335 #endif
00336 };
00337
00338
00339
00340 class Cube_aux
00341 {
00342 public:
00343
00344 template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
00345 template<typename T> arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
00346
00347 template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x);
00348 template<typename T> arma_inline static void postfix_pp(Cube< std::complex<T> >& x);
00349
00350 template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
00351 template<typename T> arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
00352
00353 template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
00354 template<typename T> arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
00355
00356 template<typename eT, typename T1> inline static void set_real(Cube<eT>& out, const BaseCube<eT,T1>& X);
00357 template<typename eT, typename T1> inline static void set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X);
00358
00359 template<typename T, typename T1> inline static void set_real(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
00360 template<typename T, typename T1> inline static void set_imag(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
00361 };
00362
00363
00364