Classes | Functions

Subview_field

//! More...

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

Detailed Description

//!


Function Documentation

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

Definition at line 23 of file subview_field_meat.hpp.

  {
  arma_extra_debug_sigprint();
  }

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 
) [protected, inherited]

Definition at line 33 of file subview_field_meat.hpp.

  : f(in_f)
  , f_ptr(0)
  , aux_row1(in_row1)
  , aux_col1(in_col1)
  , aux_row2(in_row2)
  , aux_col2(in_col2)
  , n_rows(1 + in_row2 - in_row1)
  , n_cols(1 + in_col2 - in_col1)
  , n_elem(n_rows*n_cols)
  {
  arma_extra_debug_sigprint();
  }

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 
) [protected, inherited]

Definition at line 58 of file subview_field_meat.hpp.

  : f(in_f)
  , f_ptr(&in_f)
  , aux_row1(in_row1)
  , aux_col1(in_col1)
  , aux_row2(in_row2)
  , aux_col2(in_col2)
  , n_rows(1 + in_row2 - in_row1)
  , n_cols(1 + in_col2 - in_col1)
  , n_elem(n_rows*n_cols)
  {
  arma_extra_debug_sigprint();
  }

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.

  {
  arma_extra_debug_sigprint();
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
  
  for(u32 col=0; col<t.n_cols; ++col)
    {
    for(u32 row=0; row<t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  }

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.

  {
  arma_extra_debug_sigprint();
  
  const bool overlap = check_overlap(x_in);
        
        field<oT>*         tmp_field   = overlap ? new field<oT>(x_in.f) : 0;
  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;
  const subview_field<oT>& x           = overlap ? (*tmp_subview) : x_in;
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
  
  for(u32 col=0; col<t.n_cols; ++col)
    {
    for(u32 row=0; row<t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
    
  if(overlap)
    {
    delete tmp_subview;
    delete tmp_field;
    }
  }

template<typename oT >
arma_inline oT & subview_field< oT >::operator[] ( const u32  i  )  [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.

  {
  arma_check( (f_ptr == 0), "subview_field::operator[]: field is read-only");
  
  const u32 in_col = i / n_rows;
  const u32 in_row = i % n_rows;
    
  const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
  
  return *((*f_ptr).mem[index]);
  }

template<typename oT >
arma_inline const oT & subview_field< oT >::operator[] ( const u32  i  )  const [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.

  {
  const u32 in_col = i / n_rows;
  const u32 in_row = i % n_rows;
  
  const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
  
  return *(f.mem[index]);
  }

template<typename oT >
arma_inline oT & subview_field< oT >::operator() ( const u32  i  )  [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.

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

template<typename oT >
arma_inline const oT & subview_field< oT >::operator() ( const u32  i  )  const [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.

  {
  arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds");
  
  const u32 in_col = i / n_rows;
  const u32 in_row = i % n_rows;
  
  const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
  
  return *(f.mem[index]);
  }

template<typename oT >
arma_inline oT & subview_field< oT >::operator() ( const u32  row,
const u32  col 
) [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.

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

template<typename oT >
arma_inline const oT & subview_field< oT >::operator() ( const u32  row,
const u32  col 
) const [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.

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

template<typename oT >
arma_inline oT & subview_field< oT >::at ( const u32  row,
const u32  col 
) [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().

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

template<typename oT >
arma_inline const oT & subview_field< oT >::at ( const u32  row,
const u32  col 
) const [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.

  {
  //arma_extra_debug_sigprint();
  
  const u32 index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
  
  return *(f.mem[index]);
  }

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

  {
  const subview_field<oT>& t = *this;
  
  if(&t.f != &x.f)
    {
    return false;
    }
  else
    {
    const bool row_overlap =
      (
      ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) )
      || 
      ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) )
      );
    
    const bool col_overlap =
      (
      ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) )
      || 
      ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) )
      );
    
    
    return (row_overlap & col_overlap);
    }
  }

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

  {
  arma_extra_debug_sigprint();
  
  //
  const bool alias = (&actual_out == &in.f);
  
  field<oT>* tmp = (alias) ? new field<oT> : 0;
  field<oT>& out = (alias) ? (*tmp)        : actual_out;
  
  //
  
  const u32 n_rows = in.n_rows;
  const u32 n_cols = in.n_cols;
  
  out.set_size(n_rows, n_cols);
  
  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 );
  
  for(u32 col = 0; col<n_cols; ++col)
    {
    for(u32 row = 0; row<n_rows; ++row)
      {
      out.at(row,col) = in.at(row,col);
      }
    }
  
  
  if(alias)
    {
    actual_out = out;
    delete tmp;
    }
  
  }