Subview_field

Classes

class  subview_field< oT >
 Class for storing data required to construct or apply operations to a subfield (i.e. where the subfield starts and ends as well as a reference/pointer to the original field),. More...

Functions

 subview_field::~subview_field ()
arma_inline subview_field::subview_field (const field< oT > &in_f, const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
arma_inline subview_field::subview_field (field< oT > &in_f, const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
void subview_field::operator= (const field< oT > &x)
void subview_field::operator= (const subview_field &x)
 x.subfield(...) = y.subfield(...)
arma_inline oT & subview_field::operator[] (const u32 i)
arma_inline const oT & subview_field::operator[] (const u32 i) const
arma_inline oT & subview_field::operator() (const u32 i)
arma_inline const oT & subview_field::operator() (const u32 i) const
arma_inline oT & subview_field::operator() (const u32 row, const u32 col)
arma_inline const oT & subview_field::operator() (const u32 row, const u32 col) const
arma_inline oT & subview_field::at (const u32 row, const u32 col)
arma_inline const oT & subview_field::at (const u32 row, const u32 col) const
bool subview_field::check_overlap (const subview_field &x) const
static void subview_field::extract (field< oT > &out, const subview_field &in)
 X = Y.subfield(...).

Function Documentation

template<typename oT >
subview_field< oT >::~subview_field (  )  [inline, inherited]

Definition at line 23 of file subview_field_meat.hpp.

00024   {
00025   arma_extra_debug_sigprint();
00026   }

template<typename oT >
arma_inline subview_field< oT >::subview_field ( const field< oT > &  in_f,
const u32  in_row1,
const u32  in_col1,
const u32  in_row2,
const u32  in_col2 
) [inline, protected, inherited]

Definition at line 33 of file subview_field_meat.hpp.

00040   : f(in_f)
00041   , f_ptr(0)
00042   , aux_row1(in_row1)
00043   , aux_col1(in_col1)
00044   , aux_row2(in_row2)
00045   , aux_col2(in_col2)
00046   , n_rows(1 + in_row2 - in_row1)
00047   , n_cols(1 + in_col2 - in_col1)
00048   , n_elem(n_rows*n_cols)
00049   {
00050   arma_extra_debug_sigprint();
00051   }

template<typename oT >
arma_inline subview_field< oT >::subview_field ( field< oT > &  in_f,
const u32  in_row1,
const u32  in_col1,
const u32  in_row2,
const u32  in_col2 
) [inline, protected, inherited]

Definition at line 58 of file subview_field_meat.hpp.

00065   : f(in_f)
00066   , f_ptr(&in_f)
00067   , aux_row1(in_row1)
00068   , aux_col1(in_col1)
00069   , aux_row2(in_row2)
00070   , aux_col2(in_col2)
00071   , n_rows(1 + in_row2 - in_row1)
00072   , n_cols(1 + in_col2 - in_col1)
00073   , n_elem(n_rows*n_cols)
00074   {
00075   arma_extra_debug_sigprint();
00076   }

template<typename oT >
void subview_field< oT >::operator= ( const field< oT > &  x  )  [inline, inherited]

Definition at line 83 of file subview_field_meat.hpp.

References field< oT >::at(), subview_field< oT >::at(), field< oT >::n_cols, subview_field< oT >::n_cols, field< oT >::n_rows, and subview_field< oT >::n_rows.

00084   {
00085   arma_extra_debug_sigprint();
00086   
00087   subview_field<oT>& t = *this;
00088   
00089   arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
00090   
00091   for(u32 col=0; col<t.n_cols; ++col)
00092     {
00093     for(u32 row=0; row<t.n_rows; ++row)
00094       {
00095       t.at(row,col) = x.at(row,col);
00096       }
00097     }
00098   }

template<typename oT >
void subview_field< oT >::operator= ( const subview_field< oT > &  x  )  [inline, inherited]

x.subfield(...) = y.subfield(...)

Definition at line 106 of file subview_field_meat.hpp.

References subview_field< oT >::at(), subview_field< oT >::aux_col1, subview_field< oT >::aux_col2, subview_field< oT >::aux_row1, subview_field< oT >::aux_row2, subview_field< oT >::check_overlap(), subview_field< oT >::f, subview_field< oT >::n_cols, and subview_field< oT >::n_rows.

00107   {
00108   arma_extra_debug_sigprint();
00109   
00110   const bool overlap = check_overlap(x_in);
00111         
00112         field<oT>*         tmp_field   = overlap ? new field<oT>(x_in.f) : 0;
00113   const subview_field<oT>* tmp_subview = overlap ? new subview_field<oT>(*tmp_field, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00114   const subview_field<oT>& x           = overlap ? (*tmp_subview) : x_in;
00115   
00116   subview_field<oT>& t = *this;
00117   
00118   arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
00119   
00120   for(u32 col=0; col<t.n_cols; ++col)
00121     {
00122     for(u32 row=0; row<t.n_rows; ++row)
00123       {
00124       t.at(row,col) = x.at(row,col);
00125       }
00126     }
00127     
00128   if(overlap)
00129     {
00130     delete tmp_subview;
00131     delete tmp_field;
00132     }
00133   }

template<typename oT >
arma_inline oT & subview_field< oT >::operator[] ( const u32  i  )  [inline, inherited]

Definition at line 140 of file subview_field_meat.hpp.

References arma_check(), subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, subview_field< oT >::f_ptr, and subview_field< oT >::n_rows.

00141   {
00142   arma_check( (f_ptr == 0), "subview_field::operator[]: field is read-only");
00143   
00144   const u32 in_col = i / n_rows;
00145   const u32 in_row = i % n_rows;
00146     
00147   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00148   
00149   return *((*f_ptr).mem[index]);
00150   }

template<typename oT >
arma_inline const oT & subview_field< oT >::operator[] ( const u32  i  )  const [inline, inherited]

Definition at line 157 of file subview_field_meat.hpp.

References subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, and subview_field< oT >::n_rows.

00158   {
00159   const u32 in_col = i / n_rows;
00160   const u32 in_row = i % n_rows;
00161   
00162   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00163   
00164   return *(f.mem[index]);
00165   }

template<typename oT >
arma_inline oT & subview_field< oT >::operator() ( const u32  i  )  [inline, inherited]

Definition at line 172 of file subview_field_meat.hpp.

References arma_check(), subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, subview_field< oT >::f_ptr, subview_field< oT >::n_elem, and subview_field< oT >::n_rows.

00173   {
00174   arma_check( (f_ptr == 0), "subview_field::operator(): field is read-only");
00175   arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds");
00176     
00177   const u32 in_col = i / n_rows;
00178   const u32 in_row = i % n_rows;
00179   
00180   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00181   
00182   return *((*f_ptr).mem[index]);
00183   }

template<typename oT >
arma_inline const oT & subview_field< oT >::operator() ( const u32  i  )  const [inline, inherited]

Definition at line 190 of file subview_field_meat.hpp.

References subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, subview_field< oT >::n_elem, and subview_field< oT >::n_rows.

00191   {
00192   arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds");
00193   
00194   const u32 in_col = i / n_rows;
00195   const u32 in_row = i % n_rows;
00196   
00197   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00198   
00199   return *(f.mem[index]);
00200   }

template<typename oT >
arma_inline oT & subview_field< oT >::operator() ( const u32  row,
const u32  col 
) [inline, inherited]

Definition at line 207 of file subview_field_meat.hpp.

References arma_check(), subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, subview_field< oT >::f_ptr, subview_field< oT >::n_cols, and subview_field< oT >::n_rows.

00208   {
00209   arma_check( (f_ptr == 0), "subview_field::operator(): field is read-only");
00210   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds");
00211   
00212   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00213   
00214   return *((*f_ptr).mem[index]);
00215   }

template<typename oT >
arma_inline const oT & subview_field< oT >::operator() ( const u32  row,
const u32  col 
) const [inline, inherited]

Definition at line 222 of file subview_field_meat.hpp.

References subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, subview_field< oT >::n_cols, and subview_field< oT >::n_rows.

00223   {
00224   arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds");
00225   
00226   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00227   
00228   return *(f.mem[index]);
00229   }

template<typename oT >
arma_inline oT & subview_field< oT >::at ( const u32  row,
const u32  col 
) [inline, inherited]

Definition at line 236 of file subview_field_meat.hpp.

References arma_check(), subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, subview_field< oT >::f, and subview_field< oT >::f_ptr.

Referenced by subview_field< oT >::extract(), subview_field< oT >::operator=(), and arma_ostream::print().

00237   {
00238   //arma_extra_debug_sigprint();
00239   
00240   arma_check( (f_ptr == 0), "subview_field::at(): field is read-only");
00241   
00242   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00243   
00244   return *((*f_ptr).mem[index]);
00245   }

template<typename oT >
arma_inline const oT & subview_field< oT >::at ( const u32  row,
const u32  col 
) const [inline, inherited]

Definition at line 252 of file subview_field_meat.hpp.

References subview_field< oT >::aux_col1, subview_field< oT >::aux_row1, and subview_field< oT >::f.

00253   {
00254   //arma_extra_debug_sigprint();
00255   
00256   const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
00257   
00258   return *(f.mem[index]);
00259   }

template<typename oT >
bool subview_field< oT >::check_overlap ( const subview_field< oT > &  x  )  const [inline, inherited]

Definition at line 266 of file subview_field_meat.hpp.

References subview_field< oT >::aux_col1, subview_field< oT >::aux_col2, subview_field< oT >::aux_row1, subview_field< oT >::aux_row2, and subview_field< oT >::f.

Referenced by subview_field< oT >::operator=().

00267   {
00268   const subview_field<oT>& t = *this;
00269   
00270   if(&t.f != &x.f)
00271     {
00272     return false;
00273     }
00274   else
00275     {
00276     const bool row_overlap =
00277       (
00278       ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) )
00279       || 
00280       ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) )
00281       );
00282     
00283     const bool col_overlap =
00284       (
00285       ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) )
00286       || 
00287       ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) )
00288       );
00289     
00290     
00291     return (row_overlap & col_overlap);
00292     }
00293   }

