annotate armadillo-2.4.4/include/armadillo_bits/Cube_bones.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2008-2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup Cube
max@0 15 //! @{
max@0 16
max@0 17
max@0 18
max@0 19 struct Cube_prealloc
max@0 20 {
max@0 21 static const uword mat_ptrs_size = 4;
max@0 22 static const uword mem_n_elem = 64;
max@0 23 };
max@0 24
max@0 25
max@0 26
max@0 27 //! Dense cube class
max@0 28
max@0 29 template<typename eT>
max@0 30 class Cube : public BaseCube< eT, Cube<eT> >
max@0 31 {
max@0 32 public:
max@0 33
max@0 34 typedef eT elem_type; //!< the type of elements stored in the cube
max@0 35 typedef typename 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::complex
max@0 36
max@0 37 const uword n_rows; //!< number of rows in each slice (read-only)
max@0 38 const uword n_cols; //!< number of columns in each slice (read-only)
max@0 39 const uword n_elem_slice; //!< number of elements in each slice (read-only)
max@0 40 const uword n_slices; //!< number of slices in the cube (read-only)
max@0 41 const uword n_elem; //!< number of elements in the cube (read-only)
max@0 42 const uword mem_state;
max@0 43
max@0 44 // mem_state = 0: normal cube that can be resized;
max@0 45 // mem_state = 1: use auxiliary memory until change in the number of elements is requested;
max@0 46 // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed;
max@0 47 // mem_state = 3: fixed size (e.g. via template based size specification).
max@0 48
max@0 49
max@0 50 arma_aligned const Mat<eT>** const mat_ptrs; //!< pointer to an array containing pointers to Mat instances (one for each slice)
max@0 51 arma_aligned const eT* const mem; //!< pointer to the memory used by the cube (memory is read-only)
max@0 52
max@0 53 protected:
max@0 54 arma_aligned Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ];
max@0 55 arma_aligned eT mem_local[ Cube_prealloc::mem_n_elem ];
max@0 56
max@0 57
max@0 58 public:
max@0 59
max@0 60 inline ~Cube();
max@0 61 inline Cube();
max@0 62
max@0 63 inline Cube(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 64
max@0 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);
max@0 66 inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices);
max@0 67
max@0 68 arma_inline const Cube& operator=(const eT val);
max@0 69 arma_inline const Cube& operator+=(const eT val);
max@0 70 arma_inline const Cube& operator-=(const eT val);
max@0 71 arma_inline const Cube& operator*=(const eT val);
max@0 72 arma_inline const Cube& operator/=(const eT val);
max@0 73
max@0 74 inline Cube(const Cube& m);
max@0 75 inline const Cube& operator=(const Cube& m);
max@0 76 inline const Cube& operator+=(const Cube& m);
max@0 77 inline const Cube& operator-=(const Cube& m);
max@0 78 inline const Cube& operator%=(const Cube& m);
max@0 79 inline const Cube& operator/=(const Cube& m);
max@0 80
max@0 81 template<typename T1, typename T2>
max@0 82 inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
max@0 83
max@0 84 inline Cube(const subview_cube<eT>& X);
max@0 85 inline const Cube& operator=(const subview_cube<eT>& X);
max@0 86 inline const Cube& operator+=(const subview_cube<eT>& X);
max@0 87 inline const Cube& operator-=(const subview_cube<eT>& X);
max@0 88 inline const Cube& operator%=(const subview_cube<eT>& X);
max@0 89 inline const Cube& operator/=(const subview_cube<eT>& X);
max@0 90
max@0 91 arma_inline Mat<eT>& slice(const uword in_slice);
max@0 92 arma_inline const Mat<eT>& slice(const uword in_slice) const;
max@0 93
max@0 94 arma_inline subview_cube<eT> slices(const uword in_slice1, const uword in_slice2);
max@0 95 arma_inline const subview_cube<eT> slices(const uword in_slice1, const uword in_slice2) const;
max@0 96
max@0 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);
max@0 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;
max@0 99
max@0 100 inline subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span);
max@0 101 inline const subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span) const;
max@0 102
max@0 103 inline subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span);
max@0 104 inline const subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span) const;
max@0 105
max@0 106
max@0 107 inline void shed_slice(const uword slice_num);
max@0 108
max@0 109 inline void shed_slices(const uword in_slice1, const uword in_slice2);
max@0 110
max@0 111 inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true);
max@0 112
max@0 113 template<typename T1>
max@0 114 inline void insert_slices(const uword row_num, const BaseCube<eT,T1>& X);
max@0 115
max@0 116
max@0 117 template<typename gen_type> inline Cube(const GenCube<eT, gen_type>& X);
max@0 118 template<typename gen_type> inline const Cube& operator=(const GenCube<eT, gen_type>& X);
max@0 119 template<typename gen_type> inline const Cube& operator+=(const GenCube<eT, gen_type>& X);
max@0 120 template<typename gen_type> inline const Cube& operator-=(const GenCube<eT, gen_type>& X);
max@0 121 template<typename gen_type> inline const Cube& operator%=(const GenCube<eT, gen_type>& X);
max@0 122 template<typename gen_type> inline const Cube& operator/=(const GenCube<eT, gen_type>& X);
max@0 123
max@0 124 template<typename T1, typename op_type> inline Cube(const OpCube<T1, op_type>& X);
max@0 125 template<typename T1, typename op_type> inline const Cube& operator=(const OpCube<T1, op_type>& X);
max@0 126 template<typename T1, typename op_type> inline const Cube& operator+=(const OpCube<T1, op_type>& X);
max@0 127 template<typename T1, typename op_type> inline const Cube& operator-=(const OpCube<T1, op_type>& X);
max@0 128 template<typename T1, typename op_type> inline const Cube& operator%=(const OpCube<T1, op_type>& X);
max@0 129 template<typename T1, typename op_type> inline const Cube& operator/=(const OpCube<T1, op_type>& X);
max@0 130
max@0 131 template<typename T1, typename eop_type> inline Cube(const eOpCube<T1, eop_type>& X);
max@0 132 template<typename T1, typename eop_type> inline const Cube& operator=(const eOpCube<T1, eop_type>& X);
max@0 133 template<typename T1, typename eop_type> inline const Cube& operator+=(const eOpCube<T1, eop_type>& X);
max@0 134 template<typename T1, typename eop_type> inline const Cube& operator-=(const eOpCube<T1, eop_type>& X);
max@0 135 template<typename T1, typename eop_type> inline const Cube& operator%=(const eOpCube<T1, eop_type>& X);
max@0 136 template<typename T1, typename eop_type> inline const Cube& operator/=(const eOpCube<T1, eop_type>& X);
max@0 137
max@0 138 template<typename T1, typename op_type> inline Cube(const mtOpCube<eT, T1, op_type>& X);
max@0 139 template<typename T1, typename op_type> inline const Cube& operator=(const mtOpCube<eT, T1, op_type>& X);
max@0 140 template<typename T1, typename op_type> inline const Cube& operator+=(const mtOpCube<eT, T1, op_type>& X);
max@0 141 template<typename T1, typename op_type> inline const Cube& operator-=(const mtOpCube<eT, T1, op_type>& X);
max@0 142 template<typename T1, typename op_type> inline const Cube& operator%=(const mtOpCube<eT, T1, op_type>& X);
max@0 143 template<typename T1, typename op_type> inline const Cube& operator/=(const mtOpCube<eT, T1, op_type>& X);
max@0 144
max@0 145 template<typename T1, typename T2, typename glue_type> inline Cube(const GlueCube<T1, T2, glue_type>& X);
max@0 146 template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const GlueCube<T1, T2, glue_type>& X);
max@0 147 template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const GlueCube<T1, T2, glue_type>& X);
max@0 148 template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const GlueCube<T1, T2, glue_type>& X);
max@0 149 template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const GlueCube<T1, T2, glue_type>& X);
max@0 150 template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const GlueCube<T1, T2, glue_type>& X);
max@0 151
max@0 152 template<typename T1, typename T2, typename eglue_type> inline Cube(const eGlueCube<T1, T2, eglue_type>& X);
max@0 153 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator=(const eGlueCube<T1, T2, eglue_type>& X);
max@0 154 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
max@0 155 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
max@0 156 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
max@0 157 template<typename T1, typename T2, typename eglue_type> inline const Cube& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
max@0 158
max@0 159 template<typename T1, typename T2, typename glue_type> inline Cube(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 160 template<typename T1, typename T2, typename glue_type> inline const Cube& operator=(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 161 template<typename T1, typename T2, typename glue_type> inline const Cube& operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 162 template<typename T1, typename T2, typename glue_type> inline const Cube& operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 163 template<typename T1, typename T2, typename glue_type> inline const Cube& operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 164 template<typename T1, typename T2, typename glue_type> inline const Cube& operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X);
max@0 165
max@0 166
max@0 167 arma_inline arma_warn_unused eT& operator[] (const uword i);
max@0 168 arma_inline arma_warn_unused eT operator[] (const uword i) const;
max@0 169
max@0 170 arma_inline arma_warn_unused eT& at(const uword i);
max@0 171 arma_inline arma_warn_unused eT at(const uword i) const;
max@0 172
max@0 173 arma_inline arma_warn_unused eT& operator() (const uword i);
max@0 174 arma_inline arma_warn_unused eT operator() (const uword i) const;
max@0 175
max@0 176 arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice);
max@0 177 arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col, const uword in_slice) const;
max@0 178
max@0 179 arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice);
max@0 180 arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col, const uword in_slice) const;
max@0 181
max@0 182 arma_inline const Cube& operator++();
max@0 183 arma_inline void operator++(int);
max@0 184
max@0 185 arma_inline const Cube& operator--();
max@0 186 arma_inline void operator--(int);
max@0 187
max@0 188 arma_inline arma_warn_unused bool is_finite() const;
max@0 189 arma_inline arma_warn_unused bool is_empty() const;
max@0 190
max@0 191 arma_inline arma_warn_unused bool in_range(const uword i) const;
max@0 192 arma_inline arma_warn_unused bool in_range(const span& x) const;
max@0 193
max@0 194 arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const;
max@0 195 inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const;
max@0 196
max@0 197 arma_inline arma_warn_unused eT* memptr();
max@0 198 arma_inline arma_warn_unused const eT* memptr() const;
max@0 199
max@0 200 arma_inline arma_warn_unused eT* slice_memptr(const uword slice);
max@0 201 arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const;
max@0 202
max@0 203 arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col);
max@0 204 arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const;
max@0 205
max@0 206 inline void impl_print(const std::string& extra_text) const;
max@0 207 inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
max@0 208
max@0 209 inline void impl_raw_print(const std::string& extra_text) const;
max@0 210 inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
max@0 211
max@0 212 inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 213 inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim = 0);
max@0 214 inline void resize(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 215
max@0 216 template<typename eT2> inline void copy_size(const Cube<eT2>& m);
max@0 217
max@0 218 inline const Cube& fill(const eT val);
max@0 219
max@0 220 inline const Cube& zeros();
max@0 221 inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 222
max@0 223 inline const Cube& ones();
max@0 224 inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 225
max@0 226 inline const Cube& randu();
max@0 227 inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 228
max@0 229 inline const Cube& randn();
max@0 230 inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 231
max@0 232 inline void reset();
max@0 233
max@0 234
max@0 235 template<typename T1> inline void set_real(const BaseCube<pod_type,T1>& X);
max@0 236 template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X);
max@0 237
max@0 238
max@0 239 inline arma_warn_unused eT min() const;
max@0 240 inline arma_warn_unused eT max() const;
max@0 241
max@0 242 inline eT min(uword& index_of_min_val) const;
max@0 243 inline eT max(uword& index_of_max_val) const;
max@0 244
max@0 245 inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const;
max@0 246 inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const;
max@0 247
max@0 248
max@0 249 inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
max@0 250 inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
max@0 251
max@0 252 inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true);
max@0 253 inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true);
max@0 254
max@0 255 inline bool quiet_save(const std::string name, const file_type type = arma_binary) const;
max@0 256 inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
max@0 257
max@0 258 inline bool quiet_load(const std::string name, const file_type type = auto_detect);
max@0 259 inline bool quiet_load( std::istream& is, const file_type type = auto_detect);
max@0 260
max@0 261
max@0 262 // iterators
max@0 263
max@0 264 typedef eT* iterator;
max@0 265 typedef const eT* const_iterator;
max@0 266
max@0 267 typedef eT* slice_iterator;
max@0 268 typedef const eT* const_slice_iterator;
max@0 269
max@0 270 inline iterator begin();
max@0 271 inline const_iterator begin() const;
max@0 272
max@0 273 inline iterator end();
max@0 274 inline const_iterator end() const;
max@0 275
max@0 276 inline slice_iterator begin_slice(const uword slice_num);
max@0 277 inline const_slice_iterator begin_slice(const uword slice_num) const;
max@0 278
max@0 279 inline slice_iterator end_slice(const uword slice_num);
max@0 280 inline const_slice_iterator end_slice(const uword slice_num) const;
max@0 281
max@0 282
max@0 283 template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
max@0 284 class fixed : public Cube<eT>
max@0 285 {
max@0 286 private:
max@0 287
max@0 288 static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices;
max@0 289
max@0 290 arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
max@0 291 arma_aligned eT mem_local_extra [ (fixed_n_elem > Cube_prealloc::mem_n_elem) ? fixed_n_elem : 1 ];
max@0 292
max@0 293 arma_inline void mem_setup();
max@0 294
max@0 295
max@0 296 public:
max@0 297
max@0 298 inline fixed() { mem_setup(); }
max@0 299
max@0 300 inline const Cube& operator=(const eT val) { mem_setup(); Cube<eT>::operator=(val); return *this; }
max@0 301
max@0 302 template<typename T1>
max@0 303 inline fixed(const BaseCube<eT,T1>& A) { mem_setup(); Cube<eT>::operator=(A.get_ref()); }
max@0 304
max@0 305 template<typename T1>
max@0 306 inline const Cube& operator=(const BaseCube<eT,T1>& A) { Cube<eT>::operator=(A.get_ref()); return *this; }
max@0 307
max@0 308 template<typename T1, typename T2>
max@0 309 inline explicit fixed(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B) { mem_setup(); Cube<eT>::init(A,B); }
max@0 310 };
max@0 311
max@0 312
max@0 313 protected:
max@0 314
max@0 315 inline void init_cold();
max@0 316 inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices);
max@0 317
max@0 318 template<typename T1, typename T2>
max@0 319 inline void init(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
max@0 320
max@0 321 inline void steal_mem(Cube& X);
max@0 322
max@0 323 inline void delete_mat();
max@0 324 inline void create_mat();
max@0 325
max@0 326 friend class glue_join;
max@0 327 friend class op_reshape;
max@0 328 friend class op_resize;
max@0 329
max@0 330
max@0 331 public:
max@0 332
max@0 333 #ifdef ARMA_EXTRA_CUBE_PROTO
max@0 334 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO)
max@0 335 #endif
max@0 336 };
max@0 337
max@0 338
max@0 339
max@0 340 class Cube_aux
max@0 341 {
max@0 342 public:
max@0 343
max@0 344 template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
max@0 345 template<typename T> arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
max@0 346
max@0 347 template<typename eT> arma_inline static void postfix_pp(Cube<eT>& x);
max@0 348 template<typename T> arma_inline static void postfix_pp(Cube< std::complex<T> >& x);
max@0 349
max@0 350 template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
max@0 351 template<typename T> arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
max@0 352
max@0 353 template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
max@0 354 template<typename T> arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
max@0 355
max@0 356 template<typename eT, typename T1> inline static void set_real(Cube<eT>& out, const BaseCube<eT,T1>& X);
max@0 357 template<typename eT, typename T1> inline static void set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X);
max@0 358
max@0 359 template<typename T, typename T1> inline static void set_real(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
max@0 360 template<typename T, typename T1> inline static void set_imag(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
max@0 361 };
max@0 362
max@0 363
max@0 364
max@0 365 //! @}