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 22 of file subview_field_meat.hpp.

00023   {
00024   arma_extra_debug_sigprint();
00025   }

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 32 of file subview_field_meat.hpp.

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

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 57 of file subview_field_meat.hpp.

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

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

Definition at line 82 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.

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

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

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

Definition at line 105 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.

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

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

Definition at line 139 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.

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

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

Definition at line 156 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.

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

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

Definition at line 171 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.

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

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

Definition at line 189 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.

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

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

Definition at line 206 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.

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

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

Definition at line 221 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.

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

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

Definition at line 235 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().

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

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

Definition at line 251 of file subview_field_meat.hpp.

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

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

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

Definition at line 265 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=().

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

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 300 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().

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