Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/field_meat.hpp @ 49:1ec0e2823891
Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author | Chris Cannam |
---|---|
date | Thu, 13 Jun 2013 10:25:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:69251e11a913 | 49:1ec0e2823891 |
---|---|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2008-2013 Conrad Sanderson | |
3 // Copyright (C) 2009-2010 Ian Cullinan | |
4 // | |
5 // This Source Code Form is subject to the terms of the Mozilla Public | |
6 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
8 | |
9 | |
10 //! \addtogroup field | |
11 //! @{ | |
12 | |
13 | |
14 template<typename oT> | |
15 inline | |
16 field<oT>::~field() | |
17 { | |
18 arma_extra_debug_sigprint_this(this); | |
19 | |
20 delete_objects(); | |
21 | |
22 if(n_elem > sizeof(mem_local)/sizeof(oT*) ) | |
23 { | |
24 delete [] mem; | |
25 } | |
26 | |
27 if(arma_config::debug == true) | |
28 { | |
29 // try to expose buggy user code that accesses deleted objects | |
30 access::rw(n_rows) = 0; | |
31 access::rw(n_cols) = 0; | |
32 access::rw(n_elem) = 0; | |
33 mem = 0; | |
34 } | |
35 } | |
36 | |
37 | |
38 | |
39 template<typename oT> | |
40 inline | |
41 field<oT>::field() | |
42 : n_rows(0) | |
43 , n_cols(0) | |
44 , n_elem(0) | |
45 , mem(0) | |
46 { | |
47 arma_extra_debug_sigprint_this(this); | |
48 } | |
49 | |
50 | |
51 | |
52 //! construct a field from a given field | |
53 template<typename oT> | |
54 inline | |
55 field<oT>::field(const field& x) | |
56 : n_rows(0) | |
57 , n_cols(0) | |
58 , n_elem(0) | |
59 , mem(0) | |
60 { | |
61 arma_extra_debug_sigprint(arma_boost::format("this = %x x = %x") % this % &x); | |
62 | |
63 init(x); | |
64 } | |
65 | |
66 | |
67 | |
68 //! construct a field from a given field | |
69 template<typename oT> | |
70 inline | |
71 const field<oT>& | |
72 field<oT>::operator=(const field& x) | |
73 { | |
74 arma_extra_debug_sigprint(); | |
75 | |
76 init(x); | |
77 return *this; | |
78 } | |
79 | |
80 | |
81 | |
82 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) | |
83 template<typename oT> | |
84 inline | |
85 field<oT>::field(const subview_field<oT>& X) | |
86 : n_rows(0) | |
87 , n_cols(0) | |
88 , n_elem(0) | |
89 , mem(0) | |
90 { | |
91 arma_extra_debug_sigprint_this(this); | |
92 | |
93 this->operator=(X); | |
94 } | |
95 | |
96 | |
97 | |
98 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) | |
99 template<typename oT> | |
100 inline | |
101 const field<oT>& | |
102 field<oT>::operator=(const subview_field<oT>& X) | |
103 { | |
104 arma_extra_debug_sigprint(); | |
105 | |
106 subview_field<oT>::extract(*this, X); | |
107 return *this; | |
108 } | |
109 | |
110 | |
111 | |
112 //! construct the field with the specified number of elements, | |
113 //! assuming a column-major layout | |
114 template<typename oT> | |
115 inline | |
116 field<oT>::field(const uword n_elem_in) | |
117 : n_rows(0) | |
118 , n_cols(0) | |
119 , n_elem(0) | |
120 , mem(0) | |
121 { | |
122 arma_extra_debug_sigprint_this(this); | |
123 | |
124 init(n_elem_in, 1); | |
125 } | |
126 | |
127 | |
128 | |
129 //! construct the field with the specified dimensions | |
130 template<typename oT> | |
131 inline | |
132 field<oT>::field(const uword n_rows_in, const uword n_cols_in) | |
133 : n_rows(0) | |
134 , n_cols(0) | |
135 , n_elem(0) | |
136 , mem(0) | |
137 { | |
138 arma_extra_debug_sigprint_this(this); | |
139 | |
140 init(n_rows_in, n_cols_in); | |
141 } | |
142 | |
143 | |
144 | |
145 //! change the field to have the specified number of elements, | |
146 //! assuming a column-major layout (data is not preserved) | |
147 template<typename oT> | |
148 inline | |
149 void | |
150 field<oT>::set_size(const uword n_elem_in) | |
151 { | |
152 arma_extra_debug_sigprint(arma_boost::format("n_elem_in = %d") % n_elem_in); | |
153 | |
154 init(n_elem_in, 1); | |
155 } | |
156 | |
157 | |
158 | |
159 //! change the field to have the specified dimensions (data is not preserved) | |
160 template<typename oT> | |
161 inline | |
162 void | |
163 field<oT>::set_size(const uword n_rows_in, const uword n_cols_in) | |
164 { | |
165 arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in); | |
166 | |
167 init(n_rows_in, n_cols_in); | |
168 } | |
169 | |
170 | |
171 | |
172 //! change the field to have the specified dimensions (data is not preserved) | |
173 template<typename oT> | |
174 template<typename oT2> | |
175 inline | |
176 void | |
177 field<oT>::copy_size(const field<oT2>& x) | |
178 { | |
179 arma_extra_debug_sigprint(); | |
180 | |
181 init(x.n_rows, x.n_cols); | |
182 } | |
183 | |
184 | |
185 | |
186 //! linear element accessor (treats the field as a vector); no bounds check | |
187 template<typename oT> | |
188 arma_inline | |
189 oT& | |
190 field<oT>::operator[] (const uword i) | |
191 { | |
192 return (*mem[i]); | |
193 } | |
194 | |
195 | |
196 | |
197 //! linear element accessor (treats the field as a vector); no bounds check | |
198 template<typename oT> | |
199 arma_inline | |
200 const oT& | |
201 field<oT>::operator[] (const uword i) const | |
202 { | |
203 return (*mem[i]); | |
204 } | |
205 | |
206 | |
207 | |
208 //! linear element accessor (treats the field as a vector); no bounds check | |
209 template<typename oT> | |
210 arma_inline | |
211 oT& | |
212 field<oT>::at(const uword i) | |
213 { | |
214 return (*mem[i]); | |
215 } | |
216 | |
217 | |
218 | |
219 //! linear element accessor (treats the field as a vector); no bounds check | |
220 template<typename oT> | |
221 arma_inline | |
222 const oT& | |
223 field<oT>::at(const uword i) const | |
224 { | |
225 return (*mem[i]); | |
226 } | |
227 | |
228 | |
229 | |
230 //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined | |
231 template<typename oT> | |
232 arma_inline | |
233 oT& | |
234 field<oT>::operator() (const uword i) | |
235 { | |
236 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); | |
237 return (*mem[i]); | |
238 } | |
239 | |
240 | |
241 | |
242 //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined | |
243 template<typename oT> | |
244 arma_inline | |
245 const oT& | |
246 field<oT>::operator() (const uword i) const | |
247 { | |
248 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); | |
249 return (*mem[i]); | |
250 } | |
251 | |
252 | |
253 | |
254 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined | |
255 template<typename oT> | |
256 arma_inline | |
257 oT& | |
258 field<oT>::operator() (const uword in_row, const uword in_col) | |
259 { | |
260 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); | |
261 return (*mem[in_row + in_col*n_rows]); | |
262 } | |
263 | |
264 | |
265 | |
266 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined | |
267 template<typename oT> | |
268 arma_inline | |
269 const oT& | |
270 field<oT>::operator() (const uword in_row, const uword in_col) const | |
271 { | |
272 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); | |
273 return (*mem[in_row + in_col*n_rows]); | |
274 } | |
275 | |
276 | |
277 | |
278 //! element accessor; no bounds check | |
279 template<typename oT> | |
280 arma_inline | |
281 oT& | |
282 field<oT>::at(const uword in_row, const uword in_col) | |
283 { | |
284 return (*mem[in_row + in_col*n_rows]); | |
285 } | |
286 | |
287 | |
288 | |
289 //! element accessor; no bounds check | |
290 template<typename oT> | |
291 arma_inline | |
292 const oT& | |
293 field<oT>::at(const uword in_row, const uword in_col) const | |
294 { | |
295 return (*mem[in_row + in_col*n_rows]); | |
296 } | |
297 | |
298 | |
299 | |
300 template<typename oT> | |
301 inline | |
302 field_injector< field<oT> > | |
303 field<oT>::operator<<(const oT& val) | |
304 { | |
305 return field_injector< field<oT> >(*this, val); | |
306 } | |
307 | |
308 | |
309 | |
310 template<typename oT> | |
311 inline | |
312 field_injector< field<oT> > | |
313 field<oT>::operator<<(const injector_end_of_row<>& x) | |
314 { | |
315 return field_injector< field<oT> >(*this, x); | |
316 } | |
317 | |
318 | |
319 | |
320 //! creation of subview_field (row of a field) | |
321 template<typename oT> | |
322 inline | |
323 subview_field<oT> | |
324 field<oT>::row(const uword row_num) | |
325 { | |
326 arma_extra_debug_sigprint(); | |
327 | |
328 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); | |
329 | |
330 return subview_field<oT>(*this, row_num, 0, 1, n_cols); | |
331 } | |
332 | |
333 | |
334 | |
335 //! creation of subview_field (row of a field) | |
336 template<typename oT> | |
337 inline | |
338 const subview_field<oT> | |
339 field<oT>::row(const uword row_num) const | |
340 { | |
341 arma_extra_debug_sigprint(); | |
342 | |
343 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); | |
344 | |
345 return subview_field<oT>(*this, row_num, 0, 1, n_cols); | |
346 } | |
347 | |
348 | |
349 | |
350 //! creation of subview_field (column of a field) | |
351 template<typename oT> | |
352 inline | |
353 subview_field<oT> | |
354 field<oT>::col(const uword col_num) | |
355 { | |
356 arma_extra_debug_sigprint(); | |
357 | |
358 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | |
359 | |
360 return subview_field<oT>(*this, 0, col_num, n_rows, 1); | |
361 } | |
362 | |
363 | |
364 | |
365 //! creation of subview_field (column of a field) | |
366 template<typename oT> | |
367 inline | |
368 const subview_field<oT> | |
369 field<oT>::col(const uword col_num) const | |
370 { | |
371 arma_extra_debug_sigprint(); | |
372 | |
373 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); | |
374 | |
375 return subview_field<oT>(*this, 0, col_num, n_rows, 1); | |
376 } | |
377 | |
378 | |
379 | |
380 //! creation of subview_field (subfield comprised of specified rows) | |
381 template<typename oT> | |
382 inline | |
383 subview_field<oT> | |
384 field<oT>::rows(const uword in_row1, const uword in_row2) | |
385 { | |
386 arma_extra_debug_sigprint(); | |
387 | |
388 arma_debug_check | |
389 ( | |
390 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | |
391 "field::rows(): indicies out of bounds or incorrectly used" | |
392 ); | |
393 | |
394 const uword sub_n_rows = in_row2 - in_row1 + 1; | |
395 | |
396 return subview_field<oT>(*this, in_row1, 0, sub_n_rows, n_cols); | |
397 } | |
398 | |
399 | |
400 | |
401 //! creation of subview_field (subfield comprised of specified rows) | |
402 template<typename oT> | |
403 inline | |
404 const subview_field<oT> | |
405 field<oT>::rows(const uword in_row1, const uword in_row2) const | |
406 { | |
407 arma_extra_debug_sigprint(); | |
408 | |
409 arma_debug_check | |
410 ( | |
411 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), | |
412 "field::rows(): indicies out of bounds or incorrectly used" | |
413 ); | |
414 | |
415 const uword sub_n_rows = in_row2 - in_row1 + 1; | |
416 | |
417 return subview_field<oT>(*this, in_row1, 0, sub_n_rows, n_cols); | |
418 } | |
419 | |
420 | |
421 | |
422 //! creation of subview_field (subfield comprised of specified columns) | |
423 template<typename oT> | |
424 inline | |
425 subview_field<oT> | |
426 field<oT>::cols(const uword in_col1, const uword in_col2) | |
427 { | |
428 arma_extra_debug_sigprint(); | |
429 | |
430 arma_debug_check | |
431 ( | |
432 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | |
433 "field::cols(): indicies out of bounds or incorrectly used" | |
434 ); | |
435 | |
436 const uword sub_n_cols = in_col2 - in_col1 + 1; | |
437 | |
438 return subview_field<oT>(*this, 0, in_col1, n_rows, sub_n_cols); | |
439 } | |
440 | |
441 | |
442 | |
443 //! creation of subview_field (subfield comprised of specified columns) | |
444 template<typename oT> | |
445 inline | |
446 const subview_field<oT> | |
447 field<oT>::cols(const uword in_col1, const uword in_col2) const | |
448 { | |
449 arma_extra_debug_sigprint(); | |
450 | |
451 arma_debug_check | |
452 ( | |
453 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), | |
454 "field::cols(): indicies out of bounds or incorrectly used" | |
455 ); | |
456 | |
457 const uword sub_n_cols = in_col2 - in_col1 + 1; | |
458 | |
459 return subview_field<oT>(*this, 0, in_col1, n_rows, sub_n_cols); | |
460 } | |
461 | |
462 | |
463 | |
464 //! creation of subview_field (subfield with arbitrary dimensions) | |
465 template<typename oT> | |
466 inline | |
467 subview_field<oT> | |
468 field<oT>::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) | |
469 { | |
470 arma_extra_debug_sigprint(); | |
471 | |
472 arma_debug_check | |
473 ( | |
474 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), | |
475 "field::subfield(): indices out of bounds or incorrectly used" | |
476 ); | |
477 | |
478 const uword sub_n_rows = in_row2 - in_row1 + 1; | |
479 const uword sub_n_cols = in_col2 - in_col1 + 1; | |
480 | |
481 return subview_field<oT>(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); | |
482 } | |
483 | |
484 | |
485 | |
486 //! creation of subview_field (subfield with arbitrary dimensions) | |
487 template<typename oT> | |
488 inline | |
489 const subview_field<oT> | |
490 field<oT>::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const | |
491 { | |
492 arma_extra_debug_sigprint(); | |
493 | |
494 arma_debug_check | |
495 ( | |
496 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), | |
497 "field::subfield(): indices out of bounds or incorrectly used" | |
498 ); | |
499 | |
500 const uword sub_n_rows = in_row2 - in_row1 + 1; | |
501 const uword sub_n_cols = in_col2 - in_col1 + 1; | |
502 | |
503 return subview_field<oT>(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); | |
504 } | |
505 | |
506 | |
507 | |
508 //! creation of subview_field (subfield with arbitrary dimensions) | |
509 template<typename oT> | |
510 inline | |
511 subview_field<oT> | |
512 field<oT>::subfield(const span& row_span, const span& col_span) | |
513 { | |
514 arma_extra_debug_sigprint(); | |
515 | |
516 const bool row_all = row_span.whole; | |
517 const bool col_all = col_span.whole; | |
518 | |
519 const uword local_n_rows = n_rows; | |
520 const uword local_n_cols = n_cols; | |
521 | |
522 const uword in_row1 = row_all ? 0 : row_span.a; | |
523 const uword in_row2 = row_span.b; | |
524 const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
525 | |
526 const uword in_col1 = col_all ? 0 : col_span.a; | |
527 const uword in_col2 = col_span.b; | |
528 const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
529 | |
530 arma_debug_check | |
531 ( | |
532 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) | |
533 || | |
534 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) | |
535 , | |
536 "field::subfield(): indices out of bounds or incorrectly used" | |
537 ); | |
538 | |
539 return subview_field<oT>(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); | |
540 } | |
541 | |
542 | |
543 | |
544 //! creation of subview_field (subfield with arbitrary dimensions) | |
545 template<typename oT> | |
546 inline | |
547 const subview_field<oT> | |
548 field<oT>::subfield(const span& row_span, const span& col_span) const | |
549 { | |
550 arma_extra_debug_sigprint(); | |
551 | |
552 const bool row_all = row_span.whole; | |
553 const bool col_all = col_span.whole; | |
554 | |
555 const uword local_n_rows = n_rows; | |
556 const uword local_n_cols = n_cols; | |
557 | |
558 const uword in_row1 = row_all ? 0 : row_span.a; | |
559 const uword in_row2 = row_span.b; | |
560 const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; | |
561 | |
562 const uword in_col1 = col_all ? 0 : col_span.a; | |
563 const uword in_col2 = col_span.b; | |
564 const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; | |
565 | |
566 arma_debug_check | |
567 ( | |
568 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) | |
569 || | |
570 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) | |
571 , | |
572 "field::subfield(): indices out of bounds or incorrectly used" | |
573 ); | |
574 | |
575 return subview_field<oT>(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); | |
576 } | |
577 | |
578 | |
579 | |
580 template<typename oT> | |
581 inline | |
582 subview_field<oT> | |
583 field<oT>::operator()(const span& row_span, const span& col_span) | |
584 { | |
585 arma_extra_debug_sigprint(); | |
586 | |
587 return (*this).subfield(row_span, col_span); | |
588 } | |
589 | |
590 | |
591 | |
592 template<typename oT> | |
593 inline | |
594 const subview_field<oT> | |
595 field<oT>::operator()(const span& row_span, const span& col_span) const | |
596 { | |
597 arma_extra_debug_sigprint(); | |
598 | |
599 return (*this).subfield(row_span, col_span); | |
600 } | |
601 | |
602 | |
603 | |
604 //! print contents of the field (to the cout stream), | |
605 //! optionally preceding with a user specified line of text. | |
606 //! the field class preserves the stream's flags | |
607 //! but the associated operator<< function for type oT | |
608 //! may still modify the stream's parameters. | |
609 //! NOTE: this function assumes that type oT can be printed, | |
610 //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | |
611 //! has been defined. | |
612 | |
613 template<typename oT> | |
614 inline | |
615 void | |
616 field<oT>::print(const std::string extra_text) const | |
617 { | |
618 arma_extra_debug_sigprint(); | |
619 | |
620 if(extra_text.length() != 0) | |
621 { | |
622 const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); | |
623 | |
624 ARMA_DEFAULT_OSTREAM << extra_text << '\n'; | |
625 | |
626 ARMA_DEFAULT_OSTREAM.width(orig_width); | |
627 } | |
628 | |
629 arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this); | |
630 } | |
631 | |
632 | |
633 | |
634 //! print contents of the field to a user specified stream, | |
635 //! optionally preceding with a user specified line of text. | |
636 //! the field class preserves the stream's flags | |
637 //! but the associated operator<< function for type oT | |
638 //! may still modify the stream's parameters. | |
639 //! NOTE: this function assumes that type oT can be printed, | |
640 //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" | |
641 //! has been defined. | |
642 | |
643 template<typename oT> | |
644 inline | |
645 void | |
646 field<oT>::print(std::ostream& user_stream, const std::string extra_text) const | |
647 { | |
648 arma_extra_debug_sigprint(); | |
649 | |
650 if(extra_text.length() != 0) | |
651 { | |
652 const std::streamsize orig_width = user_stream.width(); | |
653 | |
654 user_stream << extra_text << '\n'; | |
655 | |
656 user_stream.width(orig_width); | |
657 } | |
658 | |
659 arma_ostream::print(user_stream, *this); | |
660 } | |
661 | |
662 | |
663 | |
664 //! fill the field with an object | |
665 template<typename oT> | |
666 inline | |
667 void | |
668 field<oT>::fill(const oT& x) | |
669 { | |
670 arma_extra_debug_sigprint(); | |
671 | |
672 field<oT>& t = *this; | |
673 | |
674 for(uword i=0; i<n_elem; ++i) | |
675 { | |
676 t[i] = x; | |
677 } | |
678 } | |
679 | |
680 | |
681 | |
682 //! reset the field to an empty state (i.e. the field will have no objects) | |
683 template<typename oT> | |
684 inline | |
685 void | |
686 field<oT>::reset() | |
687 { | |
688 arma_extra_debug_sigprint(); | |
689 | |
690 init(0,0); | |
691 } | |
692 | |
693 | |
694 | |
695 //! reset each object | |
696 template<typename oT> | |
697 inline | |
698 void | |
699 field<oT>::reset_objects() | |
700 { | |
701 arma_extra_debug_sigprint(); | |
702 | |
703 field_aux::reset_objects(*this); | |
704 } | |
705 | |
706 | |
707 | |
708 //! returns true if the field has no objects | |
709 template<typename oT> | |
710 arma_inline | |
711 bool | |
712 field<oT>::is_empty() const | |
713 { | |
714 return (n_elem == 0); | |
715 } | |
716 | |
717 | |
718 | |
719 //! returns true if the given index is currently in range | |
720 template<typename oT> | |
721 arma_inline | |
722 arma_warn_unused | |
723 bool | |
724 field<oT>::in_range(const uword i) const | |
725 { | |
726 return (i < n_elem); | |
727 } | |
728 | |
729 | |
730 | |
731 //! returns true if the given start and end indices are currently in range | |
732 template<typename oT> | |
733 arma_inline | |
734 arma_warn_unused | |
735 bool | |
736 field<oT>::in_range(const span& x) const | |
737 { | |
738 arma_extra_debug_sigprint(); | |
739 | |
740 if(x.whole == true) | |
741 { | |
742 return true; | |
743 } | |
744 else | |
745 { | |
746 const uword a = x.a; | |
747 const uword b = x.b; | |
748 | |
749 return ( (a <= b) && (b < n_elem) ); | |
750 } | |
751 } | |
752 | |
753 | |
754 | |
755 //! returns true if the given location is currently in range | |
756 template<typename oT> | |
757 arma_inline | |
758 arma_warn_unused | |
759 bool | |
760 field<oT>::in_range(const uword in_row, const uword in_col) const | |
761 { | |
762 return ( (in_row < n_rows) && (in_col < n_cols) ); | |
763 } | |
764 | |
765 | |
766 | |
767 template<typename oT> | |
768 arma_inline | |
769 arma_warn_unused | |
770 bool | |
771 field<oT>::in_range(const span& row_span, const uword in_col) const | |
772 { | |
773 arma_extra_debug_sigprint(); | |
774 | |
775 if(row_span.whole == true) | |
776 { | |
777 return (in_col < n_cols); | |
778 } | |
779 else | |
780 { | |
781 const uword in_row1 = row_span.a; | |
782 const uword in_row2 = row_span.b; | |
783 | |
784 return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); | |
785 } | |
786 } | |
787 | |
788 | |
789 | |
790 template<typename oT> | |
791 arma_inline | |
792 arma_warn_unused | |
793 bool | |
794 field<oT>::in_range(const uword in_row, const span& col_span) const | |
795 { | |
796 arma_extra_debug_sigprint(); | |
797 | |
798 if(col_span.whole == true) | |
799 { | |
800 return (in_row < n_rows); | |
801 } | |
802 else | |
803 { | |
804 const uword in_col1 = col_span.a; | |
805 const uword in_col2 = col_span.b; | |
806 | |
807 return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); | |
808 } | |
809 } | |
810 | |
811 | |
812 | |
813 template<typename oT> | |
814 arma_inline | |
815 arma_warn_unused | |
816 bool | |
817 field<oT>::in_range(const span& row_span, const span& col_span) const | |
818 { | |
819 arma_extra_debug_sigprint(); | |
820 | |
821 const uword in_row1 = row_span.a; | |
822 const uword in_row2 = row_span.b; | |
823 | |
824 const uword in_col1 = col_span.a; | |
825 const uword in_col2 = col_span.b; | |
826 | |
827 const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); | |
828 const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); | |
829 | |
830 return ( (rows_ok == true) && (cols_ok == true) ); | |
831 } | |
832 | |
833 | |
834 | |
835 template<typename oT> | |
836 inline | |
837 bool | |
838 field<oT>::save(const std::string name, const file_type type, const bool print_status) const | |
839 { | |
840 arma_extra_debug_sigprint(); | |
841 | |
842 std::string err_msg; | |
843 const bool save_okay = field_aux::save(*this, name, type, err_msg); | |
844 | |
845 if( (print_status == true) && (save_okay == false) ) | |
846 { | |
847 if(err_msg.length() > 0) | |
848 { | |
849 arma_warn(true, "field::save(): ", err_msg, name); | |
850 } | |
851 else | |
852 { | |
853 arma_warn(true, "field::save(): couldn't write to ", name); | |
854 } | |
855 } | |
856 | |
857 return save_okay; | |
858 } | |
859 | |
860 | |
861 | |
862 template<typename oT> | |
863 inline | |
864 bool | |
865 field<oT>::save(std::ostream& os, const file_type type, const bool print_status) const | |
866 { | |
867 arma_extra_debug_sigprint(); | |
868 | |
869 std::string err_msg; | |
870 const bool save_okay = field_aux::save(*this, os, type, err_msg); | |
871 | |
872 if( (print_status == true) && (save_okay == false) ) | |
873 { | |
874 if(err_msg.length() > 0) | |
875 { | |
876 arma_warn(true, "field::save(): ", err_msg, "[ostream]"); | |
877 } | |
878 else | |
879 { | |
880 arma_warn(true, "field::save(): couldn't write to [ostream]"); | |
881 } | |
882 } | |
883 | |
884 return save_okay; | |
885 } | |
886 | |
887 | |
888 | |
889 template<typename oT> | |
890 inline | |
891 bool | |
892 field<oT>::load(const std::string name, const file_type type, const bool print_status) | |
893 { | |
894 arma_extra_debug_sigprint(); | |
895 | |
896 std::string err_msg; | |
897 const bool load_okay = field_aux::load(*this, name, type, err_msg); | |
898 | |
899 if( (print_status == true) && (load_okay == false) ) | |
900 { | |
901 if(err_msg.length() > 0) | |
902 { | |
903 arma_warn(true, "field::load(): ", err_msg, name); | |
904 } | |
905 else | |
906 { | |
907 arma_warn(true, "field::load(): couldn't read from ", name); | |
908 } | |
909 } | |
910 | |
911 if(load_okay == false) | |
912 { | |
913 (*this).reset(); | |
914 } | |
915 | |
916 return load_okay; | |
917 } | |
918 | |
919 | |
920 | |
921 template<typename oT> | |
922 inline | |
923 bool | |
924 field<oT>::load(std::istream& is, const file_type type, const bool print_status) | |
925 { | |
926 arma_extra_debug_sigprint(); | |
927 | |
928 std::string err_msg; | |
929 const bool load_okay = field_aux::load(*this, is, type, err_msg); | |
930 | |
931 if( (print_status == true) && (load_okay == false) ) | |
932 { | |
933 if(err_msg.length() > 0) | |
934 { | |
935 arma_warn(true, "field::load(): ", err_msg, "[istream]"); | |
936 } | |
937 else | |
938 { | |
939 arma_warn(true, "field::load(): couldn't read from [istream]"); | |
940 } | |
941 } | |
942 | |
943 if(load_okay == false) | |
944 { | |
945 (*this).reset(); | |
946 } | |
947 | |
948 return load_okay; | |
949 } | |
950 | |
951 | |
952 | |
953 template<typename oT> | |
954 inline | |
955 bool | |
956 field<oT>::quiet_save(const std::string name, const file_type type) const | |
957 { | |
958 arma_extra_debug_sigprint(); | |
959 | |
960 return (*this).save(name, type, false); | |
961 } | |
962 | |
963 | |
964 | |
965 template<typename oT> | |
966 inline | |
967 bool | |
968 field<oT>::quiet_save(std::ostream& os, const file_type type) const | |
969 { | |
970 arma_extra_debug_sigprint(); | |
971 | |
972 return (*this).save(os, type, false); | |
973 } | |
974 | |
975 | |
976 | |
977 template<typename oT> | |
978 inline | |
979 bool | |
980 field<oT>::quiet_load(const std::string name, const file_type type) | |
981 { | |
982 arma_extra_debug_sigprint(); | |
983 | |
984 return (*this).load(name, type, false); | |
985 } | |
986 | |
987 | |
988 | |
989 template<typename oT> | |
990 inline | |
991 bool | |
992 field<oT>::quiet_load(std::istream& is, const file_type type) | |
993 { | |
994 arma_extra_debug_sigprint(); | |
995 | |
996 return (*this).load(is, type, false); | |
997 } | |
998 | |
999 | |
1000 | |
1001 //! construct a field from a given field | |
1002 template<typename oT> | |
1003 inline | |
1004 void | |
1005 field<oT>::init(const field<oT>& x) | |
1006 { | |
1007 arma_extra_debug_sigprint(); | |
1008 | |
1009 if(this != &x) | |
1010 { | |
1011 const uword x_n_rows = x.n_rows; | |
1012 const uword x_n_cols = x.n_cols; | |
1013 | |
1014 init(x_n_rows, x_n_cols); | |
1015 | |
1016 field& t = *this; | |
1017 | |
1018 for(uword ucol=0; ucol < x_n_cols; ++ucol) | |
1019 for(uword urow=0; urow < x_n_rows; ++urow) | |
1020 { | |
1021 t.at(urow,ucol) = x.at(urow,ucol); | |
1022 } | |
1023 } | |
1024 | |
1025 } | |
1026 | |
1027 | |
1028 | |
1029 //! internal field construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new' | |
1030 template<typename oT> | |
1031 inline | |
1032 void | |
1033 field<oT>::init(const uword n_rows_in, const uword n_cols_in) | |
1034 { | |
1035 arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in ); | |
1036 | |
1037 arma_debug_check | |
1038 ( | |
1039 ( | |
1040 ( (n_rows_in > ARMA_MAX_UHWORD) || (n_cols_in > ARMA_MAX_UHWORD) ) | |
1041 ? ( (float(n_rows_in) * float(n_cols_in)) > float(ARMA_MAX_UWORD) ) | |
1042 : false | |
1043 ), | |
1044 "field::init(): requested size is too large" | |
1045 ); | |
1046 | |
1047 const uword n_elem_new = n_rows_in * n_cols_in; | |
1048 | |
1049 if(n_elem == n_elem_new) | |
1050 { | |
1051 // delete_objects(); | |
1052 // create_objects(); | |
1053 access::rw(n_rows) = n_rows_in; | |
1054 access::rw(n_cols) = n_cols_in; | |
1055 } | |
1056 else | |
1057 { | |
1058 delete_objects(); | |
1059 | |
1060 if(n_elem > sizeof(mem_local)/sizeof(oT*) ) | |
1061 { | |
1062 delete [] mem; | |
1063 } | |
1064 | |
1065 if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) ) | |
1066 { | |
1067 mem = mem_local; | |
1068 } | |
1069 else | |
1070 { | |
1071 mem = new(std::nothrow) oT* [n_elem_new]; | |
1072 arma_check_bad_alloc( (mem == 0), "field::init(): out of memory" ); | |
1073 } | |
1074 | |
1075 access::rw(n_elem) = n_elem_new; | |
1076 | |
1077 if(n_elem_new == 0) | |
1078 { | |
1079 access::rw(n_rows) = 0; | |
1080 access::rw(n_cols) = 0; | |
1081 } | |
1082 else | |
1083 { | |
1084 access::rw(n_rows) = n_rows_in; | |
1085 access::rw(n_cols) = n_cols_in; | |
1086 } | |
1087 | |
1088 create_objects(); | |
1089 | |
1090 } | |
1091 | |
1092 } | |
1093 | |
1094 | |
1095 | |
1096 template<typename oT> | |
1097 inline | |
1098 void | |
1099 field<oT>::delete_objects() | |
1100 { | |
1101 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); | |
1102 | |
1103 for(uword i=0; i<n_elem; ++i) | |
1104 { | |
1105 if(mem[i] != 0) | |
1106 { | |
1107 delete mem[i]; | |
1108 mem[i] = 0; | |
1109 } | |
1110 } | |
1111 | |
1112 } | |
1113 | |
1114 | |
1115 | |
1116 template<typename oT> | |
1117 inline | |
1118 void | |
1119 field<oT>::create_objects() | |
1120 { | |
1121 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); | |
1122 | |
1123 for(uword i=0; i<n_elem; ++i) | |
1124 { | |
1125 mem[i] = new oT; | |
1126 } | |
1127 | |
1128 } | |
1129 | |
1130 | |
1131 | |
1132 template<typename oT> | |
1133 inline | |
1134 field<oT>::iterator::iterator(field<oT>& in_M, const bool at_end) | |
1135 : M(in_M) | |
1136 , i( (at_end == false) ? 0 : in_M.n_elem ) | |
1137 { | |
1138 arma_extra_debug_sigprint(); | |
1139 } | |
1140 | |
1141 | |
1142 | |
1143 template<typename oT> | |
1144 inline | |
1145 oT& | |
1146 field<oT>::iterator::operator*() | |
1147 { | |
1148 return M[i]; | |
1149 } | |
1150 | |
1151 | |
1152 | |
1153 template<typename oT> | |
1154 inline | |
1155 typename field<oT>::iterator& | |
1156 field<oT>::iterator::operator++() | |
1157 { | |
1158 ++i; | |
1159 | |
1160 return *this; | |
1161 } | |
1162 | |
1163 | |
1164 | |
1165 template<typename oT> | |
1166 inline | |
1167 void | |
1168 field<oT>::iterator::operator++(int) | |
1169 { | |
1170 operator++(); | |
1171 } | |
1172 | |
1173 | |
1174 | |
1175 template<typename oT> | |
1176 inline | |
1177 typename field<oT>::iterator& | |
1178 field<oT>::iterator::operator--() | |
1179 { | |
1180 if(i > 0) | |
1181 { | |
1182 --i; | |
1183 } | |
1184 | |
1185 return *this; | |
1186 } | |
1187 | |
1188 | |
1189 | |
1190 template<typename oT> | |
1191 inline | |
1192 void | |
1193 field<oT>::iterator::operator--(int) | |
1194 { | |
1195 operator--(); | |
1196 } | |
1197 | |
1198 | |
1199 | |
1200 template<typename oT> | |
1201 inline | |
1202 bool | |
1203 field<oT>::iterator::operator!=(const typename field<oT>::iterator& X) const | |
1204 { | |
1205 return (i != X.i); | |
1206 } | |
1207 | |
1208 | |
1209 | |
1210 template<typename oT> | |
1211 inline | |
1212 bool | |
1213 field<oT>::iterator::operator==(const typename field<oT>::iterator& X) const | |
1214 { | |
1215 return (i == X.i); | |
1216 } | |
1217 | |
1218 | |
1219 | |
1220 template<typename oT> | |
1221 inline | |
1222 field<oT>::const_iterator::const_iterator(const field<oT>& in_M, const bool at_end) | |
1223 : M(in_M) | |
1224 , i( (at_end == false) ? 0 : in_M.n_elem ) | |
1225 { | |
1226 arma_extra_debug_sigprint(); | |
1227 } | |
1228 | |
1229 | |
1230 | |
1231 template<typename oT> | |
1232 inline | |
1233 field<oT>::const_iterator::const_iterator(const typename field<oT>::iterator& X) | |
1234 : M(X.M) | |
1235 , i(X.i) | |
1236 { | |
1237 arma_extra_debug_sigprint(); | |
1238 } | |
1239 | |
1240 | |
1241 | |
1242 template<typename oT> | |
1243 inline | |
1244 const oT& | |
1245 field<oT>::const_iterator::operator*() const | |
1246 { | |
1247 return M[i]; | |
1248 } | |
1249 | |
1250 | |
1251 | |
1252 template<typename oT> | |
1253 inline | |
1254 typename field<oT>::const_iterator& | |
1255 field<oT>::const_iterator::operator++() | |
1256 { | |
1257 ++i; | |
1258 | |
1259 return *this; | |
1260 } | |
1261 | |
1262 | |
1263 | |
1264 template<typename oT> | |
1265 inline | |
1266 void | |
1267 field<oT>::const_iterator::operator++(int) | |
1268 { | |
1269 operator++(); | |
1270 } | |
1271 | |
1272 | |
1273 | |
1274 template<typename oT> | |
1275 inline | |
1276 typename field<oT>::const_iterator& | |
1277 field<oT>::const_iterator::operator--() | |
1278 { | |
1279 if(i > 0) | |
1280 { | |
1281 --i; | |
1282 } | |
1283 | |
1284 return *this; | |
1285 } | |
1286 | |
1287 | |
1288 | |
1289 template<typename oT> | |
1290 inline | |
1291 void | |
1292 field<oT>::const_iterator::operator--(int) | |
1293 { | |
1294 operator--(); | |
1295 } | |
1296 | |
1297 | |
1298 | |
1299 template<typename oT> | |
1300 inline | |
1301 bool | |
1302 field<oT>::const_iterator::operator!=(const typename field<oT>::const_iterator& X) const | |
1303 { | |
1304 return (i != X.i); | |
1305 } | |
1306 | |
1307 | |
1308 | |
1309 template<typename oT> | |
1310 inline | |
1311 bool | |
1312 field<oT>::const_iterator::operator==(const typename field<oT>::const_iterator& X) const | |
1313 { | |
1314 return (i == X.i); | |
1315 } | |
1316 | |
1317 | |
1318 | |
1319 template<typename oT> | |
1320 inline | |
1321 typename field<oT>::iterator | |
1322 field<oT>::begin() | |
1323 { | |
1324 arma_extra_debug_sigprint(); | |
1325 | |
1326 return field<oT>::iterator(*this); | |
1327 } | |
1328 | |
1329 | |
1330 | |
1331 template<typename oT> | |
1332 inline | |
1333 typename field<oT>::const_iterator | |
1334 field<oT>::begin() const | |
1335 { | |
1336 arma_extra_debug_sigprint(); | |
1337 | |
1338 return field<oT>::const_iterator(*this); | |
1339 } | |
1340 | |
1341 | |
1342 | |
1343 template<typename oT> | |
1344 inline | |
1345 typename field<oT>::const_iterator | |
1346 field<oT>::cbegin() const | |
1347 { | |
1348 arma_extra_debug_sigprint(); | |
1349 | |
1350 return field<oT>::const_iterator(*this); | |
1351 } | |
1352 | |
1353 | |
1354 | |
1355 template<typename oT> | |
1356 inline | |
1357 typename field<oT>::iterator | |
1358 field<oT>::end() | |
1359 { | |
1360 arma_extra_debug_sigprint(); | |
1361 | |
1362 return field<oT>::iterator(*this, true); | |
1363 } | |
1364 | |
1365 | |
1366 | |
1367 template<typename oT> | |
1368 inline | |
1369 typename field<oT>::const_iterator | |
1370 field<oT>::end() const | |
1371 { | |
1372 arma_extra_debug_sigprint(); | |
1373 | |
1374 return field<oT>::const_iterator(*this, true); | |
1375 } | |
1376 | |
1377 | |
1378 | |
1379 template<typename oT> | |
1380 inline | |
1381 typename field<oT>::const_iterator | |
1382 field<oT>::cend() const | |
1383 { | |
1384 arma_extra_debug_sigprint(); | |
1385 | |
1386 return field<oT>::const_iterator(*this, true); | |
1387 } | |
1388 | |
1389 | |
1390 | |
1391 template<typename oT> | |
1392 inline | |
1393 void | |
1394 field<oT>::clear() | |
1395 { | |
1396 reset(); | |
1397 } | |
1398 | |
1399 | |
1400 | |
1401 template<typename oT> | |
1402 inline | |
1403 bool | |
1404 field<oT>::empty() const | |
1405 { | |
1406 return (n_elem == 0); | |
1407 } | |
1408 | |
1409 | |
1410 | |
1411 template<typename oT> | |
1412 inline | |
1413 uword | |
1414 field<oT>::size() const | |
1415 { | |
1416 return n_elem; | |
1417 } | |
1418 | |
1419 | |
1420 | |
1421 // | |
1422 // | |
1423 // | |
1424 | |
1425 | |
1426 | |
1427 template<typename oT> | |
1428 inline | |
1429 void | |
1430 field_aux::reset_objects(field<oT>& x) | |
1431 { | |
1432 arma_extra_debug_sigprint(); | |
1433 | |
1434 x.delete_objects(); | |
1435 x.create_objects(); | |
1436 } | |
1437 | |
1438 | |
1439 | |
1440 template<typename eT> | |
1441 inline | |
1442 void | |
1443 field_aux::reset_objects(field< Mat<eT> >& x) | |
1444 { | |
1445 arma_extra_debug_sigprint(); | |
1446 | |
1447 for(uword i=0; i<x.n_elem; ++i) | |
1448 { | |
1449 (*(x.mem[i])).reset(); | |
1450 } | |
1451 } | |
1452 | |
1453 | |
1454 | |
1455 template<typename eT> | |
1456 inline | |
1457 void | |
1458 field_aux::reset_objects(field< Col<eT> >& x) | |
1459 { | |
1460 arma_extra_debug_sigprint(); | |
1461 | |
1462 for(uword i=0; i<x.n_elem; ++i) | |
1463 { | |
1464 (*(x.mem[i])).reset(); | |
1465 } | |
1466 } | |
1467 | |
1468 | |
1469 | |
1470 template<typename eT> | |
1471 inline | |
1472 void | |
1473 field_aux::reset_objects(field< Row<eT> >& x) | |
1474 { | |
1475 arma_extra_debug_sigprint(); | |
1476 | |
1477 for(uword i=0; i<x.n_elem; ++i) | |
1478 { | |
1479 (*(x.mem[i])).reset(); | |
1480 } | |
1481 } | |
1482 | |
1483 | |
1484 | |
1485 template<typename eT> | |
1486 inline | |
1487 void | |
1488 field_aux::reset_objects(field< Cube<eT> >& x) | |
1489 { | |
1490 arma_extra_debug_sigprint(); | |
1491 | |
1492 for(uword i=0; i<x.n_elem; ++i) | |
1493 { | |
1494 (*(x.mem[i])).reset(); | |
1495 } | |
1496 } | |
1497 | |
1498 | |
1499 | |
1500 inline | |
1501 void | |
1502 field_aux::reset_objects(field< std::string >& x) | |
1503 { | |
1504 arma_extra_debug_sigprint(); | |
1505 | |
1506 for(uword i=0; i<x.n_elem; ++i) | |
1507 { | |
1508 (*(x.mem[i])).clear(); | |
1509 } | |
1510 } | |
1511 | |
1512 | |
1513 | |
1514 // | |
1515 // | |
1516 // | |
1517 | |
1518 | |
1519 | |
1520 template<typename oT> | |
1521 inline | |
1522 bool | |
1523 field_aux::save(const field<oT>&, const std::string&, const file_type, std::string& err_msg) | |
1524 { | |
1525 arma_extra_debug_sigprint(); | |
1526 | |
1527 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; | |
1528 | |
1529 return false; | |
1530 } | |
1531 | |
1532 | |
1533 | |
1534 template<typename oT> | |
1535 inline | |
1536 bool | |
1537 field_aux::save(const field<oT>&, std::ostream&, const file_type, std::string& err_msg) | |
1538 { | |
1539 arma_extra_debug_sigprint(); | |
1540 | |
1541 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; | |
1542 | |
1543 return false; | |
1544 } | |
1545 | |
1546 | |
1547 | |
1548 template<typename oT> | |
1549 inline | |
1550 bool | |
1551 field_aux::load(field<oT>&, const std::string&, const file_type, std::string& err_msg) | |
1552 { | |
1553 arma_extra_debug_sigprint(); | |
1554 | |
1555 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; | |
1556 | |
1557 return false; | |
1558 } | |
1559 | |
1560 | |
1561 | |
1562 template<typename oT> | |
1563 inline | |
1564 bool | |
1565 field_aux::load(field<oT>&, std::istream&, const file_type, std::string& err_msg) | |
1566 { | |
1567 arma_extra_debug_sigprint(); | |
1568 | |
1569 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; | |
1570 | |
1571 return false; | |
1572 } | |
1573 | |
1574 | |
1575 | |
1576 template<typename eT> | |
1577 inline | |
1578 bool | |
1579 field_aux::save(const field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1580 { | |
1581 arma_extra_debug_sigprint(); | |
1582 | |
1583 switch(type) | |
1584 { | |
1585 case arma_binary: | |
1586 return diskio::save_arma_binary(x, name); | |
1587 break; | |
1588 | |
1589 case ppm_binary: | |
1590 return diskio::save_ppm_binary(x, name); | |
1591 break; | |
1592 | |
1593 default: | |
1594 err_msg = " [unsupported type] filename = "; | |
1595 return false; | |
1596 } | |
1597 } | |
1598 | |
1599 | |
1600 | |
1601 template<typename eT> | |
1602 inline | |
1603 bool | |
1604 field_aux::save(const field< Mat<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg) | |
1605 { | |
1606 arma_extra_debug_sigprint(); | |
1607 | |
1608 switch(type) | |
1609 { | |
1610 case arma_binary: | |
1611 return diskio::save_arma_binary(x, os); | |
1612 break; | |
1613 | |
1614 case ppm_binary: | |
1615 return diskio::save_ppm_binary(x, os); | |
1616 break; | |
1617 | |
1618 default: | |
1619 err_msg = " [unsupported type] filename = "; | |
1620 return false; | |
1621 } | |
1622 } | |
1623 | |
1624 | |
1625 | |
1626 template<typename eT> | |
1627 inline | |
1628 bool | |
1629 field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1630 { | |
1631 arma_extra_debug_sigprint(); | |
1632 | |
1633 switch(type) | |
1634 { | |
1635 case auto_detect: | |
1636 return diskio::load_auto_detect(x, name, err_msg); | |
1637 break; | |
1638 | |
1639 case arma_binary: | |
1640 return diskio::load_arma_binary(x, name, err_msg); | |
1641 break; | |
1642 | |
1643 case ppm_binary: | |
1644 return diskio::load_ppm_binary(x, name, err_msg); | |
1645 break; | |
1646 | |
1647 default: | |
1648 err_msg = " [unsupported type] filename = "; | |
1649 return false; | |
1650 } | |
1651 } | |
1652 | |
1653 | |
1654 | |
1655 template<typename eT> | |
1656 inline | |
1657 bool | |
1658 field_aux::load(field< Mat<eT> >& x, std::istream& is, const file_type type, std::string& err_msg) | |
1659 { | |
1660 arma_extra_debug_sigprint(); | |
1661 | |
1662 switch(type) | |
1663 { | |
1664 case auto_detect: | |
1665 return diskio::load_auto_detect(x, is, err_msg); | |
1666 break; | |
1667 | |
1668 case arma_binary: | |
1669 return diskio::load_arma_binary(x, is, err_msg); | |
1670 break; | |
1671 | |
1672 case ppm_binary: | |
1673 return diskio::load_ppm_binary(x, is, err_msg); | |
1674 break; | |
1675 | |
1676 default: | |
1677 err_msg = " [unsupported type] filename = "; | |
1678 return false; | |
1679 } | |
1680 } | |
1681 | |
1682 | |
1683 | |
1684 template<typename eT> | |
1685 inline | |
1686 bool | |
1687 field_aux::save(const field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1688 { | |
1689 arma_extra_debug_sigprint(); | |
1690 | |
1691 switch(type) | |
1692 { | |
1693 case arma_binary: | |
1694 return diskio::save_arma_binary(x, name); | |
1695 break; | |
1696 | |
1697 case ppm_binary: | |
1698 return diskio::save_ppm_binary(x, name); | |
1699 break; | |
1700 | |
1701 default: | |
1702 err_msg = " [unsupported type] filename = "; | |
1703 return false; | |
1704 } | |
1705 } | |
1706 | |
1707 | |
1708 | |
1709 template<typename eT> | |
1710 inline | |
1711 bool | |
1712 field_aux::save(const field< Col<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg) | |
1713 { | |
1714 arma_extra_debug_sigprint(); | |
1715 | |
1716 switch(type) | |
1717 { | |
1718 case arma_binary: | |
1719 return diskio::save_arma_binary(x, os); | |
1720 break; | |
1721 | |
1722 case ppm_binary: | |
1723 return diskio::save_ppm_binary(x, os); | |
1724 break; | |
1725 | |
1726 default: | |
1727 err_msg = " [unsupported type] filename = "; | |
1728 return false; | |
1729 } | |
1730 } | |
1731 | |
1732 | |
1733 | |
1734 template<typename eT> | |
1735 inline | |
1736 bool | |
1737 field_aux::load(field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1738 { | |
1739 arma_extra_debug_sigprint(); | |
1740 | |
1741 switch(type) | |
1742 { | |
1743 case auto_detect: | |
1744 return diskio::load_auto_detect(x, name, err_msg); | |
1745 break; | |
1746 | |
1747 case arma_binary: | |
1748 return diskio::load_arma_binary(x, name, err_msg); | |
1749 break; | |
1750 | |
1751 case ppm_binary: | |
1752 return diskio::load_ppm_binary(x, name, err_msg); | |
1753 break; | |
1754 | |
1755 default: | |
1756 err_msg = " [unsupported type] filename = "; | |
1757 return false; | |
1758 } | |
1759 } | |
1760 | |
1761 | |
1762 | |
1763 template<typename eT> | |
1764 inline | |
1765 bool | |
1766 field_aux::load(field< Col<eT> >& x, std::istream& is, const file_type type, std::string& err_msg) | |
1767 { | |
1768 arma_extra_debug_sigprint(); | |
1769 | |
1770 switch(type) | |
1771 { | |
1772 case auto_detect: | |
1773 return diskio::load_auto_detect(x, is, err_msg); | |
1774 break; | |
1775 | |
1776 case arma_binary: | |
1777 return diskio::load_arma_binary(x, is, err_msg); | |
1778 break; | |
1779 | |
1780 case ppm_binary: | |
1781 return diskio::load_ppm_binary(x, is, err_msg); | |
1782 break; | |
1783 | |
1784 default: | |
1785 err_msg = " [unsupported type] filename = "; | |
1786 return false; | |
1787 } | |
1788 } | |
1789 | |
1790 | |
1791 | |
1792 template<typename eT> | |
1793 inline | |
1794 bool | |
1795 field_aux::save(const field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1796 { | |
1797 arma_extra_debug_sigprint(); | |
1798 | |
1799 switch(type) | |
1800 { | |
1801 case arma_binary: | |
1802 return diskio::save_arma_binary(x, name, err_msg); | |
1803 break; | |
1804 | |
1805 case ppm_binary: | |
1806 return diskio::save_ppm_binary(x, name, err_msg); | |
1807 break; | |
1808 | |
1809 default: | |
1810 err_msg = " [unsupported type] filename = "; | |
1811 return false; | |
1812 } | |
1813 } | |
1814 | |
1815 | |
1816 | |
1817 template<typename eT> | |
1818 inline | |
1819 bool | |
1820 field_aux::save(const field< Row<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg) | |
1821 { | |
1822 arma_extra_debug_sigprint(); | |
1823 | |
1824 switch(type) | |
1825 { | |
1826 case arma_binary: | |
1827 return diskio::save_arma_binary(x, os, err_msg); | |
1828 break; | |
1829 | |
1830 case ppm_binary: | |
1831 return diskio::save_ppm_binary(x, os, err_msg); | |
1832 break; | |
1833 | |
1834 default: | |
1835 err_msg = " [unsupported type] filename = "; | |
1836 return false; | |
1837 } | |
1838 } | |
1839 | |
1840 | |
1841 | |
1842 template<typename eT> | |
1843 inline | |
1844 bool | |
1845 field_aux::load(field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1846 { | |
1847 arma_extra_debug_sigprint(); | |
1848 | |
1849 switch(type) | |
1850 { | |
1851 case auto_detect: | |
1852 return diskio::load_auto_detect(x, name, err_msg); | |
1853 break; | |
1854 | |
1855 case arma_binary: | |
1856 return diskio::load_arma_binary(x, name, err_msg); | |
1857 break; | |
1858 | |
1859 case ppm_binary: | |
1860 return diskio::load_ppm_binary(x, name, err_msg); | |
1861 break; | |
1862 | |
1863 default: | |
1864 err_msg = " [unsupported type] filename = "; | |
1865 return false; | |
1866 } | |
1867 } | |
1868 | |
1869 | |
1870 | |
1871 template<typename eT> | |
1872 inline | |
1873 bool | |
1874 field_aux::load(field< Row<eT> >& x, std::istream& is, const file_type type, std::string& err_msg) | |
1875 { | |
1876 arma_extra_debug_sigprint(); | |
1877 | |
1878 switch(type) | |
1879 { | |
1880 case auto_detect: | |
1881 return diskio::load_auto_detect(x, is, err_msg); | |
1882 break; | |
1883 | |
1884 case arma_binary: | |
1885 return diskio::load_arma_binary(x, is, err_msg); | |
1886 break; | |
1887 | |
1888 case ppm_binary: | |
1889 return diskio::load_ppm_binary(x, is, err_msg); | |
1890 break; | |
1891 | |
1892 default: | |
1893 err_msg = " [unsupported type] filename = "; | |
1894 return false; | |
1895 } | |
1896 } | |
1897 | |
1898 | |
1899 | |
1900 template<typename eT> | |
1901 inline | |
1902 bool | |
1903 field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1904 { | |
1905 arma_extra_debug_sigprint(); | |
1906 | |
1907 switch(type) | |
1908 { | |
1909 case arma_binary: | |
1910 return diskio::save_arma_binary(x, name, err_msg); | |
1911 break; | |
1912 | |
1913 case ppm_binary: | |
1914 return diskio::save_ppm_binary(x, name, err_msg); | |
1915 break; | |
1916 | |
1917 default: | |
1918 err_msg = " [unsupported type] filename = "; | |
1919 return false; | |
1920 } | |
1921 } | |
1922 | |
1923 | |
1924 | |
1925 template<typename eT> | |
1926 inline | |
1927 bool | |
1928 field_aux::save(const field< Cube<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg) | |
1929 { | |
1930 arma_extra_debug_sigprint(); | |
1931 | |
1932 switch(type) | |
1933 { | |
1934 case arma_binary: | |
1935 return diskio::save_arma_binary(x, os, err_msg); | |
1936 break; | |
1937 | |
1938 case ppm_binary: | |
1939 return diskio::save_ppm_binary(x, os, err_msg); | |
1940 break; | |
1941 | |
1942 default: | |
1943 err_msg = " [unsupported type] filename = "; | |
1944 return false; | |
1945 } | |
1946 } | |
1947 | |
1948 | |
1949 | |
1950 template<typename eT> | |
1951 inline | |
1952 bool | |
1953 field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg) | |
1954 { | |
1955 arma_extra_debug_sigprint(); | |
1956 | |
1957 switch(type) | |
1958 { | |
1959 case auto_detect: | |
1960 return diskio::load_auto_detect(x, name, err_msg); | |
1961 break; | |
1962 | |
1963 case arma_binary: | |
1964 return diskio::load_arma_binary(x, name, err_msg); | |
1965 break; | |
1966 | |
1967 case ppm_binary: | |
1968 return diskio::load_ppm_binary(x, name, err_msg); | |
1969 break; | |
1970 | |
1971 default: | |
1972 err_msg = " [unsupported type] filename = "; | |
1973 return false; | |
1974 } | |
1975 } | |
1976 | |
1977 | |
1978 | |
1979 template<typename eT> | |
1980 inline | |
1981 bool | |
1982 field_aux::load(field< Cube<eT> >& x, std::istream& is, const file_type type, std::string& err_msg) | |
1983 { | |
1984 arma_extra_debug_sigprint(); | |
1985 | |
1986 switch(type) | |
1987 { | |
1988 case auto_detect: | |
1989 return diskio::load_auto_detect(x, is, err_msg); | |
1990 break; | |
1991 | |
1992 case arma_binary: | |
1993 return diskio::load_arma_binary(x, is, err_msg); | |
1994 break; | |
1995 | |
1996 case ppm_binary: | |
1997 return diskio::load_ppm_binary(x, is, err_msg); | |
1998 break; | |
1999 | |
2000 default: | |
2001 err_msg = " [unsupported type] filename = "; | |
2002 return false; | |
2003 } | |
2004 } | |
2005 | |
2006 | |
2007 | |
2008 inline | |
2009 bool | |
2010 field_aux::save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) | |
2011 { | |
2012 arma_extra_debug_sigprint(); | |
2013 | |
2014 arma_ignore(type); | |
2015 | |
2016 err_msg.clear(); | |
2017 | |
2018 return diskio::save_std_string(x, name); | |
2019 } | |
2020 | |
2021 | |
2022 | |
2023 inline | |
2024 bool | |
2025 field_aux::save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg) | |
2026 { | |
2027 arma_extra_debug_sigprint(); | |
2028 | |
2029 arma_ignore(type); | |
2030 | |
2031 err_msg.clear(); | |
2032 | |
2033 return diskio::save_std_string(x, os); | |
2034 } | |
2035 | |
2036 | |
2037 | |
2038 inline | |
2039 bool | |
2040 field_aux::load(field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) | |
2041 { | |
2042 arma_extra_debug_sigprint(); | |
2043 | |
2044 arma_ignore(type); | |
2045 | |
2046 return diskio::load_std_string(x, name, err_msg); | |
2047 } | |
2048 | |
2049 | |
2050 | |
2051 inline | |
2052 bool | |
2053 field_aux::load(field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg) | |
2054 { | |
2055 arma_extra_debug_sigprint(); | |
2056 | |
2057 arma_ignore(type); | |
2058 | |
2059 return diskio::load_std_string(x, is, err_msg); | |
2060 } | |
2061 | |
2062 | |
2063 | |
2064 #ifdef ARMA_EXTRA_FIELD_MEAT | |
2065 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_MEAT) | |
2066 #endif | |
2067 | |
2068 | |
2069 | |
2070 //! @} |