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 Col 20 //! @{ 21 22 //! Class for column vectors (matrices with only one column) 23 24 template<typename eT> 25 class Col : 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 = true; 33 static constexpr bool is_row = false; 34 static constexpr bool is_xvec = false; 35 36 inline Col(); 37 inline Col(const Col<eT>& X); 38 39 inline explicit Col(const uword n_elem); 40 inline explicit Col(const uword in_rows, const uword in_cols); 41 inline explicit Col(const SizeMat& s); 42 43 template<bool do_zeros> inline explicit Col(const uword n_elem, const arma_initmode_indicator<do_zeros>&); 44 template<bool do_zeros> inline explicit Col(const uword in_rows, const uword in_cols, const arma_initmode_indicator<do_zeros>&); 45 template<bool do_zeros> inline explicit Col(const SizeMat& s, const arma_initmode_indicator<do_zeros>&); 46 47 template<typename fill_type> inline Col(const uword n_elem, const fill::fill_class<fill_type>& f); 48 template<typename fill_type> inline Col(const uword in_rows, const uword in_cols, const fill::fill_class<fill_type>& f); 49 template<typename fill_type> inline Col(const SizeMat& s, const fill::fill_class<fill_type>& f); 50 51 inline Col(const uword N, const fill::scalar_holder<eT> f); 52 inline Col(const uword in_rows, const uword in_cols, const fill::scalar_holder<eT> f); 53 inline Col(const SizeMat& s, const fill::scalar_holder<eT> f); 54 55 inline Col(const char* text); 56 inline Col& operator=(const char* text); 57 58 inline Col(const std::string& text); 59 inline Col& operator=(const std::string& text); 60 61 inline Col(const std::vector<eT>& x); 62 inline Col& operator=(const std::vector<eT>& x); 63 64 inline Col(const std::initializer_list<eT>& list); 65 inline Col& operator=(const std::initializer_list<eT>& list); 66 67 inline Col(Col&& m); 68 inline Col& operator=(Col&& m); 69 70 inline Col& operator=(const eT val); 71 inline Col& operator=(const Col& m); 72 73 template<typename T1> inline Col(const Base<eT,T1>& X); 74 template<typename T1> inline Col& operator=(const Base<eT,T1>& X); 75 76 template<typename T1> inline explicit Col(const SpBase<eT,T1>& X); 77 template<typename T1> inline Col& operator=(const SpBase<eT,T1>& X); 78 79 inline Col( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = false); 80 inline Col(const eT* aux_mem, const uword aux_length); 81 82 template<typename T1, typename T2> 83 inline explicit Col(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B); 84 85 template<typename T1> inline Col(const BaseCube<eT,T1>& X); 86 template<typename T1> inline Col& operator=(const BaseCube<eT,T1>& X); 87 88 inline Col(const subview_cube<eT>& X); 89 inline Col& operator=(const subview_cube<eT>& X); 90 91 arma_cold inline mat_injector<Col> operator<<(const eT val); 92 93 arma_inline arma_warn_unused const Op<Col<eT>,op_htrans> t() const; 94 arma_inline arma_warn_unused const Op<Col<eT>,op_htrans> ht() const; 95 arma_inline arma_warn_unused const Op<Col<eT>,op_strans> st() const; 96 97 arma_inline arma_warn_unused const Op<Col<eT>,op_strans> as_row() const; 98 99 arma_inline subview_col<eT> row(const uword row_num); 100 arma_inline const subview_col<eT> row(const uword row_num) const; 101 102 using Mat<eT>::rows; 103 using Mat<eT>::operator(); 104 105 arma_inline subview_col<eT> rows(const uword in_row1, const uword in_row2); 106 arma_inline const subview_col<eT> rows(const uword in_row1, const uword in_row2) const; 107 108 arma_inline subview_col<eT> subvec(const uword in_row1, const uword in_row2); 109 arma_inline const subview_col<eT> subvec(const uword in_row1, const uword in_row2) const; 110 111 arma_inline subview_col<eT> rows(const span& row_span); 112 arma_inline const subview_col<eT> rows(const span& row_span) const; 113 114 arma_inline subview_col<eT> subvec(const span& row_span); 115 arma_inline const subview_col<eT> subvec(const span& row_span) const; 116 117 arma_inline subview_col<eT> operator()(const span& row_span); 118 arma_inline const subview_col<eT> operator()(const span& row_span) const; 119 120 arma_inline subview_col<eT> subvec(const uword start_row, const SizeMat& s); 121 arma_inline const subview_col<eT> subvec(const uword start_row, const SizeMat& s) const; 122 123 arma_inline subview_col<eT> head(const uword N); 124 arma_inline const subview_col<eT> head(const uword N) const; 125 126 arma_inline subview_col<eT> tail(const uword N); 127 arma_inline const subview_col<eT> tail(const uword N) const; 128 129 arma_inline subview_col<eT> head_rows(const uword N); 130 arma_inline const subview_col<eT> head_rows(const uword N) const; 131 132 arma_inline subview_col<eT> tail_rows(const uword N); 133 arma_inline const subview_col<eT> tail_rows(const uword N) const; 134 135 136 inline void shed_row (const uword row_num); 137 inline void shed_rows(const uword in_row1, const uword in_row2); 138 139 template<typename T1> inline void shed_rows(const Base<uword, T1>& indices); 140 141 inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); 142 template<typename T1> inline void insert_rows(const uword row_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 Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); 168 169 170 public: 171 172 #ifdef ARMA_EXTRA_COL_PROTO 173 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_PROTO) 174 #endif 175 }; 176 177 178 179 template<typename eT> 180 template<uword fixed_n_elem> 181 class Col<eT>::fixed : public Col<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> Col_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 = true; 198 static constexpr bool is_row = false; 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 Col& operator=(const Base<eT,T1>& A); 220 221 inline Col& operator=(const eT val); 222 inline Col& operator=(const char* text); 223 inline Col& operator=(const std::string& text); 224 inline Col& operator=(const subview_cube<eT>& X); 225 226 using Col<eT>::operator(); 227 228 inline fixed(const std::initializer_list<eT>& list); 229 inline Col& operator=(const std::initializer_list<eT>& list); 230 231 arma_inline Col& operator=(const fixed<fixed_n_elem>& X); 232 233 #if defined(ARMA_GOOD_COMPILER) 234 template<typename T1, typename eop_type> inline Col& operator=(const eOp<T1, eop_type>& X); 235 template<typename T1, typename T2, typename eglue_type> inline Col& operator=(const eGlue<T1, T2, eglue_type>& X); 236 #endif 237 238 arma_inline arma_warn_unused const Op< Col_fixed_type, op_htrans > t() const; 239 arma_inline arma_warn_unused const Op< Col_fixed_type, op_htrans > ht() const; 240 arma_inline arma_warn_unused const Op< Col_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 Col<eT>& fill(const eT val); 260 arma_hot inline const Col<eT>& zeros(); 261 arma_hot inline const Col<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 Col<eT>::fixed<fixed_n_elem>::n_rows = fixed_n_elem; 272 273 template<typename eT> 274 template<uword fixed_n_elem> 275 const uword Col<eT>::fixed<fixed_n_elem>::n_cols = 1u; 276 277 template<typename eT> 278 template<uword fixed_n_elem> 279 const uword Col<eT>::fixed<fixed_n_elem>::n_elem = fixed_n_elem; 280 281 282 283 //! @} 284