1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) 4 // Copyright 2008-2016 National ICT Australia (NICTA) 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ------------------------------------------------------------------------ 17 18 19 //! \addtogroup Row 20 //! @{ 21 22 //! Class for row vectors (matrices with only one row) 23 24 template<typename eT> 25 class Row : public Mat<eT> 26 { 27 public: 28 29 typedef eT elem_type; 30 typedef typename get_pod_type<eT>::result pod_type; 31 32 static constexpr bool is_col = false; 33 static constexpr bool is_row = true; 34 static constexpr bool is_xvec = false; 35 36 inline Row(); 37 inline Row(const Row<eT>& X); 38 39 inline explicit Row(const uword N); 40 inline explicit Row(const uword in_rows, const uword in_cols); 41 inline explicit Row(const SizeMat& s); 42 43 template<bool do_zeros> inline explicit Row(const uword N, const arma_initmode_indicator<do_zeros>&); 44 template<bool do_zeros> inline explicit Row(const uword in_rows, const uword in_cols, const arma_initmode_indicator<do_zeros>&); 45 template<bool do_zeros> inline explicit Row(const SizeMat& s, const arma_initmode_indicator<do_zeros>&); 46 47 template<typename fill_type> inline Row(const uword n_elem, const fill::fill_class<fill_type>& f); 48 template<typename fill_type> inline Row(const uword in_rows, const uword in_cols, const fill::fill_class<fill_type>& f); 49 template<typename fill_type> inline Row(const SizeMat& s, const fill::fill_class<fill_type>& f); 50 51 inline Row(const uword N, const fill::scalar_holder<eT> f); 52 inline Row(const uword in_rows, const uword in_cols, const fill::scalar_holder<eT> f); 53 inline Row(const SizeMat& s, const fill::scalar_holder<eT> f); 54 55 inline Row(const char* text); 56 inline Row& operator=(const char* text); 57 58 inline Row(const std::string& text); 59 inline Row& operator=(const std::string& text); 60 61 inline Row(const std::vector<eT>& x); 62 inline Row& operator=(const std::vector<eT>& x); 63 64 inline Row(const std::initializer_list<eT>& list); 65 inline Row& operator=(const std::initializer_list<eT>& list); 66 67 inline Row(Row&& m); 68 inline Row& operator=(Row&& m); 69 70 inline Row& operator=(const eT val); 71 inline Row& operator=(const Row& X); 72 73 template<typename T1> inline Row(const Base<eT,T1>& X); 74 template<typename T1> inline Row& operator=(const Base<eT,T1>& X); 75 76 template<typename T1> inline explicit Row(const SpBase<eT,T1>& X); 77 template<typename T1> inline Row& operator=(const SpBase<eT,T1>& X); 78 79 inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = false); 80 inline Row(const eT* aux_mem, const uword aux_length); 81 82 template<typename T1, typename T2> 83 inline explicit Row(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); 84 85 template<typename T1> inline Row(const BaseCube<eT,T1>& X); 86 template<typename T1> inline Row& operator=(const BaseCube<eT,T1>& X); 87 88 inline Row(const subview_cube<eT>& X); 89 inline Row& operator=(const subview_cube<eT>& X); 90 91 arma_cold inline mat_injector<Row> operator<<(const eT val); 92 93 arma_inline arma_warn_unused const Op<Row<eT>,op_htrans> t() const; 94 arma_inline arma_warn_unused const Op<Row<eT>,op_htrans> ht() const; 95 arma_inline arma_warn_unused const Op<Row<eT>,op_strans> st() const; 96 97 arma_inline arma_warn_unused const Op<Row<eT>,op_strans> as_col() const; 98 99 arma_inline subview_row<eT> col(const uword col_num); 100 arma_inline const subview_row<eT> col(const uword col_num) const; 101 102 using Mat<eT>::cols; 103 using Mat<eT>::operator(); 104 105 arma_inline subview_row<eT> cols(const uword in_col1, const uword in_col2); 106 arma_inline const subview_row<eT> cols(const uword in_col1, const uword in_col2) const; 107 108 arma_inline subview_row<eT> subvec(const uword in_col1, const uword in_col2); 109 arma_inline const subview_row<eT> subvec(const uword in_col1, const uword in_col2) const; 110 111 arma_inline subview_row<eT> cols(const span& col_span); 112 arma_inline const subview_row<eT> cols(const span& col_span) const; 113 114 arma_inline subview_row<eT> subvec(const span& col_span); 115 arma_inline const subview_row<eT> subvec(const span& col_span) const; 116 117 arma_inline subview_row<eT> operator()(const span& col_span); 118 arma_inline const subview_row<eT> operator()(const span& col_span) const; 119 120 arma_inline subview_row<eT> subvec(const uword start_col, const SizeMat& s); 121 arma_inline const subview_row<eT> subvec(const uword start_col, const SizeMat& s) const; 122 123 arma_inline subview_row<eT> head(const uword N); 124 arma_inline const subview_row<eT> head(const uword N) const; 125 126 arma_inline subview_row<eT> tail(const uword N); 127 arma_inline const subview_row<eT> tail(const uword N) const; 128 129 arma_inline subview_row<eT> head_cols(const uword N); 130 arma_inline const subview_row<eT> head_cols(const uword N) const; 131 132 arma_inline subview_row<eT> tail_cols(const uword N); 133 arma_inline const subview_row<eT> tail_cols(const uword N) const; 134 135 136 inline void shed_col (const uword col_num); 137 inline void shed_cols(const uword in_col1, const uword in_col2); 138 139 template<typename T1> inline void shed_cols(const Base<uword, T1>& indices); 140 141 inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); 142 template<typename T1> inline void insert_cols(const uword col_num, const Base<eT,T1>& X); 143 144 145 arma_inline arma_warn_unused eT& at(const uword i); 146 arma_inline arma_warn_unused const eT& at(const uword i) const; 147 148 arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); 149 arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; 150 151 152 typedef eT* row_iterator; 153 typedef const eT* const_row_iterator; 154 155 inline row_iterator begin_row(const uword row_num); 156 inline const_row_iterator begin_row(const uword row_num) const; 157 158 inline row_iterator end_row (const uword row_num); 159 inline const_row_iterator end_row (const uword row_num) const; 160 161 162 template<uword fixed_n_elem> class fixed; 163 164 165 protected: 166 167 inline Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); 168 169 170 public: 171 172 #ifdef ARMA_EXTRA_ROW_PROTO 173 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_PROTO) 174 #endif 175 }; 176 177 178 179 template<typename eT> 180 template<uword fixed_n_elem> 181 class Row<eT>::fixed : public Row<eT> 182 { 183 private: 184 185 static constexpr bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); 186 187 arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; 188 189 190 public: 191 192 typedef fixed<fixed_n_elem> Row_fixed_type; 193 194 typedef eT elem_type; 195 typedef typename get_pod_type<eT>::result pod_type; 196 197 static constexpr bool is_col = false; 198 static constexpr bool is_row = true; 199 static constexpr bool is_xvec = false; 200 201 static const uword n_rows; // value provided below the class definition 202 static const uword n_cols; // value provided below the class definition 203 static const uword n_elem; // value provided below the class definition 204 205 arma_inline fixed(); 206 arma_inline fixed(const fixed<fixed_n_elem>& X); 207 inline fixed(const subview_cube<eT>& X); 208 209 inline fixed(const fill::scalar_holder<eT> f); 210 template<typename fill_type> inline fixed(const fill::fill_class<fill_type>& f); 211 template<typename T1> inline fixed(const Base<eT,T1>& A); 212 template<typename T1, typename T2> inline fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); 213 214 inline fixed(const eT* aux_mem); 215 216 inline fixed(const char* text); 217 inline fixed(const std::string& text); 218 219 template<typename T1> inline Row& operator=(const Base<eT,T1>& A); 220 221 inline Row& operator=(const eT val); 222 inline Row& operator=(const char* text); 223 inline Row& operator=(const std::string& text); 224 inline Row& operator=(const subview_cube<eT>& X); 225 226 using Row<eT>::operator(); 227 228 inline fixed(const std::initializer_list<eT>& list); 229 inline Row& operator=(const std::initializer_list<eT>& list); 230 231 arma_inline Row& operator=(const fixed<fixed_n_elem>& X); 232 233 #if defined(ARMA_GOOD_COMPILER) 234 template<typename T1, typename eop_type> inline Row& operator=(const eOp<T1, eop_type>& X); 235 template<typename T1, typename T2, typename eglue_type> inline Row& operator=(const eGlue<T1, T2, eglue_type>& X); 236 #endif 237 238 arma_inline arma_warn_unused const Op< Row_fixed_type, op_htrans > t() const; 239 arma_inline arma_warn_unused const Op< Row_fixed_type, op_htrans > ht() const; 240 arma_inline arma_warn_unused const Op< Row_fixed_type, op_strans > st() const; 241 242 arma_inline arma_warn_unused const eT& at_alt (const uword i) const; 243 244 arma_inline arma_warn_unused eT& operator[] (const uword i); 245 arma_inline arma_warn_unused const eT& operator[] (const uword i) const; 246 arma_inline arma_warn_unused eT& at (const uword i); 247 arma_inline arma_warn_unused const eT& at (const uword i) const; 248 arma_inline arma_warn_unused eT& operator() (const uword i); 249 arma_inline arma_warn_unused const eT& operator() (const uword i) const; 250 251 arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); 252 arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; 253 arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); 254 arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; 255 256 arma_inline arma_warn_unused eT* memptr(); 257 arma_inline arma_warn_unused const eT* memptr() const; 258 259 arma_hot inline const Row<eT>& fill(const eT val); 260 arma_hot inline const Row<eT>& zeros(); 261 arma_hot inline const Row<eT>& ones(); 262 }; 263 264 265 266 // these definitions are outside of the class due to bizarre C++ rules; 267 // C++17 has inline variables to address this shortcoming 268 269 template<typename eT> 270 template<uword fixed_n_elem> 271 const uword Row<eT>::fixed<fixed_n_elem>::n_rows = 1u; 272 273 template<typename eT> 274 template<uword fixed_n_elem> 275 const uword Row<eT>::fixed<fixed_n_elem>::n_cols = fixed_n_elem; 276 277 template<typename eT> 278 template<uword fixed_n_elem> 279 const uword Row<eT>::fixed<fixed_n_elem>::n_elem = fixed_n_elem; 280 281 282 283 //! @} 284