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