field_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup field
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     // try to expose buggy user code that accesses deleted objects
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 //! construct a field from a given field
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 //! construct a field from a given field
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 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation)
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 //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation)
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 //! construct the field with the specified number of elements,
00119 //! assuming a column-major layout
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 //! construct the field with the specified dimensions
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 //! change the field to have the specified number of elements,
00152 //! assuming a column-major layout (data is not preserved)
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 //! change the field to have the specified dimensions (data is not preserved)
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 //! change the field to have the specified dimensions (data is not preserved)
00179 template<typename oT>
00180 inline
00181 void
00182 field<oT>::copy_size(const field<oT>& x)
00183   {
00184   arma_extra_debug_sigprint();
00185   
00186   if(this != &x)
00187     {
00188     init(x.n_rows, x.n_cols);
00189     }
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>::load(const std::string name, const file_type type)
00573   {
00574   arma_extra_debug_sigprint();
00575   
00576   field_aux::load(*this, name, type);
00577   }
00578 
00579 
00580 
00581 //! construct a field from a given field
00582 template<typename oT>
00583 inline
00584 void
00585 field<oT>::init(const field<oT>& x)
00586   {
00587   arma_extra_debug_sigprint();
00588   
00589   if(this != &x)
00590     {
00591     init(x.n_rows, x.n_cols);
00592     
00593     field& t = *this;
00594     
00595     for(u32 col=0; col<x.n_cols; ++col)
00596     for(u32 row=0; row<x.n_rows; ++row)
00597       {
00598       t.at(row,col) = x.at(row,col);
00599       }
00600     }
00601   
00602   }
00603 
00604 
00605 
00606 //! internal field construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new'
00607 template<typename oT>
00608 inline
00609 void
00610 field<oT>::init(const u32 n_rows_in, const u32 n_cols_in)
00611   {
00612   arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in );
00613   
00614   const u32 n_elem_new = n_rows_in * n_cols_in;
00615 
00616   if(n_elem == n_elem_new)
00617     {
00618     // delete_objects();
00619     // create_objects();
00620     access::rw(n_rows) = n_rows_in;
00621     access::rw(n_cols) = n_cols_in;
00622     }
00623   else
00624     {
00625     delete_objects();
00626     
00627     if(n_elem > sizeof(mem_local)/sizeof(oT*) )
00628       {
00629       delete [] mem;
00630       }
00631     
00632     if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) )
00633       {
00634       mem = mem_local;
00635       }
00636     else
00637       {
00638       mem = new(std::nothrow) oT* [n_elem_new];
00639       arma_check( (mem == 0), "field::init(): out of memory" );
00640       }
00641     
00642     access::rw(n_elem) = n_elem_new;
00643     
00644     if(n_elem_new == 0)
00645       {
00646       access::rw(n_rows) = 0;
00647       access::rw(n_cols) = 0;
00648       }
00649     else
00650       {
00651       access::rw(n_rows) = n_rows_in;
00652       access::rw(n_cols) = n_cols_in;
00653       }
00654     
00655     create_objects();
00656     
00657     }
00658   
00659   }
00660 
00661 
00662 
00663 template<typename oT>
00664 inline
00665 void
00666 field<oT>::delete_objects()
00667   {
00668   arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00669   
00670   for(u32 i=0; i<n_elem; ++i)
00671     {
00672     if(mem[i] != 0)
00673       {
00674       delete mem[i];
00675       mem[i] = 0;
00676       }
00677     }
00678   
00679   }
00680 
00681 
00682 
00683 template<typename oT>
00684 inline
00685 void
00686 field<oT>::create_objects()
00687   {
00688   arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem );
00689   
00690   for(u32 i=0; i<n_elem; ++i)
00691     {
00692     mem[i] = new oT;
00693     }
00694   
00695   }
00696 
00697 
00698 
00699 //
00700 //
00701 //
00702 
00703 
00704 
00705 template<typename oT>
00706 inline
00707 void
00708 field_aux::reset_objects(field<oT>& x)
00709   {
00710   arma_extra_debug_sigprint();
00711   
00712   x.delete_objects();
00713   x.create_objects();
00714   }
00715 
00716 
00717 
00718 template<typename eT>
00719 inline
00720 void
00721 field_aux::reset_objects(field< Mat<eT> >& x)
00722   {
00723   arma_extra_debug_sigprint();
00724   
00725   for(u32 i=0; i<x.n_elem; ++i)
00726     {
00727     (*(x.mem[i])).reset();
00728     }
00729   }
00730 
00731 
00732 
00733 template<typename eT>
00734 inline
00735 void
00736 field_aux::reset_objects(field< Col<eT> >& x)
00737   {
00738   arma_extra_debug_sigprint();
00739   
00740   for(u32 i=0; i<x.n_elem; ++i)
00741     {
00742     (*(x.mem[i])).reset();
00743     }
00744   }
00745   
00746   
00747   
00748 template<typename eT>
00749 inline
00750 void
00751 field_aux::reset_objects(field< Row<eT> >& x)
00752   {
00753   arma_extra_debug_sigprint();
00754   
00755   for(u32 i=0; i<x.n_elem; ++i)
00756     {
00757     (*(x.mem[i])).reset();
00758     }
00759   }
00760 
00761 
00762 
00763 template<typename eT>
00764 inline
00765 void
00766 field_aux::reset_objects(field< Cube<eT> >& x)
00767   {
00768   arma_extra_debug_sigprint();
00769   
00770   for(u32 i=0; i<x.n_elem; ++i)
00771     {
00772     (*(x.mem[i])).reset();
00773     }
00774   }
00775 
00776 
00777 
00778 inline
00779 void
00780 field_aux::reset_objects(field< std::string >& x)
00781   {
00782   arma_extra_debug_sigprint();
00783   
00784   for(u32 i=0; i<x.n_elem; ++i)
00785     {
00786     (*(x.mem[i])).clear();
00787     }
00788   }
00789 
00790 
00791 
00792 //
00793 //
00794 //
00795 
00796 
00797 
00798 template<typename oT>
00799 inline
00800 void
00801 field_aux::save(const field<oT>& x, const std::string& name, const file_type type)
00802   {
00803   arma_extra_debug_sigprint();
00804   
00805   arma_print("field_aux::save(): sorry, saving this type of field is currently not supported");
00806   }
00807 
00808 
00809 
00810 template<typename oT>
00811 inline
00812 void
00813 field_aux::load(field<oT>& x, const std::string& name, const file_type type)
00814   {
00815   arma_extra_debug_sigprint();
00816   
00817   arma_print("field_aux::load(): sorry, loading this type of field is currently not supported");
00818   x.reset();
00819   }
00820 
00821 
00822 
00823 template<typename eT>
00824 inline
00825 void
00826 field_aux::save(const field< Mat<eT> >& x, const std::string& name, const file_type type)
00827   {
00828   arma_extra_debug_sigprint();
00829   
00830   switch(type)
00831     {
00832     case arma_binary:
00833       diskio::save_arma_binary(x, name);
00834       break;
00835       
00836     case ppm_binary:
00837       diskio::save_ppm_binary(x, name);
00838       break;
00839     
00840     default:
00841       arma_stop("field_aux::save(): unsupported type");
00842     }
00843   }
00844 
00845 
00846 
00847 template<typename eT>
00848 inline
00849 void
00850 field_aux::load(field< Mat<eT> >& x, const std::string& name, const file_type type)
00851   {
00852   arma_extra_debug_sigprint();
00853   
00854   switch(type)
00855     {
00856     case auto_detect:
00857       diskio::load_auto_detect(x, name);
00858       break;
00859     
00860     case arma_binary:
00861       diskio::load_arma_binary(x, name);
00862       break;
00863       
00864     case ppm_binary:
00865       diskio::load_ppm_binary(x, name);
00866       break;
00867     
00868     default:
00869       arma_stop("field_aux::load(): unsupported type");
00870     }
00871   }
00872 
00873 
00874 
00875 template<typename eT>
00876 inline
00877 void
00878 field_aux::save(const field< Col<eT> >& x, const std::string& name, const file_type type)
00879   {
00880   arma_extra_debug_sigprint();
00881   
00882   switch(type)
00883     {
00884     case arma_binary:
00885       diskio::save_arma_binary(x, name);
00886       break;
00887       
00888     case ppm_binary:
00889       diskio::save_ppm_binary(x, name);
00890       break;
00891     
00892     default:
00893       arma_stop("field_aux::save(): unsupported type");
00894     }
00895   }
00896 
00897 
00898 
00899 template<typename eT>
00900 inline
00901 void
00902 field_aux::load(field< Col<eT> >& x, const std::string& name, const file_type type)
00903   {
00904   arma_extra_debug_sigprint();
00905   
00906   switch(type)
00907     {
00908     case auto_detect:
00909       diskio::load_auto_detect(x, name);
00910       break;
00911     
00912     case arma_binary:
00913       diskio::load_arma_binary(x, name);
00914       break;
00915       
00916     case ppm_binary:
00917       diskio::load_ppm_binary(x, name);
00918       break;
00919     
00920     default:
00921       arma_stop("field_aux::load(): unsupported type");
00922     }
00923   }
00924 
00925 
00926 
00927 template<typename eT>
00928 inline
00929 void
00930 field_aux::save(const field< Row<eT> >& x, const std::string& name, const file_type type)
00931   {
00932   arma_extra_debug_sigprint();
00933   
00934   switch(type)
00935     {
00936     case arma_binary:
00937       diskio::save_arma_binary(x, name);
00938       break;
00939       
00940     case ppm_binary:
00941       diskio::save_ppm_binary(x, name);
00942       break;
00943     
00944     default:
00945       arma_stop("field_aux::save(): unsupported type");
00946     }
00947   }
00948 
00949 
00950 
00951 template<typename eT>
00952 inline
00953 void
00954 field_aux::load(field< Row<eT> >& x, const std::string& name, const file_type type)
00955   {
00956   arma_extra_debug_sigprint();
00957   
00958   switch(type)
00959     {
00960     case auto_detect:
00961       diskio::load_auto_detect(x, name);
00962       break;
00963     
00964     case arma_binary:
00965       diskio::load_arma_binary(x, name);
00966       break;
00967       
00968     case ppm_binary:
00969       diskio::load_ppm_binary(x, name);
00970       break;
00971     
00972     default:
00973       arma_stop("field_aux::load(): unsupported type");
00974     }
00975   }
00976 
00977 
00978 
00979 template<typename eT>
00980 inline
00981 void
00982 field_aux::save(const field< Cube<eT> >& x, const std::string& name, const file_type type)
00983   {
00984   arma_extra_debug_sigprint();
00985   
00986   switch(type)
00987     {
00988     case arma_binary:
00989       diskio::save_arma_binary(x, name);
00990       break;
00991       
00992     case ppm_binary:
00993       diskio::save_ppm_binary(x, name);
00994       break;
00995     
00996     default:
00997       arma_stop("field_aux::save(): unsupported type");
00998     }
00999   }
01000 
01001 
01002 
01003 template<typename eT>
01004 inline
01005 void
01006 field_aux::load(field< Cube<eT> >& x, const std::string& name, const file_type type)
01007   {
01008   arma_extra_debug_sigprint();
01009   
01010   switch(type)
01011     {
01012     case auto_detect:
01013       diskio::load_auto_detect(x, name);
01014       break;
01015     
01016     case arma_binary:
01017       diskio::load_arma_binary(x, name);
01018       break;
01019       
01020     case ppm_binary:
01021       diskio::load_ppm_binary(x, name);
01022       break;
01023     
01024     default:
01025       arma_stop("field_aux::load(): unsupported type");
01026     }
01027   }
01028 
01029 
01030 
01031 inline
01032 void
01033 field_aux::save(const field< std::string >& x, const std::string& name, const file_type type)
01034   {
01035   arma_extra_debug_sigprint();
01036   
01037   diskio::save_std_string(x, name);
01038   }
01039 
01040 
01041 
01042 inline
01043 void
01044 field_aux::load(field< std::string >& x, const std::string& name, const file_type type)
01045   {
01046   arma_extra_debug_sigprint();
01047   
01048   diskio::load_std_string(x, name);
01049   }
01050 
01051 
01052 
01053 //! @}