00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 template<typename oT>
00021 inline
00022 field<oT>::~field()
00023 {
00024 arma_extra_debug_sigprint_this(this);
00025
00026 delete_objects();
00027
00028 if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00029 {
00030 delete [] mem;
00031 }
00032
00033 if(arma_config::debug == true)
00034 {
00035
00036 access::rw(n_rows) = 0;
00037 access::rw(n_cols) = 0;
00038 access::rw(n_elem) = 0;
00039 mem = 0;
00040 }
00041 }
00042
00043
00044
00045 template<typename oT>
00046 inline
00047 field<oT>::field()
00048 : n_rows(0)
00049 , n_cols(0)
00050 , n_elem(0)
00051 , mem(0)
00052 {
00053 arma_extra_debug_sigprint_this(this);
00054 }
00055
00056
00057
00058
00059 template<typename oT>
00060 inline
00061 field<oT>::field(const field& x)
00062 : n_rows(0)
00063 , n_cols(0)
00064 , n_elem(0)
00065 , mem(0)
00066 {
00067 arma_extra_debug_sigprint(arma_boost::format("this = %x x = %x") % this % &x);
00068
00069 init(x);
00070 }
00071
00072
00073
00074
00075 template<typename oT>
00076 inline
00077 const field<oT>&
00078 field<oT>::operator=(const field& x)
00079 {
00080 arma_extra_debug_sigprint();
00081
00082 init(x);
00083 return *this;
00084 }
00085
00086
00087
00088
00089 template<typename oT>
00090 inline
00091 field<oT>::field(const subview_field<oT>& X)
00092 : n_rows(0)
00093 , n_cols(0)
00094 , n_elem(0)
00095 , mem(0)
00096 {
00097 arma_extra_debug_sigprint_this(this);
00098
00099 this->operator=(X);
00100 }
00101
00102
00103
00104
00105 template<typename oT>
00106 inline
00107 const field<oT>&
00108 field<oT>::operator=(const subview_field<oT>& X)
00109 {
00110 arma_extra_debug_sigprint();
00111
00112 subview_field<oT>::extract(*this, X);
00113 return *this;
00114 }
00115
00116
00117
00118
00119
00120 template<typename oT>
00121 inline
00122 field<oT>::field(const u32 n_elem_in)
00123 : n_rows(0)
00124 , n_cols(0)
00125 , n_elem(0)
00126 , mem(0)
00127 {
00128 arma_extra_debug_sigprint_this(this);
00129
00130 init(n_elem_in, 1);
00131 }
00132
00133
00134
00135
00136 template<typename oT>
00137 inline
00138 field<oT>::field(const u32 n_rows_in, const u32 n_cols_in)
00139 : n_rows(0)
00140 , n_cols(0)
00141 , n_elem(0)
00142 , mem(0)
00143 {
00144 arma_extra_debug_sigprint_this(this);
00145
00146 init(n_rows_in, n_cols_in);
00147 }
00148
00149
00150
00151
00152
00153 template<typename oT>
00154 inline
00155 void
00156 field<oT>::set_size(const u32 n_elem_in)
00157 {
00158 arma_extra_debug_sigprint(arma_boost::format("n_elem_in = %d") % n_elem_in);
00159
00160 init(n_elem_in, 1);
00161 }
00162
00163
00164
00165
00166 template<typename oT>
00167 inline
00168 void
00169 field<oT>::set_size(const u32 n_rows_in, const u32 n_cols_in)
00170 {
00171 arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in);
00172
00173 init(n_rows_in, n_cols_in);
00174 }
00175
00176
00177
00178
00179 template<typename oT>
00180 arma_inline
00181 oT&
00182 field<oT>::operator[] (const u32 i)
00183 {
00184 return (*mem[i]);
00185 }
00186
00187
00188
00189
00190 template<typename oT>
00191 arma_inline
00192 const oT&
00193 field<oT>::operator[] (const u32 i) const
00194 {
00195 return (*mem[i]);
00196 }
00197
00198
00199
00200 template<typename oT>
00201 arma_inline
00202 oT&
00203 field<oT>::operator() (const u32 i)
00204 {
00205 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds");
00206 return (*mem[i]);
00207 }
00208
00209
00210
00211
00212 template<typename oT>
00213 arma_inline
00214 const oT&
00215 field<oT>::operator() (const u32 i) const
00216 {
00217 arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds");
00218 return (*mem[i]);
00219 }
00220
00221
00222
00223
00224 template<typename oT>
00225 arma_inline
00226 oT&
00227 field<oT>::operator() (const u32 in_row, const u32 in_col)
00228 {
00229 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds");
00230 return (*mem[in_row + in_col*n_rows]);
00231 }
00232
00233
00234
00235
00236 template<typename oT>
00237 arma_inline
00238 const oT&
00239 field<oT>::operator() (const u32 in_row, const u32 in_col) const
00240 {
00241 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds");
00242 return (*mem[in_row + in_col*n_rows]);
00243 }
00244
00245
00246
00247
00248 template<typename oT>
00249 arma_inline
00250 oT&
00251 field<oT>::at(const u32 in_row, const u32 in_col)
00252 {
00253 return (*mem[in_row + in_col*n_rows]);
00254 }
00255
00256
00257
00258
00259 template<typename oT>
00260 arma_inline
00261 const oT&
00262 field<oT>::at(const u32 in_row, const u32 in_col) const
00263 {
00264 return (*mem[in_row + in_col*n_rows]);
00265 }
00266
00267
00268
00269
00270 template<typename oT>
00271 inline
00272 subview_field<oT>
00273 field<oT>::row(const u32 row_num)
00274 {
00275 arma_extra_debug_sigprint();
00276
00277 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" );
00278 return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1);
00279 }
00280
00281
00282
00283
00284 template<typename oT>
00285 inline
00286 const subview_field<oT>
00287 field<oT>::row(const u32 row_num) const
00288 {
00289 arma_extra_debug_sigprint();
00290
00291 arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" );
00292 return subview_field<oT>(*this, row_num, 0, row_num, n_cols-1);
00293 }
00294
00295
00296
00297
00298 template<typename oT>
00299 inline
00300 subview_field<oT>
00301 field<oT>::col(const u32 col_num)
00302 {
00303 arma_extra_debug_sigprint();
00304
00305 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds");
00306 return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num);
00307 }
00308
00309
00310
00311
00312 template<typename oT>
00313 inline
00314 const subview_field<oT>
00315 field<oT>::col(const u32 col_num) const
00316 {
00317 arma_extra_debug_sigprint();
00318
00319 arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds");
00320 return subview_field<oT>(*this, 0, col_num, n_rows-1, col_num);
00321 }
00322
00323
00324
00325
00326 template<typename oT>
00327 inline
00328 subview_field<oT>
00329 field<oT>::rows(const u32 in_row1, const u32 in_row2)
00330 {
00331 arma_extra_debug_sigprint();
00332
00333 arma_debug_check
00334 (
00335 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ),
00336 "field::rows(): indicies out of bounds or incorrectly used"
00337 );
00338
00339 return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1);
00340 }
00341
00342
00343
00344
00345 template<typename oT>
00346 inline
00347 const subview_field<oT>
00348 field<oT>::rows(const u32 in_row1, const u32 in_row2) const
00349 {
00350 arma_extra_debug_sigprint();
00351
00352 arma_debug_check
00353 (
00354 ( (in_row1 > in_row2) || (in_row2 >= n_rows) ),
00355 "field::rows(): indicies out of bounds or incorrectly used"
00356 );
00357
00358 return subview_field<oT>(*this, in_row1, 0, in_row2, n_cols-1);
00359 }
00360
00361
00362
00363
00364 template<typename oT>
00365 inline
00366 subview_field<oT>
00367 field<oT>::cols(const u32 in_col1, const u32 in_col2)
00368 {
00369 arma_extra_debug_sigprint();
00370
00371 arma_debug_check
00372 (
00373 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ),
00374 "field::cols(): indicies out of bounds or incorrectly used"
00375 );
00376
00377 return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2);
00378 }
00379
00380
00381
00382
00383 template<typename oT>
00384 inline
00385 const subview_field<oT>
00386 field<oT>::cols(const u32 in_col1, const u32 in_col2) const
00387 {
00388 arma_extra_debug_sigprint();
00389
00390 arma_debug_check
00391 (
00392 ( (in_col1 > in_col2) || (in_col2 >= n_cols) ),
00393 "field::cols(): indicies out of bounds or incorrectly used"
00394 );
00395
00396 return subview_field<oT>(*this, 0, in_col1, n_rows-1, in_col2);
00397 }
00398
00399
00400
00401
00402 template<typename oT>
00403 inline
00404 subview_field<oT>
00405 field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
00406 {
00407 arma_extra_debug_sigprint();
00408
00409 arma_debug_check
00410 (
00411 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
00412 "field::subfield(): indices out of bounds or incorrectly used"
00413 );
00414
00415 return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2);
00416 }
00417
00418
00419
00420
00421 template<typename oT>
00422 inline
00423 const subview_field<oT>
00424 field<oT>::subfield(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2) const
00425 {
00426 arma_extra_debug_sigprint();
00427
00428 arma_debug_check
00429 (
00430 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
00431 "field::subfield(): indices out of bounds or incorrectly used"
00432 );
00433
00434 return subview_field<oT>(*this, in_row1, in_col1, in_row2, in_col2);
00435 }
00436
00437
00438
00439
00440 template<typename oT>
00441 inline
00442 void
00443 field<oT>::print(const std::string extra_text) const
00444 {
00445 arma_extra_debug_sigprint();
00446
00447 if(extra_text.length() != 0)
00448 {
00449 cout << extra_text << '\n';
00450 }
00451
00452 cout << *this << '\n';
00453 }
00454
00455
00456
00457
00458 template<typename oT>
00459 inline
00460 void
00461 field<oT>::fill(const oT& x)
00462 {
00463 arma_extra_debug_sigprint();
00464
00465 field<oT>& t = *this;
00466
00467 for(u32 i=0; i<n_elem; ++i)
00468 {
00469 t[i] = x;
00470 }
00471 }
00472
00473
00474
00475 template<typename oT>
00476 inline
00477 void
00478 field<oT>::reset()
00479 {
00480 arma_extra_debug_sigprint();
00481
00482 init(0,0);
00483 }
00484
00485
00486
00487 template<typename oT>
00488 inline
00489 void
00490 field<oT>::reset_objects()
00491 {
00492 arma_extra_debug_sigprint();
00493
00494 field_aux::reset_objects(*this);
00495 }
00496
00497
00498
00499 template<typename oT>
00500 inline
00501 void
00502 field<oT>::save(const std::string name, const file_type type) const
00503 {
00504 arma_extra_debug_sigprint();
00505
00506 field_aux::save(*this, name, type);
00507 }
00508
00509
00510
00511 template<typename oT>
00512 inline
00513 void
00514 field<oT>::load(const std::string name, const file_type type)
00515 {
00516 arma_extra_debug_sigprint();
00517
00518 field_aux::load(*this, name, type);
00519 }
00520
00521
00522
00523
00524 template<typename oT>
00525 inline
00526 void
00527 field<oT>::init(const field<oT>& x)
00528 {
00529 arma_extra_debug_sigprint();
00530
00531 if(this != &x)
00532 {
00533 init(x.n_rows, x.n_cols);
00534
00535 field& t = *this;
00536
00537 for(u32 col=0; col<x.n_cols; ++col)
00538 for(u32 row=0; row<x.n_rows; ++row)
00539 {
00540 t.at(row,col) = x.at(row,col);
00541 }
00542 }
00543
00544 }
00545
00546
00547
00548
00549 template<typename oT>
00550 inline
00551 void
00552 field<oT>::init(const u32 n_rows_in, const u32 n_cols_in)
00553 {
00554 arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in );
00555
00556 const u32 n_elem_new = n_rows_in * n_cols_in;
00557
00558 if(n_elem == n_elem_new)
00559 {
00560
00561
00562 access::rw(n_rows) = n_rows_in;
00563 access::rw(n_cols) = n_cols_in;
00564 }
00565 else
00566 {
00567 delete_objects();
00568
00569 if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00570 {
00571 delete [] mem;
00572 }
00573
00574 if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) )
00575 {
00576 mem = mem_local;
00577 }
00578 else
00579 {
00580 mem = new(std::nothrow) oT* [n_elem_new];
00581 arma_check( (mem == 0), "field::init(): out of memory" );
00582 }
00583
00584 access::rw(n_elem) = n_elem_new;
00585
00586 if(n_elem_new == 0)
00587 {
00588 access::rw(n_rows) = 0;
00589 access::rw(n_cols) = 0;
00590 }
00591 else
00592 {
00593 access::rw(n_rows) = n_rows_in;
00594 access::rw(n_cols) = n_cols_in;
00595 }
00596
00597 create_objects();
00598
00599 }
00600
00601 }
00602
00603
00604
00605 template<typename oT>
00606 inline
00607 void
00608 field<oT>::delete_objects()
00609 {
00610 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00611
00612 for(u32 i=0; i<n_elem; ++i)
00613 {
00614 if(mem[i] != 0)
00615 {
00616 delete mem[i];
00617 mem[i] = 0;
00618 }
00619 }
00620
00621 }
00622
00623
00624
00625 template<typename oT>
00626 inline
00627 void
00628 field<oT>::create_objects()
00629 {
00630 arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00631
00632 for(u32 i=0; i<n_elem; ++i)
00633 {
00634 mem[i] = new oT;
00635 }
00636
00637 }
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 template<typename oT>
00648 inline
00649 void
00650 field_aux::reset_objects(field<oT>& x)
00651 {
00652 arma_extra_debug_sigprint();
00653
00654 x.delete_objects();
00655 x.create_objects();
00656 }
00657
00658
00659
00660 template<typename eT>
00661 inline
00662 void
00663 field_aux::reset_objects(field< Mat<eT> >& x)
00664 {
00665 arma_extra_debug_sigprint();
00666
00667 for(u32 i=0; i<x.n_elem; ++i)
00668 {
00669 (*(x.mem[i])).reset();
00670 }
00671 }
00672
00673
00674
00675 template<typename eT>
00676 inline
00677 void
00678 field_aux::reset_objects(field< Col<eT> >& x)
00679 {
00680 arma_extra_debug_sigprint();
00681
00682 for(u32 i=0; i<x.n_elem; ++i)
00683 {
00684 (*(x.mem[i])).reset();
00685 }
00686 }
00687
00688
00689
00690 template<typename eT>
00691 inline
00692 void
00693 field_aux::reset_objects(field< Row<eT> >& x)
00694 {
00695 arma_extra_debug_sigprint();
00696
00697 for(u32 i=0; i<x.n_elem; ++i)
00698 {
00699 (*(x.mem[i])).reset();
00700 }
00701 }
00702
00703
00704
00705 inline
00706 void
00707 field_aux::reset_objects(field< std::string >& x)
00708 {
00709 arma_extra_debug_sigprint();
00710
00711 for(u32 i=0; i<x.n_elem; ++i)
00712 {
00713 (*(x.mem[i])).clear();
00714 }
00715 }
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725 template<typename oT>
00726 inline
00727 void
00728 field_aux::save(const field<oT>& x, const std::string& name, const file_type type)
00729 {
00730 arma_extra_debug_sigprint();
00731
00732 arma_print("field_aux::save(): sorry, saving this type of field is currently not supported");
00733 }
00734
00735
00736
00737 template<typename oT>
00738 inline
00739 void
00740 field_aux::load(field<oT>& x, const std::string& name, const file_type type)
00741 {
00742 arma_extra_debug_sigprint();
00743
00744 arma_print("field_aux::load(): sorry, loading this type of field is currently not supported");
00745 x.reset();
00746 }
00747
00748
00749
00750 template<typename eT>
00751 inline
00752 void
00753 field_aux::save(const field< Mat<eT> >& x, const std::string& name, const file_type type)
00754 {
00755 arma_extra_debug_sigprint();
00756
00757 switch(type)
00758 {
00759 case arma_binary:
00760 diskio::save_field_arma_binary(x, name);
00761 break;
00762
00763 case ppm_binary:
00764 diskio::save_field_ppm_binary(x, name);
00765 break;
00766
00767 default:
00768 arma_stop("field_aux::save(): unsupported type");
00769 }
00770 }
00771
00772
00773
00774 template<typename eT>
00775 inline
00776 void
00777 field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_type type)
00778 {
00779 arma_extra_debug_sigprint();
00780
00781 switch(type)
00782 {
00783 case auto_detect:
00784 diskio::load_field_auto_detect(x, name);
00785 break;
00786
00787 case arma_binary:
00788 diskio::load_field_arma_binary(x, name);
00789 break;
00790
00791 case ppm_binary:
00792 diskio::load_field_ppm_binary(x, name);
00793 break;
00794
00795 default:
00796 arma_stop("field_aux::load(): unsupported type");
00797 }
00798 }
00799
00800
00801
00802 template<typename eT>
00803 inline
00804 void
00805 field_aux::save(const field< Col<eT> >& x, const std::string& name, const file_type type)
00806 {
00807 arma_extra_debug_sigprint();
00808
00809 switch(type)
00810 {
00811 case arma_binary:
00812 diskio::save_field_arma_binary(x, name);
00813 break;
00814
00815 case ppm_binary:
00816 diskio::save_field_ppm_binary(x, name);
00817 break;
00818
00819 default:
00820 arma_stop("field_aux::save(): unsupported type");
00821 }
00822 }
00823
00824
00825
00826 template<typename eT>
00827 inline
00828 void
00829 field_aux::load(field< Col<eT> >& x, const std::string& name, const file_type type)
00830 {
00831 arma_extra_debug_sigprint();
00832
00833 switch(type)
00834 {
00835 case auto_detect:
00836 diskio::load_field_auto_detect(x, name);
00837 break;
00838
00839 case arma_binary:
00840 diskio::load_field_arma_binary(x, name);
00841 break;
00842
00843 case ppm_binary:
00844 diskio::load_field_ppm_binary(x, name);
00845 break;
00846
00847 default:
00848 arma_stop("field_aux::load(): unsupported type");
00849 }
00850 }
00851
00852
00853
00854 template<typename eT>
00855 inline
00856 void
00857 field_aux::save(const field< Row<eT> >& x, const std::string& name, const file_type type)
00858 {
00859 arma_extra_debug_sigprint();
00860
00861 switch(type)
00862 {
00863 case arma_binary:
00864 diskio::save_field_arma_binary(x, name);
00865 break;
00866
00867 case ppm_binary:
00868 diskio::save_field_ppm_binary(x, name);
00869 break;
00870
00871 default:
00872 arma_stop("field_aux::save(): unsupported type");
00873 }
00874 }
00875
00876
00877
00878 template<typename eT>
00879 inline
00880 void
00881 field_aux::load(field< Row<eT> >& x, const std::string& name, const file_type type)
00882 {
00883 arma_extra_debug_sigprint();
00884
00885 switch(type)
00886 {
00887 case auto_detect:
00888 diskio::load_field_auto_detect(x, name);
00889 break;
00890
00891 case arma_binary:
00892 diskio::load_field_arma_binary(x, name);
00893 break;
00894
00895 case ppm_binary:
00896 diskio::load_field_ppm_binary(x, name);
00897 break;
00898
00899 default:
00900 arma_stop("field_aux::load(): unsupported type");
00901 }
00902 }
00903
00904
00905
00906 inline
00907 void
00908 field_aux::save(const field< std::string >& x, const std::string& name, const file_type type)
00909 {
00910 arma_extra_debug_sigprint();
00911
00912 diskio::save_field_std_string(x, name);
00913 }
00914
00915
00916
00917 inline
00918 void
00919 field_aux::load(field< std::string >& x, const std::string& name, const file_type type)
00920 {
00921 arma_extra_debug_sigprint();
00922
00923 diskio::load_field_std_string(x, name);
00924 }
00925
00926
00927
00928