fn_conv_to.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 fn_conv_to
00018 //! @{
00019 
00020 
00021 
00022 //! conversion from Armadillo Base and BaseCube objects to scalars
00023 //! (kept only for compatibility with old code; use as_scalar() instead for Base objects like Mat)
00024 template<typename out_eT>
00025 class conv_to
00026   {
00027   public:
00028   
00029   template<typename in_eT, typename T1>
00030   inline static out_eT from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00031 
00032   template<typename in_eT, typename T1>
00033   inline static out_eT from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00034   
00035   template<typename in_eT, typename T1>
00036   inline static out_eT from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00037   
00038   template<typename in_eT, typename T1>
00039   inline static out_eT from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00040   };
00041 
00042 
00043 
00044 template<typename out_eT>
00045 template<typename in_eT, typename T1>
00046 inline
00047 out_eT
00048 conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00049   {
00050   arma_extra_debug_sigprint();
00051   
00052   arma_type_check< is_supported_elem_type<out_eT>::value == false >::apply();
00053   
00054   const unwrap<T1>      tmp(in.get_ref());
00055   const Mat<in_eT>& X = tmp.M;
00056   
00057   arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
00058   
00059   return out_eT(X.mem[0]);
00060   }
00061 
00062 
00063 
00064 template<typename out_eT>
00065 template<typename in_eT, typename T1>
00066 inline
00067 out_eT
00068 conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00069   {
00070   arma_extra_debug_sigprint();
00071   
00072   arma_type_check< is_supported_elem_type<out_eT>::value == false >::apply();
00073   
00074   const unwrap<T1>      tmp(in.get_ref());
00075   const Mat<in_eT>& X = tmp.M;
00076   
00077   arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
00078   
00079   out_eT out;
00080   
00081   syslib::convert_cx_scalar(out, X.mem[0]);
00082   
00083   return out;
00084   }
00085 
00086 
00087 
00088 template<typename out_eT>
00089 template<typename in_eT, typename T1>
00090 inline
00091 out_eT
00092 conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00093   {
00094   arma_extra_debug_sigprint();
00095   
00096   arma_type_check< is_supported_elem_type<out_eT>::value == false >::apply();
00097   
00098   const unwrap_cube<T1>  tmp(in.get_ref());
00099   const Cube<in_eT>& X = tmp.M;
00100   
00101   arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
00102   
00103   return out_eT(X.mem[0]);
00104   }
00105 
00106 
00107 
00108 template<typename out_eT>
00109 template<typename in_eT, typename T1>
00110 inline
00111 out_eT
00112 conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00113   {
00114   arma_extra_debug_sigprint();
00115   
00116   arma_type_check< is_supported_elem_type<out_eT>::value == false >::apply();
00117   
00118   const unwrap_cube<T1>  tmp(in.get_ref());
00119   const Cube<in_eT>& X = tmp.M;
00120   
00121   arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
00122   
00123   out_eT out;
00124   
00125   syslib::convert_cx_scalar(out, X.mem[0]);
00126   
00127   return out;
00128   }
00129 
00130 
00131 
00132 //! conversion to Armadillo matrices from Armadillo Base objects,
00133 //! as well as from std::vector, itpp::Mat and itpp::Vec
00134 template<typename out_eT>
00135 class conv_to< Mat<out_eT> >
00136   {
00137   public:
00138   
00139   template<typename in_eT, typename T1>
00140   inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00141   
00142   template<typename in_eT, typename T1>
00143   inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00144   
00145   
00146   
00147   template<typename in_eT>
00148   inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00149   
00150   template<typename in_eT>
00151   inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00152   
00153   
00154   
00155   template<typename in_eT>
00156   inline static Mat<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00157   
00158   template<typename in_eT>
00159   inline static Mat<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00160   
00161   
00162   
00163   template<typename in_eT>
00164   inline static Mat<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00165   
00166   template<typename in_eT>
00167   inline static Mat<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00168   };
00169 
00170 
00171 
00172 template<typename out_eT>
00173 template<typename in_eT, typename T1>
00174 inline
00175 Mat<out_eT>
00176 conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00177   {
00178   arma_extra_debug_sigprint();
00179   
00180   const unwrap<T1>      tmp(in.get_ref());
00181   const Mat<in_eT>& X = tmp.M;
00182   
00183   Mat<out_eT> out(X.n_rows, X.n_cols);
00184   
00185   syslib::copy_and_convert_elem( out.memptr(), X.memptr(), out.n_elem );
00186   
00187   return out;
00188   }
00189 
00190 
00191 
00192 template<typename out_eT>
00193 template<typename in_eT, typename T1>
00194 inline
00195 Mat<out_eT>
00196 conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00197   {
00198   arma_extra_debug_sigprint();
00199   
00200   const unwrap<T1>      tmp(in.get_ref());
00201   const Mat<in_eT>& X = tmp.M;
00202   
00203   Mat<out_eT> out(X.n_rows, X.n_cols);
00204   
00205   syslib::copy_and_convert_cx_elem( out.memptr(), X.memptr(), out.n_elem );
00206   
00207   return out;
00208   }
00209 
00210 
00211 
00212 template<typename out_eT>
00213 template<typename in_eT>
00214 inline
00215 Mat<out_eT>
00216 conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00217   {
00218   arma_extra_debug_sigprint();
00219   
00220   Mat<out_eT> out(in.size(), 1);
00221   
00222   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00223   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00224   
00225   typename Mat<out_eT>::iterator out_begin = out.begin();
00226   typename Mat<out_eT>::iterator out_end   = out.end();
00227   
00228   typename std::vector<in_eT>::const_iterator in_it;
00229   typename Mat<out_eT>::iterator              out_it;
00230   
00231   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00232     {
00233     (*out_it) = out_eT(*in_it);
00234     }
00235   
00236   return out;
00237   }
00238 
00239 
00240 
00241 template<typename out_eT>
00242 template<typename in_eT>
00243 inline
00244 Mat<out_eT>
00245 conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00246   {
00247   arma_extra_debug_sigprint();
00248   
00249   Mat<out_eT> out(in.size(), 1);
00250   
00251   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00252   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00253   
00254   typename Mat<out_eT>::iterator out_begin = out.begin();
00255   typename Mat<out_eT>::iterator out_end   = out.end();
00256   
00257   typename std::vector<in_eT>::const_iterator in_it;
00258   typename Mat<out_eT>::iterator              out_it;
00259   
00260   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00261     {
00262           out_eT& out_elem = (*out_it);
00263     const in_eT&  in_elem  = (*in_it);
00264     
00265     syslib::convert_cx_scalar(out_elem, in_elem);
00266     }
00267   
00268   return out;
00269   }
00270 
00271 
00272 
00273 template<typename out_eT>
00274 template<typename in_eT>
00275 inline
00276 Mat<out_eT>
00277 conv_to< Mat<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00278   {
00279   arma_extra_debug_sigprint();
00280   
00281   Mat<out_eT> out(in.rows(), in.cols());
00282   
00283   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00284   
00285   return out;
00286   }
00287 
00288 
00289 
00290 template<typename out_eT>
00291 template<typename in_eT>
00292 inline
00293 Mat<out_eT>
00294 conv_to< Mat<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00295   {
00296   arma_extra_debug_sigprint();
00297   
00298   Mat<out_eT> out(in.rows(), in.cols());
00299   
00300   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00301   
00302   return out;
00303   }
00304 
00305 
00306 
00307 template<typename out_eT>
00308 template<typename in_eT>
00309 inline
00310 Mat<out_eT>
00311 conv_to< Mat<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00312   {
00313   arma_extra_debug_sigprint();
00314   
00315   Mat<out_eT> out(in.length(), 1);
00316   
00317   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00318   
00319   return out;
00320   }
00321 
00322 
00323 
00324 template<typename out_eT>
00325 template<typename in_eT>
00326 inline
00327 Mat<out_eT>
00328 conv_to< Mat<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00329   {
00330   arma_extra_debug_sigprint();
00331   
00332   Mat<out_eT> out(in.length(), 1);
00333   
00334   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00335   
00336   return out;
00337   }
00338 
00339 
00340 
00341 //! conversion to Armadillo row vectors from Armadillo Base objects,
00342 //! as well as from std::vector, itpp::Mat and itpp::Vec
00343 template<typename out_eT>
00344 class conv_to< Row<out_eT> >
00345   {
00346   public:
00347   
00348   template<typename in_eT, typename T1>
00349   inline static Row<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00350   
00351   template<typename in_eT, typename T1>
00352   inline static Row<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00353   
00354   
00355   
00356   template<typename in_eT>
00357   inline static Row<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00358   
00359   template<typename in_eT>
00360   inline static Row<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00361   
00362   
00363   
00364   template<typename in_eT>
00365   inline static Row<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00366   
00367   template<typename in_eT>
00368   inline static Row<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00369   
00370   
00371   
00372   template<typename in_eT>
00373   inline static Row<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00374   
00375   template<typename in_eT>
00376   inline static Row<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00377   };
00378 
00379 
00380 
00381 template<typename out_eT>
00382 template<typename in_eT, typename T1>
00383 inline
00384 Row<out_eT>
00385 conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00386   {
00387   arma_extra_debug_sigprint();
00388   
00389   const unwrap<T1>      tmp(in.get_ref());
00390   const Mat<in_eT>& X = tmp.M;
00391   
00392   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00393   
00394   Row<out_eT> out(X.n_elem);
00395   
00396   syslib::copy_and_convert_elem( out.memptr(), X.memptr(), out.n_elem );
00397   
00398   return out;
00399   }
00400 
00401 
00402 
00403 template<typename out_eT>
00404 template<typename in_eT, typename T1>
00405 inline
00406 Row<out_eT>
00407 conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00408   {
00409   arma_extra_debug_sigprint();
00410   
00411   const unwrap<T1>      tmp(in.get_ref());
00412   const Mat<in_eT>& X = tmp.M;
00413   
00414   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00415   
00416   Row<out_eT> out(X.n_rows, X.n_cols);
00417   
00418   syslib::copy_and_convert_cx_elem( out.memptr(), X.memptr(), out.n_elem );
00419   
00420   return out;
00421   }
00422 
00423 
00424 
00425 template<typename out_eT>
00426 template<typename in_eT>
00427 inline
00428 Row<out_eT>
00429 conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00430   {
00431   arma_extra_debug_sigprint();
00432   
00433   Row<out_eT> out( in.size() );
00434   
00435   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00436   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00437   
00438   typename Col<out_eT>::iterator out_begin = out.begin();
00439   typename Col<out_eT>::iterator out_end   = out.end();
00440   
00441   typename std::vector<in_eT>::const_iterator in_it;
00442   typename Col<out_eT>::iterator              out_it;
00443   
00444   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00445     {
00446     (*out_it) = out_eT(*in_it);
00447     }
00448   
00449   return out;
00450   }
00451 
00452 
00453 
00454 template<typename out_eT>
00455 template<typename in_eT>
00456 inline
00457 Row<out_eT>
00458 conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00459   {
00460   arma_extra_debug_sigprint();
00461   
00462   Row<out_eT> out( in.size() );
00463   
00464   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00465   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00466   
00467   typename Col<out_eT>::iterator out_begin = out.begin();
00468   typename Col<out_eT>::iterator out_end   = out.end();
00469   
00470   typename std::vector<in_eT>::const_iterator in_it;
00471   typename Col<out_eT>::iterator              out_it;
00472   
00473   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00474     {
00475           out_eT& out_elem = (*out_it);
00476     const in_eT&  in_elem  = (*in_it);
00477     
00478     syslib::convert_cx_scalar(out_elem, in_elem);
00479     }
00480   
00481   return out;
00482   }
00483 
00484 
00485 
00486 template<typename out_eT>
00487 template<typename in_eT>
00488 inline
00489 Row<out_eT>
00490 conv_to< Row<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00491   {
00492   arma_extra_debug_sigprint();
00493   
00494   const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
00495   
00496   arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" );
00497   
00498   Row<out_eT> out(in.rows() * in.cols());
00499   
00500   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00501   
00502   return out;
00503   }
00504 
00505 
00506 
00507 template<typename out_eT>
00508 template<typename in_eT>
00509 inline
00510 Row<out_eT>
00511 conv_to< Row<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00512   {
00513   arma_extra_debug_sigprint();
00514   
00515   const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
00516   
00517   Row<out_eT> out(in.rows() * in.cols());
00518   
00519   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00520   
00521   return out;
00522   }
00523 
00524 
00525 
00526 template<typename out_eT>
00527 template<typename in_eT>
00528 inline
00529 Row<out_eT>
00530 conv_to< Row<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00531   {
00532   arma_extra_debug_sigprint();
00533   
00534   Row<out_eT> out(in.length());
00535   
00536   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00537   
00538   return out;
00539   }
00540 
00541 
00542 
00543 template<typename out_eT>
00544 template<typename in_eT>
00545 inline
00546 Row<out_eT>
00547 conv_to< Row<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00548   {
00549   arma_extra_debug_sigprint();
00550   
00551   Row<out_eT> out(in.length());
00552   
00553   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00554   
00555   return out;
00556   }
00557 
00558 
00559 
00560 //! conversion to Armadillo column vectors from Armadillo Base objects,
00561 //! as well as from std::vector, itpp::Mat and itpp::Vec
00562 template<typename out_eT>
00563 class conv_to< Col<out_eT> >
00564   {
00565   public:
00566   
00567   template<typename in_eT, typename T1>
00568   inline static Col<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00569   
00570   template<typename in_eT, typename T1>
00571   inline static Col<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00572   
00573   
00574   
00575   template<typename in_eT>
00576   inline static Col<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00577   
00578   template<typename in_eT>
00579   inline static Col<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00580   
00581   
00582   
00583   template<typename in_eT>
00584   inline static Col<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00585   
00586   template<typename in_eT>
00587   inline static Col<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00588   
00589   
00590   
00591   template<typename in_eT>
00592   inline static Col<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00593   
00594   template<typename in_eT>
00595   inline static Col<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00596   };
00597 
00598 
00599 
00600 template<typename out_eT>
00601 template<typename in_eT, typename T1>
00602 inline
00603 Col<out_eT>
00604 conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00605   {
00606   arma_extra_debug_sigprint();
00607   
00608   const unwrap<T1>      tmp(in.get_ref());
00609   const Mat<in_eT>& X = tmp.M;
00610   
00611   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00612   
00613   Col<out_eT> out(X.n_elem);
00614   
00615   syslib::copy_and_convert_elem( out.memptr(), X.memptr(), out.n_elem );
00616   
00617   return out;
00618   }
00619 
00620 
00621 
00622 template<typename out_eT>
00623 template<typename in_eT, typename T1>
00624 inline
00625 Col<out_eT>
00626 conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00627   {
00628   arma_extra_debug_sigprint();
00629   
00630   const unwrap<T1>      tmp(in.get_ref());
00631   const Mat<in_eT>& X = tmp.M;
00632   
00633   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00634   
00635   Col<out_eT> out(X.n_rows, X.n_cols);
00636   
00637   syslib::copy_and_convert_cx_elem( out.memptr(), X.memptr(), out.n_elem );
00638   
00639   return out;
00640   }
00641 
00642 
00643 
00644 template<typename out_eT>
00645 template<typename in_eT>
00646 inline
00647 Col<out_eT>
00648 conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00649   {
00650   arma_extra_debug_sigprint();
00651   
00652   Col<out_eT> out( in.size() );
00653   
00654   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00655   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00656   
00657   typename Col<out_eT>::iterator out_begin = out.begin();
00658   typename Col<out_eT>::iterator out_end   = out.end();
00659   
00660   typename std::vector<in_eT>::const_iterator in_it;
00661   typename Col<out_eT>::iterator              out_it;
00662   
00663   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00664     {
00665     (*out_it) = out_eT(*in_it);
00666     }
00667   
00668   return out;
00669   }
00670 
00671 
00672 
00673 template<typename out_eT>
00674 template<typename in_eT>
00675 inline
00676 Col<out_eT>
00677 conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00678   {
00679   arma_extra_debug_sigprint();
00680   
00681   Col<out_eT> out( in.size() );
00682   
00683   typename std::vector<in_eT>::const_iterator in_begin = in.begin();
00684   typename std::vector<in_eT>::const_iterator in_end   = in.end();
00685   
00686   typename Col<out_eT>::iterator out_begin = out.begin();
00687   typename Col<out_eT>::iterator out_end   = out.end();
00688   
00689   typename std::vector<in_eT>::const_iterator in_it;
00690   typename Col<out_eT>::iterator              out_it;
00691   
00692   for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
00693     {
00694           out_eT& out_elem = (*out_it);
00695     const in_eT&  in_elem  = (*in_it);
00696     
00697     syslib::convert_cx_scalar(out_elem, in_elem);
00698     }
00699   
00700   return out;
00701   }
00702 
00703 
00704 
00705 template<typename out_eT>
00706 template<typename in_eT>
00707 inline
00708 Col<out_eT>
00709 conv_to< Col<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00710   {
00711   arma_extra_debug_sigprint();
00712   
00713   const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
00714   
00715   arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" );
00716   
00717   Col<out_eT> out(in.rows() * in.cols());
00718   
00719   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00720   
00721   return out;
00722   }
00723 
00724 
00725 
00726 template<typename out_eT>
00727 template<typename in_eT>
00728 inline
00729 Col<out_eT>
00730 conv_to< Col<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00731   {
00732   arma_extra_debug_sigprint();
00733   
00734   const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
00735   
00736   Col<out_eT> out(in.rows() * in.cols());
00737   
00738   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00739   
00740   return out;
00741   }
00742 
00743 
00744 
00745 template<typename out_eT>
00746 template<typename in_eT>
00747 inline
00748 Col<out_eT>
00749 conv_to< Col<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
00750   {
00751   arma_extra_debug_sigprint();
00752   
00753   Col<out_eT> out( in.length() );
00754   
00755   syslib::copy_and_convert_elem( out.memptr(), in._data(), out.n_elem );
00756   
00757   return out;
00758   }
00759 
00760 
00761 
00762 template<typename out_eT>
00763 template<typename in_eT>
00764 inline
00765 Col<out_eT>
00766 conv_to< Col<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
00767   {
00768   arma_extra_debug_sigprint();
00769   
00770   Col<out_eT> out( in.length() );
00771   
00772   syslib::copy_and_convert_cx_elem( out.memptr(), in._data(), out.n_elem );
00773   
00774   return out;
00775   }
00776 
00777 
00778 
00779 //! conversion to Armadillo cubes from Armadillo BaseCube objects
00780 template<typename out_eT>
00781 class conv_to< Cube<out_eT> >
00782   {
00783   public:
00784   
00785   template<typename in_eT, typename T1>
00786   inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00787   
00788   template<typename in_eT, typename T1>
00789   inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00790   };
00791 
00792 
00793 
00794 template<typename out_eT>
00795 template<typename in_eT, typename T1>
00796 inline
00797 Cube<out_eT>
00798 conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00799   {
00800   arma_extra_debug_sigprint();
00801   
00802   const unwrap_cube<T1>  tmp( in.get_ref() );
00803   const Cube<in_eT>& X = tmp.M;
00804   
00805   Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices);
00806   
00807   syslib::copy_and_convert_elem( out.memptr(), X.memptr(), out.n_elem );
00808   
00809   return out;
00810   }
00811 
00812 
00813 
00814 template<typename out_eT>
00815 template<typename in_eT, typename T1>
00816 inline
00817 Cube<out_eT>
00818 conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00819   {
00820   arma_extra_debug_sigprint();
00821   
00822   const unwrap_cube<T1>  tmp( in.get_ref() );
00823   const Cube<in_eT>& X = tmp.M;
00824   
00825   Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices);
00826   
00827   syslib::copy_and_convert_cx_elem( out.memptr(), X.memptr(), out.n_elem );
00828   
00829   return out;
00830   }
00831 
00832 
00833 
00834 //! conversion to std::vector from Armadillo Base objects
00835 template<typename out_eT>
00836 class conv_to< std::vector<out_eT> >
00837   {
00838   public:
00839   
00840   template<typename in_eT, typename T1>
00841   inline static std::vector<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00842   
00843   template<typename in_eT, typename T1>
00844   inline static std::vector<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00845   };
00846 
00847 
00848 
00849 template<typename out_eT>
00850 template<typename in_eT, typename T1>
00851 inline
00852 std::vector<out_eT>
00853 conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00854   {
00855   arma_extra_debug_sigprint();
00856   
00857   const unwrap<T1>      tmp(in.get_ref());
00858   const Mat<in_eT>& X = tmp.M;
00859   
00860   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00861   
00862   std::vector<out_eT> out(X.n_elem);
00863   
00864   typename Mat<in_eT>::const_iterator X_begin = X.begin();
00865   typename Mat<in_eT>::const_iterator X_end   = X.end();
00866 
00867   typename std::vector<out_eT>::iterator out_begin = out.begin();
00868   typename std::vector<out_eT>::iterator out_end   = out.end();
00869   
00870   typename Mat<in_eT>::const_iterator    X_it;
00871   typename std::vector<out_eT>::iterator out_it;
00872   
00873   for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it)
00874     {
00875     (*out_it) = out_eT(*X_it);
00876     }
00877   
00878   return out;
00879   }
00880 
00881 
00882 
00883 template<typename out_eT>
00884 template<typename in_eT, typename T1>
00885 inline
00886 std::vector<out_eT>
00887 conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00888   {
00889   arma_extra_debug_sigprint();
00890   
00891   const unwrap<T1>      tmp(in.get_ref());
00892   const Mat<in_eT>& X = tmp.M;
00893   
00894   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
00895   
00896   std::vector<out_eT> out(X.n_elem);
00897   
00898   typename Mat<in_eT>::const_iterator X_begin = X.begin();
00899   typename Mat<in_eT>::const_iterator X_end   = X.end();
00900 
00901   typename std::vector<out_eT>::iterator out_begin = out.begin();
00902   typename std::vector<out_eT>::iterator out_end   = out.end();
00903   
00904   typename Mat<in_eT>::const_iterator    X_it;
00905   typename std::vector<out_eT>::iterator out_it;
00906   
00907   for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it)
00908     {
00909           out_eT& out_elem = (*out_it);
00910     const in_eT&  X_elem   = (*X_it);
00911     
00912     syslib::convert_cx_scalar(out_elem, X_elem);
00913     }
00914   
00915   return out;
00916   }
00917 
00918 
00919 
00920 //! conversion to itpp::Mat from Armadillo Base objects
00921 template<typename out_eT>
00922 class conv_to< itpp::Mat<out_eT> >
00923   {
00924   public:
00925   
00926   template<typename in_eT, typename T1>
00927   inline static itpp::Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00928   
00929   template<typename in_eT, typename T1>
00930   inline static itpp::Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00931   };
00932 
00933 
00934 
00935 template<typename out_eT>
00936 template<typename in_eT, typename T1>
00937 inline
00938 itpp::Mat<out_eT>
00939 conv_to< itpp::Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00940   {
00941   arma_extra_debug_sigprint();
00942   
00943   const unwrap<T1>      tmp( in.get_ref() );
00944   const Mat<in_eT>& X = tmp.M;
00945   
00946   itpp::Mat<out_eT> out(X.n_rows, X.n_cols);
00947   
00948   syslib::copy_and_convert_elem( out._data(), X.memptr(), X.n_elem );
00949   
00950   return out;
00951   }
00952 
00953 
00954 
00955 template<typename out_eT>
00956 template<typename in_eT, typename T1>
00957 inline
00958 itpp::Mat<out_eT>
00959 conv_to< itpp::Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
00960   {
00961   arma_extra_debug_sigprint();
00962   
00963   const unwrap<T1>      tmp( in.get_ref() );
00964   const Mat<in_eT>& X = tmp.M;
00965   
00966   itpp::Mat<out_eT> out(X.n_rows, X.n_cols);
00967   
00968   syslib::copy_and_convert_cx_elem( out._data(), X.memptr(), X.n_elem );
00969   
00970   return out;
00971   }
00972 
00973 
00974 
00975 
00976 //! conversion to itpp::Vec from Armadillo Base objects
00977 template<typename out_eT>
00978 class conv_to< itpp::Vec<out_eT> >
00979   {
00980   public:
00981   
00982   template<typename in_eT, typename T1>
00983   inline static itpp::Vec<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
00984   
00985   template<typename in_eT, typename T1>
00986   inline static itpp::Vec<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
00987   };
00988 
00989 
00990 
00991 template<typename out_eT>
00992 template<typename in_eT, typename T1>
00993 inline
00994 itpp::Vec<out_eT>
00995 conv_to< itpp::Vec<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
00996   {
00997   arma_extra_debug_sigprint();
00998   
00999   const unwrap<T1>      tmp( in.get_ref() );
01000   const Mat<in_eT>& X = tmp.M;
01001   
01002   arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
01003   
01004   itpp::Vec<out_eT> out(X.n_elem);
01005   
01006   syslib::copy_and_convert_elem( out._data(), X.memptr(), X.n_elem );
01007   
01008   return out;
01009   }
01010 
01011 
01012 
01013 template<typename out_eT>
01014 template<typename in_eT, typename T1>
01015 inline
01016 itpp::Vec<out_eT>
01017 conv_to< itpp::Vec<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
01018   {
01019   arma_extra_debug_sigprint();
01020   
01021   const unwrap<T1>      tmp( in.get_ref() );
01022   const Mat<in_eT>& X = tmp.M;
01023   
01024   itpp::Vec<out_eT> out(X.n_elem);
01025   
01026   syslib::copy_and_convert_cx_elem( out._data(), X.memptr(), X.n_elem );
01027   
01028   return out;
01029   }
01030 
01031 
01032 
01033 //! @}