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