comparison armadillo-2.4.4/include/armadillo_bits/fn_conv_to.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2010 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup fn_conv_to
15 //! @{
16
17
18
19 //! conversion from Armadillo Base and BaseCube objects to scalars
20 //! (kept only for compatibility with old code; use as_scalar() instead for Base objects like Mat)
21 template<typename out_eT>
22 class conv_to
23 {
24 public:
25
26 template<typename in_eT, typename T1>
27 inline static out_eT from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
28
29 template<typename in_eT, typename T1>
30 inline static out_eT from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
31
32 template<typename in_eT, typename T1>
33 inline static out_eT from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
34
35 template<typename in_eT, typename T1>
36 inline static out_eT from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
37 };
38
39
40
41 template<typename out_eT>
42 template<typename in_eT, typename T1>
43 inline
44 out_eT
45 conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
46 {
47 arma_extra_debug_sigprint();
48
49 arma_ignore(junk);
50
51 arma_type_check(( is_supported_elem_type<out_eT>::value == false ));
52
53 const unwrap<T1> tmp(in.get_ref());
54 const Mat<in_eT>& X = tmp.M;
55
56 arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
57
58 return out_eT(X.mem[0]);
59 }
60
61
62
63 template<typename out_eT>
64 template<typename in_eT, typename T1>
65 inline
66 out_eT
67 conv_to<out_eT>::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
68 {
69 arma_extra_debug_sigprint();
70
71 arma_ignore(junk);
72
73 arma_type_check(( is_supported_elem_type<out_eT>::value == false ));
74
75 const unwrap<T1> tmp(in.get_ref());
76 const Mat<in_eT>& X = tmp.M;
77
78 arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
79
80 out_eT out;
81
82 arrayops::convert_cx_scalar(out, X.mem[0]);
83
84 return out;
85 }
86
87
88
89 template<typename out_eT>
90 template<typename in_eT, typename T1>
91 inline
92 out_eT
93 conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
94 {
95 arma_extra_debug_sigprint();
96
97 arma_ignore(junk);
98
99 arma_type_check(( is_supported_elem_type<out_eT>::value == false ));
100
101 const unwrap_cube<T1> tmp(in.get_ref());
102 const Cube<in_eT>& X = tmp.M;
103
104 arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
105
106 return out_eT(X.mem[0]);
107 }
108
109
110
111 template<typename out_eT>
112 template<typename in_eT, typename T1>
113 inline
114 out_eT
115 conv_to<out_eT>::from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
116 {
117 arma_extra_debug_sigprint();
118
119 arma_ignore(junk);
120
121 arma_type_check(( is_supported_elem_type<out_eT>::value == false ));
122
123 const unwrap_cube<T1> tmp(in.get_ref());
124 const Cube<in_eT>& X = tmp.M;
125
126 arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" );
127
128 out_eT out;
129
130 arrayops::convert_cx_scalar(out, X.mem[0]);
131
132 return out;
133 }
134
135
136
137 //! conversion to Armadillo matrices from Armadillo Base objects,
138 //! as well as from std::vector, itpp::Mat and itpp::Vec
139 template<typename out_eT>
140 class conv_to< Mat<out_eT> >
141 {
142 public:
143
144 template<typename in_eT, typename T1>
145 inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
146
147 template<typename in_eT, typename T1>
148 inline static Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
149
150
151
152 template<typename in_eT>
153 inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
154
155 template<typename in_eT>
156 inline static Mat<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
157
158
159
160 template<typename in_eT>
161 inline static Mat<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
162
163 template<typename in_eT>
164 inline static Mat<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
165
166
167
168 template<typename in_eT>
169 inline static Mat<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
170
171 template<typename in_eT>
172 inline static Mat<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
173 };
174
175
176
177 template<typename out_eT>
178 template<typename in_eT, typename T1>
179 inline
180 Mat<out_eT>
181 conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
182 {
183 arma_extra_debug_sigprint();
184
185 arma_ignore(junk);
186
187 const unwrap<T1> tmp(in.get_ref());
188 const Mat<in_eT>& X = tmp.M;
189
190 Mat<out_eT> out(X.n_rows, X.n_cols);
191
192 arrayops::convert( out.memptr(), X.memptr(), out.n_elem );
193
194 return out;
195 }
196
197
198
199 template<typename out_eT>
200 template<typename in_eT, typename T1>
201 inline
202 Mat<out_eT>
203 conv_to< Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
204 {
205 arma_extra_debug_sigprint();
206
207 arma_ignore(junk);
208
209 const unwrap<T1> tmp(in.get_ref());
210 const Mat<in_eT>& X = tmp.M;
211
212 Mat<out_eT> out(X.n_rows, X.n_cols);
213
214 arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem );
215
216 return out;
217 }
218
219
220
221 template<typename out_eT>
222 template<typename in_eT>
223 inline
224 Mat<out_eT>
225 conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
226 {
227 arma_extra_debug_sigprint();
228
229 arma_ignore(junk);
230
231 Mat<out_eT> out(in.size(), 1);
232
233 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
234 typename std::vector<in_eT>::const_iterator in_end = in.end();
235
236 typename Mat<out_eT>::iterator out_begin = out.begin();
237 typename Mat<out_eT>::iterator out_end = out.end();
238
239 typename std::vector<in_eT>::const_iterator in_it;
240 typename Mat<out_eT>::iterator out_it;
241
242 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
243 {
244 (*out_it) = out_eT(*in_it);
245 }
246
247 return out;
248 }
249
250
251
252 template<typename out_eT>
253 template<typename in_eT>
254 inline
255 Mat<out_eT>
256 conv_to< Mat<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
257 {
258 arma_extra_debug_sigprint();
259
260 arma_ignore(junk);
261
262 Mat<out_eT> out(in.size(), 1);
263
264 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
265 typename std::vector<in_eT>::const_iterator in_end = in.end();
266
267 typename Mat<out_eT>::iterator out_begin = out.begin();
268 typename Mat<out_eT>::iterator out_end = out.end();
269
270 typename std::vector<in_eT>::const_iterator in_it;
271 typename Mat<out_eT>::iterator out_it;
272
273 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
274 {
275 out_eT& out_elem = (*out_it);
276 const in_eT& in_elem = (*in_it);
277
278 arrayops::convert_cx_scalar(out_elem, in_elem);
279 }
280
281 return out;
282 }
283
284
285
286 template<typename out_eT>
287 template<typename in_eT>
288 inline
289 Mat<out_eT>
290 conv_to< Mat<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
291 {
292 arma_extra_debug_sigprint();
293
294 arma_ignore(junk);
295
296 Mat<out_eT> out(in.rows(), in.cols());
297
298 arrayops::convert( out.memptr(), in._data(), out.n_elem );
299
300 return out;
301 }
302
303
304
305 template<typename out_eT>
306 template<typename in_eT>
307 inline
308 Mat<out_eT>
309 conv_to< Mat<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
310 {
311 arma_extra_debug_sigprint();
312
313 arma_ignore(junk);
314
315 Mat<out_eT> out(in.rows(), in.cols());
316
317 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
318
319 return out;
320 }
321
322
323
324 template<typename out_eT>
325 template<typename in_eT>
326 inline
327 Mat<out_eT>
328 conv_to< Mat<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
329 {
330 arma_extra_debug_sigprint();
331
332 arma_ignore(junk);
333
334 Mat<out_eT> out(in.length(), 1);
335
336 arrayops::convert( out.memptr(), in._data(), out.n_elem );
337
338 return out;
339 }
340
341
342
343 template<typename out_eT>
344 template<typename in_eT>
345 inline
346 Mat<out_eT>
347 conv_to< Mat<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
348 {
349 arma_extra_debug_sigprint();
350
351 arma_ignore(junk);
352
353 Mat<out_eT> out(in.length(), 1);
354
355 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
356
357 return out;
358 }
359
360
361
362 //! conversion to Armadillo row vectors from Armadillo Base objects,
363 //! as well as from std::vector, itpp::Mat and itpp::Vec
364 template<typename out_eT>
365 class conv_to< Row<out_eT> >
366 {
367 public:
368
369 template<typename in_eT, typename T1>
370 inline static Row<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
371
372 template<typename in_eT, typename T1>
373 inline static Row<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
374
375
376
377 template<typename in_eT>
378 inline static Row<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
379
380 template<typename in_eT>
381 inline static Row<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
382
383
384
385 template<typename in_eT>
386 inline static Row<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
387
388 template<typename in_eT>
389 inline static Row<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
390
391
392
393 template<typename in_eT>
394 inline static Row<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
395
396 template<typename in_eT>
397 inline static Row<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
398 };
399
400
401
402 template<typename out_eT>
403 template<typename in_eT, typename T1>
404 inline
405 Row<out_eT>
406 conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
407 {
408 arma_extra_debug_sigprint();
409
410 arma_ignore(junk);
411
412 const unwrap<T1> tmp(in.get_ref());
413 const Mat<in_eT>& X = tmp.M;
414
415 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
416
417 Row<out_eT> out(X.n_elem);
418
419 arrayops::convert( out.memptr(), X.memptr(), out.n_elem );
420
421 return out;
422 }
423
424
425
426 template<typename out_eT>
427 template<typename in_eT, typename T1>
428 inline
429 Row<out_eT>
430 conv_to< Row<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
431 {
432 arma_extra_debug_sigprint();
433
434 arma_ignore(junk);
435
436 const unwrap<T1> tmp(in.get_ref());
437 const Mat<in_eT>& X = tmp.M;
438
439 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
440
441 Row<out_eT> out(X.n_rows, X.n_cols);
442
443 arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem );
444
445 return out;
446 }
447
448
449
450 template<typename out_eT>
451 template<typename in_eT>
452 inline
453 Row<out_eT>
454 conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
455 {
456 arma_extra_debug_sigprint();
457
458 arma_ignore(junk);
459
460 Row<out_eT> out( in.size() );
461
462 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
463 typename std::vector<in_eT>::const_iterator in_end = in.end();
464
465 typename Row<out_eT>::iterator out_begin = out.begin();
466 typename Row<out_eT>::iterator out_end = out.end();
467
468 typename std::vector<in_eT>::const_iterator in_it;
469 typename Row<out_eT>::iterator out_it;
470
471 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
472 {
473 (*out_it) = out_eT(*in_it);
474 }
475
476 return out;
477 }
478
479
480
481 template<typename out_eT>
482 template<typename in_eT>
483 inline
484 Row<out_eT>
485 conv_to< Row<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
486 {
487 arma_extra_debug_sigprint();
488
489 arma_ignore(junk);
490
491 Row<out_eT> out( in.size() );
492
493 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
494 typename std::vector<in_eT>::const_iterator in_end = in.end();
495
496 typename Row<out_eT>::iterator out_begin = out.begin();
497 typename Row<out_eT>::iterator out_end = out.end();
498
499 typename std::vector<in_eT>::const_iterator in_it;
500 typename Row<out_eT>::iterator out_it;
501
502 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
503 {
504 out_eT& out_elem = (*out_it);
505 const in_eT& in_elem = (*in_it);
506
507 arrayops::convert_cx_scalar(out_elem, in_elem);
508 }
509
510 return out;
511 }
512
513
514
515 template<typename out_eT>
516 template<typename in_eT>
517 inline
518 Row<out_eT>
519 conv_to< Row<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
520 {
521 arma_extra_debug_sigprint();
522
523 arma_ignore(junk);
524
525 const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
526
527 arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" );
528
529 Row<out_eT> out(in.rows() * in.cols());
530
531 arrayops::convert( out.memptr(), in._data(), out.n_elem );
532
533 return out;
534 }
535
536
537
538 template<typename out_eT>
539 template<typename in_eT>
540 inline
541 Row<out_eT>
542 conv_to< Row<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
543 {
544 arma_extra_debug_sigprint();
545
546 arma_ignore(junk);
547
548 //const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
549
550 Row<out_eT> out(in.rows() * in.cols());
551
552 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
553
554 return out;
555 }
556
557
558
559 template<typename out_eT>
560 template<typename in_eT>
561 inline
562 Row<out_eT>
563 conv_to< Row<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
564 {
565 arma_extra_debug_sigprint();
566
567 arma_ignore(junk);
568
569 Row<out_eT> out(in.length());
570
571 arrayops::convert( out.memptr(), in._data(), out.n_elem );
572
573 return out;
574 }
575
576
577
578 template<typename out_eT>
579 template<typename in_eT>
580 inline
581 Row<out_eT>
582 conv_to< Row<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
583 {
584 arma_extra_debug_sigprint();
585
586 arma_ignore(junk);
587
588 Row<out_eT> out(in.length());
589
590 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
591
592 return out;
593 }
594
595
596
597 //! conversion to Armadillo column vectors from Armadillo Base objects,
598 //! as well as from std::vector, itpp::Mat and itpp::Vec
599 template<typename out_eT>
600 class conv_to< Col<out_eT> >
601 {
602 public:
603
604 template<typename in_eT, typename T1>
605 inline static Col<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
606
607 template<typename in_eT, typename T1>
608 inline static Col<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
609
610
611
612 template<typename in_eT>
613 inline static Col<out_eT> from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
614
615 template<typename in_eT>
616 inline static Col<out_eT> from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
617
618
619
620 template<typename in_eT>
621 inline static Col<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
622
623 template<typename in_eT>
624 inline static Col<out_eT> from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
625
626
627
628 template<typename in_eT>
629 inline static Col<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
630
631 template<typename in_eT>
632 inline static Col<out_eT> from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
633 };
634
635
636
637 template<typename out_eT>
638 template<typename in_eT, typename T1>
639 inline
640 Col<out_eT>
641 conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
642 {
643 arma_extra_debug_sigprint();
644
645 arma_ignore(junk);
646
647 const unwrap<T1> tmp(in.get_ref());
648 const Mat<in_eT>& X = tmp.M;
649
650 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
651
652 Col<out_eT> out(X.n_elem);
653
654 arrayops::convert( out.memptr(), X.memptr(), out.n_elem );
655
656 return out;
657 }
658
659
660
661 template<typename out_eT>
662 template<typename in_eT, typename T1>
663 inline
664 Col<out_eT>
665 conv_to< Col<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
666 {
667 arma_extra_debug_sigprint();
668
669 arma_ignore(junk);
670
671 const unwrap<T1> tmp(in.get_ref());
672 const Mat<in_eT>& X = tmp.M;
673
674 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
675
676 Col<out_eT> out(X.n_rows, X.n_cols);
677
678 arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem );
679
680 return out;
681 }
682
683
684
685 template<typename out_eT>
686 template<typename in_eT>
687 inline
688 Col<out_eT>
689 conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
690 {
691 arma_extra_debug_sigprint();
692
693 arma_ignore(junk);
694
695 Col<out_eT> out( in.size() );
696
697 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
698 typename std::vector<in_eT>::const_iterator in_end = in.end();
699
700 typename Col<out_eT>::iterator out_begin = out.begin();
701 typename Col<out_eT>::iterator out_end = out.end();
702
703 typename std::vector<in_eT>::const_iterator in_it;
704 typename Col<out_eT>::iterator out_it;
705
706 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
707 {
708 (*out_it) = out_eT(*in_it);
709 }
710
711 return out;
712 }
713
714
715
716 template<typename out_eT>
717 template<typename in_eT>
718 inline
719 Col<out_eT>
720 conv_to< Col<out_eT> >::from(const std::vector<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
721 {
722 arma_extra_debug_sigprint();
723
724 arma_ignore(junk);
725
726 Col<out_eT> out( in.size() );
727
728 typename std::vector<in_eT>::const_iterator in_begin = in.begin();
729 typename std::vector<in_eT>::const_iterator in_end = in.end();
730
731 typename Col<out_eT>::iterator out_begin = out.begin();
732 typename Col<out_eT>::iterator out_end = out.end();
733
734 typename std::vector<in_eT>::const_iterator in_it;
735 typename Col<out_eT>::iterator out_it;
736
737 for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it)
738 {
739 out_eT& out_elem = (*out_it);
740 const in_eT& in_elem = (*in_it);
741
742 arrayops::convert_cx_scalar(out_elem, in_elem);
743 }
744
745 return out;
746 }
747
748
749
750 template<typename out_eT>
751 template<typename in_eT>
752 inline
753 Col<out_eT>
754 conv_to< Col<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
755 {
756 arma_extra_debug_sigprint();
757
758 arma_ignore(junk);
759
760 const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
761
762 arma_debug_check( (is_vec == false), "conv_to(): given object can't be interpreted as a vector" );
763
764 Col<out_eT> out(in.rows() * in.cols());
765
766 arrayops::convert( out.memptr(), in._data(), out.n_elem );
767
768 return out;
769 }
770
771
772
773 template<typename out_eT>
774 template<typename in_eT>
775 inline
776 Col<out_eT>
777 conv_to< Col<out_eT> >::from(const itpp::Mat<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
778 {
779 arma_extra_debug_sigprint();
780
781 arma_ignore(junk);
782
783 //const bool is_vec = ( (in.rows() == 1) || (in.cols() == 1) );
784
785 Col<out_eT> out(in.rows() * in.cols());
786
787 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
788
789 return out;
790 }
791
792
793
794 template<typename out_eT>
795 template<typename in_eT>
796 inline
797 Col<out_eT>
798 conv_to< Col<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_not_cx<in_eT>::result* junk)
799 {
800 arma_extra_debug_sigprint();
801
802 arma_ignore(junk);
803
804 Col<out_eT> out( in.length() );
805
806 arrayops::convert( out.memptr(), in._data(), out.n_elem );
807
808 return out;
809 }
810
811
812
813 template<typename out_eT>
814 template<typename in_eT>
815 inline
816 Col<out_eT>
817 conv_to< Col<out_eT> >::from(const itpp::Vec<in_eT>& in, const typename arma_cx_only<in_eT>::result* junk)
818 {
819 arma_extra_debug_sigprint();
820
821 arma_ignore(junk);
822
823 Col<out_eT> out( in.length() );
824
825 arrayops::convert_cx( out.memptr(), in._data(), out.n_elem );
826
827 return out;
828 }
829
830
831
832 //! conversion to Armadillo cubes from Armadillo BaseCube objects
833 template<typename out_eT>
834 class conv_to< Cube<out_eT> >
835 {
836 public:
837
838 template<typename in_eT, typename T1>
839 inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
840
841 template<typename in_eT, typename T1>
842 inline static Cube<out_eT> from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
843 };
844
845
846
847 template<typename out_eT>
848 template<typename in_eT, typename T1>
849 inline
850 Cube<out_eT>
851 conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
852 {
853 arma_extra_debug_sigprint();
854
855 arma_ignore(junk);
856
857 const unwrap_cube<T1> tmp( in.get_ref() );
858 const Cube<in_eT>& X = tmp.M;
859
860 Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices);
861
862 arrayops::convert( out.memptr(), X.memptr(), out.n_elem );
863
864 return out;
865 }
866
867
868
869 template<typename out_eT>
870 template<typename in_eT, typename T1>
871 inline
872 Cube<out_eT>
873 conv_to< Cube<out_eT> >::from(const BaseCube<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
874 {
875 arma_extra_debug_sigprint();
876
877 arma_ignore(junk);
878
879 const unwrap_cube<T1> tmp( in.get_ref() );
880 const Cube<in_eT>& X = tmp.M;
881
882 Cube<out_eT> out(X.n_rows, X.n_cols, X.n_slices);
883
884 arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem );
885
886 return out;
887 }
888
889
890
891 //! conversion to std::vector from Armadillo Base objects
892 template<typename out_eT>
893 class conv_to< std::vector<out_eT> >
894 {
895 public:
896
897 template<typename in_eT, typename T1>
898 inline static std::vector<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
899
900 template<typename in_eT, typename T1>
901 inline static std::vector<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
902 };
903
904
905
906 template<typename out_eT>
907 template<typename in_eT, typename T1>
908 inline
909 std::vector<out_eT>
910 conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
911 {
912 arma_extra_debug_sigprint();
913
914 arma_ignore(junk);
915
916 const unwrap<T1> tmp(in.get_ref());
917 const Mat<in_eT>& X = tmp.M;
918
919 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
920
921 std::vector<out_eT> out(X.n_elem);
922
923 typename Mat<in_eT>::const_iterator X_begin = X.begin();
924 typename Mat<in_eT>::const_iterator X_end = X.end();
925
926 typename std::vector<out_eT>::iterator out_begin = out.begin();
927 typename std::vector<out_eT>::iterator out_end = out.end();
928
929 typename Mat<in_eT>::const_iterator X_it;
930 typename std::vector<out_eT>::iterator out_it;
931
932 for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it)
933 {
934 (*out_it) = out_eT(*X_it);
935 }
936
937 return out;
938 }
939
940
941
942 template<typename out_eT>
943 template<typename in_eT, typename T1>
944 inline
945 std::vector<out_eT>
946 conv_to< std::vector<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
947 {
948 arma_extra_debug_sigprint();
949
950 arma_ignore(junk);
951
952 const unwrap<T1> tmp(in.get_ref());
953 const Mat<in_eT>& X = tmp.M;
954
955 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
956
957 std::vector<out_eT> out(X.n_elem);
958
959 typename Mat<in_eT>::const_iterator X_begin = X.begin();
960 typename Mat<in_eT>::const_iterator X_end = X.end();
961
962 typename std::vector<out_eT>::iterator out_begin = out.begin();
963 typename std::vector<out_eT>::iterator out_end = out.end();
964
965 typename Mat<in_eT>::const_iterator X_it;
966 typename std::vector<out_eT>::iterator out_it;
967
968 for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it)
969 {
970 out_eT& out_elem = (*out_it);
971 const in_eT& X_elem = (*X_it);
972
973 arrayops::convert_cx_scalar(out_elem, X_elem);
974 }
975
976 return out;
977 }
978
979
980
981 //! conversion to itpp::Mat from Armadillo Base objects
982 template<typename out_eT>
983 class conv_to< itpp::Mat<out_eT> >
984 {
985 public:
986
987 template<typename in_eT, typename T1>
988 inline static itpp::Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
989
990 template<typename in_eT, typename T1>
991 inline static itpp::Mat<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
992 };
993
994
995
996 template<typename out_eT>
997 template<typename in_eT, typename T1>
998 inline
999 itpp::Mat<out_eT>
1000 conv_to< itpp::Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
1001 {
1002 arma_extra_debug_sigprint();
1003
1004 arma_ignore(junk);
1005
1006 const unwrap<T1> tmp( in.get_ref() );
1007 const Mat<in_eT>& X = tmp.M;
1008
1009 itpp::Mat<out_eT> out(X.n_rows, X.n_cols);
1010
1011 arrayops::convert( out._data(), X.memptr(), X.n_elem );
1012
1013 return out;
1014 }
1015
1016
1017
1018 template<typename out_eT>
1019 template<typename in_eT, typename T1>
1020 inline
1021 itpp::Mat<out_eT>
1022 conv_to< itpp::Mat<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
1023 {
1024 arma_extra_debug_sigprint();
1025
1026 arma_ignore(junk);
1027
1028 const unwrap<T1> tmp( in.get_ref() );
1029 const Mat<in_eT>& X = tmp.M;
1030
1031 itpp::Mat<out_eT> out(X.n_rows, X.n_cols);
1032
1033 arrayops::convert_cx( out._data(), X.memptr(), X.n_elem );
1034
1035 return out;
1036 }
1037
1038
1039
1040
1041 //! conversion to itpp::Vec from Armadillo Base objects
1042 template<typename out_eT>
1043 class conv_to< itpp::Vec<out_eT> >
1044 {
1045 public:
1046
1047 template<typename in_eT, typename T1>
1048 inline static itpp::Vec<out_eT> from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk = 0);
1049
1050 template<typename in_eT, typename T1>
1051 inline static itpp::Vec<out_eT> from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk = 0);
1052 };
1053
1054
1055
1056 template<typename out_eT>
1057 template<typename in_eT, typename T1>
1058 inline
1059 itpp::Vec<out_eT>
1060 conv_to< itpp::Vec<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_not_cx<in_eT>::result* junk)
1061 {
1062 arma_extra_debug_sigprint();
1063
1064 arma_ignore(junk);
1065
1066 const unwrap<T1> tmp( in.get_ref() );
1067 const Mat<in_eT>& X = tmp.M;
1068
1069 arma_debug_check( (X.is_vec() == false), "conv_to(): given object can't be interpreted as a vector" );
1070
1071 itpp::Vec<out_eT> out(X.n_elem);
1072
1073 arrayops::convert( out._data(), X.memptr(), X.n_elem );
1074
1075 return out;
1076 }
1077
1078
1079
1080 template<typename out_eT>
1081 template<typename in_eT, typename T1>
1082 inline
1083 itpp::Vec<out_eT>
1084 conv_to< itpp::Vec<out_eT> >::from(const Base<in_eT, T1>& in, const typename arma_cx_only<in_eT>::result* junk)
1085 {
1086 arma_extra_debug_sigprint();
1087
1088 arma_ignore(junk);
1089
1090 const unwrap<T1> tmp( in.get_ref() );
1091 const Mat<in_eT>& X = tmp.M;
1092
1093 itpp::Vec<out_eT> out(X.n_elem);
1094
1095 arrayops::convert_cx( out._data(), X.memptr(), X.n_elem );
1096
1097 return out;
1098 }
1099
1100
1101
1102 //! @}