$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 ProxyCube 00021 { 00022 public: 00023 inline ProxyCube(const T1& A) 00024 { 00025 arma_type_check(( is_arma_cube_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 ProxyCube< Cube<eT> > 00036 { 00037 public: 00038 00039 typedef eT elem_type; 00040 typedef typename get_pod_type<elem_type>::result pod_type; 00041 typedef Cube<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 Cube<eT>& Q; 00048 00049 inline explicit ProxyCube(const Cube<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_slice() const { return Q.n_elem_slice; } 00058 arma_inline uword get_n_slices() const { return Q.n_slices; } 00059 arma_inline uword get_n_elem() const { return Q.n_elem; } 00060 00061 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00062 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00063 00064 arma_inline ea_type get_ea() const { return Q.memptr(); } 00065 arma_inline bool is_alias(const Cube<elem_type>& X) const { return (&Q == &X); } 00066 }; 00067 00068 00069 00070 template<typename eT, typename gen_type> 00071 class ProxyCube< GenCube<eT, gen_type > > 00072 { 00073 public: 00074 00075 typedef eT elem_type; 00076 typedef typename get_pod_type<elem_type>::result pod_type; 00077 typedef GenCube<eT, gen_type> stored_type; 00078 typedef const GenCube<eT, gen_type>& ea_type; 00079 00080 static const bool prefer_at_accessor = false; 00081 static const bool has_subview = false; 00082 00083 arma_aligned const GenCube<eT, gen_type>& Q; 00084 00085 inline explicit ProxyCube(const GenCube<eT, gen_type>& A) 00086 : Q(A) 00087 { 00088 arma_extra_debug_sigprint(); 00089 } 00090 00091 arma_inline uword get_n_rows() const { return Q.n_rows; } 00092 arma_inline uword get_n_cols() const { return Q.n_cols; } 00093 arma_inline uword get_n_elem_slice() const { return Q.n_rows*Q.n_cols; } 00094 arma_inline uword get_n_slices() const { return Q.n_slices; } 00095 arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols*Q.n_slices; } 00096 00097 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00098 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00099 00100 arma_inline ea_type get_ea() const { return Q; } 00101 arma_inline bool is_alias(const Cube<elem_type>&) const { return false; } 00102 }; 00103 00104 00105 00106 template<typename T1, typename op_type> 00107 class ProxyCube< OpCube<T1, op_type> > 00108 { 00109 public: 00110 00111 typedef typename T1::elem_type elem_type; 00112 typedef typename get_pod_type<elem_type>::result pod_type; 00113 typedef Cube<elem_type> stored_type; 00114 typedef const elem_type* ea_type; 00115 00116 static const bool prefer_at_accessor = false; 00117 static const bool has_subview = false; 00118 00119 arma_aligned const Cube<elem_type> Q; 00120 00121 inline explicit ProxyCube(const OpCube<T1, op_type>& A) 00122 : Q(A) 00123 { 00124 arma_extra_debug_sigprint(); 00125 } 00126 00127 arma_inline uword get_n_rows() const { return Q.n_rows; } 00128 arma_inline uword get_n_cols() const { return Q.n_cols; } 00129 arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } 00130 arma_inline uword get_n_slices() const { return Q.n_slices; } 00131 arma_inline uword get_n_elem() const { return Q.n_elem; } 00132 00133 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00134 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00135 00136 arma_inline ea_type get_ea() const { return Q.memptr(); } 00137 arma_inline bool is_alias(const Cube<elem_type>&) const { return false; } 00138 }; 00139 00140 00141 00142 template<typename T1, typename T2, typename glue_type> 00143 class ProxyCube< GlueCube<T1, T2, glue_type> > 00144 { 00145 public: 00146 00147 typedef typename T1::elem_type elem_type; 00148 typedef typename get_pod_type<elem_type>::result pod_type; 00149 typedef Cube<elem_type> stored_type; 00150 typedef const elem_type* ea_type; 00151 00152 static const bool prefer_at_accessor = false; 00153 static const bool has_subview = false; 00154 00155 arma_aligned const Cube<elem_type> Q; 00156 00157 inline explicit ProxyCube(const GlueCube<T1, T2, glue_type>& A) 00158 : Q(A) 00159 { 00160 arma_extra_debug_sigprint(); 00161 } 00162 00163 arma_inline uword get_n_rows() const { return Q.n_rows; } 00164 arma_inline uword get_n_cols() const { return Q.n_cols; } 00165 arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } 00166 arma_inline uword get_n_slices() const { return Q.n_slices; } 00167 arma_inline uword get_n_elem() const { return Q.n_elem; } 00168 00169 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00170 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00171 00172 arma_inline ea_type get_ea() const { return Q.memptr(); } 00173 arma_inline bool is_alias(const Cube<elem_type>&) const { return false; } 00174 }; 00175 00176 00177 00178 template<typename eT> 00179 class ProxyCube< subview_cube<eT> > 00180 { 00181 public: 00182 00183 typedef eT elem_type; 00184 typedef typename get_pod_type<elem_type>::result pod_type; 00185 typedef subview_cube<eT> stored_type; 00186 typedef const subview_cube<eT>& ea_type; 00187 00188 static const bool prefer_at_accessor = true; 00189 static const bool has_subview = true; 00190 00191 arma_aligned const subview_cube<eT>& Q; 00192 00193 inline explicit ProxyCube(const subview_cube<eT>& A) 00194 : Q(A) 00195 { 00196 arma_extra_debug_sigprint(); 00197 } 00198 00199 arma_inline uword get_n_rows() const { return Q.n_rows; } 00200 arma_inline uword get_n_cols() const { return Q.n_cols; } 00201 arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } 00202 arma_inline uword get_n_slices() const { return Q.n_slices; } 00203 arma_inline uword get_n_elem() const { return Q.n_elem; } 00204 00205 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00206 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00207 00208 arma_inline ea_type get_ea() const { return Q; } 00209 arma_inline bool is_alias(const Cube<elem_type>& X) const { return (&(Q.m) == &X); } 00210 }; 00211 00212 00213 00214 template<typename T1, typename eop_type> 00215 class ProxyCube< eOpCube<T1, eop_type > > 00216 { 00217 public: 00218 00219 typedef typename T1::elem_type elem_type; 00220 typedef typename get_pod_type<elem_type>::result pod_type; 00221 typedef eOpCube<T1, eop_type> stored_type; 00222 typedef const eOpCube<T1, eop_type>& ea_type; 00223 00224 static const bool prefer_at_accessor = eOpCube<T1, eop_type>::prefer_at_accessor; 00225 static const bool has_subview = eOpCube<T1, eop_type>::has_subview; 00226 00227 arma_aligned const eOpCube<T1, eop_type>& Q; 00228 00229 inline explicit ProxyCube(const eOpCube<T1, eop_type>& A) 00230 : Q(A) 00231 { 00232 arma_extra_debug_sigprint(); 00233 } 00234 00235 arma_inline uword get_n_rows() const { return Q.get_n_rows(); } 00236 arma_inline uword get_n_cols() const { return Q.get_n_cols(); } 00237 arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } 00238 arma_inline uword get_n_slices() const { return Q.get_n_slices(); } 00239 arma_inline uword get_n_elem() const { return Q.get_n_elem(); } 00240 00241 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00242 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00243 00244 arma_inline ea_type get_ea() const { return Q; } 00245 arma_inline bool is_alias(const Cube<elem_type>& X) const { return Q.P.is_alias(X); } 00246 }; 00247 00248 00249 00250 template<typename T1, typename T2, typename eglue_type> 00251 class ProxyCube< eGlueCube<T1, T2, eglue_type > > 00252 { 00253 public: 00254 00255 typedef typename T1::elem_type elem_type; 00256 typedef typename get_pod_type<elem_type>::result pod_type; 00257 typedef eGlueCube<T1, T2, eglue_type> stored_type; 00258 typedef const eGlueCube<T1, T2, eglue_type>& ea_type; 00259 00260 static const bool prefer_at_accessor = eGlueCube<T1, T2, eglue_type>::prefer_at_accessor; 00261 static const bool has_subview = eGlueCube<T1, T2, eglue_type>::has_subview; 00262 00263 arma_aligned const eGlueCube<T1, T2, eglue_type>& Q; 00264 00265 inline explicit ProxyCube(const eGlueCube<T1, T2, eglue_type>& A) 00266 : Q(A) 00267 { 00268 arma_extra_debug_sigprint(); 00269 } 00270 00271 arma_inline uword get_n_rows() const { return Q.get_n_rows(); } 00272 arma_inline uword get_n_cols() const { return Q.get_n_cols(); } 00273 arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } 00274 arma_inline uword get_n_slices() const { return Q.get_n_slices(); } 00275 arma_inline uword get_n_elem() const { return Q.get_n_elem(); } 00276 00277 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00278 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00279 00280 arma_inline ea_type get_ea() const { return Q; } 00281 arma_inline bool is_alias(const Cube<elem_type>& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } 00282 }; 00283 00284 00285 00286 template<typename out_eT, typename T1, typename op_type> 00287 class ProxyCube< mtOpCube<out_eT, T1, op_type> > 00288 { 00289 public: 00290 00291 typedef out_eT elem_type; 00292 typedef typename get_pod_type<out_eT>::result pod_type; 00293 typedef Cube<out_eT> stored_type; 00294 typedef const elem_type* ea_type; 00295 00296 static const bool prefer_at_accessor = false; 00297 static const bool has_subview = false; 00298 00299 arma_aligned const Cube<out_eT> Q; 00300 00301 inline explicit ProxyCube(const mtOpCube<out_eT, T1, op_type>& A) 00302 : Q(A) 00303 { 00304 arma_extra_debug_sigprint(); 00305 } 00306 00307 arma_inline uword get_n_rows() const { return Q.n_rows; } 00308 arma_inline uword get_n_cols() const { return Q.n_cols; } 00309 arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } 00310 arma_inline uword get_n_slices() const { return Q.n_slices; } 00311 arma_inline uword get_n_elem() const { return Q.n_elem; } 00312 00313 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00314 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00315 00316 arma_inline ea_type get_ea() const { return Q.memptr(); } 00317 arma_inline bool is_alias(const Cube<out_eT>&) const { return false; } 00318 }; 00319 00320 00321 00322 template<typename out_eT, typename T1, typename T2, typename glue_type> 00323 class ProxyCube< mtGlueCube<out_eT, T1, T2, glue_type > > 00324 { 00325 public: 00326 00327 typedef out_eT elem_type; 00328 typedef typename get_pod_type<out_eT>::result pod_type; 00329 typedef Cube<out_eT> stored_type; 00330 typedef const elem_type* ea_type; 00331 00332 static const bool prefer_at_accessor = false; 00333 static const bool has_subview = false; 00334 00335 arma_aligned const Cube<out_eT> Q; 00336 00337 inline explicit ProxyCube(const mtGlueCube<out_eT, T1, T2, glue_type>& A) 00338 : Q(A) 00339 { 00340 arma_extra_debug_sigprint(); 00341 } 00342 00343 arma_inline uword get_n_rows() const { return Q.n_rows; } 00344 arma_inline uword get_n_cols() const { return Q.n_cols; } 00345 arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } 00346 arma_inline uword get_n_slices() const { return Q.n_slices; } 00347 arma_inline uword get_n_elem() const { return Q.n_elem; } 00348 00349 arma_inline elem_type operator[] (const uword i) const { return Q[i]; } 00350 arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } 00351 00352 arma_inline ea_type get_ea() const { return Q.memptr(); } 00353 arma_inline bool is_alias(const Cube<out_eT>&) const { return false; } 00354 }; 00355 00356 00357