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