Col_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 Col
00017 //! @{
00018 
00019 
00020 //! construct an empty column vector
00021 template<typename eT>
00022 inline
00023 Col<eT>::Col()
00024   : Mat<eT>()
00025   {
00026   arma_extra_debug_sigprint();
00027   }
00028 
00029 
00030 
00031 //! construct a column vector with the specified number of n_elem
00032 template<typename eT>
00033 inline
00034 Col<eT>::Col(const u32 in_n_elem)
00035   : Mat<eT>(in_n_elem,1)
00036   {
00037   arma_extra_debug_sigprint();
00038   }
00039 
00040 
00041 
00042 //! construct a column vector from specified text
00043 template<typename eT>
00044 inline
00045 Col<eT>::Col(const char* text)
00046   : Mat<eT>(text)
00047   {
00048   arma_extra_debug_sigprint();
00049   
00050   std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
00051   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00052   }
00053 
00054 
00055 
00056 //! construct a column vector from specified text
00057 template<typename eT>
00058 inline
00059 const Col<eT>&
00060 Col<eT>::operator=(const char* text)
00061   {
00062   arma_extra_debug_sigprint();
00063   
00064   Mat<eT>::operator=(text);
00065   std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
00066   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00067   
00068   return *this;
00069   }
00070 
00071 
00072 
00073 //! construct a column vector from a given column vector
00074 template<typename eT>
00075 inline
00076 Col<eT>::Col(const Col<eT>& X)
00077   : Mat<eT>(X)
00078   {
00079   arma_extra_debug_sigprint();
00080   }
00081 
00082 
00083 
00084 //! construct a column vector from a given column vector
00085 template<typename eT>
00086 inline
00087 const Col<eT>&
00088 Col<eT>::operator=(const Col<eT>& X)
00089   {
00090   arma_extra_debug_sigprint();
00091   
00092   Mat<eT>::operator=(X);
00093   return *this;
00094   }
00095 
00096 
00097 
00098 //! construct a column vector from a given matrix; the matrix must have exactly one column
00099 template<typename eT>
00100 inline
00101 Col<eT>::Col(const Mat<eT>& X)
00102   : Mat<eT>(X)
00103   {
00104   arma_extra_debug_sigprint();
00105   
00106   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00107   }
00108 
00109 
00110 
00111 //! construct a column vector from a given matrix; the matrix must have exactly one column
00112 template<typename eT>
00113 inline
00114 const Col<eT>&
00115 Col<eT>::operator=(const Mat<eT>& X)
00116   {
00117   arma_extra_debug_sigprint();
00118   
00119   Mat<eT>::operator=(X);
00120   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00121   
00122   return *this;
00123   }
00124 
00125 
00126 
00127 template<typename eT>
00128 inline
00129 const Col<eT>&
00130 Col<eT>::operator*=(const Mat<eT>& X)
00131   {
00132   arma_extra_debug_sigprint();
00133   
00134   Mat<eT>::operator*=(X);
00135   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00136   
00137   return *this;
00138   }
00139 
00140 
00141 
00142 //! construct a column vector from a given auxillary array of eTs
00143 template<typename eT>
00144 inline
00145 Col<eT>::Col(const eT* aux_mem, const u32 aux_length)
00146   {
00147   arma_extra_debug_sigprint();
00148   
00149   set_size(aux_length, 1);
00150 
00151   arma_check( (Mat<eT>::n_elem != aux_length), "Col::Col(): don't know how to handle the given array" );
00152 
00153   syslib::copy_elem( Mat<eT>::memptr(), aux_mem, Mat<eT>::n_elem );
00154   }
00155 
00156 
00157 
00158 template<typename eT>
00159 template<typename T1, typename T2>
00160 inline
00161 Col<eT>::Col
00162   (
00163   const Base<typename Col<eT>::pod_type, T1>& A,
00164   const Base<typename Col<eT>::pod_type, T2>& B
00165   )
00166   : Mat<eT>(A,B)
00167   {
00168   arma_extra_debug_sigprint();
00169   
00170   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00171   }
00172 
00173 
00174 
00175 //! construct a column vector from given a submatrix; the submatrix must have exactly one column
00176 template<typename eT>
00177 inline
00178 Col<eT>::Col(const subview<eT>& X)
00179   : Mat<eT>(X)
00180   {
00181   arma_extra_debug_sigprint();
00182   
00183   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00184   }
00185 
00186 
00187 
00188 //! construct a column vector from given a submatrix; the submatrix must have exactly one column
00189 template<typename eT>
00190 inline
00191 const Col<eT>&
00192 Col<eT>::operator=(const subview<eT>& X)
00193   {
00194   arma_extra_debug_sigprint();
00195   
00196   Mat<eT>::operator=(X);
00197   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00198   
00199   return *this;
00200   }
00201 
00202 
00203 
00204 template<typename eT>
00205 inline
00206 const Col<eT>&
00207 Col<eT>::operator*=(const subview<eT>& X)
00208   {
00209   arma_extra_debug_sigprint();
00210   
00211   Mat<eT>::operator*=(X);
00212   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00213   
00214   return *this;
00215   }
00216 
00217 
00218 
00219 //! construct a column vector from given a diagview
00220 template<typename eT>
00221 inline
00222 Col<eT>::Col(const diagview<eT>& X)
00223   : Mat<eT>(X)
00224   {
00225   arma_extra_debug_sigprint();
00226   
00227   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00228   }
00229 
00230 
00231 
00232 //! construct a column vector from given a diagview
00233 template<typename eT>
00234 inline
00235 const Col<eT>&
00236 Col<eT>::operator=(const diagview<eT>& X)
00237   {
00238   arma_extra_debug_sigprint();
00239   
00240   Mat<eT>::operator=(X);
00241   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00242   return *this;
00243   }
00244 
00245 
00246 
00247 template<typename eT>
00248 inline
00249 const Col<eT>&
00250 Col<eT>::operator*=(const diagview<eT>& X)
00251   {
00252   arma_extra_debug_sigprint();
00253   
00254   Mat<eT>::operator*=(X);
00255   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00256   return *this;
00257   }
00258 
00259 
00260 
00261 //! construct a column vector from Op, i.e. run the previously delayed operations; the result of the operations must have exactly one column
00262 template<typename eT>
00263 template<typename T1, typename op_type>
00264 inline
00265 Col<eT>::Col(const Op<T1, op_type>& X)
00266   : Mat<eT>(X)
00267   {
00268   arma_extra_debug_sigprint();
00269   
00270   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00271   }
00272 
00273 
00274 
00275 //! construct a column vector from Op, i.e. run the previously delayed operations; the result of the operations must have exactly one column
00276 template<typename eT>
00277 template<typename T1, typename op_type>
00278 inline
00279 const Col<eT>&
00280 Col<eT>::operator=(const Op<T1, op_type>& X)
00281   {
00282   arma_extra_debug_sigprint();
00283   
00284   Mat<eT>::operator=(X);
00285   arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): given matrix can't be interpreted as a column vector" );
00286   return *this;
00287   }
00288 
00289 
00290 
00291 template<typename eT>
00292 template<typename T1, typename op_type>
00293 inline
00294 const Col<eT>&
00295 Col<eT>::operator*=(const Op<T1, op_type>& X)
00296   {
00297   arma_extra_debug_sigprint();
00298   
00299   Mat<eT>::operator*=(X);
00300   arma_debug_check( (Mat<eT>::n_cols > 1), "Col::operator=(): incompatible dimensions" );
00301   return *this;
00302   }
00303 
00304 
00305 
00306 //! construct a column vector from Glue, i.e. run the previously delayed operations; the result of the operations must have exactly one column
00307 template<typename eT>
00308 template<typename T1, typename T2, typename glue_type>
00309 inline
00310 Col<eT>::Col(const Glue<T1, T2, glue_type>& X)
00311   : Mat<eT>(X)
00312   {
00313   arma_extra_debug_sigprint();
00314   
00315   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00316   }
00317 
00318 
00319 
00320 //! construct a column vector from Glue, i.e. run the previously delayed operations; the result of the operations must have exactly one column
00321 template<typename eT>
00322 template<typename T1, typename T2, typename glue_type>
00323 inline
00324 const Col<eT>&
00325 Col<eT>::operator=(const Glue<T1, T2, glue_type>& X)
00326   {
00327   arma_extra_debug_sigprint();
00328   
00329   Mat<eT>::operator=(X);
00330   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00331   
00332   return *this;
00333   }
00334 
00335 
00336 
00337 template<typename eT>
00338 template<typename T1, typename T2, typename glue_type>
00339 inline
00340 const Col<eT>&
00341 Col<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
00342   {
00343   arma_extra_debug_sigprint();
00344   
00345   Mat<eT>::operator*=(X);
00346   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00347   
00348   return *this;
00349   }
00350 
00351 
00352 
00353 //! change the number of n_rows
00354 template<typename eT>
00355 inline
00356 void
00357 Col<eT>::set_size(const u32 in_n_elem)
00358   {
00359   arma_extra_debug_sigprint();
00360   
00361   Mat<eT>::set_size(in_n_elem,1);
00362   }
00363 
00364 
00365 
00366 //! change the number of n_rows  (this function re-implements mat::set_size() in order to check the number of columns)
00367 template<typename eT>
00368 inline
00369 void
00370 Col<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols)
00371   {
00372   arma_extra_debug_sigprint();
00373   
00374   Mat<eT>::set_size( in_n_rows, (std::min)( u32(1), in_n_cols ) );
00375   arma_debug_check( (in_n_cols > 1), "Col::set_size(): incompatible dimensions" );
00376   }
00377 
00378 
00379 
00380 template<typename eT>
00381 inline
00382 void
00383 Col<eT>::zeros()
00384   {
00385   arma_extra_debug_sigprint();
00386   
00387   Mat<eT>::zeros();
00388   }
00389 
00390 
00391 
00392 template<typename eT>
00393 inline
00394 void
00395 Col<eT>::zeros(const u32 in_n_elem)
00396   {
00397   arma_extra_debug_sigprint();
00398   
00399   Mat<eT>::zeros(in_n_elem,1);
00400   }
00401 
00402 
00403 
00404 template<typename eT>
00405 inline
00406 void
00407 Col<eT>::zeros(const u32 in_n_rows, const u32 in_n_cols)
00408   {
00409   arma_extra_debug_sigprint();
00410   
00411   Mat<eT>::zeros( in_n_rows, (std::min)( u32(1), in_n_cols ) );
00412   arma_debug_check( (in_n_cols > 1), "Col::zeros(): incompatible dimensions" );
00413   }
00414 
00415 
00416 
00417 template<typename eT>
00418 inline
00419 void
00420 Col<eT>::load(const std::string name, const file_type type)
00421   {
00422   arma_extra_debug_sigprint();
00423   
00424   Mat<eT>::load(name,type);
00425   arma_debug_check( (Mat<eT>::n_cols > 1), "Col(): incompatible dimensions" );
00426   }
00427 
00428 
00429 //! @}