00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 template<typename oT>
00023 inline
00024 field<oT>::~field()
00025 {
00026 arma_extra_debug_sigprint_this(this);
00027
00028 delete_objects();
00029
00030 if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00031 {
00032 delete [] mem;
00033 }
00034
00035 if(arma_config::debug == true)
00036 {
00037
00038 access::rw(n_rows) = 0;
00039 access::rw(n_cols) = 0;
00040 access::rw(n_elem) = 0;
00041 mem = 0;
00042 }
00043 }
00044
00045
00046
00047 template<typename oT>
00048 inline
00049 field<oT>::field()
00050 : n_rows(0)
00051 , n_cols(0)
00052 , n_elem(0)
00053 , mem(0)
00054 {
00055 arma_extra_debug_sigprint_this(this);
00056 }
00057
00058
00059
00060
00061 template<typename oT>
00062 inline
00063 field<oT>::field(const field& x)
00064 : n_rows(0)
00065 , n_cols(0)
00066 , n_elem(0)
00067 , mem(0)
00068 {
00069 arma_extra_debug_sigprint(arma_boost::format("this = %x x = %x") % this % &x);
00070
00071 init(x);
00072 }
00073
00074
00075
00076
00077 template<typename oT>
00078 inline
00079 const field<oT>&
00080 field<oT>::operator=(const field& x)
00081 {
00082 arma_extra_debug_sigprint();
00083
00084 init(x);
00085 return *this;
00086 }
00087
00088
00089
00090
00091 template<typename oT>
00092 inline
00093 field<oT>::field(const subview_field<oT>& X)
00094 : n_rows(0)
00095 , n_cols(0)
00096 , n_elem(0)
00097 , mem(0)
00098 {
00099 arma_extra_debug_sigprint_this(this);
00100
00101 this->operator=(X);
00102 }
00103
00104
00105
00106
00107 template<typename oT>
00108 inline
00109 const field<oT>&
00110 field<oT>::operator=(const subview_field<oT>& X)
00111 {
00112 arma_extra_debug_sigprint();
00113
00114 subview_field<oT>::extract(*this, X);
00115 return *this;
00116 }
00117
00118
00119
00120
00121
00122 template<typename oT>
00123 inline
00124 field<oT>::field(const u32 n_elem_in)
00125 : n_rows(0)
00126 , n_cols(0)
00127 , n_elem(0)
00128 , mem(0)
00129 {
00130 arma_extra_debug_sigprint_this(this);
00131
00132 init(n_elem_in, 1);
00133 }
00134
00135
00136
00137
00138 template<typename oT>
00139 inline
00140 field<oT>::field(const u32 n_rows_in, const u32 n_cols_in)
00141 : n_rows(0)
00142 , n_cols(0)
00143 , n_elem(0)
00144 , mem(0)
00145 {
00146 arma_extra_debug_sigprint_this(this);
00147
00148 init(n_rows_in, n_cols_in);
00149 }
00150
00151
00152
00153
00154
00155 template<typename oT>
00156 inline
00157 void
00158 field<oT>::set_size(const u32 n_elem_in)
00159 {
00160 arma_extra_debug_sigprint(arma_boost::format("n_elem_in = %d") % n_elem_in);
00161
00162 init(n_elem_in, 1);
00163 }
00164
00165
00166
00167
00168 template<typename oT>
00169 inline
00170 void
00171 field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in)
00172 {
00173 arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in);
00174
00175 init(n_rows_in, n_cols_in);
00176 }
00177
00178
00179
00180
00181 template<typename oT>
00182 template<typename oT2>
00183 inline
00184 void
00185 field<oT>::copy_size(const field<oT2>& x)
00186 {
00187 arma_extra_debug_sigprint();
00188
00189 init(x.n_rows, x.n_cols);
00190 }
00191
00192
00193
00194
00195 template<typename oT>
00196 arma_inline
00197 oT&
00198 field<oT>::operator[] (const u32 i)
00199 {
00200 return (*mem[i]);
00201 }
00202
00203
00204
00205
00206 template<typename oT>
00207 arma_inline
00208 const oT&
00209 field<oT>::operator[] (const u32 i) const
00210 {
00211 return (*mem[i]);
00212 }
00213
00214
00215
00216 template<typename oT>
00217 arma_inline
00218 oT&
00219 field<oT>::operator() (const u32 i)
00220 {
00221 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds");
00222 return (*mem[i]);
00223 }
00224
00225
00226
00227
00228 template<typename oT>
00229 arma_inline
00230 const oT&
00231 field<oT>::operator() (const u32 i) const
00232 {
00233 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds");
00234 return (*mem[i]);
00235 }
00236
00237
00238
00239
00240 template<typename oT>
00241 arma_inline
00242 oT&
00243 field<oT>::operator() (const u32 in_row, const u32 in_col)
00244 {
00245 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds");
00246 return (*mem[in_row + in_col*n_rows]);
00247 }
00248
00249
00250
00251
00252 template<typename oT>
00253 arma_inline
00254 const oT&
00255 field<oT>::operator() (const u32 in_row, const u32 in_col) const
00256 {
00257 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds");
00258 return (*mem[in_row + in_col*n_rows]);
00259 }
00260
00261
00262
00263
00264 template<typename oT>
00265 arma_inline
00266 oT&
00267 field<oT>::at(const u32 in_row, const u32 in_col)
00268 {
00269 return (*mem[in_row + in_col*n_rows]);
00270 }
00271
00272
00273
00274
00275 template<typename oT>
00276 arma_inline
00277 const oT&
00278 field<oT>::at(const u32 in_row, const u32 in_col) const
00279 {
00280 return (*mem[in_row + in_col*n_rows]);
00281 }
00282
00283
00284
00285
00286 template<typename oT>
00287 inline
00288 subview_field<oT>
00289 field<oT>::row(const u32 row_num)
00290 {
00291 arma_extra_debug_sigprint();
00292
00293 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" );
00294 return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1);
00295 }
00296
00297
00298
00299
00300 template<typename oT>
00301 inline
00302 const subview_field<oT>
00303 field<oT>::row(const u32 row_num) const
00304 {
00305 arma_extra_debug_sigprint();
00306
00307 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" );
00308 return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1);
00309 }
00310
00311
00312
00313
00314 template<typename oT>
00315 inline
00316 subview_field<oT>
00317 field<oT>::col(const u32 col_num)
00318 {
00319 arma_extra_debug_sigprint();
00320
00321 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds");
00322 return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num);
00323 }
00324
00325
00326
00327
00328 template<typename oT>
00329 inline
00330 const subview_field<oT>
00331 field<oT>::col(const u32 col_num) const
00332 {
00333 arma_extra_debug_sigprint();
00334
00335 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds");
00336 return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num);
00337 }
00338
00339
00340
00341
00342 template<typename oT>
00343 inline
00344 subview_field<oT>
00345 field<oT>::rows(const u32 in_row1, const u32 in_row2)
00346 {
00347 arma_extra_debug_sigprint();
00348
00349 arma_debug_check
00350 (
00351 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ),
00352 "field::rows(): indicies out of bounds or incorrectly used"
00353 );
00354
00355 return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1);
00356 }
00357
00358
00359
00360
00361 template<typename oT>
00362 inline
00363 const subview_field<oT>
00364 field<oT>::rows(const u32 in_row1, const u32 in_row2) const
00365 {
00366 arma_extra_debug_sigprint();
00367
00368 arma_debug_check
00369 (
00370 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ),
00371 "field::rows(): indicies out of bounds or incorrectly used"
00372 );
00373
00374 return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1);
00375 }
00376
00377
00378
00379
00380 template<typename oT>
00381 inline
00382 subview_field<oT>
00383 field<oT>::cols(const u32 in_col1, const u32 in_col2)
00384 {
00385 arma_extra_debug_sigprint();
00386
00387 arma_debug_check
00388 (
00389 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ),
00390 "field::cols(): indicies out of bounds or incorrectly used"
00391 );
00392
00393 return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2);
00394 }
00395
00396
00397
00398
00399 template<typename oT>
00400 inline
00401 const subview_field<oT>
00402 field<oT>::cols(const u32 in_col1, const u32 in_col2) const
00403 {
00404 arma_extra_debug_sigprint();
00405
00406 arma_debug_check
00407 (
00408 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ),
00409 "field::cols(): indicies out of bounds or incorrectly used"
00410 );
00411
00412 return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2);
00413 }
00414
00415
00416
00417
00418 template<typename oT>
00419 inline
00420 subview_field<oT>
00421 field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
00422 {
00423 arma_extra_debug_sigprint();
00424
00425 arma_debug_check
00426 (
00427 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
00428 "field::subfield(): indices out of bounds or incorrectly used"
00429 );
00430
00431 return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2);
00432 }
00433
00434
00435
00436
00437 template<typename oT>
00438 inline
00439 const subview_field<oT>
00440 field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2) const
00441 {
00442 arma_extra_debug_sigprint();
00443
00444 arma_debug_check
00445 (
00446 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
00447 "field::subfield(): indices out of bounds or incorrectly used"
00448 );
00449
00450 return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2);
00451 }
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 template<typename oT>
00465 inline
00466 void
00467 field<oT>::print(const std::string extra_text) const
00468 {
00469 arma_extra_debug_sigprint();
00470
00471 if(extra_text.length() != 0)
00472 {
00473 const std::streamsize orig_width = cout.width();
00474
00475 cout << extra_text << '\n';
00476
00477 cout.width(orig_width);
00478 }
00479
00480 arma_ostream::print(cout, *this);
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 template<typename oT>
00495 inline
00496 void
00497 field<oT>::print(std::ostream& user_stream, const std::string extra_text) const
00498 {
00499 arma_extra_debug_sigprint();
00500
00501 if(extra_text.length() != 0)
00502 {
00503 const std::streamsize orig_width = user_stream.width();
00504
00505 user_stream << extra_text << '\n';
00506
00507 user_stream.width(orig_width);
00508 }
00509
00510 arma_ostream::print(user_stream, *this);
00511 }
00512
00513
00514
00515
00516 template<typename oT>
00517 inline
00518 void
00519 field<oT>::fill(const oT& x)
00520 {
00521 arma_extra_debug_sigprint();
00522
00523 field<oT>& t = *this;
00524
00525 for(u32 i=0; i<n_elem; ++i)
00526 {
00527 t[i] = x;
00528 }
00529 }
00530
00531
00532
00533 template<typename oT>
00534 inline
00535 void
00536 field<oT>::reset()
00537 {
00538 arma_extra_debug_sigprint();
00539
00540 init(0,0);
00541 }
00542
00543
00544
00545 template<typename oT>
00546 inline
00547 void
00548 field<oT>::reset_objects()
00549 {
00550 arma_extra_debug_sigprint();
00551
00552 field_aux::reset_objects(*this);
00553 }
00554
00555
00556
00557 template<typename oT>
00558 inline
00559 bool
00560 field<oT>::save(const std::string name, const file_type type, const bool print_status) const
00561 {
00562 arma_extra_debug_sigprint();
00563
00564 std::string err_msg;
00565 const bool save_okay = field_aux::save(*this, name, type, err_msg);
00566
00567 if( (print_status == true) && (save_okay == false) )
00568 {
00569 if(err_msg.length() > 0)
00570 {
00571 arma_print("field::save(): ", err_msg, name);
00572 }
00573 else
00574 {
00575 arma_print("field::save(): couldn't write to ", name);
00576 }
00577 }
00578
00579 return save_okay;
00580 }
00581
00582
00583
00584 template<typename oT>
00585 inline
00586 bool
00587 field<oT>::save(std::ostream& os, const file_type type, const bool print_status) const
00588 {
00589 arma_extra_debug_sigprint();
00590
00591 std::string err_msg;
00592 const bool save_okay = field_aux::save(*this, os, type, err_msg);
00593
00594 if( (print_status == true) && (save_okay == false) )
00595 {
00596 if(err_msg.length() > 0)
00597 {
00598 arma_print("field::save(): ", err_msg, "[ostream]");
00599 }
00600 else
00601 {
00602 arma_print("field::save(): couldn't write to [ostream]");
00603 }
00604 }
00605
00606 return save_okay;
00607 }
00608
00609
00610
00611 template<typename oT>
00612 inline
00613 bool
00614 field<oT>::load(const std::string name, const file_type type, const bool print_status)
00615 {
00616 arma_extra_debug_sigprint();
00617
00618 std::string err_msg;
00619 const bool load_okay = field_aux::load(*this, name, type, err_msg);
00620
00621 if( (print_status == true) && (load_okay == false) )
00622 {
00623 if(err_msg.length() > 0)
00624 {
00625 arma_print("field::load(): ", err_msg, name);
00626 }
00627 else
00628 {
00629 arma_print("field::load(): couldn't read from ", name);
00630 }
00631 }
00632
00633 if(load_okay == false)
00634 {
00635 (*this).reset();
00636 }
00637
00638 return load_okay;
00639 }
00640
00641
00642
00643 template<typename oT>
00644 inline
00645 bool
00646 field<oT>::load(std::istream& is, const file_type type, const bool print_status)
00647 {
00648 arma_extra_debug_sigprint();
00649
00650 std::string err_msg;
00651 const bool load_okay = field_aux::load(*this, is, type, err_msg);
00652
00653 if( (print_status == true) && (load_okay == false) )
00654 {
00655 if(err_msg.length() > 0)
00656 {
00657 arma_print("field::load(): ", err_msg, "[istream]");
00658 }
00659 else
00660 {
00661 arma_print("field::load(): couldn't read from [istream]");
00662 }
00663 }
00664
00665 if(load_okay == false)
00666 {
00667 (*this).reset();
00668 }
00669
00670 return load_okay;
00671 }
00672
00673
00674
00675 template<typename oT>
00676 inline
00677 bool
00678 field<oT>::quiet_save(const std::string name, const file_type type) const
00679 {
00680 arma_extra_debug_sigprint();
00681
00682 return (*this).save(name, type, false);
00683 }
00684
00685
00686
00687 template<typename oT>
00688 inline
00689 bool
00690 field<oT>::quiet_save(std::ostream& os, const file_type type) const
00691 {
00692 arma_extra_debug_sigprint();
00693
00694 return (*this).save(os, type, false);
00695 }
00696
00697
00698
00699 template<typename oT>
00700 inline
00701 bool
00702 field<oT>::quiet_load(const std::string name, const file_type type)
00703 {
00704 arma_extra_debug_sigprint();
00705
00706 return (*this).load(name, type, false);
00707 }
00708
00709
00710
00711 template<typename oT>
00712 inline
00713 bool
00714 field<oT>::quiet_load(std::istream& is, const file_type type)
00715 {
00716 arma_extra_debug_sigprint();
00717
00718 return (*this).load(is, type, false);
00719 }
00720
00721
00722
00723
00724 template<typename oT>
00725 inline
00726 void
00727 field<oT>::init(const field<oT>& x)
00728 {
00729 arma_extra_debug_sigprint();
00730
00731 if(this != &x)
00732 {
00733 init(x.n_rows, x.n_cols);
00734
00735 field& t = *this;
00736
00737 for(u32 col=0; col<x.n_cols; ++col)
00738 for(u32 row=0; row<x.n_rows; ++row)
00739 {
00740 t.at(row,col) = x.at(row,col);
00741 }
00742 }
00743
00744 }
00745
00746
00747
00748
00749 template<typename oT>
00750 inline
00751 void
00752 field<oT>::init(const u32 n_rows_in, const u32 n_cols_in)
00753 {
00754 arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in );
00755
00756 const u32 n_elem_new = n_rows_in * n_cols_in;
00757
00758 if(n_elem == n_elem_new)
00759 {
00760
00761
00762 access::rw(n_rows) = n_rows_in;
00763 access::rw(n_cols) = n_cols_in;
00764 }
00765 else
00766 {
00767 delete_objects();
00768
00769 if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00770 {
00771 delete [] mem;
00772 }
00773
00774 if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) )
00775 {
00776 mem = mem_local;
00777 }
00778 else
00779 {
00780 mem = new(std::nothrow) oT* [n_elem_new];
00781 arma_check( (mem == 0), "field::init(): out of memory" );
00782 }
00783
00784 access::rw(n_elem) = n_elem_new;
00785
00786 if(n_elem_new == 0)
00787 {
00788 access::rw(n_rows) = 0;
00789 access::rw(n_cols) = 0;
00790 }
00791 else
00792 {
00793 access::rw(n_rows) = n_rows_in;
00794 access::rw(n_cols) = n_cols_in;
00795 }
00796
00797 create_objects();
00798
00799 }
00800
00801 }
00802
00803
00804
00805 template<typename oT>
00806 inline
00807 void
00808 field<oT>::delete_objects()
00809 {
00810 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00811
00812 for(u32 i=0; i<n_elem; ++i)
00813 {
00814 if(mem[i] != 0)
00815 {
00816 delete mem[i];
00817 mem[i] = 0;
00818 }
00819 }
00820
00821 }
00822
00823
00824
00825 template<typename oT>
00826 inline
00827 void
00828 field<oT>::create_objects()
00829 {
00830 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00831
00832 for(u32 i=0; i<n_elem; ++i)
00833 {
00834 mem[i] = new oT;
00835 }
00836
00837 }
00838
00839
00840
00841 template<typename oT>
00842 inline
00843 field<oT>::iterator::iterator(field<oT>& in_M, const bool at_end)
00844 : M(in_M)
00845 , i( (at_end == false) ? 0 : in_M.n_elem )
00846 {
00847 arma_extra_debug_sigprint();
00848 }
00849
00850
00851
00852 template<typename oT>
00853 inline
00854 oT&
00855 field<oT>::iterator::operator*()
00856 {
00857 return M[i];
00858 }
00859
00860
00861
00862 template<typename oT>
00863 inline
00864 typename field<oT>::iterator&
00865 field<oT>::iterator::operator++()
00866 {
00867 ++i;
00868
00869 return *this;
00870 }
00871
00872
00873
00874 template<typename oT>
00875 inline
00876 void
00877 field<oT>::iterator::operator++(int)
00878 {
00879 operator++();
00880 }
00881
00882
00883
00884 template<typename oT>
00885 inline
00886 typename field<oT>::iterator&
00887 field<oT>::iterator::operator--()
00888 {
00889 if(i > 0)
00890 {
00891 --i;
00892 }
00893
00894 return *this;
00895 }
00896
00897
00898
00899 template<typename oT>
00900 inline
00901 void
00902 field<oT>::iterator::operator--(int)
00903 {
00904 operator--();
00905 }
00906
00907
00908
00909 template<typename oT>
00910 inline
00911 bool
00912 field<oT>::iterator::operator!=(const typename field<oT>::iterator& X) const
00913 {
00914 return (i != X.i);
00915 }
00916
00917
00918
00919 template<typename oT>
00920 inline
00921 bool
00922 field<oT>::iterator::operator==(const typename field<oT>::iterator& X) const
00923 {
00924 return (i == X.i);
00925 }
00926
00927
00928
00929 template<typename oT>
00930 inline
00931 field<oT>::const_iterator::const_iterator(const field<oT>& in_M, const bool at_end)
00932 : M(in_M)
00933 , i( (at_end == false) ? 0 : in_M.n_elem )
00934 {
00935 arma_extra_debug_sigprint();
00936 }
00937
00938
00939
00940 template<typename oT>
00941 inline
00942 field<oT>::const_iterator::const_iterator(const typename field<oT>::iterator& X)
00943 : M(X.M)
00944 , i(X.i)
00945 {
00946 arma_extra_debug_sigprint();
00947 }
00948
00949
00950
00951 template<typename oT>
00952 inline
00953 const oT&
00954 field<oT>::const_iterator::operator*() const
00955 {
00956 return M[i];
00957 }
00958
00959
00960
00961 template<typename oT>
00962 inline
00963 typename field<oT>::const_iterator&
00964 field<oT>::const_iterator::operator++()
00965 {
00966 ++i;
00967
00968 return *this;
00969 }
00970
00971
00972
00973 template<typename oT>
00974 inline
00975 void
00976 field<oT>::const_iterator::operator++(int)
00977 {
00978 operator++();
00979 }
00980
00981
00982
00983 template<typename oT>
00984 inline
00985 typename field<oT>::const_iterator&
00986 field<oT>::const_iterator::operator--()
00987 {
00988 if(i > 0)
00989 {
00990 --i;
00991 }
00992
00993 return *this;
00994 }
00995
00996
00997
00998 template<typename oT>
00999 inline
01000 void
01001 field<oT>::const_iterator::operator--(int)
01002 {
01003 operator--();
01004 }
01005
01006
01007
01008 template<typename oT>
01009 inline
01010 bool
01011 field<oT>::const_iterator::operator!=(const typename field<oT>::const_iterator& X) const
01012 {
01013 return (i != X.i);
01014 }
01015
01016
01017
01018 template<typename oT>
01019 inline
01020 bool
01021 field<oT>::const_iterator::operator==(const typename field<oT>::const_iterator& X) const
01022 {
01023 return (i == X.i);
01024 }
01025
01026
01027
01028 template<typename oT>
01029 inline
01030 typename field<oT>::iterator
01031 field<oT>::begin()
01032 {
01033 arma_extra_debug_sigprint();
01034
01035 return field<oT>::iterator(*this);
01036 }
01037
01038
01039
01040 template<typename oT>
01041 inline
01042 typename field<oT>::const_iterator
01043 field<oT>::begin() const
01044 {
01045 arma_extra_debug_sigprint();
01046
01047 return field<oT>::const_iterator(*this);
01048 }
01049
01050
01051
01052 template<typename oT>
01053 inline
01054 typename field<oT>::iterator
01055 field<oT>::end()
01056 {
01057 arma_extra_debug_sigprint();
01058
01059 return field<oT>::iterator(*this, true);
01060 }
01061
01062
01063
01064 template<typename oT>
01065 inline
01066 typename field<oT>::const_iterator
01067 field<oT>::end() const
01068 {
01069 arma_extra_debug_sigprint();
01070
01071 return field<oT>::const_iterator(*this, true);
01072 }
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 template<typename oT>
01083 inline
01084 void
01085 field_aux::reset_objects(field<oT>& x)
01086 {
01087 arma_extra_debug_sigprint();
01088
01089 x.delete_objects();
01090 x.create_objects();
01091 }
01092
01093
01094
01095 template<typename eT>
01096 inline
01097 void
01098 field_aux::reset_objects(field< Mat<eT> >& x)
01099 {
01100 arma_extra_debug_sigprint();
01101
01102 for(u32 i=0; i<x.n_elem; ++i)
01103 {
01104 (*(x.mem[i])).reset();
01105 }
01106 }
01107
01108
01109
01110 template<typename eT>
01111 inline
01112 void
01113 field_aux::reset_objects(field< Col<eT> >& x)
01114 {
01115 arma_extra_debug_sigprint();
01116
01117 for(u32 i=0; i<x.n_elem; ++i)
01118 {
01119 (*(x.mem[i])).reset();
01120 }
01121 }
01122
01123
01124
01125 template<typename eT>
01126 inline
01127 void
01128 field_aux::reset_objects(field< Row<eT> >& x)
01129 {
01130 arma_extra_debug_sigprint();
01131
01132 for(u32 i=0; i<x.n_elem; ++i)
01133 {
01134 (*(x.mem[i])).reset();
01135 }
01136 }
01137
01138
01139
01140 template<typename eT>
01141 inline
01142 void
01143 field_aux::reset_objects(field< Cube<eT> >& x)
01144 {
01145 arma_extra_debug_sigprint();
01146
01147 for(u32 i=0; i<x.n_elem; ++i)
01148 {
01149 (*(x.mem[i])).reset();
01150 }
01151 }
01152
01153
01154
01155 inline
01156 void
01157 field_aux::reset_objects(field< std::string >& x)
01158 {
01159 arma_extra_debug_sigprint();
01160
01161 for(u32 i=0; i<x.n_elem; ++i)
01162 {
01163 (*(x.mem[i])).clear();
01164 }
01165 }
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175 template<typename oT>
01176 inline
01177 bool
01178 field_aux::save(const field<oT>& x, const std::string& name, const file_type type, std::string& err_msg)
01179 {
01180 arma_extra_debug_sigprint();
01181
01182 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = ";
01183
01184 return false;
01185 }
01186
01187
01188
01189 template<typename oT>
01190 inline
01191 bool
01192 field_aux::save(const field<oT>& x, std::ostream& os, const file_type type, std::string& err_msg)
01193 {
01194 arma_extra_debug_sigprint();
01195
01196 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = ";
01197
01198 return false;
01199 }
01200
01201
01202
01203 template<typename oT>
01204 inline
01205 bool
01206 field_aux::load(field<oT>& x, const std::string& name, const file_type type, std::string& err_msg)
01207 {
01208 arma_extra_debug_sigprint();
01209
01210 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = ";
01211
01212 return false;
01213 }
01214
01215
01216
01217 template<typename oT>
01218 inline
01219 bool
01220 field_aux::load(field<oT>& x, std::istream& is, const file_type type, std::string& err_msg)
01221 {
01222 arma_extra_debug_sigprint();
01223
01224 err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = ";
01225
01226 return false;
01227 }
01228
01229
01230
01231 template<typename eT>
01232 inline
01233 bool
01234 field_aux::save(const field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01235 {
01236 arma_extra_debug_sigprint();
01237
01238 switch(type)
01239 {
01240 case arma_binary:
01241 return diskio::save_arma_binary(x, name);
01242 break;
01243
01244 case ppm_binary:
01245 return diskio::save_ppm_binary(x, name);
01246 break;
01247
01248 default:
01249 err_msg = " [unsupported type] filename = ";
01250 return false;
01251 }
01252 }
01253
01254
01255
01256 template<typename eT>
01257 inline
01258 bool
01259 field_aux::save(const field< Mat<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg)
01260 {
01261 arma_extra_debug_sigprint();
01262
01263 switch(type)
01264 {
01265 case arma_binary:
01266 return diskio::save_arma_binary(x, os);
01267 break;
01268
01269 case ppm_binary:
01270 return diskio::save_ppm_binary(x, os);
01271 break;
01272
01273 default:
01274 err_msg = " [unsupported type] filename = ";
01275 return false;
01276 }
01277 }
01278
01279
01280
01281 template<typename eT>
01282 inline
01283 bool
01284 field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01285 {
01286 arma_extra_debug_sigprint();
01287
01288 switch(type)
01289 {
01290 case auto_detect:
01291 return diskio::load_auto_detect(x, name, err_msg);
01292 break;
01293
01294 case arma_binary:
01295 return diskio::load_arma_binary(x, name, err_msg);
01296 break;
01297
01298 case ppm_binary:
01299 return diskio::load_ppm_binary(x, name, err_msg);
01300 break;
01301
01302 default:
01303 err_msg = " [unsupported type] filename = ";
01304 return false;
01305 }
01306 }
01307
01308
01309
01310 template<typename eT>
01311 inline
01312 bool
01313 field_aux::load(field< Mat<eT> >& x, std::istream& is, const file_type type, std::string& err_msg)
01314 {
01315 arma_extra_debug_sigprint();
01316
01317 switch(type)
01318 {
01319 case auto_detect:
01320 return diskio::load_auto_detect(x, is, err_msg);
01321 break;
01322
01323 case arma_binary:
01324 return diskio::load_arma_binary(x, is, err_msg);
01325 break;
01326
01327 case ppm_binary:
01328 return diskio::load_ppm_binary(x, is, err_msg);
01329 break;
01330
01331 default:
01332 err_msg = " [unsupported type] filename = ";
01333 return false;
01334 }
01335 }
01336
01337
01338
01339 template<typename eT>
01340 inline
01341 bool
01342 field_aux::save(const field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01343 {
01344 arma_extra_debug_sigprint();
01345
01346 switch(type)
01347 {
01348 case arma_binary:
01349 return diskio::save_arma_binary(x, name);
01350 break;
01351
01352 case ppm_binary:
01353 return diskio::save_ppm_binary(x, name);
01354 break;
01355
01356 default:
01357 err_msg = " [unsupported type] filename = ";
01358 return false;
01359 }
01360 }
01361
01362
01363
01364 template<typename eT>
01365 inline
01366 bool
01367 field_aux::save(const field< Col<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg)
01368 {
01369 arma_extra_debug_sigprint();
01370
01371 switch(type)
01372 {
01373 case arma_binary:
01374 return diskio::save_arma_binary(x, os);
01375 break;
01376
01377 case ppm_binary:
01378 return diskio::save_ppm_binary(x, os);
01379 break;
01380
01381 default:
01382 err_msg = " [unsupported type] filename = ";
01383 return false;
01384 }
01385 }
01386
01387
01388
01389 template<typename eT>
01390 inline
01391 bool
01392 field_aux::load(field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01393 {
01394 arma_extra_debug_sigprint();
01395
01396 switch(type)
01397 {
01398 case auto_detect:
01399 return diskio::load_auto_detect(x, name, err_msg);
01400 break;
01401
01402 case arma_binary:
01403 return diskio::load_arma_binary(x, name, err_msg);
01404 break;
01405
01406 case ppm_binary:
01407 return diskio::load_ppm_binary(x, name, err_msg);
01408 break;
01409
01410 default:
01411 err_msg = " [unsupported type] filename = ";
01412 return false;
01413 }
01414 }
01415
01416
01417
01418 template<typename eT>
01419 inline
01420 bool
01421 field_aux::load(field< Col<eT> >& x, std::istream& is, const file_type type, std::string& err_msg)
01422 {
01423 arma_extra_debug_sigprint();
01424
01425 switch(type)
01426 {
01427 case auto_detect:
01428 return diskio::load_auto_detect(x, is, err_msg);
01429 break;
01430
01431 case arma_binary:
01432 return diskio::load_arma_binary(x, is, err_msg);
01433 break;
01434
01435 case ppm_binary:
01436 return diskio::load_ppm_binary(x, is, err_msg);
01437 break;
01438
01439 default:
01440 err_msg = " [unsupported type] filename = ";
01441 return false;
01442 }
01443 }
01444
01445
01446
01447 template<typename eT>
01448 inline
01449 bool
01450 field_aux::save(const field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01451 {
01452 arma_extra_debug_sigprint();
01453
01454 switch(type)
01455 {
01456 case arma_binary:
01457 return diskio::save_arma_binary(x, name, err_msg);
01458 break;
01459
01460 case ppm_binary:
01461 return diskio::save_ppm_binary(x, name, err_msg);
01462 break;
01463
01464 default:
01465 err_msg = " [unsupported type] filename = ";
01466 return false;
01467 }
01468 }
01469
01470
01471
01472 template<typename eT>
01473 inline
01474 bool
01475 field_aux::save(const field< Row<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg)
01476 {
01477 arma_extra_debug_sigprint();
01478
01479 switch(type)
01480 {
01481 case arma_binary:
01482 return diskio::save_arma_binary(x, os, err_msg);
01483 break;
01484
01485 case ppm_binary:
01486 return diskio::save_ppm_binary(x, os, err_msg);
01487 break;
01488
01489 default:
01490 err_msg = " [unsupported type] filename = ";
01491 return false;
01492 }
01493 }
01494
01495
01496
01497 template<typename eT>
01498 inline
01499 bool
01500 field_aux::load(field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01501 {
01502 arma_extra_debug_sigprint();
01503
01504 switch(type)
01505 {
01506 case auto_detect:
01507 return diskio::load_auto_detect(x, name, err_msg);
01508 break;
01509
01510 case arma_binary:
01511 return diskio::load_arma_binary(x, name, err_msg);
01512 break;
01513
01514 case ppm_binary:
01515 return diskio::load_ppm_binary(x, name, err_msg);
01516 break;
01517
01518 default:
01519 err_msg = " [unsupported type] filename = ";
01520 return false;
01521 }
01522 }
01523
01524
01525
01526 template<typename eT>
01527 inline
01528 bool
01529 field_aux::load(field< Row<eT> >& x, std::istream& is, const file_type type, std::string& err_msg)
01530 {
01531 arma_extra_debug_sigprint();
01532
01533 switch(type)
01534 {
01535 case auto_detect:
01536 return diskio::load_auto_detect(x, is, err_msg);
01537 break;
01538
01539 case arma_binary:
01540 return diskio::load_arma_binary(x, is, err_msg);
01541 break;
01542
01543 case ppm_binary:
01544 return diskio::load_ppm_binary(x, is, err_msg);
01545 break;
01546
01547 default:
01548 err_msg = " [unsupported type] filename = ";
01549 return false;
01550 }
01551 }
01552
01553
01554
01555 template<typename eT>
01556 inline
01557 bool
01558 field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01559 {
01560 arma_extra_debug_sigprint();
01561
01562 switch(type)
01563 {
01564 case arma_binary:
01565 return diskio::save_arma_binary(x, name, err_msg);
01566 break;
01567
01568 case ppm_binary:
01569 return diskio::save_ppm_binary(x, name, err_msg);
01570 break;
01571
01572 default:
01573 err_msg = " [unsupported type] filename = ";
01574 return false;
01575 }
01576 }
01577
01578
01579
01580 template<typename eT>
01581 inline
01582 bool
01583 field_aux::save(const field< Cube<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg)
01584 {
01585 arma_extra_debug_sigprint();
01586
01587 switch(type)
01588 {
01589 case arma_binary:
01590 return diskio::save_arma_binary(x, os, err_msg);
01591 break;
01592
01593 case ppm_binary:
01594 return diskio::save_ppm_binary(x, os, err_msg);
01595 break;
01596
01597 default:
01598 err_msg = " [unsupported type] filename = ";
01599 return false;
01600 }
01601 }
01602
01603
01604
01605 template<typename eT>
01606 inline
01607 bool
01608 field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg)
01609 {
01610 arma_extra_debug_sigprint();
01611
01612 switch(type)
01613 {
01614 case auto_detect:
01615 return diskio::load_auto_detect(x, name, err_msg);
01616 break;
01617
01618 case arma_binary:
01619 return diskio::load_arma_binary(x, name, err_msg);
01620 break;
01621
01622 case ppm_binary:
01623 return diskio::load_ppm_binary(x, name, err_msg);
01624 break;
01625
01626 default:
01627 err_msg = " [unsupported type] filename = ";
01628 return false;
01629 }
01630 }
01631
01632
01633
01634 template<typename eT>
01635 inline
01636 bool
01637 field_aux::load(field< Cube<eT> >& x, std::istream& is, const file_type type, std::string& err_msg)
01638 {
01639 arma_extra_debug_sigprint();
01640
01641 switch(type)
01642 {
01643 case auto_detect:
01644 return diskio::load_auto_detect(x, is, err_msg);
01645 break;
01646
01647 case arma_binary:
01648 return diskio::load_arma_binary(x, is, err_msg);
01649 break;
01650
01651 case ppm_binary:
01652 return diskio::load_ppm_binary(x, is, err_msg);
01653 break;
01654
01655 default:
01656 err_msg = " [unsupported type] filename = ";
01657 return false;
01658 }
01659 }
01660
01661
01662
01663 inline
01664 bool
01665 field_aux::save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg)
01666 {
01667 arma_extra_debug_sigprint();
01668
01669 err_msg.clear();
01670
01671 return diskio::save_std_string(x, name);
01672 }
01673
01674
01675
01676 inline
01677 bool
01678 field_aux::save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg)
01679 {
01680 arma_extra_debug_sigprint();
01681
01682 err_msg.clear();
01683
01684 return diskio::save_std_string(x, os);
01685 }
01686
01687
01688
01689 inline
01690 bool
01691 field_aux::load(field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg)
01692 {
01693 arma_extra_debug_sigprint();
01694
01695 return diskio::load_std_string(x, name, err_msg);
01696 }
01697
01698
01699
01700 inline
01701 bool
01702 field_aux::load(field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg)
01703 {
01704 arma_extra_debug_sigprint();
01705
01706 return diskio::load_std_string(x, is, err_msg);
01707 }
01708
01709
01710
01711