$search
00001 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2010-2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00016 00017 00018 00019 template<typename T1> 00020 class Proxy 00021 { 00022 public: 00023 inline Proxy(const T1& A) 00024 { 00025 arma_type_check(( is_arma_type<T1>::value == false )); 00026 } 00027 }; 00028 00029 00030 00031 // ea_type is the "element accessor" type, 00032 // which can provide access to elements via operator[] 00033 00034 template<typename eT> 00035 class Proxy< Mat<eT> > 00036 { 00037 public: 00038 00039 typedef eT elem_type; 00040 typedef typename get_pod_type<elem_type>::result pod_type; 00041 typedef Mat<eT> stored_type; 00042 typedef const eT* ea_type; 00043 00044 static const bool prefer_at_accessor = false; 00045 static const bool has_subview = false; 00046 00047 arma_aligned const Mat<eT>& Q; 00048 00049 inline explicit Proxy(const Mat<eT>& A) 00050 : Q(A) 00051 { 00052 arma_extra_debug_sigprint(); 00053 } 00054 00055 arma_inline uword get_n_rows() const { return Q.n_rows; } 00056 arma_inline uword get_n_cols() const { return Q.n_cols; } 00057 arma_inline uword get_n_elem() const { return Q.n_elem; } 00058 00059 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00060 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00061 00062 arma_inline ea_type get_ea() const { return Q.memptr(); } 00063 arma_inline bool is_alias(const Mat<eT>& X) const { return (&Q == &X); } 00064 }; 00065 00066 00067 00068 template<typename eT> 00069 class Proxy< Col<eT> > 00070 { 00071 public: 00072 00073 typedef eT elem_type; 00074 typedef typename get_pod_type<elem_type>::result pod_type; 00075 typedef Col<eT> stored_type; 00076 typedef const eT* ea_type; 00077 00078 static const bool prefer_at_accessor = false; 00079 static const bool has_subview = false; 00080 00081 arma_aligned const Col<eT>& Q; 00082 00083 inline explicit Proxy(const Col<eT>& A) 00084 : Q(A) 00085 { 00086 arma_extra_debug_sigprint(); 00087 } 00088 00089 arma_inline uword get_n_rows() const { return Q.n_rows; } 00090 arma_inline uword get_n_cols() const { return 1; } 00091 arma_inline uword get_n_elem() const { return Q.n_elem; } 00092 00093 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00094 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00095 00096 arma_inline ea_type get_ea() const { return Q.memptr(); } 00097 arma_inline bool is_alias(const Mat<eT>& X) const { return (&Q == &X); } 00098 }; 00099 00100 00101 00102 template<typename eT> 00103 class Proxy< Row<eT> > 00104 { 00105 public: 00106 00107 typedef eT elem_type; 00108 typedef typename get_pod_type<elem_type>::result pod_type; 00109 typedef Row<eT> stored_type; 00110 typedef const eT* ea_type; 00111 00112 static const bool prefer_at_accessor = false; 00113 static const bool has_subview = false; 00114 00115 arma_aligned const Row<eT>& Q; 00116 00117 inline explicit Proxy(const Row<eT>& A) 00118 : Q(A) 00119 { 00120 arma_extra_debug_sigprint(); 00121 } 00122 00123 arma_inline uword get_n_rows() const { return 1; } 00124 arma_inline uword get_n_cols() const { return Q.n_cols; } 00125 arma_inline uword get_n_elem() const { return Q.n_elem; } 00126 00127 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00128 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00129 00130 arma_inline ea_type get_ea() const { return Q.memptr(); } 00131 arma_inline bool is_alias(const Mat<eT>& X) const { return (&Q == &X); } 00132 }; 00133 00134 00135 00136 template<typename eT, typename gen_type> 00137 class Proxy< Gen<eT, gen_type > > 00138 { 00139 public: 00140 00141 typedef eT elem_type; 00142 typedef typename get_pod_type<elem_type>::result pod_type; 00143 typedef Gen<eT, gen_type> stored_type; 00144 typedef const Gen<eT, gen_type>& ea_type; 00145 00146 static const bool prefer_at_accessor = Gen<eT, gen_type>::prefer_at_accessor; 00147 static const bool has_subview = false; 00148 00149 arma_aligned const Gen<eT, gen_type>& Q; 00150 00151 inline explicit Proxy(const Gen<eT, gen_type>& A) 00152 : Q(A) 00153 { 00154 arma_extra_debug_sigprint(); 00155 } 00156 00157 arma_inline uword get_n_rows() const { return Q.n_rows; } 00158 arma_inline uword get_n_cols() const { return Q.n_cols; } 00159 arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols; } 00160 00161 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00162 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00163 00164 arma_inline ea_type get_ea() const { return Q; } 00165 arma_inline bool is_alias(const Mat<elem_type>&) const { return false; } 00166 }; 00167 00168 00169 00170 template<typename T1, typename op_type> 00171 class Proxy< Op<T1, op_type> > 00172 { 00173 public: 00174 00175 typedef typename T1::elem_type elem_type; 00176 typedef typename get_pod_type<elem_type>::result pod_type; 00177 typedef Mat<elem_type> stored_type; 00178 typedef const elem_type* ea_type; 00179 00180 static const bool prefer_at_accessor = false; 00181 static const bool has_subview = false; 00182 00183 arma_aligned const Mat<elem_type> Q; 00184 00185 inline explicit Proxy(const Op<T1, op_type>& A) 00186 : Q(A) 00187 { 00188 arma_extra_debug_sigprint(); 00189 } 00190 00191 arma_inline uword get_n_rows() const { return Q.n_rows; } 00192 arma_inline uword get_n_cols() const { return Q.n_cols; } 00193 arma_inline uword get_n_elem() const { return Q.n_elem; } 00194 00195 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00196 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00197 00198 arma_inline ea_type get_ea() const { return Q.memptr(); } 00199 arma_inline bool is_alias(const Mat<elem_type>&) const { return false; } 00200 }; 00201 00202 00203 00204 template<typename T1, typename T2, typename glue_type> 00205 class Proxy< Glue<T1, T2, glue_type> > 00206 { 00207 public: 00208 00209 typedef typename T1::elem_type elem_type; 00210 typedef typename get_pod_type<elem_type>::result pod_type; 00211 typedef Mat<elem_type> stored_type; 00212 typedef const elem_type* ea_type; 00213 00214 static const bool prefer_at_accessor = false; 00215 static const bool has_subview = false; 00216 00217 arma_aligned const Mat<elem_type> Q; 00218 00219 inline explicit Proxy(const Glue<T1, T2, glue_type>& A) 00220 : Q(A) 00221 { 00222 arma_extra_debug_sigprint(); 00223 } 00224 00225 arma_inline uword get_n_rows() const { return Q.n_rows; } 00226 arma_inline uword get_n_cols() const { return Q.n_cols; } 00227 arma_inline uword get_n_elem() const { return Q.n_elem; } 00228 00229 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00230 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00231 00232 arma_inline ea_type get_ea() const { return Q.memptr(); } 00233 arma_inline bool is_alias(const Mat<elem_type>&) const { return false; } 00234 }; 00235 00236 00237 00238 template<typename eT> 00239 class Proxy< subview<eT> > 00240 { 00241 public: 00242 00243 typedef eT elem_type; 00244 typedef typename get_pod_type<elem_type>::result pod_type; 00245 typedef subview<eT> stored_type; 00246 typedef const subview<eT>& ea_type; 00247 00248 static const bool prefer_at_accessor = true; 00249 static const bool has_subview = true; 00250 00251 arma_aligned const subview<eT>& Q; 00252 00253 inline explicit Proxy(const subview<eT>& A) 00254 : Q(A) 00255 { 00256 arma_extra_debug_sigprint(); 00257 } 00258 00259 arma_inline uword get_n_rows() const { return Q.n_rows; } 00260 arma_inline uword get_n_cols() const { return Q.n_cols; } 00261 arma_inline uword get_n_elem() const { return Q.n_elem; } 00262 00263 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00264 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00265 00266 arma_inline ea_type get_ea() const { return Q; } 00267 arma_inline bool is_alias(const Mat<eT>& X) const { return (&(Q.m) == &X); } 00268 }; 00269 00270 00271 00272 template<typename eT, typename T1> 00273 class Proxy< subview_elem1<eT,T1> > 00274 { 00275 public: 00276 00277 typedef eT elem_type; 00278 typedef typename get_pod_type<elem_type>::result pod_type; 00279 typedef Mat<eT> stored_type; 00280 typedef const eT* ea_type; 00281 00282 static const bool prefer_at_accessor = false; 00283 static const bool has_subview = false; 00284 00285 arma_aligned const Mat<eT> Q; 00286 00287 inline explicit Proxy(const subview_elem1<eT,T1>& A) 00288 : Q(A) 00289 { 00290 arma_extra_debug_sigprint(); 00291 } 00292 00293 arma_inline uword get_n_rows() const { return Q.n_rows; } 00294 arma_inline uword get_n_cols() const { return 1; } 00295 arma_inline uword get_n_elem() const { return Q.n_elem; } 00296 00297 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00298 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00299 00300 arma_inline ea_type get_ea() const { return Q.memptr(); } 00301 arma_inline bool is_alias(const Mat<eT>&) const { return false; } 00302 }; 00303 00304 00305 00306 template<typename eT> 00307 class Proxy< diagview<eT> > 00308 { 00309 public: 00310 00311 typedef eT elem_type; 00312 typedef typename get_pod_type<elem_type>::result pod_type; 00313 typedef diagview<eT> stored_type; 00314 typedef const diagview<eT>& ea_type; 00315 00316 static const bool prefer_at_accessor = false; 00317 static const bool has_subview = true; 00318 00319 arma_aligned const diagview<eT>& Q; 00320 00321 inline explicit Proxy(const diagview<eT>& A) 00322 : Q(A) 00323 { 00324 arma_extra_debug_sigprint(); 00325 } 00326 00327 arma_inline uword get_n_rows() const { return Q.n_rows; } 00328 arma_inline uword get_n_cols() const { return 1; } 00329 arma_inline uword get_n_elem() const { return Q.n_elem; } 00330 00331 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00332 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00333 00334 arma_inline ea_type get_ea() const { return Q; } 00335 arma_inline bool is_alias(const Mat<eT>& X) const { return (&(Q.m) == &X); } 00336 }; 00337 00338 00339 00340 00341 template<typename T1, typename eop_type> 00342 class Proxy< eOp<T1, eop_type > > 00343 { 00344 public: 00345 00346 typedef typename T1::elem_type elem_type; 00347 typedef typename get_pod_type<elem_type>::result pod_type; 00348 typedef eOp<T1, eop_type> stored_type; 00349 typedef const eOp<T1, eop_type>& ea_type; 00350 00351 static const bool prefer_at_accessor = eOp<T1, eop_type>::prefer_at_accessor; 00352 static const bool has_subview = eOp<T1, eop_type>::has_subview; 00353 00354 arma_aligned const eOp<T1, eop_type>& Q; 00355 00356 inline explicit Proxy(const eOp<T1, eop_type>& A) 00357 : Q(A) 00358 { 00359 arma_extra_debug_sigprint(); 00360 } 00361 00362 arma_inline uword get_n_rows() const { return Q.get_n_rows(); } 00363 arma_inline uword get_n_cols() const { return Q.get_n_cols(); } 00364 arma_inline uword get_n_elem() const { return Q.get_n_elem(); } 00365 00366 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00367 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00368 00369 arma_inline ea_type get_ea() const { return Q; } 00370 arma_inline bool is_alias(const Mat<elem_type>& X) const { return Q.P.is_alias(X); } 00371 }; 00372 00373 00374 00375 template<typename T1, typename T2, typename eglue_type> 00376 class Proxy< eGlue<T1, T2, eglue_type > > 00377 { 00378 public: 00379 00380 typedef typename T1::elem_type elem_type; 00381 typedef typename get_pod_type<elem_type>::result pod_type; 00382 typedef eGlue<T1, T2, eglue_type> stored_type; 00383 typedef const eGlue<T1, T2, eglue_type>& ea_type; 00384 00385 static const bool prefer_at_accessor = eGlue<T1, T2, eglue_type>::prefer_at_accessor; 00386 static const bool has_subview = eGlue<T1, T2, eglue_type>::has_subview; 00387 00388 arma_aligned const eGlue<T1, T2, eglue_type>& Q; 00389 00390 inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A) 00391 : Q(A) 00392 { 00393 arma_extra_debug_sigprint(); 00394 } 00395 00396 arma_inline uword get_n_rows() const { return Q.get_n_rows(); } 00397 arma_inline uword get_n_cols() const { return Q.get_n_cols(); } 00398 arma_inline uword get_n_elem() const { return Q.get_n_elem(); } 00399 00400 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00401 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } 00402 00403 arma_inline ea_type get_ea() const { return Q; } 00404 arma_inline bool is_alias(const Mat<elem_type>& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } 00405 }; 00406 00407 00408 00409 template<typename out_eT, typename T1, typename op_type> 00410 class Proxy< mtOp<out_eT, T1, op_type> > 00411 { 00412 public: 00413 00414 typedef out_eT elem_type; 00415 typedef typename get_pod_type<out_eT>::result pod_type; 00416 typedef Mat<out_eT> stored_type; 00417 typedef const elem_type* ea_type; 00418 00419 static const bool prefer_at_accessor = false; 00420 static const bool has_subview = false; 00421 00422 arma_aligned const Mat<out_eT> Q; 00423 00424 inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A) 00425 : Q(A) 00426 { 00427 arma_extra_debug_sigprint(); 00428 } 00429 00430 arma_inline uword get_n_rows() const { return Q.n_rows; } 00431 arma_inline uword get_n_cols() const { return Q.n_cols; } 00432 arma_inline uword get_n_elem() const { return Q.n_elem; } 00433 00434 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00435 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } 00436 00437 arma_inline ea_type get_ea() const { return Q.memptr(); } 00438 arma_inline bool is_alias(const Mat<out_eT>&) const { return false; } 00439 }; 00440 00441 00442 00443 template<typename out_eT, typename T1, typename T2, typename glue_type> 00444 class Proxy< mtGlue<out_eT, T1, T2, glue_type > > 00445 { 00446 public: 00447 00448 typedef out_eT elem_type; 00449 typedef typename get_pod_type<out_eT>::result pod_type; 00450 typedef Mat<out_eT> stored_type; 00451 typedef const elem_type* ea_type; 00452 00453 static const bool prefer_at_accessor = false; 00454 static const bool has_subview = false; 00455 00456 arma_aligned const Mat<out_eT> Q; 00457 00458 inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A) 00459 : Q(A) 00460 { 00461 arma_extra_debug_sigprint(); 00462 } 00463 00464 arma_inline uword get_n_rows() const { return Q.n_rows; } 00465 arma_inline uword get_n_cols() const { return Q.n_cols; } 00466 arma_inline uword get_n_elem() const { return Q.n_elem; } 00467 00468 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00469 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } 00470 00471 arma_inline ea_type get_ea() const { return Q.memptr(); } 00472 arma_inline bool is_alias(const Mat<out_eT>&) const { return false; } 00473 }; 00474 00475 00476