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