Row_bones.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 Row
  16. //! @{
  17. //! Class for row vectors (matrices with only one row)
  18. template<typename eT>
  19. class Row : public Mat<eT>
  20. {
  21. public:
  22. typedef eT elem_type;
  23. typedef typename get_pod_type<eT>::result pod_type;
  24. static const bool is_col = false;
  25. static const bool is_row = true;
  26. static const bool is_xvec = false;
  27. inline Row();
  28. inline Row(const Row<eT>& X);
  29. inline explicit Row(const uword N);
  30. inline explicit Row(const uword in_rows, const uword in_cols);
  31. inline explicit Row(const SizeMat& s);
  32. template<typename fill_type> inline Row(const uword n_elem, const fill::fill_class<fill_type>& f);
  33. template<typename fill_type> inline Row(const uword in_rows, const uword in_cols, const fill::fill_class<fill_type>& f);
  34. template<typename fill_type> inline Row(const SizeMat& s, const fill::fill_class<fill_type>& f);
  35. inline Row(const char* text);
  36. inline Row& operator=(const char* text);
  37. inline Row(const std::string& text);
  38. inline Row& operator=(const std::string& text);
  39. inline Row(const std::vector<eT>& x);
  40. inline Row& operator=(const std::vector<eT>& x);
  41. #if defined(ARMA_USE_CXX11)
  42. inline Row(const std::initializer_list<eT>& list);
  43. inline Row& operator=(const std::initializer_list<eT>& list);
  44. inline Row(Row&& m);
  45. inline Row& operator=(Row&& m);
  46. #endif
  47. inline Row& operator=(const eT val);
  48. inline Row& operator=(const Row& X);
  49. template<typename T1> inline Row(const Base<eT,T1>& X);
  50. template<typename T1> inline Row& operator=(const Base<eT,T1>& X);
  51. template<typename T1> inline explicit Row(const SpBase<eT,T1>& X);
  52. template<typename T1> inline Row& operator=(const SpBase<eT,T1>& X);
  53. inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = false);
  54. inline Row(const eT* aux_mem, const uword aux_length);
  55. template<typename T1, typename T2>
  56. inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
  57. template<typename T1> inline Row(const BaseCube<eT,T1>& X);
  58. template<typename T1> inline Row& operator=(const BaseCube<eT,T1>& X);
  59. inline Row(const subview_cube<eT>& X);
  60. inline Row& operator=(const subview_cube<eT>& X);
  61. inline mat_injector<Row> operator<<(const eT val);
  62. arma_inline const Op<Row<eT>,op_htrans> t() const;
  63. arma_inline const Op<Row<eT>,op_htrans> ht() const;
  64. arma_inline const Op<Row<eT>,op_strans> st() const;
  65. arma_inline const Op<Row<eT>,op_strans> as_col() const;
  66. arma_inline subview_row<eT> col(const uword col_num);
  67. arma_inline const subview_row<eT> col(const uword col_num) const;
  68. using Mat<eT>::cols;
  69. using Mat<eT>::operator();
  70. arma_inline subview_row<eT> cols(const uword in_col1, const uword in_col2);
  71. arma_inline const subview_row<eT> cols(const uword in_col1, const uword in_col2) const;
  72. arma_inline subview_row<eT> subvec(const uword in_col1, const uword in_col2);
  73. arma_inline const subview_row<eT> subvec(const uword in_col1, const uword in_col2) const;
  74. arma_inline subview_row<eT> cols(const span& col_span);
  75. arma_inline const subview_row<eT> cols(const span& col_span) const;
  76. arma_inline subview_row<eT> subvec(const span& col_span);
  77. arma_inline const subview_row<eT> subvec(const span& col_span) const;
  78. arma_inline subview_row<eT> operator()(const span& col_span);
  79. arma_inline const subview_row<eT> operator()(const span& col_span) const;
  80. arma_inline subview_row<eT> subvec(const uword start_col, const SizeMat& s);
  81. arma_inline const subview_row<eT> subvec(const uword start_col, const SizeMat& s) const;
  82. arma_inline subview_row<eT> head(const uword N);
  83. arma_inline const subview_row<eT> head(const uword N) const;
  84. arma_inline subview_row<eT> tail(const uword N);
  85. arma_inline const subview_row<eT> tail(const uword N) const;
  86. arma_inline subview_row<eT> head_cols(const uword N);
  87. arma_inline const subview_row<eT> head_cols(const uword N) const;
  88. arma_inline subview_row<eT> tail_cols(const uword N);
  89. arma_inline const subview_row<eT> tail_cols(const uword N) const;
  90. inline void shed_col (const uword col_num);
  91. inline void shed_cols(const uword in_col1, const uword in_col2);
  92. template<typename T1> inline void shed_cols(const Base<uword, T1>& indices);
  93. inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true);
  94. template<typename T1> inline void insert_cols(const uword col_num, const Base<eT,T1>& X);
  95. arma_inline arma_warn_unused eT& at(const uword i);
  96. arma_inline arma_warn_unused const eT& at(const uword i) const;
  97. arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col);
  98. arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const;
  99. typedef eT* row_iterator;
  100. typedef const eT* const_row_iterator;
  101. inline row_iterator begin_row(const uword row_num);
  102. inline const_row_iterator begin_row(const uword row_num) const;
  103. inline row_iterator end_row (const uword row_num);
  104. inline const_row_iterator end_row (const uword row_num) const;
  105. template<uword fixed_n_elem> class fixed;
  106. protected:
  107. inline Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem);
  108. public:
  109. #ifdef ARMA_EXTRA_ROW_PROTO
  110. #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_PROTO)
  111. #endif
  112. };
  113. template<typename eT>
  114. template<uword fixed_n_elem>
  115. class Row<eT>::fixed : public Row<eT>
  116. {
  117. private:
  118. static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc);
  119. arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ];
  120. public:
  121. typedef fixed<fixed_n_elem> Row_fixed_type;
  122. typedef eT elem_type;
  123. typedef typename get_pod_type<eT>::result pod_type;
  124. static const bool is_col = false;
  125. static const bool is_row = true;
  126. static const bool is_xvec = false;
  127. static const uword n_rows; // value provided below the class definition
  128. static const uword n_cols; // value provided below the class definition
  129. static const uword n_elem; // value provided below the class definition
  130. arma_inline fixed();
  131. arma_inline fixed(const fixed<fixed_n_elem>& X);
  132. inline fixed(const subview_cube<eT>& X);
  133. template<typename fill_type> inline fixed(const fill::fill_class<fill_type>& f);
  134. template<typename T1> inline fixed(const Base<eT,T1>& A);
  135. template<typename T1, typename T2> inline fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B);
  136. inline fixed(const eT* aux_mem);
  137. inline fixed(const char* text);
  138. inline fixed(const std::string& text);
  139. template<typename T1> inline Row& operator=(const Base<eT,T1>& A);
  140. inline Row& operator=(const eT val);
  141. inline Row& operator=(const char* text);
  142. inline Row& operator=(const std::string& text);
  143. inline Row& operator=(const subview_cube<eT>& X);
  144. using Row<eT>::operator();
  145. #if defined(ARMA_USE_CXX11)
  146. inline fixed(const std::initializer_list<eT>& list);
  147. inline Row& operator=(const std::initializer_list<eT>& list);
  148. #endif
  149. arma_inline Row& operator=(const fixed<fixed_n_elem>& X);
  150. #if defined(ARMA_GOOD_COMPILER)
  151. template<typename T1, typename eop_type> inline Row& operator=(const eOp<T1, eop_type>& X);
  152. template<typename T1, typename T2, typename eglue_type> inline Row& operator=(const eGlue<T1, T2, eglue_type>& X);
  153. #endif
  154. arma_inline const Op< Row_fixed_type, op_htrans > t() const;
  155. arma_inline const Op< Row_fixed_type, op_htrans > ht() const;
  156. arma_inline const Op< Row_fixed_type, op_strans > st() const;
  157. arma_inline arma_warn_unused const eT& at_alt (const uword i) const;
  158. arma_inline arma_warn_unused eT& operator[] (const uword i);
  159. arma_inline arma_warn_unused const eT& operator[] (const uword i) const;
  160. arma_inline arma_warn_unused eT& at (const uword i);
  161. arma_inline arma_warn_unused const eT& at (const uword i) const;
  162. arma_inline arma_warn_unused eT& operator() (const uword i);
  163. arma_inline arma_warn_unused const eT& operator() (const uword i) const;
  164. arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col);
  165. arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const;
  166. arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col);
  167. arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const;
  168. arma_inline arma_warn_unused eT* memptr();
  169. arma_inline arma_warn_unused const eT* memptr() const;
  170. arma_hot inline const Row<eT>& fill(const eT val);
  171. arma_hot inline const Row<eT>& zeros();
  172. arma_hot inline const Row<eT>& ones();
  173. };
  174. // these definitions are outside of the class due to bizarre C++ rules;
  175. // C++17 has inline variables to address this shortcoming
  176. template<typename eT>
  177. template<uword fixed_n_elem>
  178. const uword Row<eT>::fixed<fixed_n_elem>::n_rows = 1u;
  179. template<typename eT>
  180. template<uword fixed_n_elem>
  181. const uword Row<eT>::fixed<fixed_n_elem>::n_cols = fixed_n_elem;
  182. template<typename eT>
  183. template<uword fixed_n_elem>
  184. const uword Row<eT>::fixed<fixed_n_elem>::n_elem = fixed_n_elem;
  185. //! @}