subview_meat.hpp
Go to the documentation of this file.
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 
00019 template<typename eT>
00020 inline
00021 subview<eT>::~subview()
00022   {
00023   arma_extra_debug_sigprint();
00024   }
00025 
00026 
00027 template<typename eT>
00028 inline
00029 subview<eT>::subview(const Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
00030   : m(in_m)
00031   , m_ptr(0)
00032   , aux_row1(in_row1)
00033   , aux_col1(in_col1)
00034   , n_rows(in_n_rows)
00035   , n_cols(in_n_cols)
00036   , n_elem(in_n_rows*in_n_cols)
00037   {
00038   arma_extra_debug_sigprint();
00039   }
00040 
00041 
00042 
00043 template<typename eT>
00044 inline
00045 subview<eT>::subview(Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
00046   : m(in_m)
00047   , m_ptr(&in_m)
00048   , aux_row1(in_row1)
00049   , aux_col1(in_col1)
00050   , n_rows(in_n_rows)
00051   , n_cols(in_n_cols)
00052   , n_elem(in_n_rows*in_n_cols)
00053   {
00054   arma_extra_debug_sigprint();
00055   }
00056 
00057 
00058 
00059 template<typename eT>
00060 inline
00061 void
00062 subview<eT>::operator+= (const eT val)
00063   {
00064   arma_extra_debug_sigprint();
00065   
00066   const uword local_n_cols = n_cols;
00067   const uword local_n_rows = n_rows;
00068   
00069   if(local_n_rows == 1)
00070     {
00071     Mat<eT>& X = (*m_ptr);
00072     
00073     const uword row           = aux_row1;
00074     const uword start_col     = aux_col1;
00075     const uword end_col_plus1 = start_col + local_n_cols;
00076     
00077     uword i,j;
00078     
00079     for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
00080       {
00081       X.at(row, i) += val;
00082       X.at(row, j) += val;
00083       }
00084     
00085     if(i < end_col_plus1)
00086       {
00087       X.at(row, i) += val;
00088       }
00089     }
00090   else
00091     {
00092     for(uword col=0; col<local_n_cols; ++col)
00093       {
00094       arrayops::inplace_plus( colptr(col), val, local_n_rows );
00095       }
00096     }
00097   }
00098 
00099 
00100 
00101 template<typename eT>
00102 inline
00103 void
00104 subview<eT>::operator-= (const eT val)
00105   {
00106   arma_extra_debug_sigprint();
00107   
00108   const uword local_n_cols = n_cols;
00109   const uword local_n_rows = n_rows;
00110   
00111   if(local_n_rows == 1)
00112     {
00113     Mat<eT>& X = (*m_ptr);
00114     
00115     const uword row           = aux_row1;
00116     const uword start_col     = aux_col1;
00117     const uword end_col_plus1 = start_col + local_n_cols;
00118     
00119     uword i,j;
00120     
00121     for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
00122       {
00123       X.at(row, i) -= val;
00124       X.at(row, j) -= val;
00125       }
00126     
00127     if(i < end_col_plus1)
00128       {
00129       X.at(row, i) -= val;
00130       }
00131     }
00132   else
00133     {
00134     for(uword col=0; col<local_n_cols; ++col)
00135       {
00136       arrayops::inplace_minus( colptr(col), val, local_n_rows );
00137       }
00138     }
00139   }
00140 
00141 
00142 
00143 template<typename eT>
00144 inline
00145 void
00146 subview<eT>::operator*= (const eT val)
00147   {
00148   arma_extra_debug_sigprint();
00149   
00150   const uword local_n_cols = n_cols;
00151   const uword local_n_rows = n_rows;
00152   
00153   if(local_n_rows == 1)
00154     {
00155     Mat<eT>& X = (*m_ptr);
00156     
00157     const uword row           = aux_row1;
00158     const uword start_col     = aux_col1;
00159     const uword end_col_plus1 = start_col + local_n_cols;
00160     
00161     uword i,j;
00162     
00163     for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
00164       {
00165       X.at(row, i) *= val;
00166       X.at(row, j) *= val;
00167       }
00168     
00169     if(i < end_col_plus1)
00170       {
00171       X.at(row, i) *= val;
00172       }
00173     }
00174   else
00175     {
00176     for(uword col=0; col<local_n_cols; ++col)
00177       {
00178       arrayops::inplace_mul( colptr(col), val, local_n_rows );
00179       }
00180     }
00181   }
00182 
00183 
00184 
00185 template<typename eT>
00186 inline
00187 void
00188 subview<eT>::operator/= (const eT val)
00189   {
00190   arma_extra_debug_sigprint();
00191   
00192   const uword local_n_cols = n_cols;
00193   const uword local_n_rows = n_rows;
00194   
00195   if(local_n_rows == 1)
00196     {
00197     Mat<eT>& X = (*m_ptr);
00198     
00199     const uword row           = aux_row1;
00200     const uword start_col     = aux_col1;
00201     const uword end_col_plus1 = start_col + local_n_cols;
00202     
00203     uword i,j;
00204     
00205     for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
00206       {
00207       X.at(row, i) /= val;
00208       X.at(row, j) /= val;
00209       }
00210     
00211     if(i < end_col_plus1)
00212       {
00213       X.at(row, i) /= val;
00214       }
00215     }
00216   else
00217     {
00218     for(uword col=0; col<local_n_cols; ++col)
00219       {
00220       arrayops::inplace_div( colptr(col), val, local_n_rows );
00221       }
00222     }
00223   }
00224 
00225 
00226 
00227 template<typename eT>
00228 template<typename T1>
00229 inline
00230 void
00231 subview<eT>::operator= (const Base<eT,T1>& in)
00232   {
00233   arma_extra_debug_sigprint();
00234   
00235   const Proxy<T1> P(in.get_ref());
00236   
00237   subview<eT>& t = *this;
00238   
00239   const uword t_n_rows = t.n_rows;
00240   const uword t_n_cols = t.n_cols;
00241     
00242   arma_debug_assert_same_size(t, P, "insert into submatrix");
00243   
00244   const bool alias = P.is_alias(t.m);
00245   
00246   arma_extra_debug_warn(alias, "aliasing detected");
00247   
00248   if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
00249     {
00250     const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
00251     const Mat<eT>& x = tmp.M;
00252     
00253     if(t_n_rows == 1)
00254       {
00255       const eT* x_mem = x.memptr();
00256       
00257       Mat<eT>& A = (*m_ptr);
00258       
00259       const uword row       = aux_row1;
00260       const uword start_col = aux_col1;
00261       
00262       uword i,j;
00263       
00264       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00265         {
00266         A.at(row, start_col+i) = x_mem[i];
00267         A.at(row, start_col+j) = x_mem[j];
00268         }
00269       
00270       if(i < t_n_cols)
00271         {
00272         A.at(row, start_col+i) = x_mem[i];
00273         }
00274       }
00275     else
00276       {
00277       for(uword col=0; col<t_n_cols; ++col)
00278         {
00279         arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows );
00280         }
00281       }
00282     }
00283   else
00284     {
00285     if(t_n_rows == 1)
00286       {
00287       Mat<eT>& A = (*m_ptr);
00288       
00289       const uword row       = aux_row1;
00290       const uword start_col = aux_col1;
00291       
00292       uword i,j;
00293       
00294       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00295         {
00296         const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00297         const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
00298         
00299         A.at(row, start_col+i) = tmp1;
00300         A.at(row, start_col+j) = tmp2;
00301         }
00302       
00303       if(i < t_n_cols)
00304         {
00305         A.at(row, start_col+i) = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00306         }
00307       }
00308     else
00309       {
00310       for(uword col=0; col<t_n_cols; ++col)
00311         {
00312         eT* t_col_data = t.colptr(col);
00313         
00314         uword i,j;
00315         for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
00316           {
00317           const eT tmp1 = P.at(i,col);
00318           const eT tmp2 = P.at(j,col);
00319           
00320           t_col_data[i] = tmp1;
00321           t_col_data[j] = tmp2;
00322           }
00323         
00324         if(i < t_n_rows)
00325           {
00326           t_col_data[i] = P.at(i,col);
00327           }
00328         }
00329       }
00330     }
00331   }
00332 
00333 
00334 
00335 template<typename eT>
00336 template<typename T1>
00337 inline
00338 void
00339 subview<eT>::operator+= (const Base<eT,T1>& in)
00340   {
00341   arma_extra_debug_sigprint();
00342   
00343   const Proxy<T1> P(in.get_ref());
00344   
00345   subview<eT>& t = *this;
00346   
00347   const uword t_n_rows = t.n_rows;
00348   const uword t_n_cols = t.n_cols;
00349   
00350   arma_debug_assert_same_size(t, P, "addition");
00351   
00352   const bool alias = P.is_alias(t.m);
00353   
00354   arma_extra_debug_warn(alias, "aliasing detected");
00355   
00356   if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
00357     {
00358     const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
00359     const Mat<eT>& x = tmp.M;
00360     
00361     if(t_n_rows == 1)
00362       {
00363       const eT* x_mem = x.memptr();
00364       
00365       Mat<eT>& A = (*m_ptr);
00366       
00367       const uword row       = aux_row1;
00368       const uword start_col = aux_col1;
00369       
00370       uword i,j;
00371       
00372       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00373         {
00374         A.at(row, start_col+i) += x_mem[i];
00375         A.at(row, start_col+j) += x_mem[j];
00376         }
00377       
00378       if(i < t_n_cols)
00379         {
00380         A.at(row, start_col+i) += x_mem[i];
00381         }
00382       }
00383     else
00384       {
00385       for(uword col=0; col<t_n_cols; ++col)
00386         {
00387         arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows );
00388         }
00389       }
00390     }
00391   else
00392     {
00393     if(t_n_rows == 1)
00394       {
00395       Mat<eT>& A = (*m_ptr);
00396       
00397       const uword row       = aux_row1;
00398       const uword start_col = aux_col1;
00399       
00400       uword i,j;
00401       
00402       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00403         {
00404         const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00405         const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
00406         
00407         A.at(row, start_col+i) += tmp1;
00408         A.at(row, start_col+j) += tmp2;
00409         }
00410       
00411       if(i < t_n_cols)
00412         {
00413         A.at(row, start_col+i) += (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00414         }
00415       }
00416     else
00417       {
00418       for(uword col=0; col<t_n_cols; ++col)
00419         {
00420         eT* t_col_data = t.colptr(col);
00421         
00422         uword i,j;
00423         for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
00424           {
00425           const eT val1 = P.at(i,col);
00426           const eT val2 = P.at(j,col);
00427           
00428           t_col_data[i] += val1;
00429           t_col_data[j] += val2;
00430           }
00431         
00432         if(i < t_n_rows)
00433           {
00434           t_col_data[i] += P.at(i,col);
00435           }
00436         }
00437       }
00438     }
00439   }
00440 
00441 
00442 
00443 template<typename eT>
00444 template<typename T1>
00445 inline
00446 void
00447 subview<eT>::operator-= (const Base<eT,T1>& in)
00448   {
00449   arma_extra_debug_sigprint();
00450   
00451   const Proxy<T1> P(in.get_ref());
00452   
00453   subview<eT>& t = *this;
00454   
00455   const uword t_n_rows = t.n_rows;
00456   const uword t_n_cols = t.n_cols;
00457   
00458   arma_debug_assert_same_size(t, P, "subtraction");
00459   
00460   const bool alias = P.is_alias(t.m);
00461   
00462   if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
00463     {
00464     const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
00465     const Mat<eT>& x = tmp.M;
00466     
00467     if(t_n_rows == 1)
00468       {
00469       const eT* x_mem = x.memptr();
00470       
00471       Mat<eT>& A = (*m_ptr);
00472       
00473       const uword row       = aux_row1;
00474       const uword start_col = aux_col1;
00475       
00476       uword i,j;
00477       
00478       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00479         {
00480         A.at(row, start_col+i) -= x_mem[i];
00481         A.at(row, start_col+j) -= x_mem[j];
00482         }
00483       
00484       if(i < t_n_cols)
00485         {
00486         A.at(row, start_col+i) -= x_mem[i];
00487         }
00488       }
00489     else
00490       {
00491       for(uword col=0; col<t_n_cols; ++col)
00492         {
00493         arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows );
00494         }
00495       }
00496     }
00497   else
00498     {
00499     if(t_n_rows == 1)
00500       {
00501       Mat<eT>& A = (*m_ptr);
00502       
00503       const uword row       = aux_row1;
00504       const uword start_col = aux_col1;
00505       
00506       uword i,j;
00507       
00508       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00509         {
00510         const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00511         const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
00512         
00513         A.at(row, start_col+i) -= tmp1;
00514         A.at(row, start_col+j) -= tmp2;
00515         }
00516       
00517       if(i < t_n_cols)
00518         {
00519         A.at(row, start_col+i) -= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00520         }
00521       }
00522     else
00523       {
00524       for(uword col=0; col<t_n_cols; ++col)
00525         {
00526         eT* t_col_data = t.colptr(col);
00527         
00528         uword i,j;
00529         for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
00530           {
00531           const eT val1 = P.at(i,col);
00532           const eT val2 = P.at(j,col);
00533           
00534           t_col_data[i] -= val1;
00535           t_col_data[j] -= val2;
00536           }
00537         
00538         if(i < t_n_rows)
00539           {
00540           t_col_data[i] -= P.at(i,col);
00541           }
00542         }
00543       }
00544     }
00545   }
00546 
00547 
00548 
00549 template<typename eT>
00550 template<typename T1>
00551 inline
00552 void
00553 subview<eT>::operator%= (const Base<eT,T1>& in)
00554   {
00555   arma_extra_debug_sigprint();
00556   
00557   const Proxy<T1> P(in.get_ref());
00558   
00559   subview<eT>& t = *this;
00560   
00561   const uword t_n_rows = t.n_rows;
00562   const uword t_n_cols = t.n_cols;
00563   
00564   arma_debug_assert_same_size(t, P, "element-wise multiplication");
00565   
00566   const bool alias = P.is_alias(t.m);
00567   
00568   arma_extra_debug_warn(alias, "aliasing detected");
00569   
00570   if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
00571     {
00572     const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
00573     const Mat<eT>& x = tmp.M;
00574     
00575     if(t_n_rows == 1)
00576       {
00577       const eT* x_mem = x.memptr();
00578       
00579       Mat<eT>& A = (*m_ptr);
00580       
00581       const uword row       = aux_row1;
00582       const uword start_col = aux_col1;
00583       
00584       uword i,j;
00585       
00586       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00587         {
00588         A.at(row, start_col+i) *= x_mem[i];
00589         A.at(row, start_col+j) *= x_mem[j];
00590         }
00591       
00592       if(i < t_n_cols)
00593         {
00594         A.at(row, start_col+i) *= x_mem[i];
00595         }
00596       }
00597     else
00598       {
00599       for(uword col=0; col<t_n_cols; ++col)
00600         {
00601         arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows );
00602         }
00603       }
00604     }
00605   else
00606     {
00607     if(t_n_rows == 1)
00608       {
00609       Mat<eT>& A = (*m_ptr);
00610       
00611       const uword row       = aux_row1;
00612       const uword start_col = aux_col1;
00613       
00614       uword i,j;
00615       
00616       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00617         {
00618         const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00619         const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
00620         
00621         A.at(row, start_col+i) *= tmp1;
00622         A.at(row, start_col+j) *= tmp2;
00623         }
00624       
00625       if(i < t_n_cols)
00626         {
00627         A.at(row, start_col+i) *= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00628         }
00629       }
00630     else
00631       {
00632       for(uword col=0; col<t_n_cols; ++col)
00633         {
00634         eT* t_col_data = t.colptr(col);
00635         
00636         uword i,j;
00637         for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
00638           {
00639           const eT val1 = P.at(i,col);
00640           const eT val2 = P.at(j,col);
00641           
00642           t_col_data[i] *= val1;
00643           t_col_data[j] *= val2;
00644           }
00645         
00646         if(i < t_n_rows)
00647           {
00648           t_col_data[i] *= P.at(i,col);
00649           }
00650         }
00651       }
00652     }
00653   }
00654 
00655 
00656 
00657 template<typename eT>
00658 template<typename T1>
00659 inline
00660 void
00661 subview<eT>::operator/= (const Base<eT,T1>& in)
00662   {
00663   arma_extra_debug_sigprint();
00664   
00665   const Proxy<T1> P(in.get_ref());
00666   
00667   subview<eT>& t = *this;
00668   
00669   const uword t_n_rows = t.n_rows;
00670   const uword t_n_cols = t.n_cols;
00671   
00672   arma_debug_assert_same_size(t, P, "element-wise division");
00673   
00674   const bool alias = P.is_alias(t.m);
00675   
00676   arma_extra_debug_warn(alias, "aliasing detected");
00677   
00678   if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
00679     {
00680     const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
00681     const Mat<eT>& x = tmp.M;
00682     
00683     if(t_n_rows == 1)
00684       {
00685       const eT* x_mem = x.memptr();
00686       
00687       Mat<eT>& A = (*m_ptr);
00688       
00689       const uword row       = aux_row1;
00690       const uword start_col = aux_col1;
00691       
00692       uword i,j;
00693       
00694       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00695         {
00696         A.at(row, start_col+i) /= x_mem[i];
00697         A.at(row, start_col+j) /= x_mem[j];
00698         }
00699       
00700       if(i < t_n_cols)
00701         {
00702         A.at(row, start_col+i) /= x_mem[i];
00703         }
00704       }
00705     else
00706       {
00707       for(uword col=0; col<t_n_cols; ++col)
00708         {
00709         arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows );
00710         }
00711       }
00712     }
00713   else
00714     {
00715     if(t_n_rows == 1)
00716       {
00717       Mat<eT>& A = (*m_ptr);
00718       
00719       const uword row       = aux_row1;
00720       const uword start_col = aux_col1;
00721       
00722       uword i,j;
00723       
00724       for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00725         {
00726         const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00727         const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
00728         
00729         A.at(row, start_col+i) /= tmp1;
00730         A.at(row, start_col+j) /= tmp2;
00731         }
00732       
00733       if(i < t_n_cols)
00734         {
00735         A.at(row, start_col+i) /= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
00736         }
00737       }
00738     else
00739       {
00740       for(uword col=0; col<t_n_cols; ++col)
00741         {
00742         eT* t_col_data = t.colptr(col);
00743         
00744         uword i,j;
00745         for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
00746           {
00747           const eT val1 = P.at(i,col);
00748           const eT val2 = P.at(j,col);
00749           
00750           t_col_data[i] /= val1;
00751           t_col_data[j] /= val2;
00752           }
00753         
00754         if(i < t_n_rows)
00755           {
00756           t_col_data[i] /= P.at(i,col);
00757           }
00758         }
00759       }
00760     }
00761   }
00762 
00763 
00764 
00766 template<typename eT>
00767 inline
00768 void
00769 subview<eT>::operator= (const subview<eT>& x_in)
00770   {
00771   arma_extra_debug_sigprint();
00772   
00773   const bool overlap = check_overlap(x_in);
00774   
00775         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00776   const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
00777   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00778   
00779   subview<eT>& t = *this;
00780   
00781   arma_debug_assert_same_size(t, x, "insert into submatrix");
00782   
00783   const uword t_n_cols = t.n_cols;
00784   const uword t_n_rows = t.n_rows;
00785   
00786   if(t_n_rows == 1)
00787     {
00788           Mat<eT>& A = *(t.m_ptr);
00789     const Mat<eT>& B = x.m;
00790     
00791     const uword row_A = t.aux_row1;
00792     const uword row_B = x.aux_row1;
00793     
00794     const uword start_col_A = t.aux_col1;
00795     const uword start_col_B = x.aux_col1;
00796     
00797     uword i,j;
00798     
00799     for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00800       {
00801       const eT tmp1 = B.at(row_B, start_col_B + i);
00802       const eT tmp2 = B.at(row_B, start_col_B + j);
00803       
00804       A.at(row_A, start_col_A + i) = tmp1;
00805       A.at(row_A, start_col_A + j) = tmp2;
00806       }
00807     
00808     if(i < t_n_cols)
00809       {
00810       A.at(row_A, start_col_A + i) = B.at(row_B, start_col_B + i);
00811       }
00812     }
00813   else
00814     {
00815     for(uword col=0; col<t_n_cols; ++col)
00816       {
00817       arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows );
00818       }
00819     }
00820   
00821   if(overlap)
00822     {
00823     delete tmp_subview;
00824     delete tmp_mat;
00825     }
00826   }
00827 
00828 
00829 
00830 template<typename eT>
00831 inline
00832 void
00833 subview<eT>::operator+= (const subview<eT>& x_in)
00834   {
00835   arma_extra_debug_sigprint();
00836   
00837   const bool overlap = check_overlap(x_in);
00838   
00839         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00840   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
00841   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00842   
00843   subview<eT>& t = *this;
00844   
00845   arma_debug_assert_same_size(t, x, "addition");
00846   
00847   const uword t_n_rows = t.n_rows;
00848   const uword t_n_cols = t.n_cols;
00849   
00850   if(t_n_rows == 1)
00851     {
00852           Mat<eT>& A = *(t.m_ptr);
00853     const Mat<eT>& B = x.m;
00854     
00855     const uword row_A = t.aux_row1;
00856     const uword row_B = x.aux_row1;
00857     
00858     const uword start_col_A = t.aux_col1;
00859     const uword start_col_B = x.aux_col1;
00860     
00861     uword i,j;
00862     
00863     for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00864       {
00865       const eT tmp1 = B.at(row_B, start_col_B + i);
00866       const eT tmp2 = B.at(row_B, start_col_B + j);
00867       
00868       A.at(row_A, start_col_A + i) += tmp1;
00869       A.at(row_A, start_col_A + j) += tmp2;
00870       }
00871     
00872     if(i < t_n_cols)
00873       {
00874       A.at(row_A, start_col_A + i) += B.at(row_B, start_col_B + i);
00875       }
00876     }
00877   else
00878     {
00879     for(uword col=0; col<t_n_cols; ++col)
00880       {
00881       arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows );
00882       }
00883     }
00884   
00885   if(overlap)
00886     {
00887     delete tmp_subview;
00888     delete tmp_mat;
00889     }
00890   }
00891 
00892 
00893 
00894 template<typename eT>
00895 inline
00896 void
00897 subview<eT>::operator-= (const subview<eT>& x_in)
00898   {
00899   arma_extra_debug_sigprint();
00900   
00901   const bool overlap = check_overlap(x_in);
00902   
00903         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00904   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
00905   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00906   
00907   subview<eT>& t = *this;
00908   
00909   arma_debug_assert_same_size(t, x, "subtraction");
00910   
00911   const uword t_n_rows = t.n_rows;
00912   const uword t_n_cols = t.n_cols;
00913   
00914   if(t_n_rows == 1)
00915     {
00916           Mat<eT>& A = *(t.m_ptr);
00917     const Mat<eT>& B = x.m;
00918     
00919     const uword row_A = t.aux_row1;
00920     const uword row_B = x.aux_row1;
00921     
00922     const uword start_col_A = t.aux_col1;
00923     const uword start_col_B = x.aux_col1;
00924     
00925     uword i,j;
00926     
00927     for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00928       {
00929       const eT tmp1 = B.at(row_B, start_col_B + i);
00930       const eT tmp2 = B.at(row_B, start_col_B + j);
00931       
00932       A.at(row_A, start_col_A + i) -= tmp1;
00933       A.at(row_A, start_col_A + j) -= tmp2;
00934       }
00935     
00936     if(i < t_n_cols)
00937       {
00938       A.at(row_A, start_col_A + i) -= B.at(row_B, start_col_B + i);
00939       }
00940     }
00941   else
00942     {
00943     for(uword col=0; col<t_n_cols; ++col)
00944       {
00945       arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows );
00946       }
00947     }
00948     
00949   if(overlap)
00950     {
00951     delete tmp_subview;
00952     delete tmp_mat;
00953     }
00954   
00955   }
00956 
00957 
00958 
00959 template<typename eT>
00960 inline
00961 void
00962 subview<eT>::operator%= (const subview& x_in)
00963   {
00964   arma_extra_debug_sigprint();
00965   
00966   const bool overlap = check_overlap(x_in);
00967   
00968         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00969   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
00970   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00971   
00972   subview<eT>& t = *this;
00973   
00974   arma_debug_assert_same_size(t, x, "element-wise multiplication");
00975   
00976   const uword t_n_rows = t.n_rows;
00977   const uword t_n_cols = t.n_cols;
00978   
00979   if(t_n_rows == 1)
00980     {
00981           Mat<eT>& A = *(t.m_ptr);
00982     const Mat<eT>& B = x.m;
00983     
00984     const uword row_A = t.aux_row1;
00985     const uword row_B = x.aux_row1;
00986     
00987     const uword start_col_A = t.aux_col1;
00988     const uword start_col_B = x.aux_col1;
00989     
00990     uword i,j;
00991     
00992     for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
00993       {
00994       const eT tmp1 = B.at(row_B, start_col_B + i);
00995       const eT tmp2 = B.at(row_B, start_col_B + j);
00996       
00997       A.at(row_A, start_col_A + i) *= tmp1;
00998       A.at(row_A, start_col_A + j) *= tmp2;
00999       }
01000     
01001     if(i < t_n_cols)
01002       {
01003       A.at(row_A, start_col_A + i) *= B.at(row_B, start_col_B + i);
01004       }
01005     }
01006   else
01007     {
01008     for(uword col=0; col<t_n_cols; ++col)
01009       {
01010       arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows );
01011       }
01012     }
01013   
01014   if(overlap)
01015     {
01016     delete tmp_subview;
01017     delete tmp_mat;
01018     }
01019   
01020   }
01021 
01022 
01023 
01024 template<typename eT>
01025 inline
01026 void
01027 subview<eT>::operator/= (const subview& x_in)
01028   {
01029   arma_extra_debug_sigprint();
01030   
01031   const bool overlap = check_overlap(x_in);
01032   
01033         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
01034   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
01035   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
01036   
01037   subview<eT>& t = *this;
01038   
01039   arma_debug_assert_same_size(t, x, "element-wise division");
01040   
01041   const uword t_n_rows = t.n_rows;
01042   const uword t_n_cols = t.n_cols;
01043   
01044   if(t_n_rows == 1)
01045     {
01046           Mat<eT>& A = *(t.m_ptr);
01047     const Mat<eT>& B = x.m;
01048     
01049     const uword row_A = t.aux_row1;
01050     const uword row_B = x.aux_row1;
01051     
01052     const uword start_col_A = t.aux_col1;
01053     const uword start_col_B = x.aux_col1;
01054     
01055     uword i,j;
01056     
01057     for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
01058       {
01059       const eT tmp1 = B.at(row_B, start_col_B + i);
01060       const eT tmp2 = B.at(row_B, start_col_B + j);
01061       
01062       A.at(row_A, start_col_A + i) /= tmp1;
01063       A.at(row_A, start_col_A + j) /= tmp2;
01064       }
01065     
01066     if(i < t_n_cols)
01067       {
01068       A.at(row_A, start_col_A + i) /= B.at(row_B, start_col_B + i);
01069       }
01070     }
01071   else
01072     {
01073     for(uword col=0; col<t_n_cols; ++col)
01074       {
01075       arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows );
01076       }
01077     }
01078     
01079   if(overlap)
01080     {
01081     delete tmp_subview;
01082     delete tmp_mat;
01083     }
01084   
01085   }
01086 
01087 
01088 
01089 template<typename eT>
01090 inline
01091 void
01092 subview<eT>::fill(const eT val)
01093   {
01094   arma_extra_debug_sigprint();
01095   
01096   const uword local_n_cols = n_cols;
01097   const uword local_n_rows = n_rows;
01098   
01099   if(local_n_rows == 1)
01100     {
01101     Mat<eT>& X = (*m_ptr);
01102     
01103     const uword row           = aux_row1;
01104     const uword start_col     = aux_col1;
01105     const uword end_col_plus1 = start_col + local_n_cols;
01106     
01107     uword i,j;
01108     
01109     for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
01110       {
01111       X.at(row, i) = val;
01112       X.at(row, j) = val;
01113       }
01114     
01115     if(i < end_col_plus1)
01116       {
01117       X.at(row, i) = val;
01118       }
01119     }
01120   else
01121     {
01122     for(uword col=0; col<local_n_cols; ++col)
01123       {
01124       arrayops::inplace_set( colptr(col), val, local_n_rows );
01125       }
01126     }
01127   }
01128 
01129 
01130 
01131 template<typename eT>
01132 inline
01133 void
01134 subview<eT>::zeros()
01135   {
01136   arma_extra_debug_sigprint();
01137   
01138   (*this).fill(eT(0));
01139   }
01140 
01141 
01142 
01143 template<typename eT>
01144 inline
01145 void
01146 subview<eT>::ones()
01147   {
01148   arma_extra_debug_sigprint();
01149   
01150   (*this).fill(eT(1));
01151   }
01152 
01153 
01154 
01155 template<typename eT>
01156 inline
01157 void
01158 subview<eT>::eye()
01159   {
01160   arma_extra_debug_sigprint();
01161   
01162   fill(eT(0));
01163   
01164   const uword N = (std::min)(n_rows, n_cols);
01165   
01166   for(uword i=0; i<N; ++i)
01167     {
01168     at(i,i) = eT(1);
01169     }
01170   }
01171 
01172 
01173 
01174 template<typename eT>
01175 inline
01176 eT&
01177 subview<eT>::operator[](const uword i)
01178   {
01179   const uword in_col = i / n_rows;
01180   const uword in_row = i % n_rows;
01181     
01182   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01183   return access::rw( (*m_ptr).mem[index] );
01184   }
01185 
01186 
01187 
01188 template<typename eT>
01189 inline
01190 eT
01191 subview<eT>::operator[](const uword i) const
01192   {
01193   const uword in_col = i / n_rows;
01194   const uword in_row = i % n_rows;
01195   
01196   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01197   return m.mem[index];
01198   }
01199 
01200 
01201 
01202 template<typename eT>
01203 inline
01204 eT&
01205 subview<eT>::operator()(const uword i)
01206   {
01207   arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
01208     
01209   const uword in_col = i / n_rows;
01210   const uword in_row = i % n_rows;
01211   
01212   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01213   return access::rw( (*m_ptr).mem[index] );
01214   }
01215 
01216 
01217 
01218 template<typename eT>
01219 inline
01220 eT
01221 subview<eT>::operator()(const uword i) const
01222   {
01223   arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
01224   
01225   const uword in_col = i / n_rows;
01226   const uword in_row = i % n_rows;
01227   
01228   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01229   return m.mem[index];
01230   }
01231 
01232 
01233 
01234 template<typename eT>
01235 inline
01236 eT&
01237 subview<eT>::operator()(const uword in_row, const uword in_col)
01238   {
01239   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
01240   
01241   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01242   return access::rw( (*m_ptr).mem[index] );
01243   }
01244 
01245 
01246 
01247 template<typename eT>
01248 inline
01249 eT
01250 subview<eT>::operator()(const uword in_row, const uword in_col) const
01251   {
01252   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
01253   
01254   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01255   return m.mem[index];
01256   }
01257 
01258 
01259 
01260 template<typename eT>
01261 inline
01262 eT&
01263 subview<eT>::at(const uword in_row, const uword in_col)
01264   {
01265   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01266   return access::rw( (*m_ptr).mem[index] );
01267   }
01268 
01269 
01270 
01271 template<typename eT>
01272 inline
01273 eT
01274 subview<eT>::at(const uword in_row, const uword in_col) const
01275   {
01276   const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
01277   return m.mem[index];
01278   }
01279 
01280 
01281 
01282 template<typename eT>
01283 arma_inline
01284 eT*
01285 subview<eT>::colptr(const uword in_col)
01286   {
01287   return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]);
01288   }
01289 
01290 
01291 
01292 template<typename eT>
01293 arma_inline
01294 const eT*
01295 subview<eT>::colptr(const uword in_col) const
01296   {
01297   return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ];
01298   }
01299 
01300 
01301 
01302 template<typename eT>
01303 inline
01304 bool
01305 subview<eT>::check_overlap(const subview<eT>& x) const
01306   {
01307   const subview<eT>& t = *this;
01308   
01309   if(&t.m != &x.m)
01310     {
01311     return false;
01312     }
01313   else
01314     {
01315     if( (t.n_elem == 0) || (x.n_elem == 0) )
01316       {
01317       return false;
01318       }
01319     else
01320       {
01321       const uword t_row_start  = t.aux_row1;
01322       const uword t_row_end_p1 = t_row_start + t.n_rows;
01323       
01324       const uword t_col_start  = t.aux_col1;
01325       const uword t_col_end_p1 = t_col_start + t.n_cols;
01326       
01327       
01328       const uword x_row_start  = x.aux_row1;
01329       const uword x_row_end_p1 = x_row_start + x.n_rows;
01330       
01331       const uword x_col_start  = x.aux_col1;
01332       const uword x_col_end_p1 = x_col_start + x.n_cols;
01333       
01334       
01335       const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) );
01336       const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) );
01337       
01338       return ( (outside_rows == false) && (outside_cols == false) );
01339       }
01340     }
01341   }
01342 
01343 
01344 
01345 template<typename eT>
01346 inline
01347 bool
01348 subview<eT>::is_vec() const
01349   {
01350   return ( (n_rows == 1) || (n_cols == 1) );
01351   }
01352 
01353 
01354 
01356 template<typename eT>
01357 inline
01358 void
01359 subview<eT>::extract(Mat<eT>& out, const subview<eT>& in)
01360   {
01361   arma_extra_debug_sigprint();
01362   
01363   // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
01364   // size setting and alias checking is done by either the Mat contructor or operator=()
01365   
01366   const uword n_rows = in.n_rows;  // number of rows in the subview
01367   const uword n_cols = in.n_cols;  // number of columns in the subview
01368   
01369   arma_extra_debug_print(arma_boost::format("out.n_rows = %d   out.n_cols = %d    in.m.n_rows = %d  in.m.n_cols = %d") % out.n_rows % out.n_cols % in.m.n_rows % in.m.n_cols );
01370   
01371   
01372   if(in.is_vec() == true)
01373     {
01374     if(n_cols == 1)   // a column vector
01375       {
01376       arma_extra_debug_print("subview::extract(): copying col (going across rows)");
01377       
01378       // in.colptr(0) the first column of the subview, taking into account any row offset
01379       arrayops::copy( out.memptr(), in.colptr(0), n_rows );
01380       }
01381     else   // a row vector (possibly empty)
01382       {
01383       arma_extra_debug_print("subview::extract(): copying row (going across columns)");
01384       
01385       const Mat<eT>& X = in.m;
01386       
01387       eT* out_mem = out.memptr();
01388       
01389       const uword row       = in.aux_row1;
01390       const uword start_col = in.aux_col1;
01391       
01392       uword i,j;
01393       
01394       for(i=0, j=1; j < n_cols; i+=2, j+=2)
01395         {
01396         const eT tmp1 = X.at(row, start_col+i);
01397         const eT tmp2 = X.at(row, start_col+j);
01398         
01399         out_mem[i] = tmp1;
01400         out_mem[j] = tmp2;
01401         }
01402       
01403       if(i < n_cols)
01404         {
01405         out_mem[i] = X.at(row, start_col+i);
01406         }
01407       }
01408     }
01409   else   // general submatrix
01410     {
01411     arma_extra_debug_print("subview::extract(): general submatrix");
01412     
01413     for(uword col = 0; col<n_cols; ++col)   
01414       {
01415       arrayops::copy( out.colptr(col), in.colptr(col), n_rows );
01416       }
01417     }
01418   }
01419 
01420 
01421 
01423 template<typename eT>
01424 inline
01425 void
01426 subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in)
01427   {
01428   arma_extra_debug_sigprint();
01429   
01430   arma_debug_assert_same_size(out, in, "addition");
01431   
01432   const uword n_rows = in.n_rows;
01433   const uword n_cols = in.n_cols;
01434   
01435   if(n_rows == 1)
01436     {
01437     eT* out_mem = out.memptr();
01438     
01439     const Mat<eT>& X = in.m;
01440     
01441     const uword row       = in.aux_row1;
01442     const uword start_col = in.aux_col1;
01443     
01444     uword i,j;
01445     for(i=0, j=1; j < n_cols; i+=2, j+=2)
01446       {
01447       const eT tmp1 = X.at(row, start_col+i);
01448       const eT tmp2 = X.at(row, start_col+j);
01449         
01450       out_mem[i] += tmp1;
01451       out_mem[j] += tmp2;
01452       }
01453     
01454     if(i < n_cols)
01455       {
01456       out_mem[i] += X.at(row, start_col+i);
01457       }
01458     }
01459   else
01460     {
01461     for(uword col=0; col<n_cols; ++col)
01462       {
01463       arrayops::inplace_plus(out.colptr(col), in.colptr(col), n_rows);
01464       }
01465     }
01466   }
01467 
01468 
01469 
01471 template<typename eT>
01472 inline
01473 void
01474 subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in)
01475   {
01476   arma_extra_debug_sigprint();
01477   
01478   arma_debug_assert_same_size(out, in, "subtraction");
01479   
01480   const uword n_rows = in.n_rows;
01481   const uword n_cols = in.n_cols;
01482   
01483   if(n_rows == 1)
01484     {
01485     eT* out_mem = out.memptr();
01486     
01487     const Mat<eT>& X = in.m;
01488     
01489     const uword row       = in.aux_row1;
01490     const uword start_col = in.aux_col1;
01491     
01492     uword i,j;
01493     for(i=0, j=1; j < n_cols; i+=2, j+=2)
01494       {
01495       const eT tmp1 = X.at(row, start_col+i);
01496       const eT tmp2 = X.at(row, start_col+j);
01497         
01498       out_mem[i] -= tmp1;
01499       out_mem[j] -= tmp2;
01500       }
01501     
01502     if(i < n_cols)
01503       {
01504       out_mem[i] -= X.at(row, start_col+i);
01505       }
01506     }
01507   else
01508     {
01509     for(uword col=0; col<n_cols; ++col)
01510       {
01511       arrayops::inplace_minus(out.colptr(col), in.colptr(col), n_rows);
01512       }
01513     }
01514   }
01515 
01516 
01517 
01519 template<typename eT>
01520 inline
01521 void
01522 subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in)
01523   {
01524   arma_extra_debug_sigprint();
01525   
01526   arma_debug_assert_same_size(out, in, "element-wise multiplication");
01527   
01528   const uword n_rows = in.n_rows;
01529   const uword n_cols = in.n_cols;
01530   
01531   if(n_rows == 1)
01532     {
01533     eT* out_mem = out.memptr();
01534     
01535     const Mat<eT>& X = in.m;
01536     
01537     const uword row       = in.aux_row1;
01538     const uword start_col = in.aux_col1;
01539     
01540     uword i,j;
01541     for(i=0, j=1; j < n_cols; i+=2, j+=2)
01542       {
01543       const eT tmp1 = X.at(row, start_col+i);
01544       const eT tmp2 = X.at(row, start_col+j);
01545         
01546       out_mem[i] *= tmp1;
01547       out_mem[j] *= tmp2;
01548       }
01549     
01550     if(i < n_cols)
01551       {
01552       out_mem[i] *= X.at(row, start_col+i);
01553       }
01554     }
01555   else
01556     {
01557     for(uword col=0; col<n_cols; ++col)
01558       {
01559       arrayops::inplace_mul(out.colptr(col), in.colptr(col), n_rows);
01560       }
01561     }
01562   }
01563 
01564 
01565 
01567 template<typename eT>
01568 inline
01569 void
01570 subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in)
01571   {
01572   arma_extra_debug_sigprint();
01573   
01574   arma_debug_assert_same_size(out, in, "element-wise division");
01575   
01576   const uword n_rows = in.n_rows;
01577   const uword n_cols = in.n_cols;
01578   
01579   if(n_rows == 1)
01580     {
01581     eT* out_mem = out.memptr();
01582     
01583     const Mat<eT>& X = in.m;
01584     
01585     const uword row       = in.aux_row1;
01586     const uword start_col = in.aux_col1;
01587     
01588     uword i,j;
01589     for(i=0, j=1; j < n_cols; i+=2, j+=2)
01590       {
01591       const eT tmp1 = X.at(row, start_col+i);
01592       const eT tmp2 = X.at(row, start_col+j);
01593         
01594       out_mem[i] /= tmp1;
01595       out_mem[j] /= tmp2;
01596       }
01597     
01598     if(i < n_cols)
01599       {
01600       out_mem[i] /= X.at(row, start_col+i);
01601       }
01602     }
01603   else
01604     {
01605     for(uword col=0; col<n_cols; ++col)
01606       {
01607       arrayops::inplace_div(out.colptr(col), in.colptr(col), n_rows);
01608       }
01609     }
01610   }
01611 
01612 
01613 
01615 template<typename eT>
01616 inline
01617 subview_row<eT>
01618 subview<eT>::row(const uword row_num)
01619   {
01620   arma_extra_debug_sigprint();
01621   
01622   arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" );
01623   
01624   const uword base_row = aux_row1 + row_num;
01625   
01626   return subview_row<eT>(*m_ptr, base_row, aux_col1, n_cols);
01627   }
01628 
01629 
01630 
01632 template<typename eT>
01633 inline
01634 const subview_row<eT>
01635 subview<eT>::row(const uword row_num) const
01636   {
01637   arma_extra_debug_sigprint();
01638   
01639   arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" );
01640   
01641   const uword base_row = aux_row1 + row_num;
01642   
01643   return subview_row<eT>(m, base_row, aux_col1, n_cols);
01644   }
01645 
01646 
01647 
01648 template<typename eT>
01649 inline
01650 subview_row<eT>
01651 subview<eT>::operator()(const uword row_num, const span& col_span)
01652   {
01653   arma_extra_debug_sigprint();
01654   
01655   const bool col_all = col_span.whole;
01656   
01657   const uword local_n_cols = n_cols;
01658   
01659   const uword in_col1       = col_all ? 0            : col_span.a;
01660   const uword in_col2       =                          col_span.b;
01661   const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
01662   
01663   const uword base_col1     = aux_col1 + in_col1;  
01664   const uword base_row      = aux_row1 + row_num;
01665   
01666   arma_debug_check
01667     (
01668     (row_num >= n_rows)
01669     ||
01670     ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
01671     ,
01672     "subview::operator(): indices out of bounds or incorrectly used"
01673     );
01674   
01675   return subview_row<eT>(*m_ptr, base_row, base_col1, submat_n_cols);
01676   }
01677 
01678 
01679 
01680 template<typename eT>
01681 inline
01682 const subview_row<eT>
01683 subview<eT>::operator()(const uword row_num, const span& col_span) const
01684   {
01685   arma_extra_debug_sigprint();
01686   
01687   const bool col_all = col_span.whole;
01688   
01689   const uword local_n_cols = n_cols;
01690   
01691   const uword in_col1       = col_all ? 0            : col_span.a;
01692   const uword in_col2       =                          col_span.b;
01693   const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
01694   
01695   const uword base_col1     = aux_col1 + in_col1;
01696   const uword base_row      = aux_row1 + row_num;
01697   
01698   arma_debug_check
01699     (
01700     (row_num >= n_rows)
01701     ||
01702     ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
01703     ,
01704     "subview::operator(): indices out of bounds or incorrectly used"
01705     );
01706   
01707   return subview_row<eT>(m, base_row, base_col1, submat_n_cols);
01708   }
01709 
01710 
01711 
01713 template<typename eT>
01714 inline
01715 subview_col<eT>
01716 subview<eT>::col(const uword col_num)
01717   {
01718   arma_extra_debug_sigprint();
01719   
01720   arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds");
01721   
01722   const uword base_col = aux_col1 + col_num;
01723   
01724   return subview_col<eT>(*m_ptr, base_col, aux_row1, n_rows);
01725   }
01726 
01727 
01728 
01730 template<typename eT>
01731 inline
01732 const subview_col<eT>
01733 subview<eT>::col(const uword col_num) const
01734   {
01735   arma_extra_debug_sigprint();
01736   
01737   arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds");
01738   
01739   const uword base_col = aux_col1 + col_num;
01740   
01741   return subview_col<eT>(m, base_col, aux_row1, n_rows);
01742   }
01743 
01744 
01745 
01746 template<typename eT>
01747 inline
01748 subview_col<eT>
01749 subview<eT>::operator()(const span& row_span, const uword col_num)
01750   {
01751   arma_extra_debug_sigprint();
01752   
01753   const bool row_all = row_span.whole;
01754   
01755   const uword local_n_rows = n_rows;
01756   
01757   const uword in_row1       = row_all ? 0            : row_span.a;
01758   const uword in_row2       =                          row_span.b;
01759   const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
01760   
01761   const uword base_row1       = aux_row1 + in_row1;  
01762   const uword base_col        = aux_col1 + col_num;
01763   
01764   arma_debug_check
01765     (
01766     (col_num >= n_cols)
01767     ||
01768     ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
01769     ,
01770     "subview::operator(): indices out of bounds or incorrectly used"
01771     );
01772   
01773   return subview_col<eT>(*m_ptr, base_col, base_row1, submat_n_rows);
01774   }
01775 
01776 
01777 
01778 template<typename eT>
01779 inline
01780 const subview_col<eT>
01781 subview<eT>::operator()(const span& row_span, const uword col_num) const
01782   {
01783   arma_extra_debug_sigprint();
01784   
01785   const bool row_all = row_span.whole;
01786   
01787   const uword local_n_rows = n_rows;
01788   
01789   const uword in_row1       = row_all ? 0            : row_span.a;
01790   const uword in_row2       =                          row_span.b;
01791   const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
01792   
01793   const uword base_row1       = aux_row1 + in_row1;
01794   const uword base_col        = aux_col1 + col_num;
01795   
01796   arma_debug_check
01797     (
01798     (col_num >= n_cols)
01799     ||
01800     ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
01801     ,
01802     "subview::operator(): indices out of bounds or incorrectly used"
01803     );
01804   
01805   return subview_col<eT>(m, base_col, base_row1, submat_n_rows);
01806   }
01807 
01808 
01809 
01815 template<typename eT>
01816 inline
01817 Col<eT>
01818 subview<eT>::unsafe_col(const uword col_num)
01819   {
01820   arma_extra_debug_sigprint();
01821   
01822   arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds");
01823   
01824   return Col<eT>(colptr(col_num), n_rows, false, true);
01825   }
01826 
01827 
01828 
01834 template<typename eT>
01835 inline
01836 const Col<eT>
01837 subview<eT>::unsafe_col(const uword col_num) const
01838   {
01839   arma_extra_debug_sigprint();
01840   
01841   arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds");
01842   
01843   return Col<eT>(const_cast<eT*>(colptr(col_num)), n_rows, false, true);
01844   }
01845 
01846 
01847 
01849 template<typename eT>
01850 inline
01851 subview<eT>
01852 subview<eT>::rows(const uword in_row1, const uword in_row2)
01853   {
01854   arma_extra_debug_sigprint();
01855   
01856   arma_debug_check
01857     (
01858     (in_row1 > in_row2) || (in_row2 >= n_rows),
01859     "subview::rows(): indices out of bounds or incorrectly used"
01860     );
01861   
01862   const uword subview_n_rows = in_row2 - in_row1 + 1;
01863   const uword base_row1 = aux_row1 + in_row1;
01864   
01865   return subview<eT>(*m_ptr, base_row1, aux_col1, subview_n_rows, n_cols );
01866   }
01867 
01868 
01869 
01871 template<typename eT>
01872 inline
01873 const subview<eT>
01874 subview<eT>::rows(const uword in_row1, const uword in_row2) const
01875   {
01876   arma_extra_debug_sigprint();
01877   
01878   arma_debug_check
01879     (
01880     (in_row1 > in_row2) || (in_row2 >= n_rows),
01881     "subview::rows(): indices out of bounds or incorrectly used"
01882     );
01883   
01884   const uword subview_n_rows = in_row2 - in_row1 + 1;
01885   const uword base_row1 = aux_row1 + in_row1;
01886   
01887   return subview<eT>(m, base_row1, aux_col1, subview_n_rows, n_cols );
01888   }
01889 
01890 
01891 
01893 template<typename eT>
01894 inline
01895 subview<eT>
01896 subview<eT>::cols(const uword in_col1, const uword in_col2)
01897   {
01898   arma_extra_debug_sigprint();
01899   
01900   arma_debug_check
01901     (
01902     (in_col1 > in_col2) || (in_col2 >= n_cols),
01903     "subview::cols(): indices out of bounds or incorrectly used"
01904     );
01905   
01906   const uword subview_n_cols = in_col2 - in_col1 + 1;
01907   const uword base_col1 = aux_col1 + in_col1;
01908   
01909   return subview<eT>(*m_ptr, aux_row1, base_col1, n_rows, subview_n_cols);
01910   }
01911 
01912 
01913 
01915 template<typename eT>
01916 inline
01917 const subview<eT>
01918 subview<eT>::cols(const uword in_col1, const uword in_col2) const
01919   {
01920   arma_extra_debug_sigprint();
01921   
01922   arma_debug_check
01923     (
01924     (in_col1 > in_col2) || (in_col2 >= n_cols),
01925     "subview::cols(): indices out of bounds or incorrectly used"
01926     );
01927   
01928   const uword subview_n_cols = in_col2 - in_col1 + 1;
01929   const uword base_col1 = aux_col1 + in_col1;
01930   
01931   return subview<eT>(m, aux_row1, base_col1, n_rows, subview_n_cols);
01932   }
01933 
01934 
01935 
01937 template<typename eT>
01938 inline
01939 subview<eT>
01940 subview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
01941   {
01942   arma_extra_debug_sigprint();
01943   
01944   arma_debug_check
01945     (
01946     (in_row1 > in_row2) || (in_col1 >  in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
01947     "subview::submat(): indices out of bounds or incorrectly used"
01948     );
01949   
01950   const uword subview_n_rows = in_row2 - in_row1 + 1;
01951   const uword subview_n_cols = in_col2 - in_col1 + 1;
01952   
01953   const uword base_row1 = aux_row1 + in_row1;
01954   const uword base_col1 = aux_col1 + in_col1;
01955   
01956   return subview<eT>(*m_ptr, base_row1, base_col1, subview_n_rows, subview_n_cols);
01957   }
01958 
01959 
01960 
01962 template<typename eT>
01963 inline
01964 const subview<eT>
01965 subview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
01966   {
01967   arma_extra_debug_sigprint();
01968   
01969   arma_debug_check
01970     (
01971     (in_row1 > in_row2) || (in_col1 >  in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
01972     "subview::submat(): indices out of bounds or incorrectly used"
01973     );
01974   
01975   const uword subview_n_rows = in_row2 - in_row1 + 1;
01976   const uword subview_n_cols = in_col2 - in_col1 + 1;
01977   
01978   const uword base_row1 = aux_row1 + in_row1;
01979   const uword base_col1 = aux_col1 + in_col1;
01980   
01981   return subview<eT>(m, base_row1, base_col1, subview_n_rows, subview_n_cols);
01982   }
01983 
01984 
01985 
01987 template<typename eT>
01988 inline
01989 subview<eT>
01990 subview<eT>::submat(const span& row_span, const span& col_span)
01991   {
01992   arma_extra_debug_sigprint();
01993   
01994   const bool row_all = row_span.whole;
01995   const bool col_all = col_span.whole;
01996   
01997   const uword local_n_rows = n_rows;
01998   const uword local_n_cols = n_cols;
01999   
02000   const uword in_row1       = row_all ? 0            : row_span.a;
02001   const uword in_row2       =                          row_span.b;
02002   const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
02003   
02004   const uword in_col1       = col_all ? 0            : col_span.a;
02005   const uword in_col2       =                          col_span.b;
02006   const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
02007   
02008   arma_debug_check
02009     (
02010     ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
02011     ||
02012     ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
02013     ,
02014     "subview::submat(): indices out of bounds or incorrectly used"
02015     );
02016   
02017   const uword base_row1 = aux_row1 + in_row1;
02018   const uword base_col1 = aux_col1 + in_col1;
02019   
02020   return subview<eT>(*m_ptr, base_row1, base_col1, submat_n_rows, submat_n_cols);
02021   }
02022 
02023 
02024 
02026 template<typename eT>
02027 inline
02028 const subview<eT>
02029 subview<eT>::submat(const span& row_span, const span& col_span) const
02030   {
02031   arma_extra_debug_sigprint();
02032   
02033   const bool row_all = row_span.whole;
02034   const bool col_all = col_span.whole;
02035   
02036   const uword local_n_rows = n_rows;
02037   const uword local_n_cols = n_cols;
02038   
02039   const uword in_row1       = row_all ? 0            : row_span.a;
02040   const uword in_row2       =                          row_span.b;
02041   const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
02042   
02043   const uword in_col1       = col_all ? 0            : col_span.a;
02044   const uword in_col2       =                          col_span.b;
02045   const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
02046   
02047   arma_debug_check
02048     (
02049     ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
02050     ||
02051     ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
02052     ,
02053     "subview::submat(): indices out of bounds or incorrectly used"
02054     );
02055   
02056   const uword base_row1 = aux_row1 + in_row1;
02057   const uword base_col1 = aux_col1 + in_col1;
02058   
02059   return subview<eT>(m, base_row1, base_col1, submat_n_rows, submat_n_cols);
02060   }
02061 
02062 
02063 
02064 template<typename eT>
02065 inline
02066 subview<eT>
02067 subview<eT>::operator()(const span& row_span, const span& col_span)
02068   {
02069   arma_extra_debug_sigprint();
02070   
02071   return (*this).submat(row_span, col_span);
02072   }
02073 
02074 
02075 
02076 template<typename eT>
02077 inline
02078 const subview<eT>
02079 subview<eT>::operator()(const span& row_span, const span& col_span) const
02080   {
02081   arma_extra_debug_sigprint();
02082   
02083   return (*this).submat(row_span, col_span);
02084   }
02085 
02086 
02087 
02089 template<typename eT>
02090 inline
02091 diagview<eT>
02092 subview<eT>::diag(const sword in_id)
02093   {
02094   arma_extra_debug_sigprint();
02095   
02096   const uword row_offset = (in_id < 0) ? uword(-in_id) : 0;
02097   const uword col_offset = (in_id > 0) ? uword( in_id) : 0;
02098   
02099   arma_debug_check
02100     (
02101     ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
02102     "subview::diag(): requested diagonal out of bounds"
02103     );
02104   
02105   const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
02106   
02107   const uword base_row_offset = aux_row1 + row_offset;
02108   const uword base_col_offset = aux_col1 + col_offset;
02109   
02110   return diagview<eT>(*m_ptr, base_row_offset, base_col_offset, len);
02111   }
02112 
02113 
02114 
02116 template<typename eT>
02117 inline
02118 const diagview<eT>
02119 subview<eT>::diag(const sword in_id) const
02120   {
02121   arma_extra_debug_sigprint();
02122   
02123   const uword row_offset = (in_id < 0) ? -in_id : 0;
02124   const uword col_offset = (in_id > 0) ?  in_id : 0;
02125   
02126   arma_debug_check
02127     (
02128     ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
02129     "subview::diag(): requested diagonal out of bounds"
02130     );
02131   
02132   const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
02133   
02134   const uword base_row_offset = aux_row1 + row_offset;
02135   const uword base_col_offset = aux_col1 + col_offset;
02136   
02137   return diagview<eT>(m, base_row_offset, base_col_offset, len);
02138   }
02139 
02140 
02141 
02142 template<typename eT>
02143 inline
02144 void
02145 subview<eT>::swap_rows(const uword in_row1, const uword in_row2)
02146   {
02147   arma_extra_debug_sigprint();
02148   
02149   arma_debug_check
02150     (
02151     (in_row1 >= n_rows) || (in_row2 >= n_rows),
02152     "subview::swap_rows(): out of bounds"
02153     );
02154   
02155   eT* mem = (*m_ptr).memptr();
02156   
02157   for(uword col=0; col<n_cols; ++col)
02158     {
02159     const uword offset = (aux_col1 + col) * m.n_rows;
02160     const uword pos1   = aux_row1 + in_row1 + offset;
02161     const uword pos2   = aux_row1 + in_row2 + offset;
02162     
02163     const eT tmp          = mem[pos1];
02164     access::rw(mem[pos1]) = mem[pos2];
02165     access::rw(mem[pos2]) = tmp;
02166     }
02167   }
02168 
02169 
02170 
02171 template<typename eT>
02172 inline
02173 void
02174 subview<eT>::swap_cols(const uword in_col1, const uword in_col2)
02175   {
02176   arma_extra_debug_sigprint();
02177   
02178   arma_debug_check
02179     (
02180     (in_col1 >= n_cols) || (in_col2 >= n_cols),
02181     "subview::swap_cols(): out of bounds"
02182     );
02183   
02184   if(n_elem > 0)
02185     {
02186     eT* ptr1 = colptr(in_col1);
02187     eT* ptr2 = colptr(in_col2);
02188     
02189     for(uword row=0; row<n_rows; ++row)
02190       {
02191       const eT tmp = ptr1[row];
02192       ptr1[row]    = ptr2[row];
02193       ptr2[row]    = tmp;
02194       }
02195     }
02196   }
02197 
02198 
02199 
02200 // template<typename eT>
02201 // inline
02202 // subview<eT>::iter::iter(const subview<eT>& S)
02203 //   : mem       (S.m.mem)
02204 //   , n_rows    (S.m.n_rows)
02205 //   , row_start (S.aux_row1)
02206 //   , row_end_p1(row_start + S.n_rows)
02207 //   , row       (row_start)
02208 //   , col       (S.aux_col1)
02209 //   , i         (row + col*n_rows)
02210 //   {
02211 //   arma_extra_debug_sigprint();
02212 //   }
02213 // 
02214 // 
02215 // 
02216 // template<typename eT>
02217 // arma_inline
02218 // eT
02219 // subview<eT>::iter::operator*() const
02220 //   {
02221 //   return mem[i];
02222 //   }
02223 // 
02224 // 
02225 // 
02226 // template<typename eT>
02227 // inline
02228 // void
02229 // subview<eT>::iter::operator++()
02230 //   {
02231 //   ++row;
02232 //   
02233 //   if(row < row_end_p1)
02234 //     {
02235 //     ++i;
02236 //     }
02237 //   else
02238 //     {
02239 //     row = row_start;
02240 //     ++col;
02241 //     
02242 //     i = row + col*n_rows;
02243 //     }
02244 //   }
02245 // 
02246 // 
02247 // 
02248 // template<typename eT>
02249 // inline
02250 // void
02251 // subview<eT>::iter::operator++(int)
02252 //   {
02253 //   operator++();
02254 //   }
02255 
02256 
02257 
02258 //
02259 //
02260 //
02261 
02262 
02263 
02264 template<typename eT>
02265 inline
02266 subview_col<eT>::subview_col(const Mat<eT>& in_m, const uword in_col)
02267   : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
02268   {
02269   arma_extra_debug_sigprint();
02270   }
02271 
02272 
02273 
02274 template<typename eT>
02275 inline
02276 subview_col<eT>::subview_col(Mat<eT>& in_m, const uword in_col)
02277   : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
02278   {
02279   arma_extra_debug_sigprint();
02280   }
02281 
02282 
02283 
02284 template<typename eT>
02285 inline
02286 subview_col<eT>::subview_col(const Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
02287   : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
02288   {
02289   arma_extra_debug_sigprint();
02290   }
02291 
02292 
02293 
02294 template<typename eT>
02295 inline
02296 subview_col<eT>::subview_col(Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
02297   : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
02298   {
02299   arma_extra_debug_sigprint();
02300   }
02301 
02302 
02303 
02304 template<typename eT>
02305 inline
02306 void
02307 subview_col<eT>::operator=(const subview<eT>& X)
02308   {
02309   arma_extra_debug_sigprint();
02310   
02311   subview<eT>::operator=(X);
02312   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
02313   }
02314 
02315 
02316 
02317 template<typename eT>
02318 inline
02319 void
02320 subview_col<eT>::operator=(const subview_col<eT>& X)
02321   {
02322   arma_extra_debug_sigprint();
02323   
02324   subview<eT>::operator=(X); // interprets 'subview_col' as 'subview'
02325   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
02326   }
02327 
02328 
02329 
02330 template<typename eT>
02331 template<typename T1>
02332 inline
02333 void
02334 subview_col<eT>::operator=(const Base<eT,T1>& X)
02335   {
02336   arma_extra_debug_sigprint();
02337   
02338   subview<eT>::operator=(X);
02339   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
02340   }
02341 
02342 
02343 
02344 template<typename eT>
02345 inline
02346 subview_col<eT>
02347 subview_col<eT>::rows(const uword in_row1, const uword in_row2)
02348   {
02349   arma_extra_debug_sigprint();
02350   
02351   arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used");
02352   
02353   const uword subview_n_rows = in_row2 - in_row1 + 1;
02354   
02355   const uword base_row1 = this->aux_row1 + in_row1;
02356   
02357   return subview_col<eT>(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows);
02358   }
02359 
02360 
02361 
02362 template<typename eT>
02363 inline
02364 const subview_col<eT>
02365 subview_col<eT>::rows(const uword in_row1, const uword in_row2) const
02366   {
02367   arma_extra_debug_sigprint();
02368   
02369   arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used");
02370   
02371   const uword subview_n_rows = in_row2 - in_row1 + 1;
02372   
02373   const uword base_row1 = this->aux_row1 + in_row1;
02374   
02375   return subview_col<eT>(this->m, this->aux_col1, base_row1, subview_n_rows);
02376   }
02377 
02378 
02379 
02380 template<typename eT>
02381 inline
02382 subview_col<eT>
02383 subview_col<eT>::subvec(const uword in_row1, const uword in_row2)
02384   {
02385   arma_extra_debug_sigprint();
02386   
02387   arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used");
02388   
02389   const uword subview_n_rows = in_row2 - in_row1 + 1;
02390   
02391   const uword base_row1 = this->aux_row1 + in_row1;
02392   
02393   return subview_col<eT>(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows);
02394   }
02395 
02396 
02397 
02398 template<typename eT>
02399 inline
02400 const subview_col<eT>
02401 subview_col<eT>::subvec(const uword in_row1, const uword in_row2) const
02402   {
02403   arma_extra_debug_sigprint();
02404   
02405   arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used");
02406   
02407   const uword subview_n_rows = in_row2 - in_row1 + 1;
02408   
02409   const uword base_row1 = this->aux_row1 + in_row1;
02410   
02411   return subview_col<eT>(this->m, this->aux_col1, base_row1, subview_n_rows);
02412   }
02413 
02414 
02415 
02416 //
02417 //
02418 //
02419 
02420 
02421 
02422 template<typename eT>
02423 inline
02424 subview_row<eT>::subview_row(const Mat<eT>& in_m, const uword in_row)
02425   : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
02426   {
02427   arma_extra_debug_sigprint();
02428   }
02429 
02430 
02431 
02432 template<typename eT>
02433 inline
02434 subview_row<eT>::subview_row(Mat<eT>& in_m, const uword in_row)
02435   : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
02436   {
02437   arma_extra_debug_sigprint();
02438   }
02439 
02440 
02441 
02442 template<typename eT>
02443 inline
02444 subview_row<eT>::subview_row(const Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
02445   : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
02446   {
02447   arma_extra_debug_sigprint();
02448   }
02449 
02450 
02451 
02452 template<typename eT>
02453 inline
02454 subview_row<eT>::subview_row(Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
02455   : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
02456   {
02457   arma_extra_debug_sigprint();
02458   }
02459 
02460 
02461 
02462 template<typename eT>
02463 inline
02464 void
02465 subview_row<eT>::operator=(const subview<eT>& X)
02466   {
02467   arma_extra_debug_sigprint();
02468   
02469   subview<eT>::operator=(X);
02470   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
02471   }
02472 
02473 
02474 
02475 template<typename eT>
02476 inline
02477 void
02478 subview_row<eT>::operator=(const subview_row<eT>& X)
02479   {
02480   arma_extra_debug_sigprint();
02481   
02482   subview<eT>::operator=(X); // interprets 'subview_row' as 'subview'
02483   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
02484   }
02485 
02486 
02487 
02488 template<typename eT>
02489 template<typename T1>
02490 inline
02491 void
02492 subview_row<eT>::operator=(const Base<eT,T1>& X)
02493   {
02494   arma_extra_debug_sigprint();
02495   
02496   subview<eT>::operator=(X);
02497   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
02498   }
02499 
02500 
02501 
02502 template<typename eT>
02503 inline
02504 subview_row<eT>
02505 subview_row<eT>::cols(const uword in_col1, const uword in_col2)
02506   {
02507   arma_extra_debug_sigprint();
02508   
02509   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used" );
02510   
02511   const uword subview_n_cols = in_col2 - in_col1 + 1;
02512   
02513   const uword base_col1 = this->aux_col1 + in_col1;
02514   
02515   return subview_row<eT>(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols);
02516   }
02517 
02518 
02519 
02520 template<typename eT>
02521 inline
02522 const subview_row<eT>
02523 subview_row<eT>::cols(const uword in_col1, const uword in_col2) const
02524   {
02525   arma_extra_debug_sigprint();
02526   
02527   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used");
02528   
02529   const uword subview_n_cols = in_col2 - in_col1 + 1;
02530   
02531   const uword base_col1 = this->aux_col1 + in_col1;
02532   
02533   return subview_row<eT>(this->m, this->aux_row1, base_col1, subview_n_cols);
02534   }
02535 
02536 
02537 
02538 template<typename eT>
02539 inline
02540 subview_row<eT>
02541 subview_row<eT>::subvec(const uword in_col1, const uword in_col2)
02542   {
02543   arma_extra_debug_sigprint();
02544   
02545   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used");
02546   
02547   const uword subview_n_cols = in_col2 - in_col1 + 1;
02548   
02549   const uword base_col1 = this->aux_col1 + in_col1;
02550   
02551   return subview_row<eT>(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols);
02552   }
02553 
02554 
02555 
02556 template<typename eT>
02557 inline
02558 const subview_row<eT>
02559 subview_row<eT>::subvec(const uword in_col1, const uword in_col2) const
02560   {
02561   arma_extra_debug_sigprint();
02562   
02563   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used");
02564   
02565   const uword subview_n_cols = in_col2 - in_col1 + 1;
02566   
02567   const uword base_col1 = this->aux_col1 + in_col1;
02568   
02569   return subview_row<eT>(this->m, this->aux_row1, base_col1, subview_n_cols);
02570   }
02571 
02572 
02573 


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