Row_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup Row
00017 //! @{
00018 
00019 template<typename eT>
00020 inline
00021 Row<eT>::Row()
00022   : Mat<eT>()
00023   {
00024   arma_extra_debug_sigprint();
00025   }
00026 
00027 
00028 
00029 template<typename eT>
00030 inline
00031 Row<eT>::Row(const u32 in_n_elem)
00032   : Mat<eT>(1,in_n_elem)
00033   {
00034   arma_extra_debug_sigprint();
00035   }
00036 
00037 
00038 
00039 template<typename eT>
00040 inline
00041 Row<eT>::Row(const u32 in_n_rows, const u32 in_n_cols)
00042   : Mat<eT>(in_n_rows, in_n_cols)
00043   {
00044   arma_extra_debug_sigprint();
00045   
00046   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00047   }
00048 
00049 
00050 
00051 template<typename eT>
00052 inline
00053 Row<eT>::Row(const char* text)
00054   : Mat<eT>(text)
00055   {
00056   arma_extra_debug_sigprint();
00057   
00058   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00059   }
00060   
00061 
00062 
00063 template<typename eT>
00064 inline
00065 const Row<eT>&
00066 Row<eT>::operator=(const char* text)
00067   {
00068   arma_extra_debug_sigprint();
00069   
00070   Mat<eT>::operator=(text);
00071   
00072   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00073   
00074   return *this;
00075   }
00076 
00077 
00078 
00079 template<typename eT>
00080 inline
00081 Row<eT>::Row(const std::string& text)
00082   : Mat<eT>(text)
00083   {
00084   arma_extra_debug_sigprint();
00085   
00086   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00087   }
00088   
00089 
00090 
00091 template<typename eT>
00092 inline
00093 const Row<eT>&
00094 Row<eT>::operator=(const std::string& text)
00095   {
00096   arma_extra_debug_sigprint();
00097   
00098   Mat<eT>::operator=(text);
00099   
00100   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00101   
00102   return *this;
00103   }
00104 
00105 
00106 
00107 template<typename eT>
00108 inline
00109 Row<eT>::Row(const Row<eT>& X)
00110   : Mat<eT>(X)
00111   {
00112   arma_extra_debug_sigprint();
00113   }
00114 
00115 
00116 
00117 template<typename eT>
00118 inline
00119 const Row<eT>&
00120 Row<eT>::operator=(const Row<eT>& X)
00121   {
00122   arma_extra_debug_sigprint();
00123   
00124   Mat<eT>::operator=(X);
00125   return *this;
00126   }
00127 
00128 
00129 
00130 template<typename eT>
00131 inline
00132 Row<eT>::Row(const Mat<eT>& X)
00133   : Mat<eT>(X)
00134   {
00135   arma_extra_debug_sigprint();
00136   
00137   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00138   }
00139 
00140 
00141 
00142 template<typename eT>
00143 inline
00144 const Row<eT>&
00145 Row<eT>::operator=(const Mat<eT>& X)
00146   {
00147   arma_extra_debug_sigprint();
00148   
00149   Mat<eT>::operator=(X);
00150   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00151   return *this;
00152   }
00153 
00154 
00155 
00156 template<typename eT>
00157 inline
00158 const Row<eT>&
00159 Row<eT>::operator*=(const Mat<eT>& X)
00160   {
00161   arma_extra_debug_sigprint();
00162   
00163   Mat<eT>::operator*=(X);
00164   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00165   return *this;
00166   }
00167 
00168 
00169 
00170 //! construct a row vector from a given auxiliary array
00171 template<typename eT>
00172 inline
00173 Row<eT>::Row(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const bool copy_aux_mem)
00174   : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols, copy_aux_mem)
00175   {
00176   arma_extra_debug_sigprint();
00177   
00178   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00179   }
00180 
00181 
00182 
00183 //! construct a row vector from a given auxiliary array
00184 template<typename eT>
00185 inline
00186 Row<eT>::Row(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
00187   : Mat<eT>(aux_mem, aux_n_rows, aux_n_cols)
00188   {
00189   arma_extra_debug_sigprint();
00190   
00191   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00192   }
00193 
00194 
00195 
00196 //! construct a row vector from a given auxiliary array
00197 template<typename eT>
00198 inline
00199 Row<eT>::Row(eT* aux_mem, const u32 aux_length, const bool copy_aux_mem)
00200   : Mat<eT>(aux_mem, 1, aux_length, copy_aux_mem)
00201   {
00202   arma_extra_debug_sigprint();
00203   
00204 //   Mat<eT>::set_size(1, aux_length);
00205 //   arma_check( (Mat<eT>::n_elem != aux_length), "Row(): don't know how to handle the given array" );
00206 // 
00207 //   syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem );
00208   }
00209 
00210 
00211 
00212 //! construct a row vector from a given auxiliary array
00213 template<typename eT>
00214 inline
00215 Row<eT>::Row(const eT* aux_mem, const u32 aux_length)
00216   : Mat<eT>(aux_mem, 1, aux_length)
00217   {
00218   arma_extra_debug_sigprint();
00219   
00220 //   Mat<eT>::set_size(1, aux_length);
00221 //   arma_check( (Mat<eT>::n_elem != aux_length), "Row(): don't know how to handle the given array" );
00222 // 
00223 //   syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem );
00224   }
00225 
00226 
00227 
00228 template<typename eT>
00229 template<typename T1, typename T2>
00230 inline
00231 Row<eT>::Row
00232   (
00233   const Base<typename Row<eT>::pod_type, T1>& A,
00234   const Base<typename Row<eT>::pod_type, T2>& B
00235   )
00236   : Mat<eT>(A,B)
00237   {
00238   arma_extra_debug_sigprint();
00239   
00240   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00241   }
00242 
00243 
00244 
00245 template<typename eT>
00246 inline
00247 Row<eT>::Row(const subview<eT>& X)
00248   : Mat<eT>(X)
00249   {
00250   arma_extra_debug_sigprint();
00251   
00252   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00253   }
00254 
00255 
00256 
00257 template<typename eT>
00258 inline
00259 const Row<eT>&
00260 Row<eT>::operator=(const subview<eT>& X)
00261   {
00262   arma_extra_debug_sigprint();
00263   
00264   Mat<eT>::operator=(X);
00265   
00266   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00267   
00268   return *this;
00269   }
00270 
00271 
00272 
00273 template<typename eT>
00274 inline
00275 const Row<eT>&
00276 Row<eT>::operator*=(const subview<eT>& X)
00277   {
00278   arma_extra_debug_sigprint();
00279   
00280   Mat<eT>::operator*=(X);
00281   
00282   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00283   
00284   return *this;
00285   }
00286 
00287 
00288 
00289 template<typename eT>
00290 inline
00291 Row<eT>::Row(const subview_cube<eT>& X)
00292   : Mat<eT>(X)
00293   {
00294   arma_extra_debug_sigprint();
00295   
00296   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00297   }
00298 
00299 
00300 
00301 template<typename eT>
00302 inline
00303 const Row<eT>&
00304 Row<eT>::operator=(const subview_cube<eT>& X)
00305   {
00306   arma_extra_debug_sigprint();
00307   
00308   Mat<eT>::operator=(X);
00309   
00310   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00311   
00312   return *this;
00313   }
00314 
00315 
00316 
00317 template<typename eT>
00318 inline
00319 const Row<eT>&
00320 Row<eT>::operator*=(const subview_cube<eT>& X)
00321   {
00322   arma_extra_debug_sigprint();
00323   
00324   Mat<eT>::operator*=(X);
00325   
00326   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00327   
00328   return *this;
00329   }
00330 
00331 
00332 
00333 //! construct a row vector from given a diagview
00334 template<typename eT>
00335 inline
00336 Row<eT>::Row(const diagview<eT>& X)
00337   : Mat<eT>(X)
00338   {
00339   arma_extra_debug_sigprint();
00340   
00341   std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
00342   
00343   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00344   }
00345 
00346 
00347 
00348 //! construct a row vector from given a diagview
00349 template<typename eT>
00350 inline
00351 const Row<eT>&
00352 Row<eT>::operator=(const diagview<eT>& X)
00353   {
00354   arma_extra_debug_sigprint();
00355   
00356   Mat<eT>::operator=(X);
00357   
00358   //std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
00359   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00360   
00361   return *this;
00362   }
00363 
00364 
00365 
00366 template<typename eT>
00367 inline
00368 const Row<eT>&
00369 Row<eT>::operator*=(const diagview<eT>& X)
00370   {
00371   arma_extra_debug_sigprint();
00372   
00373   Mat<eT>::operator*=(X);
00374   
00375   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00376   
00377   return *this;
00378   }
00379 
00380 
00381 
00382 template<typename eT>
00383 arma_inline
00384 eT&
00385 Row<eT>::col(const u32 col_num)
00386   {
00387   arma_debug_check( (col_num >= Mat<eT>::n_cols), "Row::col(): out of bounds" );
00388   
00389   return access::rw(Mat<eT>::mem[col_num]);
00390   }
00391 
00392 
00393 
00394 template<typename eT>
00395 arma_inline
00396 eT
00397 Row<eT>::col(const u32 col_num)
00398   const
00399   {
00400   arma_debug_check( (col_num >= Mat<eT>::n_cols), "Row::col(): out of bounds" );
00401   
00402   return Mat<eT>::mem[col_num];
00403   }
00404 
00405 
00406 
00407 template<typename eT>
00408 arma_inline
00409 subview_row<eT>
00410 Row<eT>::cols(const u32 in_col1, const u32 in_col2)
00411   {
00412   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used");
00413   
00414   return subview_row<eT>(*this, 0, in_col1, in_col2);
00415   }
00416 
00417 
00418 
00419 template<typename eT>
00420 arma_inline
00421 const subview_row<eT>
00422 Row<eT>::cols(const u32 in_col1, const u32 in_col2)
00423   const
00424   {
00425   arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat<eT>::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used");
00426   
00427   return subview_row<eT>(*this, 0, in_col1, in_col2);
00428   }
00429 
00430 
00431 
00432 template<typename eT>
00433 template<typename T1, typename op_type>
00434 inline
00435 Row<eT>::Row(const Op<T1, op_type>& X)
00436   : Mat<eT>(X)
00437   {
00438   arma_extra_debug_sigprint();
00439   
00440   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00441   }
00442 
00443 
00444 
00445 template<typename eT>
00446 template<typename T1, typename op_type>
00447 inline
00448 const Row<eT>&
00449 Row<eT>::operator=(const Op<T1, op_type>& X)
00450   {
00451   arma_extra_debug_sigprint();
00452   
00453   Mat<eT>::operator=(X);
00454   
00455   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00456   
00457   return *this;
00458   }
00459 
00460 
00461 
00462 template<typename eT>
00463 template<typename T1, typename op_type>
00464 inline
00465 const Row<eT>&
00466 Row<eT>::operator*=(const Op<T1, op_type>& X)
00467   {
00468   arma_extra_debug_sigprint();
00469   
00470   Mat<eT>::operator*=(X);
00471   
00472   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00473   
00474   return *this;
00475   }
00476 
00477 
00478 
00479 template<typename eT>
00480 template<typename T1, typename T2, typename glue_type>
00481 inline
00482 Row<eT>::Row(const Glue<T1, T2, glue_type>& X)
00483   : Mat<eT>(X)
00484   {
00485   arma_extra_debug_sigprint();
00486   
00487   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00488   }
00489 
00490 
00491 
00492 template<typename eT>
00493 template<typename T1, typename T2, typename glue_type>
00494 inline
00495 const Row<eT>&
00496 Row<eT>::operator=(const Glue<T1, T2, glue_type>& X)
00497   {
00498   arma_extra_debug_sigprint();
00499   
00500   Mat<eT>::operator=(X);
00501   
00502   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00503   
00504   return *this;
00505   }
00506 
00507 
00508 
00509 template<typename eT>
00510 template<typename T1, typename T2, typename glue_type>
00511 inline
00512 const Row<eT>&
00513 Row<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
00514   {
00515   arma_extra_debug_sigprint();
00516   
00517   Mat<eT>::operator*=(X);
00518   
00519   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00520   
00521   return *this;
00522   }
00523 
00524 
00525 
00526 template<typename eT>
00527 inline
00528 void
00529 Row<eT>::set_size(const u32 in_n_elem)
00530   {
00531   arma_extra_debug_sigprint();
00532   
00533   Mat<eT>::set_size(1,in_n_elem);
00534   }
00535 
00536 
00537 
00538 template<typename eT>
00539 inline
00540 void
00541 Row<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols)
00542   {
00543   arma_extra_debug_sigprint();
00544   
00545   // min is used in case in_n_rows is zero
00546   Mat<eT>::set_size( (std::min)( u32(1), in_n_rows), in_n_cols );
00547   
00548   arma_debug_check( (in_n_rows > 1), "Row::set_size(): incompatible dimensions" );
00549   }
00550 
00551 
00552 
00553 template<typename eT>
00554 template<typename eT2>
00555 inline
00556 void
00557 Row<eT>::copy_size(const Mat<eT2>& x)
00558   {
00559   arma_extra_debug_sigprint();
00560   
00561   // min is used in case x.n_rows is zero
00562   Mat<eT>::set_size( (std::min)( u32(1), x.n_rows), x.n_cols );
00563   
00564   arma_debug_check( (x.n_rows > 1), "Row::copy_size(): incompatible dimensions" );
00565   }
00566 
00567 
00568 
00569 template<typename eT>
00570 inline
00571 void
00572 Row<eT>::zeros()
00573   {
00574   arma_extra_debug_sigprint();
00575   
00576   Mat<eT>::zeros();
00577   }
00578 
00579 
00580 
00581 template<typename eT>
00582 inline
00583 void
00584 Row<eT>::zeros(const u32 in_n_elem)
00585   {
00586   arma_extra_debug_sigprint();
00587   
00588   Mat<eT>::zeros(1, in_n_elem);
00589   }
00590 
00591 
00592 
00593 template<typename eT>
00594 inline
00595 void
00596 Row<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols)
00597   {
00598   arma_extra_debug_sigprint();
00599   
00600   // min is used in case in_n_rows is zero
00601   Mat<eT>::zeros( (std::min)( u32(1), in_n_rows), in_n_cols );
00602   
00603   arma_debug_check( (in_n_rows > 1), "Row<eT>::zeros(): incompatible dimensions" );
00604   }
00605 
00606 
00607 
00608 template<typename eT>
00609 inline
00610 void
00611 Row<eT>::ones()
00612   {
00613   arma_extra_debug_sigprint();
00614   
00615   Mat<eT>::ones();
00616   }
00617 
00618 
00619 
00620 template<typename eT>
00621 inline
00622 void
00623 Row<eT>::ones(const u32 in_n_elem)
00624   {
00625   arma_extra_debug_sigprint();
00626   
00627   Mat<eT>::ones(1, in_n_elem);
00628   }
00629 
00630 
00631 
00632 template<typename eT>
00633 inline
00634 void
00635 Row<eT>::ones(const u32 in_n_rows, const u32 in_n_cols)
00636   {
00637   arma_extra_debug_sigprint();
00638   
00639   // min is used in case in_n_rows is zero
00640   Mat<eT>::ones( (std::min)( u32(1), in_n_rows), in_n_cols );
00641   
00642   arma_debug_check( (in_n_rows > 1), "Row<eT>::ones(): incompatible dimensions" );
00643   }
00644 
00645 
00646 
00647 template<typename eT>
00648 inline
00649 void
00650 Row<eT>::load(const std::string name, const file_type type)
00651   {
00652   arma_extra_debug_sigprint();
00653   
00654   Mat<eT>::load(name,type);
00655   
00656   arma_debug_check( (Mat<eT>::n_rows > 1), "Row(): incompatible dimensions" );
00657   }
00658 
00659 
00660 
00661 //! @}