subview_cube_bones.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 subview_cube
  16. //! @{
  17. //! Class for storing data required to construct or apply operations to a subcube
  18. //! (i.e. where the subcube starts and ends as well as a reference/pointer to the original cube),
  19. template<typename eT>
  20. class subview_cube : public BaseCube<eT, subview_cube<eT> >
  21. {
  22. public:
  23. typedef eT elem_type;
  24. typedef typename get_pod_type<elem_type>::result pod_type;
  25. arma_aligned const Cube<eT>& m;
  26. const uword aux_row1;
  27. const uword aux_col1;
  28. const uword aux_slice1;
  29. const uword n_rows;
  30. const uword n_cols;
  31. const uword n_elem_slice;
  32. const uword n_slices;
  33. const uword n_elem;
  34. protected:
  35. arma_inline subview_cube(const Cube<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices);
  36. public:
  37. inline ~subview_cube();
  38. inline void operator= (const eT val);
  39. inline void operator+= (const eT val);
  40. inline void operator-= (const eT val);
  41. inline void operator*= (const eT val);
  42. inline void operator/= (const eT val);
  43. // deliberately returning void
  44. template<typename T1> inline void operator= (const BaseCube<eT,T1>& x);
  45. template<typename T1> inline void operator+= (const BaseCube<eT,T1>& x);
  46. template<typename T1> inline void operator-= (const BaseCube<eT,T1>& x);
  47. template<typename T1> inline void operator%= (const BaseCube<eT,T1>& x);
  48. template<typename T1> inline void operator/= (const BaseCube<eT,T1>& x);
  49. inline void operator= (const subview_cube& x);
  50. inline void operator+= (const subview_cube& x);
  51. inline void operator-= (const subview_cube& x);
  52. inline void operator%= (const subview_cube& x);
  53. inline void operator/= (const subview_cube& x);
  54. template<typename T1> inline void operator= (const Base<eT,T1>& x);
  55. template<typename T1> inline void operator+= (const Base<eT,T1>& x);
  56. template<typename T1> inline void operator-= (const Base<eT,T1>& x);
  57. template<typename T1> inline void operator%= (const Base<eT,T1>& x);
  58. template<typename T1> inline void operator/= (const Base<eT,T1>& x);
  59. template<typename gen_type> inline void operator=(const GenCube<eT,gen_type>& x);
  60. inline static void extract(Cube<eT>& out, const subview_cube& in);
  61. inline static void plus_inplace(Cube<eT>& out, const subview_cube& in);
  62. inline static void minus_inplace(Cube<eT>& out, const subview_cube& in);
  63. inline static void schur_inplace(Cube<eT>& out, const subview_cube& in);
  64. inline static void div_inplace(Cube<eT>& out, const subview_cube& in);
  65. inline static void extract(Mat<eT>& out, const subview_cube& in);
  66. inline static void plus_inplace(Mat<eT>& out, const subview_cube& in);
  67. inline static void minus_inplace(Mat<eT>& out, const subview_cube& in);
  68. inline static void schur_inplace(Mat<eT>& out, const subview_cube& in);
  69. inline static void div_inplace(Mat<eT>& out, const subview_cube& in);
  70. template<typename functor> inline void for_each(functor F);
  71. template<typename functor> inline void for_each(functor F) const;
  72. template<typename functor> inline void transform(functor F);
  73. template<typename functor> inline void imbue(functor F);
  74. #if defined(ARMA_USE_CXX11)
  75. inline void each_slice(const std::function< void( Mat<eT>&) >& F);
  76. inline void each_slice(const std::function< void(const Mat<eT>&) >& F) const;
  77. #endif
  78. inline void replace(const eT old_val, const eT new_val);
  79. inline void clean(const pod_type threshold);
  80. inline void fill(const eT val);
  81. inline void zeros();
  82. inline void ones();
  83. inline void randu();
  84. inline void randn();
  85. inline arma_warn_unused bool is_finite() const;
  86. inline arma_warn_unused bool is_zero(const pod_type tol = 0) const;
  87. inline arma_warn_unused bool has_inf() const;
  88. inline arma_warn_unused bool has_nan() const;
  89. inline eT at_alt (const uword i) const;
  90. inline eT& operator[](const uword i);
  91. inline eT operator[](const uword i) const;
  92. inline eT& operator()(const uword i);
  93. inline eT operator()(const uword i) const;
  94. arma_inline eT& operator()(const uword in_row, const uword in_col, const uword in_slice);
  95. arma_inline eT operator()(const uword in_row, const uword in_col, const uword in_slice) const;
  96. arma_inline eT& at(const uword in_row, const uword in_col, const uword in_slice);
  97. arma_inline eT at(const uword in_row, const uword in_col, const uword in_slice) const;
  98. arma_inline eT* slice_colptr(const uword in_slice, const uword in_col);
  99. arma_inline const eT* slice_colptr(const uword in_slice, const uword in_col) const;
  100. inline bool check_overlap(const subview_cube& x) const;
  101. inline bool check_overlap(const Mat<eT>& x) const;
  102. class const_iterator;
  103. class iterator
  104. {
  105. public:
  106. inline iterator();
  107. inline iterator(const iterator& X);
  108. inline iterator(subview_cube<eT>& in_sv, const uword in_row, const uword in_col, const uword in_slice);
  109. inline arma_warn_unused eT& operator*();
  110. inline iterator& operator++();
  111. inline arma_warn_unused iterator operator++(int);
  112. inline arma_warn_unused bool operator==(const iterator& rhs) const;
  113. inline arma_warn_unused bool operator!=(const iterator& rhs) const;
  114. inline arma_warn_unused bool operator==(const const_iterator& rhs) const;
  115. inline arma_warn_unused bool operator!=(const const_iterator& rhs) const;
  116. typedef std::forward_iterator_tag iterator_category;
  117. typedef eT value_type;
  118. typedef std::ptrdiff_t difference_type; // TODO: not certain on this one
  119. typedef eT* pointer;
  120. typedef eT& reference;
  121. arma_aligned Cube<eT>* M;
  122. arma_aligned eT* current_ptr;
  123. arma_aligned uword current_row;
  124. arma_aligned uword current_col;
  125. arma_aligned uword current_slice;
  126. arma_aligned const uword aux_row1;
  127. arma_aligned const uword aux_col1;
  128. arma_aligned const uword aux_row2_p1;
  129. arma_aligned const uword aux_col2_p1;
  130. };
  131. class const_iterator
  132. {
  133. public:
  134. inline const_iterator();
  135. inline const_iterator(const iterator& X);
  136. inline const_iterator(const const_iterator& X);
  137. inline const_iterator(const subview_cube<eT>& in_sv, const uword in_row, const uword in_col, const uword in_slice);
  138. inline arma_warn_unused const eT& operator*();
  139. inline const_iterator& operator++();
  140. inline arma_warn_unused const_iterator operator++(int);
  141. inline arma_warn_unused bool operator==(const iterator& rhs) const;
  142. inline arma_warn_unused bool operator!=(const iterator& rhs) const;
  143. inline arma_warn_unused bool operator==(const const_iterator& rhs) const;
  144. inline arma_warn_unused bool operator!=(const const_iterator& rhs) const;
  145. // So that we satisfy the STL iterator types.
  146. typedef std::forward_iterator_tag iterator_category;
  147. typedef eT value_type;
  148. typedef std::ptrdiff_t difference_type; // TODO: not certain on this one
  149. typedef const eT* pointer;
  150. typedef const eT& reference;
  151. arma_aligned const Cube<eT>* M;
  152. arma_aligned const eT* current_ptr;
  153. arma_aligned uword current_row;
  154. arma_aligned uword current_col;
  155. arma_aligned uword current_slice;
  156. arma_aligned const uword aux_row1;
  157. arma_aligned const uword aux_col1;
  158. arma_aligned const uword aux_row2_p1;
  159. arma_aligned const uword aux_col2_p1;
  160. };
  161. inline iterator begin();
  162. inline const_iterator begin() const;
  163. inline const_iterator cbegin() const;
  164. inline iterator end();
  165. inline const_iterator end() const;
  166. inline const_iterator cend() const;
  167. private:
  168. friend class Mat<eT>;
  169. friend class Cube<eT>;
  170. subview_cube();
  171. };
  172. //! @}