Cube_bones.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup Cube
  16. //! @{
  17. struct Cube_prealloc
  18. {
  19. static const uword mat_ptrs_size = 4;
  20. static const uword mem_n_elem = 64;
  21. };
  22. //! Dense cube class
  23. template<typename eT>
  24. class Cube : public BaseCube< eT, Cube<eT> >
  25. {
  26. public:
  27. typedef eT elem_type; //!< the type of elements stored in the cube
  28. typedef typename get_pod_type<eT>::result pod_type; //!< if eT is std::complex<T>, pod_type is T; otherwise pod_type is eT
  29. const uword n_rows; //!< number of rows in each slice (read-only)
  30. const uword n_cols; //!< number of columns in each slice (read-only)
  31. const uword n_elem_slice; //!< number of elements in each slice (read-only)
  32. const uword n_slices; //!< number of slices in the cube (read-only)
  33. const uword n_elem; //!< number of elements in the cube (read-only)
  34. const uword mem_state;
  35. // mem_state = 0: normal cube which manages its own memory
  36. // mem_state = 1: use auxiliary memory until a size change
  37. // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed
  38. // mem_state = 3: fixed size (eg. via template based size specification)
  39. arma_aligned const eT* const mem; //!< pointer to the memory used for storing elements (memory is read-only)
  40. protected:
  41. arma_aligned const Mat<eT>** const mat_ptrs;
  42. arma_align_mem Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ];
  43. arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; // local storage, for small cubes
  44. public:
  45. inline ~Cube();
  46. inline Cube();
  47. inline explicit Cube(const uword in_rows, const uword in_cols, const uword in_slices);
  48. inline explicit Cube(const SizeCube& s);
  49. template<typename fill_type> inline Cube(const uword in_rows, const uword in_cols, const uword in_slices, const fill::fill_class<fill_type>& f);
  50. template<typename fill_type> inline Cube(const SizeCube& s, const fill::fill_class<fill_type>& f);
  51. #if defined(ARMA_USE_CXX11)
  52. inline Cube(Cube&& m);
  53. inline Cube& operator=(Cube&& m);
  54. #endif
  55. 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 = false, const bool prealloc_mat = false);
  56. inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices);
  57. inline Cube& operator=(const eT val);
  58. inline Cube& operator+=(const eT val);
  59. inline Cube& operator-=(const eT val);
  60. inline Cube& operator*=(const eT val);
  61. inline Cube& operator/=(const eT val);
  62. inline Cube(const Cube& m);
  63. inline Cube& operator=(const Cube& m);
  64. inline Cube& operator+=(const Cube& m);
  65. inline Cube& operator-=(const Cube& m);
  66. inline Cube& operator%=(const Cube& m);
  67. inline Cube& operator/=(const Cube& m);
  68. template<typename T1, typename T2>
  69. inline explicit Cube(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
  70. inline Cube(const subview_cube<eT>& X);
  71. inline Cube& operator=(const subview_cube<eT>& X);
  72. inline Cube& operator+=(const subview_cube<eT>& X);
  73. inline Cube& operator-=(const subview_cube<eT>& X);
  74. inline Cube& operator%=(const subview_cube<eT>& X);
  75. inline Cube& operator/=(const subview_cube<eT>& X);
  76. template<typename T1> inline Cube(const subview_cube_slices<eT,T1>& X);
  77. template<typename T1> inline Cube& operator=(const subview_cube_slices<eT,T1>& X);
  78. template<typename T1> inline Cube& operator+=(const subview_cube_slices<eT,T1>& X);
  79. template<typename T1> inline Cube& operator-=(const subview_cube_slices<eT,T1>& X);
  80. template<typename T1> inline Cube& operator%=(const subview_cube_slices<eT,T1>& X);
  81. template<typename T1> inline Cube& operator/=(const subview_cube_slices<eT,T1>& X);
  82. arma_inline subview_cube<eT> row(const uword in_row);
  83. arma_inline const subview_cube<eT> row(const uword in_row) const;
  84. arma_inline subview_cube<eT> col(const uword in_col);
  85. arma_inline const subview_cube<eT> col(const uword in_col) const;
  86. inline Mat<eT>& slice(const uword in_slice);
  87. inline const Mat<eT>& slice(const uword in_slice) const;
  88. arma_inline subview_cube<eT> rows(const uword in_row1, const uword in_row2);
  89. arma_inline const subview_cube<eT> rows(const uword in_row1, const uword in_row2) const;
  90. arma_inline subview_cube<eT> cols(const uword in_col1, const uword in_col2);
  91. arma_inline const subview_cube<eT> cols(const uword in_col1, const uword in_col2) const;
  92. arma_inline subview_cube<eT> slices(const uword in_slice1, const uword in_slice2);
  93. arma_inline const subview_cube<eT> slices(const uword in_slice1, const uword in_slice2) const;
  94. 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);
  95. 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;
  96. inline subview_cube<eT> subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s);
  97. inline const subview_cube<eT> subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const;
  98. inline subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span);
  99. inline const subview_cube<eT> subcube(const span& row_span, const span& col_span, const span& slice_span) const;
  100. inline subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span);
  101. inline const subview_cube<eT> operator()(const span& row_span, const span& col_span, const span& slice_span) const;
  102. inline subview_cube<eT> operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s);
  103. inline const subview_cube<eT> operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const;
  104. arma_inline subview_cube<eT> tube(const uword in_row1, const uword in_col1);
  105. arma_inline const subview_cube<eT> tube(const uword in_row1, const uword in_col1) const;
  106. arma_inline subview_cube<eT> tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2);
  107. arma_inline const subview_cube<eT> tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const;
  108. arma_inline subview_cube<eT> tube(const uword in_row1, const uword in_col1, const SizeMat& s);
  109. arma_inline const subview_cube<eT> tube(const uword in_row1, const uword in_col1, const SizeMat& s) const;
  110. inline subview_cube<eT> tube(const span& row_span, const span& col_span);
  111. inline const subview_cube<eT> tube(const span& row_span, const span& col_span) const;
  112. inline subview_cube<eT> head_slices(const uword N);
  113. inline const subview_cube<eT> head_slices(const uword N) const;
  114. inline subview_cube<eT> tail_slices(const uword N);
  115. inline const subview_cube<eT> tail_slices(const uword N) const;
  116. template<typename T1> arma_inline subview_elem1<eT,T1> elem(const Base<uword,T1>& a);
  117. template<typename T1> arma_inline const subview_elem1<eT,T1> elem(const Base<uword,T1>& a) const;
  118. template<typename T1> arma_inline subview_elem1<eT,T1> operator()(const Base<uword,T1>& a);
  119. template<typename T1> arma_inline const subview_elem1<eT,T1> operator()(const Base<uword,T1>& a) const;
  120. arma_inline subview_cube_each1<eT> each_slice();
  121. arma_inline const subview_cube_each1<eT> each_slice() const;
  122. template<typename T1> inline subview_cube_each2<eT, T1> each_slice(const Base<uword, T1>& indices);
  123. template<typename T1> inline const subview_cube_each2<eT, T1> each_slice(const Base<uword, T1>& indices) const;
  124. #if defined(ARMA_USE_CXX11)
  125. inline const Cube& each_slice(const std::function< void( Mat<eT>&) >& F);
  126. inline const Cube& each_slice(const std::function< void(const Mat<eT>&) >& F) const;
  127. inline const Cube& each_slice(const std::function< void( Mat<eT>&) >& F, const bool use_mp);
  128. inline const Cube& each_slice(const std::function< void(const Mat<eT>&) >& F, const bool use_mp) const;
  129. #endif
  130. template<typename T1> arma_inline subview_cube_slices<eT,T1> slices(const Base<uword,T1>& indices);
  131. template<typename T1> arma_inline const subview_cube_slices<eT,T1> slices(const Base<uword,T1>& indices) const;
  132. inline void shed_row(const uword row_num);
  133. inline void shed_col(const uword col_num);
  134. inline void shed_slice(const uword slice_num);
  135. inline void shed_rows(const uword in_row1, const uword in_row2);
  136. inline void shed_cols(const uword in_col1, const uword in_col2);
  137. inline void shed_slices(const uword in_slice1, const uword in_slice2);
  138. template<typename T1> inline void shed_slices(const Base<uword, T1>& indices);
  139. inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true);
  140. inline void insert_cols(const uword row_num, const uword N, const bool set_to_zero = true);
  141. inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true);
  142. template<typename T1> inline void insert_rows(const uword row_num, const BaseCube<eT,T1>& X);
  143. template<typename T1> inline void insert_cols(const uword col_num, const BaseCube<eT,T1>& X);
  144. template<typename T1> inline void insert_slices(const uword slice_num, const BaseCube<eT,T1>& X);
  145. template<typename gen_type> inline Cube(const GenCube<eT, gen_type>& X);
  146. template<typename gen_type> inline Cube& operator=(const GenCube<eT, gen_type>& X);
  147. template<typename gen_type> inline Cube& operator+=(const GenCube<eT, gen_type>& X);
  148. template<typename gen_type> inline Cube& operator-=(const GenCube<eT, gen_type>& X);
  149. template<typename gen_type> inline Cube& operator%=(const GenCube<eT, gen_type>& X);
  150. template<typename gen_type> inline Cube& operator/=(const GenCube<eT, gen_type>& X);
  151. template<typename T1, typename op_type> inline Cube(const OpCube<T1, op_type>& X);
  152. template<typename T1, typename op_type> inline Cube& operator=(const OpCube<T1, op_type>& X);
  153. template<typename T1, typename op_type> inline Cube& operator+=(const OpCube<T1, op_type>& X);
  154. template<typename T1, typename op_type> inline Cube& operator-=(const OpCube<T1, op_type>& X);
  155. template<typename T1, typename op_type> inline Cube& operator%=(const OpCube<T1, op_type>& X);
  156. template<typename T1, typename op_type> inline Cube& operator/=(const OpCube<T1, op_type>& X);
  157. template<typename T1, typename eop_type> inline Cube(const eOpCube<T1, eop_type>& X);
  158. template<typename T1, typename eop_type> inline Cube& operator=(const eOpCube<T1, eop_type>& X);
  159. template<typename T1, typename eop_type> inline Cube& operator+=(const eOpCube<T1, eop_type>& X);
  160. template<typename T1, typename eop_type> inline Cube& operator-=(const eOpCube<T1, eop_type>& X);
  161. template<typename T1, typename eop_type> inline Cube& operator%=(const eOpCube<T1, eop_type>& X);
  162. template<typename T1, typename eop_type> inline Cube& operator/=(const eOpCube<T1, eop_type>& X);
  163. template<typename T1, typename op_type> inline Cube(const mtOpCube<eT, T1, op_type>& X);
  164. template<typename T1, typename op_type> inline Cube& operator=(const mtOpCube<eT, T1, op_type>& X);
  165. template<typename T1, typename op_type> inline Cube& operator+=(const mtOpCube<eT, T1, op_type>& X);
  166. template<typename T1, typename op_type> inline Cube& operator-=(const mtOpCube<eT, T1, op_type>& X);
  167. template<typename T1, typename op_type> inline Cube& operator%=(const mtOpCube<eT, T1, op_type>& X);
  168. template<typename T1, typename op_type> inline Cube& operator/=(const mtOpCube<eT, T1, op_type>& X);
  169. template<typename T1, typename T2, typename glue_type> inline Cube(const GlueCube<T1, T2, glue_type>& X);
  170. template<typename T1, typename T2, typename glue_type> inline Cube& operator=(const GlueCube<T1, T2, glue_type>& X);
  171. template<typename T1, typename T2, typename glue_type> inline Cube& operator+=(const GlueCube<T1, T2, glue_type>& X);
  172. template<typename T1, typename T2, typename glue_type> inline Cube& operator-=(const GlueCube<T1, T2, glue_type>& X);
  173. template<typename T1, typename T2, typename glue_type> inline Cube& operator%=(const GlueCube<T1, T2, glue_type>& X);
  174. template<typename T1, typename T2, typename glue_type> inline Cube& operator/=(const GlueCube<T1, T2, glue_type>& X);
  175. template<typename T1, typename T2, typename eglue_type> inline Cube(const eGlueCube<T1, T2, eglue_type>& X);
  176. template<typename T1, typename T2, typename eglue_type> inline Cube& operator=(const eGlueCube<T1, T2, eglue_type>& X);
  177. template<typename T1, typename T2, typename eglue_type> inline Cube& operator+=(const eGlueCube<T1, T2, eglue_type>& X);
  178. template<typename T1, typename T2, typename eglue_type> inline Cube& operator-=(const eGlueCube<T1, T2, eglue_type>& X);
  179. template<typename T1, typename T2, typename eglue_type> inline Cube& operator%=(const eGlueCube<T1, T2, eglue_type>& X);
  180. template<typename T1, typename T2, typename eglue_type> inline Cube& operator/=(const eGlueCube<T1, T2, eglue_type>& X);
  181. template<typename T1, typename T2, typename glue_type> inline Cube(const mtGlueCube<eT, T1, T2, glue_type>& X);
  182. template<typename T1, typename T2, typename glue_type> inline Cube& operator=(const mtGlueCube<eT, T1, T2, glue_type>& X);
  183. template<typename T1, typename T2, typename glue_type> inline Cube& operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X);
  184. template<typename T1, typename T2, typename glue_type> inline Cube& operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X);
  185. template<typename T1, typename T2, typename glue_type> inline Cube& operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X);
  186. template<typename T1, typename T2, typename glue_type> inline Cube& operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X);
  187. arma_inline arma_warn_unused const eT& at_alt (const uword i) const;
  188. arma_inline arma_warn_unused eT& operator[] (const uword i);
  189. arma_inline arma_warn_unused const eT& operator[] (const uword i) const;
  190. arma_inline arma_warn_unused eT& at(const uword i);
  191. arma_inline arma_warn_unused const eT& at(const uword i) const;
  192. arma_inline arma_warn_unused eT& operator() (const uword i);
  193. arma_inline arma_warn_unused const eT& operator() (const uword i) const;
  194. arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice);
  195. arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const;
  196. arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice);
  197. arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const;
  198. arma_inline const Cube& operator++();
  199. arma_inline void operator++(int);
  200. arma_inline const Cube& operator--();
  201. arma_inline void operator--(int);
  202. inline arma_warn_unused bool is_finite() const;
  203. arma_inline arma_warn_unused bool is_empty() const;
  204. inline arma_warn_unused bool has_inf() const;
  205. inline arma_warn_unused bool has_nan() const;
  206. arma_inline arma_warn_unused bool in_range(const uword i) const;
  207. arma_inline arma_warn_unused bool in_range(const span& x) const;
  208. arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const;
  209. inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const;
  210. inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const;
  211. arma_inline arma_warn_unused eT* memptr();
  212. arma_inline arma_warn_unused const eT* memptr() const;
  213. arma_inline arma_warn_unused eT* slice_memptr(const uword slice);
  214. arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const;
  215. arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col);
  216. arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const;
  217. arma_cold inline void impl_print( const std::string& extra_text) const;
  218. arma_cold inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const;
  219. arma_cold inline void impl_raw_print( const std::string& extra_text) const;
  220. arma_cold inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const;
  221. inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices);
  222. inline void set_size(const SizeCube& s);
  223. inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices);
  224. inline void reshape(const SizeCube& s);
  225. inline void resize(const uword in_rows, const uword in_cols, const uword in_slices);
  226. inline void resize(const SizeCube& s);
  227. arma_deprecated inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim); //!< NOTE: don't use this form: it will be removed
  228. template<typename eT2> inline void copy_size(const Cube<eT2>& m);
  229. template<typename functor> inline const Cube& for_each(functor F);
  230. template<typename functor> inline const Cube& for_each(functor F) const;
  231. template<typename functor> inline const Cube& transform(functor F);
  232. template<typename functor> inline const Cube& imbue(functor F);
  233. inline const Cube& replace(const eT old_val, const eT new_val);
  234. inline const Cube& clean(const pod_type threshold);
  235. inline const Cube& fill(const eT val);
  236. inline const Cube& zeros();
  237. inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices);
  238. inline const Cube& zeros(const SizeCube& s);
  239. inline const Cube& ones();
  240. inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices);
  241. inline const Cube& ones(const SizeCube& s);
  242. inline const Cube& randu();
  243. inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices);
  244. inline const Cube& randu(const SizeCube& s);
  245. inline const Cube& randn();
  246. inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices);
  247. inline const Cube& randn(const SizeCube& s);
  248. inline void reset();
  249. inline void soft_reset();
  250. template<typename T1> inline void set_real(const BaseCube<pod_type,T1>& X);
  251. template<typename T1> inline void set_imag(const BaseCube<pod_type,T1>& X);
  252. inline arma_warn_unused eT min() const;
  253. inline arma_warn_unused eT max() const;
  254. inline eT min(uword& index_of_min_val) const;
  255. inline eT max(uword& index_of_max_val) const;
  256. inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const;
  257. inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const;
  258. inline arma_cold bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
  259. inline arma_cold bool save(const hdf5_name& spec, const file_type type = hdf5_binary, const bool print_status = true) const;
  260. inline arma_cold bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
  261. inline arma_cold bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true);
  262. inline arma_cold bool load(const hdf5_name& spec, const file_type type = hdf5_binary, const bool print_status = true);
  263. inline arma_cold bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true);
  264. inline arma_cold bool quiet_save(const std::string name, const file_type type = arma_binary) const;
  265. inline arma_cold bool quiet_save(const hdf5_name& spec, const file_type type = hdf5_binary) const;
  266. inline arma_cold bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
  267. inline arma_cold bool quiet_load(const std::string name, const file_type type = auto_detect);
  268. inline arma_cold bool quiet_load(const hdf5_name& spec, const file_type type = hdf5_binary);
  269. inline arma_cold bool quiet_load( std::istream& is, const file_type type = auto_detect);
  270. // iterators
  271. typedef eT* iterator;
  272. typedef const eT* const_iterator;
  273. typedef eT* slice_iterator;
  274. typedef const eT* const_slice_iterator;
  275. inline iterator begin();
  276. inline const_iterator begin() const;
  277. inline const_iterator cbegin() const;
  278. inline iterator end();
  279. inline const_iterator end() const;
  280. inline const_iterator cend() const;
  281. inline slice_iterator begin_slice(const uword slice_num);
  282. inline const_slice_iterator begin_slice(const uword slice_num) const;
  283. inline slice_iterator end_slice(const uword slice_num);
  284. inline const_slice_iterator end_slice(const uword slice_num) const;
  285. inline void clear();
  286. inline bool empty() const;
  287. inline uword size() const;
  288. inline eT& front();
  289. inline const eT& front() const;
  290. inline eT& back();
  291. inline const eT& back() const;
  292. inline void swap(Cube& B);
  293. inline void steal_mem(Cube& X); //!< don't use this unless you're writing code internal to Armadillo
  294. template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices> class fixed;
  295. protected:
  296. inline void init_cold();
  297. inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices);
  298. template<typename T1, typename T2>
  299. inline void init(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
  300. inline void delete_mat();
  301. inline void create_mat();
  302. friend class glue_join;
  303. friend class op_reshape;
  304. friend class op_resize;
  305. friend class subview_cube<eT>;
  306. public:
  307. #ifdef ARMA_EXTRA_CUBE_PROTO
  308. #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO)
  309. #endif
  310. };
  311. template<typename eT>
  312. template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
  313. class Cube<eT>::fixed : public Cube<eT>
  314. {
  315. private:
  316. static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices;
  317. static const uword fixed_n_elem_slice = fixed_n_rows * fixed_n_cols;
  318. static const bool use_extra = (fixed_n_elem > Cube_prealloc::mem_n_elem);
  319. arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
  320. arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ];
  321. arma_inline void mem_setup();
  322. public:
  323. inline fixed();
  324. inline fixed(const fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>& X);
  325. template<typename fill_type> inline fixed(const fill::fill_class<fill_type>& f);
  326. template<typename T1> inline fixed(const BaseCube<eT,T1>& A);
  327. template<typename T1, typename T2> inline fixed(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B);
  328. using Cube<eT>::operator=;
  329. using Cube<eT>::operator();
  330. inline Cube& operator=(const fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>& X);
  331. arma_inline arma_warn_unused eT& operator[] (const uword i);
  332. arma_inline arma_warn_unused const eT& operator[] (const uword i) const;
  333. arma_inline arma_warn_unused eT& at (const uword i);
  334. arma_inline arma_warn_unused const eT& at (const uword i) const;
  335. arma_inline arma_warn_unused eT& operator() (const uword i);
  336. arma_inline arma_warn_unused const eT& operator() (const uword i) const;
  337. arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice);
  338. arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const;
  339. arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice);
  340. arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const;
  341. };
  342. class Cube_aux
  343. {
  344. public:
  345. template<typename eT> arma_inline static void prefix_pp(Cube<eT>& x);
  346. template<typename T> arma_inline static void prefix_pp(Cube< std::complex<T> >& x);
  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. template<typename eT> arma_inline static void prefix_mm(Cube<eT>& x);
  350. template<typename T> arma_inline static void prefix_mm(Cube< std::complex<T> >& x);
  351. template<typename eT> arma_inline static void postfix_mm(Cube<eT>& x);
  352. template<typename T> arma_inline static void postfix_mm(Cube< std::complex<T> >& x);
  353. template<typename eT, typename T1> inline static void set_real(Cube<eT>& out, const BaseCube<eT,T1>& X);
  354. template<typename eT, typename T1> inline static void set_imag(Cube<eT>& out, const BaseCube<eT,T1>& X);
  355. template<typename T, typename T1> inline static void set_real(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
  356. template<typename T, typename T1> inline static void set_imag(Cube< std::complex<T> >& out, const BaseCube< T,T1>& X);
  357. };
  358. //! @}