$search
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2008-2011 Conrad Sanderson 00003 // Copyright (C) 2011 James Sanders 00004 // 00005 // This file is part of the Armadillo C++ library. 00006 // It is provided without any warranty of fitness 00007 // for any purpose. You can redistribute this file 00008 // and/or modify it under the terms of the GNU 00009 // Lesser General Public License (LGPL) as published 00010 // by the Free Software Foundation, either version 3 00011 // of the License or (at your option) any later version. 00012 // (see http://www.opensource.org/licenses for more info) 00013 00014 00017 00018 00021 template<typename eT> 00022 class subview : public Base<eT, subview<eT> > 00023 { 00024 public: arma_aligned const Mat<eT>& m; 00025 protected: arma_aligned Mat<eT>* m_ptr; 00026 00027 public: 00028 00029 typedef eT elem_type; 00030 typedef typename get_pod_type<elem_type>::result pod_type; 00031 00032 const uword aux_row1; 00033 const uword aux_col1; 00034 00035 const uword n_rows; 00036 const uword n_cols; 00037 const uword n_elem; 00038 00039 00040 protected: 00041 00042 arma_inline subview(const Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); 00043 arma_inline subview( Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); 00044 00045 00046 public: 00047 00048 inline ~subview(); 00049 00050 inline void operator+= (const eT val); 00051 inline void operator-= (const eT val); 00052 inline void operator*= (const eT val); 00053 inline void operator/= (const eT val); 00054 00055 // deliberately returning void 00056 template<typename T1> inline void operator= (const Base<eT,T1>& x); 00057 template<typename T1> inline void operator+= (const Base<eT,T1>& x); 00058 template<typename T1> inline void operator-= (const Base<eT,T1>& x); 00059 template<typename T1> inline void operator%= (const Base<eT,T1>& x); 00060 template<typename T1> inline void operator/= (const Base<eT,T1>& x); 00061 00062 inline void operator= (const subview& x); 00063 inline void operator+= (const subview& x); 00064 inline void operator-= (const subview& x); 00065 inline void operator%= (const subview& x); 00066 inline void operator/= (const subview& x); 00067 00068 inline static void extract(Mat<eT>& out, const subview& in); 00069 00070 inline static void plus_inplace(Mat<eT>& out, const subview& in); 00071 inline static void minus_inplace(Mat<eT>& out, const subview& in); 00072 inline static void schur_inplace(Mat<eT>& out, const subview& in); 00073 inline static void div_inplace(Mat<eT>& out, const subview& in); 00074 00075 inline void fill(const eT val); 00076 inline void zeros(); 00077 inline void ones(); 00078 inline void eye(); 00079 00080 inline eT& operator[](const uword i); 00081 inline eT operator[](const uword i) const; 00082 00083 inline eT& operator()(const uword i); 00084 inline eT operator()(const uword i) const; 00085 00086 inline eT& operator()(const uword in_row, const uword in_col); 00087 inline eT operator()(const uword in_row, const uword in_col) const; 00088 00089 inline eT& at(const uword in_row, const uword in_col); 00090 inline eT at(const uword in_row, const uword in_col) const; 00091 00092 arma_inline eT* colptr(const uword in_col); 00093 arma_inline const eT* colptr(const uword in_col) const; 00094 00095 inline bool check_overlap(const subview& x) const; 00096 00097 inline bool is_vec() const; 00098 00099 inline subview_row<eT> row(const uword row_num); 00100 inline const subview_row<eT> row(const uword row_num) const; 00101 00102 inline subview_row<eT> operator()(const uword row_num, const span& col_span); 00103 inline const subview_row<eT> operator()(const uword row_num, const span& col_span) const; 00104 00105 inline subview_col<eT> col(const uword col_num); 00106 inline const subview_col<eT> col(const uword col_num) const; 00107 00108 inline subview_col<eT> operator()(const span& row_span, const uword col_num); 00109 inline const subview_col<eT> operator()(const span& row_span, const uword col_num) const; 00110 00111 inline Col<eT> unsafe_col(const uword col_num); 00112 inline const Col<eT> unsafe_col(const uword col_num) const; 00113 00114 inline subview<eT> rows(const uword in_row1, const uword in_row2); 00115 inline const subview<eT> rows(const uword in_row1, const uword in_row2) const; 00116 00117 inline subview<eT> cols(const uword in_col1, const uword in_col2); 00118 inline const subview<eT> cols(const uword in_col1, const uword in_col2) const; 00119 00120 inline subview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); 00121 inline const subview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; 00122 00123 inline subview<eT> submat (const span& row_span, const span& col_span); 00124 inline const subview<eT> submat (const span& row_span, const span& col_span) const; 00125 00126 inline subview<eT> operator()(const span& row_span, const span& col_span); 00127 inline const subview<eT> operator()(const span& row_span, const span& col_span) const; 00128 00129 inline diagview<eT> diag(const sword in_id = 0); 00130 inline const diagview<eT> diag(const sword in_id = 0) const; 00131 00132 inline void swap_rows(const uword in_row1, const uword in_row2); 00133 inline void swap_cols(const uword in_col1, const uword in_col2); 00134 00135 00136 // // primitive forward iterator 00137 // class iter 00138 // { 00139 // public: 00140 // 00141 // inline iter(const subview<eT>& in_M); 00142 // 00143 // arma_inline eT operator* () const; 00144 // 00145 // inline void operator++(); 00146 // inline void operator++(int); 00147 // 00148 // 00149 // private: 00150 // 00151 // arma_aligned const eT* mem; 00152 // 00153 // arma_aligned uword n_rows; 00154 // 00155 // arma_aligned uword row_start; 00156 // arma_aligned uword row_end_p1; 00157 // 00158 // arma_aligned uword row; 00159 // arma_aligned uword col; 00160 // arma_aligned uword i; 00161 // }; 00162 00163 00164 private: 00165 00166 friend class Mat<eT>; 00167 subview(); 00168 }; 00169 00170 00171 00172 template<typename eT> 00173 class subview_col : public subview<eT> 00174 { 00175 public: 00176 00177 typedef eT elem_type; 00178 typedef typename get_pod_type<elem_type>::result pod_type; 00179 00180 inline void operator= (const subview<eT>& x); 00181 inline void operator= (const subview_col& x); 00182 00183 template<typename T1> 00184 inline void operator= (const Base<eT,T1>& x); 00185 00186 inline subview_col<eT> rows(const uword in_row1, const uword in_row2); 00187 inline const subview_col<eT> rows(const uword in_row1, const uword in_row2) const; 00188 00189 inline subview_col<eT> subvec(const uword in_row1, const uword in_row2); 00190 inline const subview_col<eT> subvec(const uword in_row1, const uword in_row2) const; 00191 00192 00193 protected: 00194 00195 inline subview_col(const Mat<eT>& in_m, const uword in_col); 00196 inline subview_col( Mat<eT>& in_m, const uword in_col); 00197 00198 inline subview_col(const Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); 00199 inline subview_col( Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); 00200 00201 00202 private: 00203 00204 friend class Mat<eT>; 00205 friend class Col<eT>; 00206 friend class subview<eT>; 00207 00208 subview_col(); 00209 }; 00210 00211 00212 00213 template<typename eT> 00214 class subview_row : public subview<eT> 00215 { 00216 public: 00217 00218 typedef eT elem_type; 00219 typedef typename get_pod_type<elem_type>::result pod_type; 00220 00221 inline void operator= (const subview<eT>& x); 00222 inline void operator= (const subview_row& x); 00223 00224 template<typename T1> 00225 inline void operator= (const Base<eT,T1>& x); 00226 00227 inline subview_row<eT> cols(const uword in_col1, const uword in_col2); 00228 inline const subview_row<eT> cols(const uword in_col1, const uword in_col2) const; 00229 00230 inline subview_row<eT> subvec(const uword in_col1, const uword in_col2); 00231 inline const subview_row<eT> subvec(const uword in_col1, const uword in_col2) const; 00232 00233 00234 protected: 00235 00236 inline subview_row(const Mat<eT>& in_m, const uword in_row); 00237 inline subview_row( Mat<eT>& in_m, const uword in_row); 00238 00239 inline subview_row(const Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); 00240 inline subview_row( Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); 00241 00242 00243 private: 00244 00245 friend class Mat<eT>; 00246 friend class Row<eT>; 00247 friend class subview<eT>; 00248 00249 subview_row(); 00250 }; 00251 00252 00253