subview_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup subview
00018 //! @{
00019 
00020 
00021 template<typename eT>
00022 inline
00023 subview<eT>::~subview()
00024   {
00025   arma_extra_debug_sigprint();
00026   }
00027 
00028 
00029 template<typename eT>
00030 arma_inline
00031 subview<eT>::subview(const Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2,  const u32 in_col2)
00032   : m(in_m)
00033   , m_ptr(0)
00034   , aux_row1(in_row1)
00035   , aux_col1(in_col1)
00036   , aux_row2(in_row2)
00037   , aux_col2(in_col2)
00038   , n_rows(1 + in_row2 - in_row1)
00039   , n_cols(1 + in_col2 - in_col1)
00040   , n_elem(n_rows*n_cols)
00041   {
00042   arma_extra_debug_sigprint();
00043   }
00044 
00045 
00046 
00047 template<typename eT>
00048 arma_inline
00049 subview<eT>::subview(Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2,  const u32 in_col2)
00050   : m(in_m)
00051   , m_ptr(&in_m)
00052   , aux_row1(in_row1)
00053   , aux_col1(in_col1)
00054   , aux_row2(in_row2)
00055   , aux_col2(in_col2)
00056   , n_rows(1 + in_row2 - in_row1)
00057   , n_cols(1 + in_col2 - in_col1)
00058   , n_elem(n_rows*n_cols)
00059   {
00060   arma_extra_debug_sigprint();
00061   }
00062 
00063 
00064 
00065 template<typename eT>
00066 inline
00067 void
00068 subview<eT>::fill(const eT val)
00069   {
00070   arma_extra_debug_sigprint();
00071   
00072   for(u32 col = 0; col<n_cols; ++col)
00073     {
00074     eT* coldata = colptr(col);
00075     
00076     for(u32 row = 0; row<n_rows; ++row)
00077       {
00078       coldata[row] = val;
00079       }
00080     }
00081   
00082   
00083   }
00084 
00085 
00086 
00087 template<typename eT>
00088 inline
00089 void
00090 subview<eT>::operator+= (const eT val)
00091   {
00092   arma_extra_debug_sigprint();
00093   
00094   for(u32 col = 0; col<n_cols; ++col)
00095     {
00096     eT* coldata = colptr(col);
00097     
00098     for(u32 row = 0; row<n_rows; ++row)
00099       {
00100       coldata[row] += val;
00101       }
00102     
00103     }
00104   
00105   }
00106 
00107 
00108 
00109 template<typename eT>
00110 inline
00111 void
00112 subview<eT>::operator-= (const eT val)
00113   {
00114   arma_extra_debug_sigprint();
00115   
00116   for(u32 col = 0; col<n_cols; ++col)
00117     {
00118     eT* coldata = colptr(col);
00119     
00120     for(u32 row = 0; row<n_rows; ++row)
00121       {
00122       coldata[row] -= val;
00123       }
00124     
00125     }
00126   
00127   }
00128 
00129 
00130 
00131 template<typename eT>
00132 inline
00133 void
00134 subview<eT>::operator*= (const eT val)
00135   {
00136   arma_extra_debug_sigprint();
00137   
00138   for(u32 col = 0; col<n_cols; ++col)
00139     {
00140     eT* coldata = colptr(col);
00141     
00142     for(u32 row = 0; row<n_rows; ++row)
00143       {
00144       coldata[row] *= val;
00145       }
00146     
00147     }
00148   
00149   }
00150 
00151 
00152 
00153 template<typename eT>
00154 inline
00155 void
00156 subview<eT>::operator/= (const eT val)
00157   {
00158   arma_extra_debug_sigprint();
00159   
00160   for(u32 col = 0; col<n_cols; ++col)
00161     {
00162     eT* coldata = colptr(col);
00163     
00164     for(u32 row = 0; row<n_rows; ++row)
00165       {
00166       coldata[row] /= val;
00167       }
00168     
00169     }
00170   
00171   }
00172 
00173 
00174 
00175 template<typename eT>
00176 template<typename T1>
00177 inline
00178 void
00179 subview<eT>::operator= (const Base<eT,T1>& in)
00180   {
00181   arma_extra_debug_sigprint();
00182   
00183   const Proxy<T1> x(in.get_ref());
00184   
00185   subview<eT>& t = *this;
00186   
00187   arma_debug_assert_same_size(t, x, "insert into submatrix");
00188   
00189   
00190   for(u32 col = 0; col<t.n_cols; ++col)
00191     {
00192     eT* t_coldata = t.colptr(col);
00193     
00194     for(u32 row = 0; row<t.n_rows; ++row)
00195       {
00196       t_coldata[row] = x.at(row,col);
00197       }
00198       
00199     }
00200   }
00201 
00202 
00203 
00204 template<typename eT>
00205 template<typename T1>
00206 inline
00207 void
00208 subview<eT>::operator+= (const Base<eT,T1>& in)
00209   {
00210   arma_extra_debug_sigprint();
00211   
00212   const Proxy<T1> x(in.get_ref());
00213   
00214   subview<eT>& t = *this;
00215   
00216   arma_debug_assert_same_size(t, x, "matrix addition");
00217   
00218   
00219   for(u32 col = 0; col<t.n_cols; ++col)
00220     {
00221     eT* t_coldata = t.colptr(col);
00222     
00223     for(u32 row = 0; row<t.n_rows; ++row)
00224       {
00225       t_coldata[row] += x.at(row,col);
00226       }
00227     }
00228   
00229   }
00230 
00231 
00232 
00233 template<typename eT>
00234 template<typename T1>
00235 inline
00236 void
00237 subview<eT>::operator-= (const Base<eT,T1>& in)
00238   {
00239   arma_extra_debug_sigprint();
00240   
00241   const Proxy<T1> x(in.get_ref());
00242   
00243   subview<eT>& t = *this;
00244   
00245   arma_debug_assert_same_size(t, x, "matrix subtraction");
00246   
00247   
00248   for(u32 col = 0; col<t.n_cols; ++col)
00249     {
00250      eT* t_coldata = t.colptr(col);
00251     
00252     for(u32 row = 0; row<t.n_rows; ++row)
00253       {
00254       t_coldata[row] -= x.at(row,col);
00255       }
00256     }
00257   
00258   }
00259 
00260 
00261 
00262 template<typename eT>
00263 template<typename T1>
00264 inline
00265 void
00266 subview<eT>::operator%= (const Base<eT,T1>& in)
00267   {
00268   arma_extra_debug_sigprint();
00269   
00270   const Proxy<T1> x(in.get_ref());
00271   
00272   subview<eT>& t = *this;
00273   
00274   arma_debug_assert_same_size(t, x, "matrix schur product");
00275   
00276   
00277   for(u32 col = 0; col<t.n_cols; ++col)
00278     {
00279     eT* t_coldata = t.colptr(col);
00280     
00281     for(u32 row = 0; row<t.n_rows; ++row)
00282       {
00283       t_coldata[row] *= x.at(row,col);
00284       }
00285     }
00286   
00287   }
00288 
00289 
00290 
00291 template<typename eT>
00292 template<typename T1>
00293 inline
00294 void
00295 subview<eT>::operator/= (const Base<eT,T1>& in)
00296   {
00297   arma_extra_debug_sigprint();
00298   
00299   const Proxy<T1> x(in.get_ref());
00300   
00301   subview<eT>& t = *this;
00302   
00303   arma_debug_assert_same_size(t, x, "element-wise matrix division");
00304   
00305   
00306   for(u32 col = 0; col<t.n_cols; ++col)
00307     {
00308     eT* t_coldata = t.colptr(col);
00309     
00310     for(u32 row = 0; row<t.n_rows; ++row)
00311       {
00312       t_coldata[row] /= x.at(row,col);
00313       }
00314     }
00315   
00316   }
00317 
00318 
00319 
00320 //! x.submat(...) = y.submat(...)
00321 template<typename eT>
00322 inline
00323 void
00324 subview<eT>::operator= (const subview<eT>& x_in)
00325   {
00326   arma_extra_debug_sigprint();
00327   
00328   const bool overlap = check_overlap(x_in);
00329   
00330         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00331   const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00332   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00333   
00334   subview<eT>& t = *this;
00335   
00336   arma_debug_assert_same_size(t, x, "insert into submatrix");
00337   
00338   
00339   for(u32 col = 0; col<t.n_cols; ++col)
00340     {
00341           eT* t_coldata = t.colptr(col);
00342     const eT* x_coldata = x.colptr(col);
00343     
00344     for(u32 row = 0; row<t.n_rows; ++row)
00345       {
00346       t_coldata[row] = x_coldata[row];
00347       }
00348     
00349     }
00350     
00351   if(overlap)
00352     {
00353     delete tmp_subview;
00354     delete tmp_mat;
00355     }
00356   
00357   }
00358 
00359 
00360 
00361 template<typename eT>
00362 inline
00363 void
00364 subview<eT>::operator+= (const subview<eT>& x_in)
00365   {
00366   arma_extra_debug_sigprint();
00367   
00368   const bool overlap = check_overlap(x_in);
00369   
00370         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00371   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00372   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00373   
00374   
00375   subview<eT>& t = *this;
00376   
00377   arma_debug_assert_same_size(t, x, "matrix addition");
00378   
00379   
00380   for(u32 col = 0; col<t.n_cols; ++col)
00381     {
00382           eT* t_coldata = t.colptr(col);
00383     const eT* x_coldata = x.colptr(col);
00384     
00385     for(u32 row = 0; row<t.n_rows; ++row)
00386       {
00387       t_coldata[row] += x_coldata[row];
00388       }
00389     
00390     }
00391   
00392   }
00393 
00394 
00395 
00396 template<typename eT>
00397 inline
00398 void
00399 subview<eT>::operator-= (const subview<eT>& x_in)
00400   {
00401   arma_extra_debug_sigprint();
00402   
00403   const bool overlap = check_overlap(x_in);
00404   
00405         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00406   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00407   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00408   
00409   subview<eT>& t = *this;
00410   
00411   arma_debug_assert_same_size(t, x, "matrix subtraction");
00412   
00413   
00414   for(u32 col = 0; col<t.n_cols; ++col)
00415     {
00416           eT* t_coldata = t.colptr(col);
00417     const eT* x_coldata = x.colptr(col);
00418     
00419     for(u32 row = 0; row<t.n_rows; ++row)
00420       {
00421       t_coldata[row] -= x_coldata[row];
00422       }
00423     }
00424     
00425   if(overlap)
00426     {
00427     delete tmp_subview;
00428     delete tmp_mat;
00429     }
00430   
00431   }
00432 
00433 
00434 
00435 template<typename eT>
00436 inline
00437 void
00438 subview<eT>::operator%= (const subview& x_in)
00439   {
00440   arma_extra_debug_sigprint();
00441   
00442   const bool overlap = check_overlap(x_in);
00443   
00444         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00445   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00446   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00447   
00448   subview<eT>& t = *this;
00449   
00450   arma_debug_assert_same_size(t, x, "matrix schur product");
00451   
00452   
00453   for(u32 col = 0; col<t.n_cols; ++col)
00454     {
00455           eT* t_coldata = t.colptr(col);
00456     const eT* x_coldata = x.colptr(col);
00457     
00458     for(u32 row = 0; row<t.n_rows; ++row)
00459       {
00460       t_coldata[row] *= x_coldata[row];
00461       }
00462     }
00463   
00464   if(overlap)
00465     {
00466     delete tmp_subview;
00467     delete tmp_mat;
00468     }
00469   
00470   }
00471 
00472 
00473 
00474 template<typename eT>
00475 inline
00476 void
00477 subview<eT>::operator/= (const subview& x_in)
00478   {
00479   arma_extra_debug_sigprint();
00480   
00481   const bool overlap = check_overlap(x_in);
00482   
00483         Mat<eT>*     tmp_mat     = overlap ? new Mat<eT>(x_in.m) : 0;
00484   const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00485   const subview<eT>&           x = overlap ? (*tmp_subview) : x_in;
00486   
00487   subview<eT>& t = *this;
00488   
00489   arma_debug_assert_same_size(t, x, "element-wise matrix division");
00490   
00491   
00492   for(u32 col = 0; col<t.n_cols; ++col)
00493     {
00494           eT* t_coldata = t.colptr(col);
00495     const eT* x_coldata = x.colptr(col);
00496     
00497     for(u32 row = 0; row<t.n_rows; ++row)
00498       {
00499       t_coldata[row] /= x_coldata[row];
00500       }
00501     }
00502     
00503   if(overlap)
00504     {
00505     delete tmp_subview;
00506     delete tmp_mat;
00507     }
00508   
00509   }
00510 
00511 
00512 
00513 template<typename eT>
00514 inline
00515 void
00516 subview<eT>::zeros()
00517   {
00518   arma_extra_debug_sigprint();
00519   
00520   subview<eT>& t = *this;
00521   
00522   for(u32 col = 0; col<t.n_cols; ++col)
00523     {
00524     eT* t_coldata = t.colptr(col);
00525     
00526     for(u32 row = 0; row<t.n_rows; ++row)
00527       {
00528       t_coldata[row] = eT(0);
00529       }
00530     
00531     }
00532   
00533   }
00534 
00535 
00536 
00537 template<typename eT>
00538 arma_inline
00539 eT&
00540 subview<eT>::operator[](const u32 i)
00541   {
00542   arma_check( (m_ptr == 0), "subview::operator[]: matrix is read-only");
00543   
00544   const u32 in_col = i / n_rows;
00545   const u32 in_row = i % n_rows;
00546     
00547   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00548   return access::rw( (*m_ptr).mem[index] );
00549   }
00550 
00551 
00552 
00553 template<typename eT>
00554 arma_inline
00555 eT
00556 subview<eT>::operator[](const u32 i) const
00557   {
00558   const u32 in_col = i / n_rows;
00559   const u32 in_row = i % n_rows;
00560   
00561   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00562   return m.mem[index];
00563   }
00564 
00565 
00566 
00567 template<typename eT>
00568 arma_inline
00569 eT&
00570 subview<eT>::operator()(const u32 i)
00571   {
00572   arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only");
00573   arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
00574     
00575   const u32 in_col = i / n_rows;
00576   const u32 in_row = i % n_rows;
00577   
00578   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00579   return access::rw( (*m_ptr).mem[index] );
00580   }
00581 
00582 
00583 
00584 template<typename eT>
00585 arma_inline
00586 eT
00587 subview<eT>::operator()(const u32 i) const
00588   {
00589   arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
00590   
00591   const u32 in_col = i / n_rows;
00592   const u32 in_row = i % n_rows;
00593   
00594   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00595   return m.mem[index];
00596   }
00597 
00598 
00599 
00600 template<typename eT>
00601 arma_inline
00602 eT&
00603 subview<eT>::operator()(const u32 in_row, const u32 in_col)
00604   {
00605   arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only");
00606   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
00607   
00608   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00609   return access::rw( (*m_ptr).mem[index] );
00610   }
00611 
00612 
00613 
00614 template<typename eT>
00615 arma_inline
00616 eT
00617 subview<eT>::operator()(const u32 in_row, const u32 in_col) const
00618   {
00619   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
00620   
00621   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00622   return m.mem[index];
00623   }
00624 
00625 
00626 
00627 template<typename eT>
00628 arma_inline
00629 eT&
00630 subview<eT>::at(const u32 in_row, const u32 in_col)
00631   {
00632   arma_check( (m_ptr == 0), "subview::at(): matrix is read-only");
00633   
00634   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00635   return access::rw( (*m_ptr).mem[index] );
00636   }
00637 
00638 
00639 
00640 template<typename eT>
00641 arma_inline
00642 eT
00643 subview<eT>::at(const u32 in_row, const u32 in_col) const
00644   {
00645   const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00646   return m.mem[index];
00647   }
00648 
00649 
00650 
00651 template<typename eT>
00652 arma_inline
00653 eT*
00654 subview<eT>::colptr(const u32 in_col)
00655   {
00656   arma_check( (m_ptr == 0), "subview::colptr(): matrix is read-only");
00657     
00658   return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]);
00659   }
00660 
00661 
00662 
00663 template<typename eT>
00664 arma_inline
00665 const eT*
00666 subview<eT>::colptr(const u32 in_col) const
00667   {
00668   return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ];
00669   }
00670 
00671 
00672 
00673 template<typename eT>
00674 inline
00675 bool
00676 subview<eT>::check_overlap(const subview<eT>& x) const
00677   {
00678   const subview<eT>& t = *this;
00679   
00680   if(&t.m != &x.m)
00681     {
00682     return false;
00683     }
00684   else
00685     {
00686     const bool row_overlap =
00687       (
00688       ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) )
00689       || 
00690       ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) )
00691       );
00692     
00693     const bool col_overlap =
00694       (
00695       ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) )
00696       || 
00697       ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) )
00698       );
00699     
00700     
00701     return (row_overlap & col_overlap);
00702     }
00703   }
00704 
00705 
00706 
00707 template<typename eT>
00708 inline
00709 bool
00710 subview<eT>::is_vec() const
00711   {
00712   return ( (n_rows == 1) || (n_cols == 1) );
00713   }
00714 
00715 
00716 
00717 //! X = Y.submat(...)
00718 template<typename eT>
00719 inline
00720 void
00721 subview<eT>::extract(Mat<eT>& actual_out, const subview<eT>& in)
00722   {
00723   arma_extra_debug_sigprint();
00724   
00725   //
00726   const bool alias = (&actual_out == &in.m);
00727   
00728   Mat<eT>* tmp = (alias) ? new Mat<eT> : 0;
00729   Mat<eT>& out = (alias) ? (*tmp)      : actual_out;
00730   
00731   //
00732   
00733   const u32 n_rows = in.n_rows;  // number of rows in the subview
00734   const u32 n_cols = in.n_cols;  // number of columns in the subview
00735   
00736   out.set_size(n_rows, n_cols);
00737   
00738   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 );
00739   
00740 
00741   if(in.is_vec() == true)
00742     {
00743     if(n_cols == 1)   // a column vector
00744       {
00745       arma_extra_debug_print("subview::extract(): copying col (going across rows)");
00746       
00747             eT* out_mem    = out.memptr();
00748       const eT* in_coldata = in.colptr(0);  // the first column of the subview, taking into account any row offset
00749       
00750       for(u32 row=0; row<n_rows; ++row)
00751         {
00752         out_mem[row] = in_coldata[row];
00753         }
00754       }
00755     else   // a row vector
00756       {
00757       arma_extra_debug_print("subview::extract(): copying row (going across columns)");
00758       
00759       const Mat<eT>& X = in.m;
00760       
00761             eT* out_mem   = out.memptr();
00762       const u32 row       = in.aux_row1;
00763       const u32 start_col = in.aux_col1;
00764       
00765       for(u32 i=0; i<n_cols; ++i)
00766         {
00767         out_mem[i] = X.at(row, i+start_col);
00768         }
00769       }
00770     }
00771   else   // general submatrix
00772     {
00773     arma_extra_debug_print("subview::extract(): general submatrix");
00774     
00775     for(u32 col = 0; col<n_cols; ++col)   
00776       {
00777             eT* out_coldata = out.colptr(col);
00778       const eT*  in_coldata =  in.colptr(col);
00779       
00780       for(u32 row = 0; row<n_rows; ++row)
00781         {
00782         out_coldata[row] = in_coldata[row];
00783         }
00784       }
00785     }
00786   
00787   
00788   if(alias)
00789     {
00790     actual_out = out;
00791     delete tmp;
00792     }
00793   
00794   }
00795 
00796 
00797 
00798 //! X += Y.submat(...)
00799 template<typename eT>
00800 inline
00801 void
00802 subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in)
00803   {
00804   arma_extra_debug_sigprint();
00805   
00806   arma_debug_assert_same_size(out, in, "matrix addition");
00807   
00808   const u32 n_rows = out.n_rows;
00809   const u32 n_cols = out.n_cols;
00810   
00811   for(u32 col = 0; col<n_cols; ++col)
00812     {
00813           eT* out_coldata = out.colptr(col);
00814     const eT*  in_coldata =  in.colptr(col);
00815     
00816     for(u32 row = 0; row<n_rows; ++row)
00817       {
00818       out_coldata[row] += in_coldata[row];
00819       }
00820     }
00821   }
00822 
00823 
00824 
00825 //! X -= Y.submat(...)
00826 template<typename eT>
00827 inline
00828 void
00829 subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in)
00830   {
00831   arma_extra_debug_sigprint();
00832   
00833   arma_debug_assert_same_size(out, in, "matrix subtraction");
00834   
00835   const u32 n_rows = out.n_rows;
00836   const u32 n_cols = out.n_cols;
00837   
00838   for(u32 col = 0; col<n_cols; ++col)
00839     {
00840           eT* out_coldata = out.colptr(col);
00841     const eT*  in_coldata =  in.colptr(col);
00842     
00843     for(u32 row = 0; row<n_rows; ++row)
00844       {
00845       out_coldata[row] -= in_coldata[row];
00846       }
00847     }
00848   }
00849 
00850 
00851 
00852 //! X %= Y.submat(...)
00853 template<typename eT>
00854 inline
00855 void
00856 subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in)
00857   {
00858   arma_extra_debug_sigprint();
00859   
00860   arma_debug_assert_same_size(out, in, "matrix schur product");
00861   
00862   const u32 n_rows = out.n_rows;
00863   const u32 n_cols = out.n_cols;
00864   
00865   for(u32 col = 0; col<n_cols; ++col)
00866     {
00867           eT* out_coldata = out.colptr(col);
00868     const eT*  in_coldata =  in.colptr(col);
00869     
00870     for(u32 row = 0; row<n_rows; ++row)
00871       {
00872       out_coldata[row] *= in_coldata[row];
00873       }
00874     }
00875   }
00876 
00877 
00878 
00879 //! X /= Y.submat(...)
00880 template<typename eT>
00881 inline
00882 void
00883 subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in)
00884   {
00885   arma_extra_debug_sigprint();
00886   
00887   arma_debug_assert_same_size(out, in, "element-wise matrix division");
00888   
00889   const u32 n_rows = out.n_rows;
00890   const u32 n_cols = out.n_cols;
00891   
00892   for(u32 col = 0; col<n_cols; ++col)
00893     {
00894           eT* out_coldata = out.colptr(col);
00895     const eT*  in_coldata =  in.colptr(col);
00896     
00897     for(u32 row = 0; row<n_rows; ++row)
00898       {
00899       out_coldata[row] /= in_coldata[row];
00900       }
00901     }
00902   }
00903 
00904 
00905 
00906 //
00907 //
00908 //
00909 
00910 
00911 
00912 template<typename eT>
00913 arma_inline
00914 subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col)
00915   : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col)
00916   {
00917   arma_extra_debug_sigprint();
00918   }
00919 
00920 
00921 
00922 template<typename eT>
00923 arma_inline
00924 subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col)
00925   : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col)
00926   {
00927   arma_extra_debug_sigprint();
00928   }
00929 
00930 
00931 
00932 template<typename eT>
00933 arma_inline
00934 subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2)
00935   : subview<eT>(in_m, in_row1, in_col, in_row2, in_col)
00936   {
00937   arma_extra_debug_sigprint();
00938   }
00939 
00940 
00941 
00942 template<typename eT>
00943 arma_inline
00944 subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col, const u32 in_row1, const u32 in_row2)
00945   : subview<eT>(in_m, in_row1, in_col, in_row2, in_col)
00946   {
00947   arma_extra_debug_sigprint();
00948   }
00949 
00950 
00951 
00952 template<typename eT>
00953 inline
00954 void
00955 subview_col<eT>::operator=(const subview<eT>& X)
00956   {
00957   arma_extra_debug_sigprint();
00958   
00959   subview<eT>::operator=(X);
00960   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
00961   }
00962 
00963 
00964 
00965 template<typename eT>
00966 inline
00967 void
00968 subview_col<eT>::operator=(const subview_col<eT>& X)
00969   {
00970   arma_extra_debug_sigprint();
00971   
00972   subview<eT>::operator=(X); // interprets 'subview_col' as 'subview'
00973   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
00974   }
00975 
00976 
00977 
00978 template<typename eT>
00979 template<typename T1>
00980 inline
00981 void
00982 subview_col<eT>::operator=(const Base<eT,T1>& X)
00983   {
00984   arma_extra_debug_sigprint();
00985   
00986   subview<eT>::operator=(X);
00987   arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
00988   }
00989 
00990 
00991 
00992 
00993 //
00994 //
00995 //
00996 
00997 
00998 
00999 template<typename eT>
01000 arma_inline
01001 subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row)
01002   : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1)
01003   {
01004   arma_extra_debug_sigprint();
01005   }
01006 
01007 
01008 
01009 template<typename eT>
01010 arma_inline
01011 subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row)
01012   : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1)
01013   {
01014   arma_extra_debug_sigprint();
01015   }
01016 
01017 
01018 
01019 template<typename eT>
01020 arma_inline
01021 subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2)
01022   : subview<eT>(in_m, in_row, in_col1, in_row, in_col2)
01023   {
01024   arma_extra_debug_sigprint();
01025   }
01026 
01027 
01028 
01029 template<typename eT>
01030 arma_inline
01031 subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row, const u32 in_col1, const u32 in_col2)
01032   : subview<eT>(in_m, in_row, in_col1, in_row, in_col2)
01033   {
01034   arma_extra_debug_sigprint();
01035   }
01036 
01037 
01038 
01039 template<typename eT>
01040 inline
01041 void
01042 subview_row<eT>::operator=(const subview<eT>& X)
01043   {
01044   arma_extra_debug_sigprint();
01045   
01046   subview<eT>::operator=(X);
01047   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01048   }
01049 
01050 
01051 
01052 template<typename eT>
01053 inline
01054 void
01055 subview_row<eT>::operator=(const subview_row<eT>& X)
01056   {
01057   arma_extra_debug_sigprint();
01058   
01059   subview<eT>::operator=(X); // interprets 'subview_row' as 'subview'
01060   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01061   }
01062 
01063 
01064 
01065 template<typename eT>
01066 template<typename T1>
01067 inline
01068 void
01069 subview_row<eT>::operator=(const Base<eT,T1>& X)
01070   {
01071   arma_extra_debug_sigprint();
01072   
01073   subview<eT>::operator=(X);
01074   arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01075   }
01076 
01077 
01078 
01079 //! @}