template<typename oT >
void subview_field< oT >::extract ( field< oT > &  out,
const subview_field< oT > &  in 
) [inline, static, inherited]

X = Y.subfield(...).

Definition at line 301 of file subview_field_meat.hpp.

References subview_field< oT >::at(), field< oT >::at(), subview_field< oT >::f, field< oT >::n_cols, subview_field< oT >::n_cols, field< oT >::n_rows, subview_field< oT >::n_rows, and field< oT >::set_size().

00302   {
00303   arma_extra_debug_sigprint();
00304   
00305   //
00306   const bool alias = (&actual_out == &in.f);
00307   
00308   field<oT>* tmp = (alias) ? new field<oT> : 0;
00309   field<oT>& out = (alias) ? (*tmp)        : actual_out;
00310   
00311   //
00312   
00313   const u32 n_rows = in.n_rows;
00314   const u32 n_cols = in.n_cols;
00315   
00316   out.set_size(n_rows, n_cols);
00317   
00318   arma_extra_debug_print(arma_boost::format("out.n_rows = %d   out.n_cols = %d    in.m.n_rows = %d  in.m.n_cols = %d") % out.n_rows % out.n_cols % in.f.n_rows % in.f.n_cols );
00319   
00320   for(u32 col = 0; col<n_cols; ++col)
00321     {
00322     for(u32 row = 0; row<n_rows; ++row)
00323       {
00324       out.at(row,col) = in.at(row,col);
00325       }
00326     }
00327   
00328   
00329   if(alias)
00330     {
00331     actual_out = out;
00332     delete tmp;
00333     }
00334   
00335   }