field_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
00007 // 
00008 // This file is part of the Armadillo C++ library.
00009 // It is provided without any warranty of fitness
00010 // for any purpose. You can redistribute this file
00011 // and/or modify it under the terms of the GNU
00012 // Lesser General Public License (LGPL) as published
00013 // by the Free Software Foundation, either version 3
00014 // of the License or (at your option) any later version.
00015 // (see http://www.opensource.org/licenses for more info)
00016 
00017 
00018 //! \addtogroup field
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     // try to expose buggy user code that accesses deleted objects
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 //! construct a field from a given field
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 //! construct a field from a given field
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 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation)
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 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation)
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 //! construct the field with the specified number of elements,
00121 //! assuming a column-major layout
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 //! construct the field with the specified dimensions
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 //! change the field to have the specified number of elements,
00154 //! assuming a column-major layout (data is not preserved)
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 //! change the field to have the specified dimensions (data is not preserved)
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 //! change the field to have the specified dimensions (data is not preserved)
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 //! linear element accessor (treats the field as a vector); no bounds check
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 //! linear element accessor (treats the field as a vector); no bounds check
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 //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
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 //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
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 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
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 //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
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 //! element accessor; no bounds check
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 //! element accessor; no bounds check
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 //! creation of subview_field (row of a field)
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 //! creation of subview_field (row of a field)
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 //! creation of subview_field (column of a field)
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 //! creation of subview_field (column of a field)
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 //! creation of subview_field (subfield comprised of specified rows)
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 //! creation of subview_field (subfield comprised of specified rows)
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 //! creation of subview_field (subfield comprised of specified columns)
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 //! creation of subview_field (subfield comprised of specified columns)
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 //! creation of subview_field (subfield with arbitrary dimensions)
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 //! creation of subview_field (generic submatrix)
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 //! print contents of the field (to the cout stream),
00456 //! optionally preceding with a user specified line of text.
00457 //! the field class preserves the stream's flags
00458 //! but the associated operator<< function for type oT 
00459 //! may still modify the stream's parameters.
00460 //! NOTE: this function assumes that type oT can be printed,
00461 //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)"
00462 //! has been defined.
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 //! print contents of the field to a user specified stream,
00486 //! optionally preceding with a user specified line of text.
00487 //! the field class preserves the stream's flags
00488 //! but the associated operator<< function for type oT 
00489 //! may still modify the stream's parameters.
00490 //! NOTE: this function assumes that type oT can be printed,
00491 //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)"
00492 //! has been defined.
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 //! fill the field with an object
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 void
00560 field<oT>::save(const std::string name, const file_type type) const
00561   {
00562   arma_extra_debug_sigprint();
00563   
00564   field_aux::save(*this, name, type);
00565   }
00566 
00567 
00568 
00569 template<typename oT>
00570 inline
00571 void
00572 field<oT>::save(std::ostream& os, const file_type type) const
00573   {
00574   arma_extra_debug_sigprint();
00575   
00576   field_aux::save(*this, os, type);
00577   }
00578 
00579 
00580 
00581 template<typename oT>
00582 inline
00583 void
00584 field<oT>::load(const std::string name, const file_type type)
00585   {
00586   arma_extra_debug_sigprint();
00587   
00588   field_aux::load(*this, name, type);
00589   }
00590 
00591 
00592 
00593 template<typename oT>
00594 inline
00595 void
00596 field<oT>::load(std::istream& is, const file_type type)
00597   {
00598   arma_extra_debug_sigprint();
00599   
00600   field_aux::load(*this, is, type);
00601   }
00602 
00603 
00604 
00605 //! construct a field from a given field
00606 template<typename oT>
00607 inline
00608 void
00609 field<oT>::init(const field<oT>& x)
00610   {
00611   arma_extra_debug_sigprint();
00612   
00613   if(this != &x)
00614     {
00615     init(x.n_rows, x.n_cols);
00616     
00617     field& t = *this;
00618     
00619     for(u32 col=0; col<x.n_cols; ++col)
00620     for(u32 row=0; row<x.n_rows; ++row)
00621       {
00622       t.at(row,col) = x.at(row,col);
00623       }
00624     }
00625   
00626   }
00627 
00628 
00629 
00630 //! internal field construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new'
00631 template<typename oT>
00632 inline
00633 void
00634 field<oT>::init(const u32 n_rows_in, const u32 n_cols_in)
00635   {
00636   arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in );
00637   
00638   const u32 n_elem_new = n_rows_in * n_cols_in;
00639 
00640   if(n_elem == n_elem_new)
00641     {
00642     // delete_objects();
00643     // create_objects();
00644     access::rw(n_rows) = n_rows_in;
00645     access::rw(n_cols) = n_cols_in;
00646     }
00647   else
00648     {
00649     delete_objects();
00650     
00651     if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00652       {
00653       delete [] mem;
00654       }
00655     
00656     if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) )
00657       {
00658       mem = mem_local;
00659       }
00660     else
00661       {
00662       mem = new(std::nothrow) oT* [n_elem_new];
00663       arma_check( (mem == 0), "field::init(): out of memory" );
00664       }
00665     
00666     access::rw(n_elem) = n_elem_new;
00667     
00668     if(n_elem_new == 0)
00669       {
00670       access::rw(n_rows) = 0;
00671       access::rw(n_cols) = 0;
00672       }
00673     else
00674       {
00675       access::rw(n_rows) = n_rows_in;
00676       access::rw(n_cols) = n_cols_in;
00677       }
00678     
00679     create_objects();
00680     
00681     }
00682   
00683   }
00684 
00685 
00686 
00687 template<typename oT>
00688 inline
00689 void
00690 field<oT>::delete_objects()
00691   {
00692   arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00693   
00694   for(u32 i=0; i<n_elem; ++i)
00695     {
00696     if(mem[i] != 0)
00697       {
00698       delete mem[i];
00699       mem[i] = 0;
00700       }
00701     }
00702   
00703   }
00704 
00705 
00706 
00707 template<typename oT>
00708 inline
00709 void
00710 field<oT>::create_objects()
00711   {
00712   arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00713   
00714   for(u32 i=0; i<n_elem; ++i)
00715     {
00716     mem[i] = new oT;
00717     }
00718   
00719   }
00720 
00721 
00722 
00723 template<typename oT>
00724 inline
00725 field<oT>::iterator::iterator(field<oT>& in_M, const bool at_end)
00726   : M(in_M)
00727   , i( (at_end == false) ? 0 : in_M.n_elem )
00728   {
00729   arma_extra_debug_sigprint();
00730   }
00731 
00732 
00733 
00734 template<typename oT>
00735 inline
00736 oT&
00737 field<oT>::iterator::operator*()
00738   {
00739   return M[i];
00740   }
00741 
00742 
00743 
00744 template<typename oT>
00745 inline
00746 typename field<oT>::iterator&
00747 field<oT>::iterator::operator++()
00748   {
00749   ++i;
00750   
00751   return *this;
00752   }
00753 
00754 
00755 
00756 template<typename oT>
00757 inline
00758 void
00759 field<oT>::iterator::operator++(int)
00760   {
00761   operator++();
00762   }
00763 
00764 
00765 
00766 template<typename oT>
00767 inline
00768 typename field<oT>::iterator&
00769 field<oT>::iterator::operator--()
00770   {
00771   if(i > 0)
00772     {
00773     --i;
00774     }
00775   
00776   return *this;
00777   }
00778 
00779 
00780 
00781 template<typename oT>
00782 inline
00783 void
00784 field<oT>::iterator::operator--(int)
00785   {
00786   operator--();
00787   }
00788 
00789 
00790 
00791 template<typename oT>
00792 inline
00793 bool
00794 field<oT>::iterator::operator!=(const typename field<oT>::iterator& X) const
00795   {
00796   return (i != X.i);
00797   }
00798 
00799 
00800 
00801 template<typename oT>
00802 inline
00803 bool
00804 field<oT>::iterator::operator==(const typename field<oT>::iterator& X) const
00805   {
00806   return (i == X.i);
00807   }
00808 
00809 
00810 
00811 template<typename oT>
00812 inline
00813 field<oT>::const_iterator::const_iterator(const field<oT>& in_M, const bool at_end)
00814   : M(in_M)
00815   , i( (at_end == false) ? 0 : in_M.n_elem )
00816   {
00817   arma_extra_debug_sigprint();
00818   }
00819 
00820 
00821 
00822 template<typename oT>
00823 inline
00824 field<oT>::const_iterator::const_iterator(const typename field<oT>::iterator& X)
00825   : M(X.M)
00826   , i(X.i)
00827   {
00828   arma_extra_debug_sigprint();
00829   }
00830 
00831 
00832 
00833 template<typename oT>
00834 inline
00835 const oT&
00836 field<oT>::const_iterator::operator*() const
00837   {
00838   return M[i];
00839   }
00840 
00841 
00842 
00843 template<typename oT>
00844 inline
00845 typename field<oT>::const_iterator&
00846 field<oT>::const_iterator::operator++()
00847   {
00848   ++i;
00849   
00850   return *this;
00851   }
00852 
00853 
00854 
00855 template<typename oT>
00856 inline
00857 void
00858 field<oT>::const_iterator::operator++(int)
00859   {
00860   operator++();
00861   }
00862 
00863 
00864 
00865 template<typename oT>
00866 inline
00867 typename field<oT>::const_iterator&
00868 field<oT>::const_iterator::operator--()
00869   {
00870   if(i > 0)
00871     {
00872     --i;
00873     }
00874   
00875   return *this;
00876   }
00877 
00878 
00879 
00880 template<typename oT>
00881 inline
00882 void
00883 field<oT>::const_iterator::operator--(int)
00884   {
00885   operator--();
00886   }
00887 
00888 
00889 
00890 template<typename oT>
00891 inline
00892 bool
00893 field<oT>::const_iterator::operator!=(const typename field<oT>::const_iterator& X) const
00894   {
00895   return (i != X.i);
00896   }
00897 
00898 
00899 
00900 template<typename oT>
00901 inline
00902 bool
00903 field<oT>::const_iterator::operator==(const typename field<oT>::const_iterator& X) const
00904   {
00905   return (i == X.i);
00906   }
00907 
00908 
00909 
00910 template<typename oT>
00911 inline
00912 typename field<oT>::iterator
00913 field<oT>::begin()
00914   {
00915   arma_extra_debug_sigprint();
00916   
00917   return field<oT>::iterator(*this);
00918   }
00919 
00920 
00921 
00922 template<typename oT>
00923 inline
00924 typename field<oT>::const_iterator
00925 field<oT>::begin() const
00926   {
00927   arma_extra_debug_sigprint();
00928   
00929   return field<oT>::const_iterator(*this);
00930   }
00931 
00932 
00933 
00934 template<typename oT>
00935 inline
00936 typename field<oT>::iterator
00937 field<oT>::end()
00938   {
00939   arma_extra_debug_sigprint();
00940   
00941   return field<oT>::iterator(*this, true);
00942   }
00943 
00944 
00945 
00946 template<typename oT>
00947 inline
00948 typename field<oT>::const_iterator
00949 field<oT>::end() const
00950   {
00951   arma_extra_debug_sigprint();
00952   
00953   return field<oT>::const_iterator(*this, true);
00954   }
00955   
00956 
00957 
00958 //
00959 //
00960 //
00961 
00962 
00963 
00964 template<typename oT>
00965 inline
00966 void
00967 field_aux::reset_objects(field<oT>& x)
00968   {
00969   arma_extra_debug_sigprint();
00970   
00971   x.delete_objects();
00972   x.create_objects();
00973   }
00974 
00975 
00976 
00977 template<typename eT>
00978 inline
00979 void
00980 field_aux::reset_objects(field< Mat<eT> >& x)
00981   {
00982   arma_extra_debug_sigprint();
00983   
00984   for(u32 i=0; i<x.n_elem; ++i)
00985     {
00986     (*(x.mem[i])).reset();
00987     }
00988   }
00989 
00990 
00991 
00992 template<typename eT>
00993 inline
00994 void
00995 field_aux::reset_objects(field< Col<eT> >& x)
00996   {
00997   arma_extra_debug_sigprint();
00998   
00999   for(u32 i=0; i<x.n_elem; ++i)
01000     {
01001     (*(x.mem[i])).reset();
01002     }
01003   }
01004   
01005   
01006   
01007 template<typename eT>
01008 inline
01009 void
01010 field_aux::reset_objects(field< Row<eT> >& x)
01011   {
01012   arma_extra_debug_sigprint();
01013   
01014   for(u32 i=0; i<x.n_elem; ++i)
01015     {
01016     (*(x.mem[i])).reset();
01017     }
01018   }
01019 
01020 
01021 
01022 template<typename eT>
01023 inline
01024 void
01025 field_aux::reset_objects(field< Cube<eT> >& x)
01026   {
01027   arma_extra_debug_sigprint();
01028   
01029   for(u32 i=0; i<x.n_elem; ++i)
01030     {
01031     (*(x.mem[i])).reset();
01032     }
01033   }
01034 
01035 
01036 
01037 inline
01038 void
01039 field_aux::reset_objects(field< std::string >& x)
01040   {
01041   arma_extra_debug_sigprint();
01042   
01043   for(u32 i=0; i<x.n_elem; ++i)
01044     {
01045     (*(x.mem[i])).clear();
01046     }
01047   }
01048 
01049 
01050 
01051 //
01052 //
01053 //
01054 
01055 
01056 
01057 template<typename oT>
01058 inline
01059 void
01060 field_aux::save(const field<oT>& x, const std::string& name, const file_type type)
01061   {
01062   arma_extra_debug_sigprint();
01063   
01064   arma_print("field_aux::save(): sorry, saving this type of field is currently not supported");
01065   }
01066 
01067 
01068 
01069 template<typename oT>
01070 inline
01071 void
01072 field_aux::save(const field<oT>& x, std::ostream& os, const file_type type)
01073   {
01074   arma_extra_debug_sigprint();
01075   
01076   arma_print("field_aux::save(): sorry, saving this type of field is currently not supported");
01077   }
01078 
01079 
01080 
01081 template<typename oT>
01082 inline
01083 void
01084 field_aux::load(field<oT>& x, const std::string& name, const file_type type)
01085   {
01086   arma_extra_debug_sigprint();
01087   
01088   arma_print("field_aux::load(): sorry, loading this type of field is currently not supported");
01089   x.reset();
01090   }
01091 
01092 
01093 
01094 template<typename oT>
01095 inline
01096 void
01097 field_aux::load(field<oT>& x, std::istream& is, const file_type type)
01098   {
01099   arma_extra_debug_sigprint();
01100   
01101   arma_print("field_aux::load(): sorry, loading this type of field is currently not supported");
01102   x.reset();
01103   }
01104 
01105 
01106 
01107 template<typename eT>
01108 inline
01109 void
01110 field_aux::save(const field< Mat<eT> >& x, const std::string& name, const file_type type)
01111   {
01112   arma_extra_debug_sigprint();
01113   
01114   switch(type)
01115     {
01116     case arma_binary:
01117       diskio::save_arma_binary(x, name);
01118       break;
01119       
01120     case ppm_binary:
01121       diskio::save_ppm_binary(x, name);
01122       break;
01123     
01124     default:
01125       arma_stop("field_aux::save(): unsupported type");
01126     }
01127   }
01128 
01129 
01130 
01131 template<typename eT>
01132 inline
01133 void
01134 field_aux::save(const field< Mat<eT> >& x, std::ostream& os, const file_type type)
01135   {
01136   arma_extra_debug_sigprint();
01137   
01138   switch(type)
01139     {
01140     case arma_binary:
01141       diskio::save_arma_binary(x, "[ostream]", os);
01142       break;
01143       
01144     case ppm_binary:
01145       diskio::save_ppm_binary(x, "[ostream]", os);
01146       break;
01147     
01148     default:
01149       arma_stop("field_aux::save(): unsupported type");
01150     }
01151   }
01152 
01153 
01154 
01155 template<typename eT>
01156 inline
01157 void
01158 field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_type type)
01159   {
01160   arma_extra_debug_sigprint();
01161   
01162   switch(type)
01163     {
01164     case auto_detect:
01165       diskio::load_auto_detect(x, name);
01166       break;
01167     
01168     case arma_binary:
01169       diskio::load_arma_binary(x, name);
01170       break;
01171       
01172     case ppm_binary:
01173       diskio::load_ppm_binary(x, name);
01174       break;
01175     
01176     default:
01177       arma_stop("field_aux::load(): unsupported type");
01178     }
01179   }
01180 
01181 
01182 
01183 template<typename eT>
01184 inline
01185 void
01186 field_aux::load(field< Mat<eT> >& x, std::istream& is, const file_type type)
01187   {
01188   arma_extra_debug_sigprint();
01189   
01190   switch(type)
01191     {
01192     case auto_detect:
01193       diskio::load_auto_detect(x, "[istream]", is);
01194       break;
01195     
01196     case arma_binary:
01197       diskio::load_arma_binary(x, "[istream]", is);
01198       break;
01199       
01200     case ppm_binary:
01201       diskio::load_ppm_binary(x, "[istream]", is);
01202       break;
01203     
01204     default:
01205       arma_stop("field_aux::load(): unsupported type");
01206     }
01207   }
01208 
01209 
01210 
01211 template<typename eT>
01212 inline
01213 void
01214 field_aux::save(const field< Col<eT> >& x, const std::string& name, const file_type type)
01215   {
01216   arma_extra_debug_sigprint();
01217   
01218   switch(type)
01219     {
01220     case arma_binary:
01221       diskio::save_arma_binary(x, name);
01222       break;
01223       
01224     case ppm_binary:
01225       diskio::save_ppm_binary(x, name);
01226       break;
01227     
01228     default:
01229       arma_stop("field_aux::save(): unsupported type");
01230     }
01231   }
01232 
01233 
01234 
01235 template<typename eT>
01236 inline
01237 void
01238 field_aux::save(const field< Col<eT> >& x, std::ostream& os, const file_type type)
01239   {
01240   arma_extra_debug_sigprint();
01241   
01242   switch(type)
01243     {
01244     case arma_binary:
01245       diskio::save_arma_binary(x, "[ostream]", os);
01246       break;
01247       
01248     case ppm_binary:
01249       diskio::save_ppm_binary(x, "[ostream]", os);
01250       break;
01251     
01252     default:
01253       arma_stop("field_aux::save(): unsupported type");
01254     }
01255   }
01256 
01257 
01258 
01259 template<typename eT>
01260 inline
01261 void
01262 field_aux::load(field< Col<eT> >& x, const std::string& name, const file_type type)
01263   {
01264   arma_extra_debug_sigprint();
01265   
01266   switch(type)
01267     {
01268     case auto_detect:
01269       diskio::load_auto_detect(x, name);
01270       break;
01271     
01272     case arma_binary:
01273       diskio::load_arma_binary(x, name);
01274       break;
01275       
01276     case ppm_binary:
01277       diskio::load_ppm_binary(x, name);
01278       break;
01279     
01280     default:
01281       arma_stop("field_aux::load(): unsupported type");
01282     }
01283   }
01284 
01285 
01286 
01287 template<typename eT>
01288 inline
01289 void
01290 field_aux::load(field< Col<eT> >& x, std::istream& is, const file_type type)
01291   {
01292   arma_extra_debug_sigprint();
01293   
01294   switch(type)
01295     {
01296     case auto_detect:
01297       diskio::load_auto_detect(x, "[istream]", is);
01298       break;
01299     
01300     case arma_binary:
01301       diskio::load_arma_binary(x, "[istream]", is);
01302       break;
01303       
01304     case ppm_binary:
01305       diskio::load_ppm_binary(x, "[istream]", is);
01306       break;
01307     
01308     default:
01309       arma_stop("field_aux::load(): unsupported type");
01310     }
01311   }
01312 
01313 
01314 
01315 template<typename eT>
01316 inline
01317 void
01318 field_aux::save(const field< Row<eT> >& x, const std::string& name, const file_type type)
01319   {
01320   arma_extra_debug_sigprint();
01321   
01322   switch(type)
01323     {
01324     case arma_binary:
01325       diskio::save_arma_binary(x, name);
01326       break;
01327       
01328     case ppm_binary:
01329       diskio::save_ppm_binary(x, name);
01330       break;
01331     
01332     default:
01333       arma_stop("field_aux::save(): unsupported type");
01334     }
01335   }
01336 
01337 
01338 
01339 template<typename eT>
01340 inline
01341 void
01342 field_aux::save(const field< Row<eT> >& x, std::ostream& os, const file_type type)
01343   {
01344   arma_extra_debug_sigprint();
01345   
01346   switch(type)
01347     {
01348     case arma_binary:
01349       diskio::save_arma_binary(x, "[ostream]", os);
01350       break;
01351       
01352     case ppm_binary:
01353       diskio::save_ppm_binary(x, "[ostream]", os);
01354       break;
01355     
01356     default:
01357       arma_stop("field_aux::save(): unsupported type");
01358     }
01359   }
01360 
01361 
01362 
01363 template<typename eT>
01364 inline
01365 void
01366 field_aux::load(field< Row<eT> >& x, const std::string& name, const file_type type)
01367   {
01368   arma_extra_debug_sigprint();
01369   
01370   switch(type)
01371     {
01372     case auto_detect:
01373       diskio::load_auto_detect(x, name);
01374       break;
01375     
01376     case arma_binary:
01377       diskio::load_arma_binary(x, name);
01378       break;
01379       
01380     case ppm_binary:
01381       diskio::load_ppm_binary(x, name);
01382       break;
01383     
01384     default:
01385       arma_stop("field_aux::load(): unsupported type");
01386     }
01387   }
01388 
01389 
01390 
01391 template<typename eT>
01392 inline
01393 void
01394 field_aux::load(field< Row<eT> >& x, std::istream& is, const file_type type)
01395   {
01396   arma_extra_debug_sigprint();
01397   
01398   switch(type)
01399     {
01400     case auto_detect:
01401       diskio::load_auto_detect(x, "[istream]", is);
01402       break;
01403     
01404     case arma_binary:
01405       diskio::load_arma_binary(x, "[istream]", is);
01406       break;
01407       
01408     case ppm_binary:
01409       diskio::load_ppm_binary(x, "[istream]", is);
01410       break;
01411     
01412     default:
01413       arma_stop("field_aux::load(): unsupported type");
01414     }
01415   }
01416 
01417 
01418 
01419 template<typename eT>
01420 inline
01421 void
01422 field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type)
01423   {
01424   arma_extra_debug_sigprint();
01425   
01426   switch(type)
01427     {
01428     case arma_binary:
01429       diskio::save_arma_binary(x, name);
01430       break;
01431       
01432     case ppm_binary:
01433       diskio::save_ppm_binary(x, name);
01434       break;
01435     
01436     default:
01437       arma_stop("field_aux::save(): unsupported type");
01438     }
01439   }
01440 
01441 
01442 
01443 template<typename eT>
01444 inline
01445 void
01446 field_aux::save(const field< Cube<eT> >& x, std::ostream& os, const file_type type)
01447   {
01448   arma_extra_debug_sigprint();
01449   
01450   switch(type)
01451     {
01452     case arma_binary:
01453       diskio::save_arma_binary(x, "[ostream]", os);
01454       break;
01455       
01456     case ppm_binary:
01457       diskio::save_ppm_binary(x, "[ostream]", os);
01458       break;
01459     
01460     default:
01461       arma_stop("field_aux::save(): unsupported type");
01462     }
01463   }
01464 
01465 
01466 
01467 template<typename eT>
01468 inline
01469 void
01470 field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_type type)
01471   {
01472   arma_extra_debug_sigprint();
01473   
01474   switch(type)
01475     {
01476     case auto_detect:
01477       diskio::load_auto_detect(x, name);
01478       break;
01479     
01480     case arma_binary:
01481       diskio::load_arma_binary(x, name);
01482       break;
01483       
01484     case ppm_binary:
01485       diskio::load_ppm_binary(x, name);
01486       break;
01487     
01488     default:
01489       arma_stop("field_aux::load(): unsupported type");
01490     }
01491   }
01492 
01493 
01494 
01495 template<typename eT>
01496 inline
01497 void
01498 field_aux::load(field< Cube<eT> >& x, std::istream& is, const file_type type)
01499   {
01500   arma_extra_debug_sigprint();
01501   
01502   switch(type)
01503     {
01504     case auto_detect:
01505       diskio::load_auto_detect(x, "[istream]", is);
01506       break;
01507     
01508     case arma_binary:
01509       diskio::load_arma_binary(x, "[istream]", is);
01510       break;
01511       
01512     case ppm_binary:
01513       diskio::load_ppm_binary(x, "[istream]", is);
01514       break;
01515     
01516     default:
01517       arma_stop("field_aux::load(): unsupported type");
01518     }
01519   }
01520 
01521 
01522 
01523 inline
01524 void
01525 field_aux::save(const field< std::string >& x, const std::string& name, const file_type type)
01526   {
01527   arma_extra_debug_sigprint();
01528   
01529   diskio::save_std_string(x, name);
01530   }
01531 
01532 
01533 
01534 inline
01535 void
01536 field_aux::save(const field< std::string >& x, std::ostream& os, const file_type type)
01537   {
01538   arma_extra_debug_sigprint();
01539   
01540   diskio::save_std_string(x, "[ostream]", os);
01541   }
01542 
01543 
01544 
01545 inline
01546 void
01547 field_aux::load(field< std::string >& x, const std::string& name, const file_type type)
01548   {
01549   arma_extra_debug_sigprint();
01550   
01551   diskio::load_std_string(x, name);
01552   }
01553 
01554 
01555 
01556 inline
01557 void
01558 field_aux::load(field< std::string >& x, std::istream& is, const file_type type)
01559   {
01560   arma_extra_debug_sigprint();
01561   
01562   diskio::load_std_string(x, "[istream]", is);
01563   }
01564 
01565 
01566 
01567 //! @}