subview_elem1_meat.hpp
Go to the documentation of this file.
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 template<typename eT, typename T1>
00019 inline
00020 subview_elem1<eT,T1>::~subview_elem1()
00021   {
00022   arma_extra_debug_sigprint();
00023   }
00024 
00025 
00026 template<typename eT, typename T1>
00027 arma_inline
00028 subview_elem1<eT,T1>::subview_elem1(const Mat<eT>& in_m, const Base<uword,T1>& in_a)
00029   : m(in_m)
00030   , m_ptr(0)
00031   , a(in_a)
00032   {
00033   arma_extra_debug_sigprint();
00034   }
00035 
00036 
00037 
00038 template<typename eT, typename T1>
00039 arma_inline
00040 subview_elem1<eT,T1>::subview_elem1(Mat<eT>& in_m, const Base<uword,T1>& in_a)
00041   : m(in_m)
00042   , m_ptr(&in_m)
00043   , a(in_a)
00044   {
00045   arma_extra_debug_sigprint();
00046   }
00047 
00048 
00049 
00050 template<typename eT, typename T1>
00051 template<typename op_type>
00052 inline
00053 void
00054 subview_elem1<eT,T1>::inplace_op(const eT val)
00055   {
00056   Mat<eT>& m_local = *m_ptr;
00057   
00058         eT*   m_mem    = m_local.memptr();
00059   const uword m_n_elem = m_local.n_elem;
00060   
00061   const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local);
00062   const umat& aa = tmp.M;
00063   
00064   arma_debug_check
00065     (
00066     ( aa.is_vec() == false ),
00067     "Mat::elem(): given object is not a vector"
00068     );
00069   
00070   const uword* aa_mem    = aa.memptr();
00071   const uword  aa_n_elem = aa.n_elem;
00072   
00073   uword i,j;
00074   for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
00075     {
00076     const uword ii = aa_mem[i];
00077     const uword jj = aa_mem[j];
00078     
00079     arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
00080     
00081          if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  val; m_mem[jj] =  val; }
00082     else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += val; m_mem[jj] += val; }
00083     else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= val; m_mem[jj] -= val; }
00084     else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= val; m_mem[jj] *= val; }
00085     else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= val; m_mem[jj] /= val; }
00086     }
00087   
00088   if(i < aa_n_elem)
00089     {
00090     const uword ii = aa_mem[i];
00091     
00092     arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); 
00093     
00094          if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  val; }
00095     else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += val; }
00096     else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= val; }
00097     else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= val; }
00098     else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= val; }
00099     }
00100   }
00101 
00102 
00103 
00104 template<typename eT, typename T1>
00105 template<typename op_type, typename T2>
00106 inline
00107 void
00108 subview_elem1<eT,T1>::inplace_op(const subview_elem1<eT,T2>& x)
00109   {
00110   subview_elem1<eT,T1>& t = *this;
00111   
00112   if(&(t.m) == &(x.m))
00113     {
00114     arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected");
00115     
00116     const Mat<eT> tmp(x);
00117     
00118          if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { t.operator= (tmp); }
00119     else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t.operator+=(tmp); }
00120     else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t.operator-=(tmp); }
00121     else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t.operator%=(tmp); }
00122     else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { t.operator/=(tmp); }
00123     }
00124   else
00125     {
00126           Mat<eT>& t_m_local = *(t.m_ptr);
00127     const Mat<eT>& x_m_local = x.m;
00128     
00129     const unwrap_check_mixed<T1> t_tmp(t.a.get_ref(), t_m_local);
00130     const unwrap_check_mixed<T2> x_tmp(x.a.get_ref(), t_m_local);
00131     
00132     const umat& t_aa = t_tmp.M;
00133     const umat& x_aa = x_tmp.M;
00134     
00135     arma_debug_check
00136       (
00137       ( (t_aa.is_vec() == false) || (x_aa.is_vec() == false) ),
00138       "Mat::elem(): given object is not a vector"
00139       );
00140     
00141     const uword* t_aa_mem = t_aa.memptr();
00142     const uword* x_aa_mem = x_aa.memptr();
00143     
00144     const uword t_aa_n_elem = t_aa.n_elem;
00145     
00146     arma_debug_check( (t_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mismatch" );
00147     
00148     
00149           eT*   t_m_mem    = t_m_local.memptr();
00150     const uword t_m_n_elem = t_m_local.n_elem;
00151     
00152     const eT*   x_m_mem    = x_m_local.memptr();
00153     const uword x_m_n_elem = x_m_local.n_elem;
00154     
00155     uword i,j;
00156     for(i=0, j=1; j<t_aa_n_elem; i+=2, j+=2)
00157       {
00158       const uword t_ii = t_aa_mem[i];
00159       const uword t_jj = t_aa_mem[j];
00160       
00161       const uword x_ii = x_aa_mem[i];
00162       const uword x_jj = x_aa_mem[j];
00163       
00164       arma_debug_check
00165         (
00166         (t_ii >= t_m_n_elem) || (t_jj >= t_m_n_elem) || (x_ii >= x_m_n_elem) || (x_jj >= x_m_n_elem),
00167         "Mat::elem(): index out of bounds"
00168         );
00169       
00170            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { t_m_mem[t_ii]  = x_m_mem[x_ii]; t_m_mem[t_jj]  = x_m_mem[x_jj]; }
00171       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t_m_mem[t_ii] += x_m_mem[x_ii]; t_m_mem[t_jj] += x_m_mem[x_jj]; }
00172       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; t_m_mem[t_jj] -= x_m_mem[x_jj]; }
00173       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; t_m_mem[t_jj] *= x_m_mem[x_jj]; }
00174       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; t_m_mem[t_jj] /= x_m_mem[x_jj]; }
00175       }
00176     
00177     if(i < t_aa_n_elem)
00178       {
00179       const uword t_ii = t_aa_mem[i];
00180       const uword x_ii = x_aa_mem[i];
00181       
00182       arma_debug_check
00183         (
00184         ( (t_ii >= t_m_n_elem) || (x_ii >= x_m_n_elem) ),
00185         "Mat::elem(): index out of bounds"
00186         );
00187       
00188            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { t_m_mem[t_ii]  = x_m_mem[x_ii]; }
00189       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t_m_mem[t_ii] += x_m_mem[x_ii]; }
00190       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; }
00191       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; }
00192       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; }
00193       }
00194     }
00195   }
00196 
00197 
00198 
00199 template<typename eT, typename T1>
00200 template<typename op_type, typename T2>
00201 inline
00202 void
00203 subview_elem1<eT,T1>::inplace_op(const Base<eT,T2>& x)
00204   {
00205   arma_extra_debug_sigprint();
00206   
00207   Mat<eT>& m_local = *m_ptr;
00208   
00209         eT*   m_mem    = m_local.memptr();
00210   const uword m_n_elem = m_local.n_elem;
00211   
00212   const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local);
00213   const umat& aa = tmp.M;
00214   
00215   arma_debug_check
00216     (
00217     ( aa.is_vec() == false ),
00218     "Mat::elem(): given object is not a vector"
00219     );
00220   
00221   const uword* aa_mem    = aa.memptr();
00222   const uword  aa_n_elem = aa.n_elem;
00223   
00224   const Proxy<T2> P(x.get_ref());
00225   
00226   arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size mismatch" );
00227   
00228   if(P.is_alias(m) == false)
00229     {
00230     typename Proxy<T2>::ea_type X = P.get_ea();
00231     
00232     uword i,j;
00233     for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
00234       {
00235       const uword ii = aa_mem[i];
00236       const uword jj = aa_mem[j];
00237       
00238       arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
00239       
00240            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  X[i]; m_mem[jj]  = X[j]; }
00241       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; }
00242       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; }
00243       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; }
00244       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; }
00245       }
00246     
00247     if(i < aa_n_elem)
00248       {
00249       const uword ii = aa_mem[i];
00250       
00251       arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
00252       
00253            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  X[i]; }
00254       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; }
00255       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; }
00256       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; }
00257       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= X[i]; }
00258       }
00259     }
00260   else
00261     {
00262     arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected");
00263     
00264     const unwrap_check<typename Proxy<T2>::stored_type> tmp(P.Q, m_local);
00265     const Mat<eT>& M = tmp.M;
00266     
00267     const eT* X = M.memptr();
00268     
00269     uword i,j;
00270     for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
00271       {
00272       const uword ii = aa_mem[i];
00273       const uword jj = aa_mem[j];
00274       
00275       arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
00276       
00277            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  X[i]; m_mem[jj]  = X[j]; }
00278       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; }
00279       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; }
00280       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; }
00281       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; }
00282       }
00283     
00284     if(i < aa_n_elem)
00285       {
00286       const uword ii = aa_mem[i];
00287       
00288       arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
00289       
00290            if(is_same_type<op_type, op_subview_elem_equ          >::value == true) { m_mem[ii] =  X[i]; }
00291       else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; }
00292       else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; }
00293       else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; }
00294       else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { m_mem[ii] /= X[i]; }
00295       }
00296     }
00297   }
00298 
00299 
00300 
00301 //
00302 //
00303 
00304 
00305 
00306 template<typename eT, typename T1>
00307 inline
00308 void
00309 subview_elem1<eT,T1>::fill(const eT val)
00310   {
00311   arma_extra_debug_sigprint();
00312   
00313   inplace_op<op_subview_elem_equ>(val);
00314   }
00315 
00316 
00317 
00318 template<typename eT, typename T1>
00319 inline
00320 void
00321 subview_elem1<eT,T1>::zeros()
00322   {
00323   arma_extra_debug_sigprint();
00324   
00325   inplace_op<op_subview_elem_equ>(eT(0));
00326   }
00327 
00328 
00329 
00330 template<typename eT, typename T1>
00331 inline
00332 void
00333 subview_elem1<eT,T1>::ones()
00334   {
00335   arma_extra_debug_sigprint();
00336   
00337   inplace_op<op_subview_elem_equ>(eT(1));
00338   }
00339 
00340 
00341 
00342 template<typename eT, typename T1>
00343 inline
00344 void
00345 subview_elem1<eT,T1>::operator+= (const eT val)
00346   {
00347   arma_extra_debug_sigprint();
00348   
00349   inplace_op<op_subview_elem_inplace_plus>(val);
00350   }
00351 
00352 
00353 
00354 template<typename eT, typename T1>
00355 inline
00356 void
00357 subview_elem1<eT,T1>::operator-= (const eT val)
00358   {
00359   arma_extra_debug_sigprint();
00360   
00361   inplace_op<op_subview_elem_inplace_minus>(val);
00362   }
00363 
00364 
00365 
00366 template<typename eT, typename T1>
00367 inline
00368 void
00369 subview_elem1<eT,T1>::operator*= (const eT val)
00370   {
00371   arma_extra_debug_sigprint();
00372   
00373   inplace_op<op_subview_elem_inplace_schur>(val);
00374   }
00375 
00376 
00377 
00378 template<typename eT, typename T1>
00379 inline
00380 void
00381 subview_elem1<eT,T1>::operator/= (const eT val)
00382   {
00383   arma_extra_debug_sigprint();
00384   
00385   inplace_op<op_subview_elem_inplace_div>(val);
00386   }
00387 
00388 
00389 
00390 //
00391 //
00392 
00393 
00394 
00395 template<typename eT, typename T1>
00396 template<typename T2>
00397 inline
00398 void
00399 subview_elem1<eT,T1>::operator_equ(const subview_elem1<eT,T2>& x)
00400   {
00401   arma_extra_debug_sigprint();
00402   
00403   inplace_op<op_subview_elem_equ>(x);
00404   }
00405 
00406 
00407 
00408 
00409 template<typename eT, typename T1>
00410 template<typename T2>
00411 inline
00412 void
00413 subview_elem1<eT,T1>::operator= (const subview_elem1<eT,T2>& x)
00414   {
00415   arma_extra_debug_sigprint();
00416   
00417   (*this).operator_equ(x);
00418   }
00419 
00420 
00421 
00423 template<typename eT, typename T1>
00424 inline
00425 void
00426 subview_elem1<eT,T1>::operator= (const subview_elem1<eT,T1>& x)
00427   {
00428   arma_extra_debug_sigprint();
00429   
00430   (*this).operator_equ(x);
00431   }
00432 
00433 
00434 
00435 template<typename eT, typename T1>
00436 template<typename T2>
00437 inline
00438 void
00439 subview_elem1<eT,T1>::operator+= (const subview_elem1<eT,T2>& x)
00440   {
00441   arma_extra_debug_sigprint();
00442   
00443   inplace_op<op_subview_elem_inplace_plus>(x);
00444   }
00445 
00446 
00447 
00448 template<typename eT, typename T1>
00449 template<typename T2>
00450 inline
00451 void
00452 subview_elem1<eT,T1>::operator-= (const subview_elem1<eT,T2>& x)
00453   {
00454   arma_extra_debug_sigprint();
00455   
00456   inplace_op<op_subview_elem_inplace_minus>(x);
00457   }
00458 
00459 
00460 
00461 template<typename eT, typename T1>
00462 template<typename T2>
00463 inline
00464 void
00465 subview_elem1<eT,T1>::operator%= (const subview_elem1<eT,T2>& x)
00466   {
00467   arma_extra_debug_sigprint();
00468   
00469   inplace_op<op_subview_elem_inplace_schur>(x);
00470   }
00471 
00472 
00473 
00474 template<typename eT, typename T1>
00475 template<typename T2>
00476 inline
00477 void
00478 subview_elem1<eT,T1>::operator/= (const subview_elem1<eT,T2>& x)
00479   {
00480   arma_extra_debug_sigprint();
00481   
00482   inplace_op<op_subview_elem_inplace_div>(x);
00483   }
00484 
00485 
00486 
00487 template<typename eT, typename T1>
00488 template<typename T2>
00489 inline
00490 void
00491 subview_elem1<eT,T1>::operator= (const Base<eT,T2>& x)
00492   {
00493   arma_extra_debug_sigprint();
00494   
00495   inplace_op<op_subview_elem_equ>(x);
00496   }
00497 
00498 
00499 
00500 template<typename eT, typename T1>
00501 template<typename T2>
00502 inline
00503 void
00504 subview_elem1<eT,T1>::operator+= (const Base<eT,T2>& x)
00505   {
00506   arma_extra_debug_sigprint();
00507   
00508   inplace_op<op_subview_elem_inplace_plus>(x);
00509   }
00510 
00511 
00512 
00513 template<typename eT, typename T1>
00514 template<typename T2>
00515 inline
00516 void
00517 subview_elem1<eT,T1>::operator-= (const Base<eT,T2>& x)
00518   {
00519   arma_extra_debug_sigprint();
00520   
00521   inplace_op<op_subview_elem_inplace_minus>(x);
00522   }
00523 
00524 
00525 
00526 template<typename eT, typename T1>
00527 template<typename T2>
00528 inline
00529 void
00530 subview_elem1<eT,T1>::operator%= (const Base<eT,T2>& x)
00531   {
00532   arma_extra_debug_sigprint();
00533   
00534   inplace_op<op_subview_elem_inplace_schur>(x);
00535   }
00536 
00537 
00538 
00539 template<typename eT, typename T1>
00540 template<typename T2>
00541 inline
00542 void
00543 subview_elem1<eT,T1>::operator/= (const Base<eT,T2>& x)
00544   {
00545   arma_extra_debug_sigprint();
00546   
00547   inplace_op<op_subview_elem_inplace_div>(x);
00548   }
00549 
00550 
00551 
00552 //
00553 //
00554 
00555 
00556 
00557 template<typename eT, typename T1>
00558 inline
00559 void
00560 subview_elem1<eT,T1>::extract(Mat<eT>& actual_out, const subview_elem1<eT,T1>& in)
00561   {
00562   arma_extra_debug_sigprint();
00563   
00564   const unwrap_check_mixed<T1> tmp1(in.a.get_ref(), actual_out);
00565   const umat& aa = tmp1.M;
00566   
00567   arma_debug_check
00568     (
00569     ( aa.is_vec() == false ),
00570     "Mat::elem(): given object is not a vector"
00571     );
00572   
00573   const uword* aa_mem    = aa.memptr();
00574   const uword  aa_n_elem = aa.n_elem;
00575   
00576   const Mat<eT>& m_local = in.m;
00577   
00578   const eT*   m_mem    = m_local.memptr();
00579   const uword m_n_elem = m_local.n_elem;
00580   
00581   const bool alias = (&actual_out == &m_local);
00582   
00583   arma_extra_debug_warn(alias, "subview_elem1::extract(): aliasing detected");
00584   
00585   Mat<eT>* tmp_out = alias ? new Mat<eT>() : 0;
00586   Mat<eT>& out     = alias ? *tmp_out      : actual_out;
00587   
00588   out.set_size(aa_n_elem, 1);
00589   
00590   eT* out_mem = out.memptr();
00591   
00592   uword i,j;
00593   for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
00594     {
00595     const uword ii = aa_mem[i];
00596     const uword jj = aa_mem[j];
00597     
00598     arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
00599     
00600     out_mem[i] = m_mem[ii];
00601     out_mem[j] = m_mem[jj];
00602     }
00603   
00604   if(i < aa_n_elem)
00605     {
00606     const uword ii = aa_mem[i];
00607     
00608     arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
00609     
00610     out_mem[i] = m_mem[ii];
00611     }
00612   
00613   if(alias == true)
00614     {
00615     actual_out = out;
00616     delete tmp_out;
00617     }
00618   }
00619 
00620 
00621 
00622 template<typename eT, typename T1>
00623 template<typename op_type>
00624 inline
00625 void
00626 subview_elem1<eT,T1>::mat_inplace_op(Mat<eT>& out, const subview_elem1& in)
00627   {
00628   arma_extra_debug_sigprint();
00629   
00630   const unwrap<T1> tmp1(in.a.get_ref());
00631   const umat& aa = tmp1.M;
00632   
00633   arma_debug_check
00634     (
00635     ( aa.is_vec() == false ),
00636     "Mat::elem(): given object is not a vector"
00637     );
00638   
00639   const uword* aa_mem    = aa.memptr();
00640   const uword  aa_n_elem = aa.n_elem;
00641   
00642   const unwrap_check< Mat<eT> > tmp2(in.m, out);
00643   const Mat<eT>& m_local      = tmp2.M;
00644   
00645   const eT*   m_mem    = m_local.memptr();
00646   const uword m_n_elem = m_local.n_elem;
00647   
00648   arma_debug_check( (out.n_elem != aa_n_elem), "Mat::elem(): size mismatch" );
00649   
00650   eT* out_mem = out.memptr();
00651   
00652   uword i,j;
00653   for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
00654     {
00655     const uword ii = aa_mem[i];
00656     const uword jj = aa_mem[j];
00657     
00658     arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
00659     
00660          if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { out_mem[i] += m_mem[ii]; out_mem[j] += m_mem[jj]; }
00661     else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { out_mem[i] -= m_mem[ii]; out_mem[j] -= m_mem[jj]; }
00662     else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { out_mem[i] *= m_mem[ii]; out_mem[j] *= m_mem[jj]; }
00663     else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { out_mem[i] /= m_mem[ii]; out_mem[j] /= m_mem[jj]; }
00664     }
00665   
00666   if(i < aa_n_elem)
00667     {
00668     const uword ii = aa_mem[i];
00669     
00670     arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
00671     
00672          if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { out_mem[i] += m_mem[ii]; }
00673     else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { out_mem[i] -= m_mem[ii]; }
00674     else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { out_mem[i] *= m_mem[ii]; }
00675     else if(is_same_type<op_type, op_subview_elem_inplace_div  >::value == true) { out_mem[i] /= m_mem[ii]; }
00676     }
00677   }
00678 
00679 
00680 
00681 template<typename eT, typename T1>
00682 inline
00683 void
00684 subview_elem1<eT,T1>::plus_inplace(Mat<eT>& out, const subview_elem1& in)
00685   {
00686   arma_extra_debug_sigprint();
00687   
00688   mat_inplace_op<op_subview_elem_inplace_plus>(out, in);
00689   }
00690 
00691 
00692 
00693 template<typename eT, typename T1>
00694 inline
00695 void
00696 subview_elem1<eT,T1>::minus_inplace(Mat<eT>& out, const subview_elem1& in)
00697   {
00698   arma_extra_debug_sigprint();
00699   
00700   mat_inplace_op<op_subview_elem_inplace_minus>(out, in);
00701   }
00702 
00703 
00704 
00705 template<typename eT, typename T1>
00706 inline
00707 void
00708 subview_elem1<eT,T1>::schur_inplace(Mat<eT>& out, const subview_elem1& in)
00709   {
00710   arma_extra_debug_sigprint();
00711   
00712   mat_inplace_op<op_subview_elem_inplace_schur>(out, in);
00713   }
00714 
00715 
00716 
00717 template<typename eT, typename T1>
00718 inline
00719 void
00720 subview_elem1<eT,T1>::div_inplace(Mat<eT>& out, const subview_elem1& in)
00721   {
00722   arma_extra_debug_sigprint();
00723   
00724   mat_inplace_op<op_subview_elem_inplace_div>(out, in);
00725   }
00726 
00727 
00728 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:06