$search
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2009-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 00020 template<typename T1, typename T2> 00021 inline 00022 void 00023 glue_mixed_times::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_times>& X) 00024 { 00025 arma_extra_debug_sigprint(); 00026 00027 typedef typename T1::elem_type eT1; 00028 typedef typename T2::elem_type eT2; 00029 00030 // TODO: extend the unwrap_check framework to handle mixed matrix types 00031 00032 const unwrap<T1> tmp1(X.A); 00033 const unwrap<T2> tmp2(X.B); 00034 00035 const Mat<eT1>& A = tmp1.M; 00036 const Mat<eT2>& B = tmp2.M; 00037 00038 const bool A_is_alias = ( ((void *)&out) == ((void *)&A) ); 00039 const bool B_is_alias = ( ((void *)&out) == ((void *)&B) ); 00040 00041 const Mat<eT1>* AA_ptr = A_is_alias ? new Mat<eT1>(A) : 0; 00042 const Mat<eT2>* BB_ptr = B_is_alias ? new Mat<eT2>(B) : 0; 00043 00044 const Mat<eT1>& AA = A_is_alias ? *AA_ptr : A; 00045 const Mat<eT2>& BB = B_is_alias ? *BB_ptr : B; 00046 00047 arma_debug_assert_mul_size(AA, BB, "multiplication"); 00048 00049 out.set_size(AA.n_rows, BB.n_cols); 00050 00051 gemm_mixed<>::apply(out, AA, BB); 00052 00053 if(A_is_alias == true) 00054 { 00055 delete AA_ptr; 00056 } 00057 00058 if(B_is_alias == true) 00059 { 00060 delete BB_ptr; 00061 } 00062 } 00063 00064 00065 00067 template<typename T1, typename T2> 00068 inline 00069 void 00070 glue_mixed_plus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_plus>& X) 00071 { 00072 arma_extra_debug_sigprint(); 00073 00074 typedef typename T1::elem_type eT1; 00075 typedef typename T2::elem_type eT2; 00076 00077 typedef typename promote_type<eT1,eT2>::result out_eT; 00078 00079 promote_type<eT1,eT2>::check(); 00080 00081 const Proxy<T1> A(X.A); 00082 const Proxy<T2> B(X.B); 00083 00084 arma_debug_assert_same_size(A, B, "addition"); 00085 00086 out.set_size(A.get_n_rows(), A.get_n_cols()); 00087 00088 out_eT* out_mem = out.memptr(); 00089 const uword n_elem = out.n_elem; 00090 00091 for(uword i=0; i<n_elem; ++i) 00092 { 00093 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>::apply(B[i]); 00094 } 00095 } 00096 00097 00098 00100 template<typename T1, typename T2> 00101 inline 00102 void 00103 glue_mixed_minus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_minus>& X) 00104 { 00105 arma_extra_debug_sigprint(); 00106 00107 typedef typename T1::elem_type eT1; 00108 typedef typename T2::elem_type eT2; 00109 00110 typedef typename promote_type<eT1,eT2>::result out_eT; 00111 00112 promote_type<eT1,eT2>::check(); 00113 00114 const Proxy<T1> A(X.A); 00115 const Proxy<T2> B(X.B); 00116 00117 arma_debug_assert_same_size(A, B, "subtraction"); 00118 00119 out.set_size(A.get_n_rows(), A.get_n_cols()); 00120 00121 out_eT* out_mem = out.memptr(); 00122 const uword n_elem = out.n_elem; 00123 00124 for(uword i=0; i<n_elem; ++i) 00125 { 00126 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>::apply(B[i]); 00127 } 00128 } 00129 00130 00131 00133 template<typename T1, typename T2> 00134 inline 00135 void 00136 glue_mixed_div::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_div>& X) 00137 { 00138 arma_extra_debug_sigprint(); 00139 00140 typedef typename T1::elem_type eT1; 00141 typedef typename T2::elem_type eT2; 00142 00143 typedef typename promote_type<eT1,eT2>::result out_eT; 00144 00145 promote_type<eT1,eT2>::check(); 00146 00147 const Proxy<T1> A(X.A); 00148 const Proxy<T2> B(X.B); 00149 00150 arma_debug_assert_same_size(A, B, "element-wise division"); 00151 00152 out.set_size(A.get_n_rows(), A.get_n_cols()); 00153 00154 out_eT* out_mem = out.memptr(); 00155 const uword n_elem = out.n_elem; 00156 00157 for(uword i=0; i<n_elem; ++i) 00158 { 00159 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::apply(B[i]); 00160 } 00161 } 00162 00163 00164 00166 template<typename T1, typename T2> 00167 inline 00168 void 00169 glue_mixed_schur::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X) 00170 { 00171 arma_extra_debug_sigprint(); 00172 00173 typedef typename T1::elem_type eT1; 00174 typedef typename T2::elem_type eT2; 00175 00176 typedef typename promote_type<eT1,eT2>::result out_eT; 00177 00178 promote_type<eT1,eT2>::check(); 00179 00180 const Proxy<T1> A(X.A); 00181 const Proxy<T2> B(X.B); 00182 00183 arma_debug_assert_same_size(A, B, "element-wise multiplication"); 00184 00185 out.set_size(A.get_n_rows(), A.get_n_cols()); 00186 00187 out_eT* out_mem = out.memptr(); 00188 const uword n_elem = out.n_elem; 00189 00190 for(uword i=0; i<n_elem; ++i) 00191 { 00192 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::apply(B[i]); 00193 } 00194 } 00195 00196 00197 00198 // 00199 // 00200 // 00201 00202 00203 00205 template<typename T1, typename T2> 00206 inline 00207 void 00208 glue_mixed_plus::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_plus>& X) 00209 { 00210 arma_extra_debug_sigprint(); 00211 00212 typedef typename T1::elem_type eT1; 00213 typedef typename T2::elem_type eT2; 00214 00215 typedef typename promote_type<eT1,eT2>::result out_eT; 00216 00217 promote_type<eT1,eT2>::check(); 00218 00219 const ProxyCube<T1> A(X.A); 00220 const ProxyCube<T2> B(X.B); 00221 00222 arma_debug_assert_same_size(A, B, "addition"); 00223 00224 out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); 00225 00226 out_eT* out_mem = out.memptr(); 00227 const uword n_elem = out.n_elem; 00228 00229 for(uword i=0; i<n_elem; ++i) 00230 { 00231 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>::apply(B[i]); 00232 } 00233 } 00234 00235 00236 00238 template<typename T1, typename T2> 00239 inline 00240 void 00241 glue_mixed_minus::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_minus>& X) 00242 { 00243 arma_extra_debug_sigprint(); 00244 00245 typedef typename T1::elem_type eT1; 00246 typedef typename T2::elem_type eT2; 00247 00248 typedef typename promote_type<eT1,eT2>::result out_eT; 00249 00250 promote_type<eT1,eT2>::check(); 00251 00252 const ProxyCube<T1> A(X.A); 00253 const ProxyCube<T2> B(X.B); 00254 00255 arma_debug_assert_same_size(A, B, "subtraction"); 00256 00257 out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); 00258 00259 out_eT* out_mem = out.memptr(); 00260 const uword n_elem = out.n_elem; 00261 00262 for(uword i=0; i<n_elem; ++i) 00263 { 00264 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>::apply(B[i]); 00265 } 00266 } 00267 00268 00269 00271 template<typename T1, typename T2> 00272 inline 00273 void 00274 glue_mixed_div::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_div>& X) 00275 { 00276 arma_extra_debug_sigprint(); 00277 00278 typedef typename T1::elem_type eT1; 00279 typedef typename T2::elem_type eT2; 00280 00281 typedef typename promote_type<eT1,eT2>::result out_eT; 00282 00283 promote_type<eT1,eT2>::check(); 00284 00285 const ProxyCube<T1> A(X.A); 00286 const ProxyCube<T2> B(X.B); 00287 00288 arma_debug_assert_same_size(A, B, "element-wise division"); 00289 00290 out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); 00291 00292 out_eT* out_mem = out.memptr(); 00293 const uword n_elem = out.n_elem; 00294 00295 for(uword i=0; i<n_elem; ++i) 00296 { 00297 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::apply(B[i]); 00298 } 00299 } 00300 00301 00302 00304 template<typename T1, typename T2> 00305 inline 00306 void 00307 glue_mixed_schur::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X) 00308 { 00309 arma_extra_debug_sigprint(); 00310 00311 typedef typename T1::elem_type eT1; 00312 typedef typename T2::elem_type eT2; 00313 00314 typedef typename promote_type<eT1,eT2>::result out_eT; 00315 00316 promote_type<eT1,eT2>::check(); 00317 00318 const ProxyCube<T1> A(X.A); 00319 const ProxyCube<T2> B(X.B); 00320 00321 arma_debug_assert_same_size(A, B, "element-wise multiplication"); 00322 00323 out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); 00324 00325 out_eT* out_mem = out.memptr(); 00326 const uword n_elem = out.n_elem; 00327 00328 for(uword i=0; i<n_elem; ++i) 00329 { 00330 out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::apply(B[i]); 00331 } 00332 } 00333 00334 00335