Diagview

Classes

class  diagview< eT >
 Class for storing data required to extract and set the diagonals of a matrix. More...

Functions

 diagview::~diagview ()
arma_inline diagview::diagview (const Mat< eT > &in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len)
arma_inline diagview::diagview (Mat< eT > &in_m, const u32 in_row_offset, const u32 in_col_offset, const u32 len)
template<typename T1 >
void diagview::operator= (const Base< eT, T1 > &x)
 set a diagonal of our matrix using data from a foreign object
void diagview::operator= (const diagview &x)
 set a diagonal of our matrix using a diagonal from a foreign matrix
static void diagview::extract (Mat< eT > &out, const diagview &in)
 extract a diagonal and store it as a column vector
static void diagview::plus_inplace (Mat< eT > &out, const diagview &in)
 X += Y.diagview(...).
static void diagview::minus_inplace (Mat< eT > &out, const diagview &in)
 X -= Y.diagview(...).
static void diagview::schur_inplace (Mat< eT > &out, const diagview &in)
 X = Y.submat(...).
static void diagview::div_inplace (Mat< eT > &out, const diagview &in)
 X /= Y.diagview(...).
arma_inline eT & diagview::operator[] (const u32 i)
arma_inline eT diagview::operator[] (const u32 i) const
arma_inline eT & diagview::at (const u32 in_n_row, const u32 in_n_col)
arma_inline eT diagview::at (const u32 in_n_row, const u32 in_n_col) const
arma_inline eT & diagview::operator() (const u32 i)
arma_inline eT diagview::operator() (const u32 i) const
arma_inline eT & diagview::operator() (const u32 in_n_row, const u32 in_n_col)
arma_inline eT diagview::operator() (const u32 in_n_row, const u32 in_n_col) const
void diagview::fill (const eT val)
void diagview::zeros ()
void diagview::ones ()

Function Documentation

template<typename eT >
diagview< eT >::~diagview (  )  [inline, inherited]

Definition at line 23 of file diagview_meat.hpp.

00024   {
00025   arma_extra_debug_sigprint();
00026   }

template<typename eT >
arma_inline diagview< eT >::diagview ( const Mat< eT > &  in_m,
const u32  in_row_offset,
const u32  in_col_offset,
const u32  len 
) [inline, protected, inherited]

Definition at line 31 of file diagview_meat.hpp.

00032   : m(in_m)
00033   , m_ptr(0)
00034   , row_offset(in_row_offset)
00035   , col_offset(in_col_offset)
00036   , n_rows(in_len)
00037   , n_cols( (in_len > 0) ? 1 : 0 )
00038   , n_elem(in_len)
00039   {
00040   arma_extra_debug_sigprint();
00041   }

template<typename eT >
arma_inline diagview< eT >::diagview ( Mat< eT > &  in_m,
const u32  in_row_offset,
const u32  in_col_offset,
const u32  len 
) [inline, protected, inherited]

Definition at line 47 of file diagview_meat.hpp.

00048   : m(in_m)
00049   , m_ptr(&in_m)
00050   , row_offset(in_row_offset)
00051   , col_offset(in_col_offset)
00052   , n_rows(in_len)
00053   , n_cols( (in_len > 0) ? 1 : 0 )
00054   , n_elem(in_len)
00055   {
00056   arma_extra_debug_sigprint();
00057   }

template<typename eT >
template<typename T1 >
void diagview< eT >::operator= ( const Base< eT, T1 > &  x  )  [inline, inherited]

set a diagonal of our matrix using data from a foreign object

Definition at line 66 of file diagview_meat.hpp.

References arma_check(), Mat< eT >::at(), diagview< eT >::col_offset, Base< elem_type, derived >::get_ref(), diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00067   {
00068   arma_extra_debug_sigprint();
00069   arma_check( (m_ptr == 0), "diagview::operator=(): matrix is read only");
00070   
00071   const unwrap<T1> tmp(o.get_ref());
00072   const Mat<eT>& x = tmp.M;
00073   
00074   diagview& t = *this;
00075   
00076   arma_debug_check( !x.is_vec(), "diagview::operator=(): need a vector");
00077   arma_debug_check( (t.n_elem != x.n_elem), "diagview::operator=(): diagonal and given vector have incompatible lengths");
00078   
00079   Mat<eT>& t_m = *(t.m_ptr);
00080   
00081   for(u32 i=0; i<n_elem; ++i)
00082     {
00083     t_m.at(i+row_offset, i+col_offset) = x.mem[i];
00084     }
00085   
00086   }

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

set a diagonal of our matrix using a diagonal from a foreign matrix

Definition at line 94 of file diagview_meat.hpp.

References arma_check(), Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00095   {
00096   arma_extra_debug_sigprint();
00097   arma_check( (m_ptr == 0), "diagview::operator=(): matrix is read only");
00098   
00099   diagview<eT>& t = *this;
00100   
00101   arma_debug_check( (t.n_elem != x.n_elem), "diagview::operator=(): diagonals have incompatible lengths");
00102   
00103         Mat<eT>& t_m = *(t.m_ptr);
00104   const Mat<eT>& x_m = x.m;
00105   
00106   for(u32 i=0; i<n_elem; ++i)
00107     {
00108     t_m.at(i+t.row_offset, i+t.col_offset) = x_m.at(i+x.row_offset, i+x.col_offset);
00109     }
00110     
00111   }

template<typename eT >
void diagview< eT >::extract ( Mat< eT > &  out,
const diagview< eT > &  in 
) [inline, static, inherited]

extract a diagonal and store it as a column vector

Definition at line 120 of file diagview_meat.hpp.

References Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, Mat< eT >::memptr(), diagview< eT >::n_elem, diagview< eT >::row_offset, and Mat< eT >::set_size().

00121   {
00122   arma_extra_debug_sigprint();
00123   
00124   const Mat<eT>& in_m = in.m;
00125   const bool alias = (&actual_out == &in_m);
00126   
00127   Mat<eT>* tmp = (alias) ? new Mat<eT> : 0;
00128   Mat<eT>& out = (alias) ? (*tmp)      : actual_out;
00129   
00130   const u32 in_n_elem     = in.n_elem;
00131   const u32 in_row_offset = in.row_offset;
00132   const u32 in_col_offset = in.col_offset;
00133   
00134   out.set_size(in_n_elem,1);
00135   eT* out_mem = out.memptr();
00136   
00137   for(u32 i=0; i<in_n_elem; ++i)
00138     {
00139     out_mem[i] = in_m.at(i+in_row_offset, i+in_col_offset);
00140     }
00141   
00142   
00143   if(alias)
00144     {
00145     actual_out = out;
00146     delete tmp;
00147     }
00148   
00149   }

template<typename eT >
void diagview< eT >::plus_inplace ( Mat< eT > &  out,
const diagview< eT > &  in 
) [inline, static, inherited]

X += Y.diagview(...).

Definition at line 157 of file diagview_meat.hpp.

References Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, Mat< eT >::memptr(), Mat< eT >::n_cols, diagview< eT >::n_elem, diagview< eT >::n_rows, Mat< eT >::n_rows, and diagview< eT >::row_offset.

00158   {
00159   arma_extra_debug_sigprint();
00160   
00161   arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "matrix addition");
00162   
00163   const Mat<eT>& in_m = in.m;
00164   
00165   const u32 in_n_elem     = in.n_elem;
00166   const u32 in_row_offset = in.row_offset;
00167   const u32 in_col_offset = in.col_offset;
00168   
00169   eT* out_mem = out.memptr();
00170   
00171   for(u32 i=0; i<in_n_elem; ++i)
00172     {
00173     out_mem[i] += in_m.at(i+in_row_offset, i+in_col_offset);
00174     }
00175   }

template<typename eT >
void diagview< eT >::minus_inplace ( Mat< eT > &  out,
const diagview< eT > &  in 
) [inline, static, inherited]

X -= Y.diagview(...).

Definition at line 183 of file diagview_meat.hpp.

References Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, Mat< eT >::memptr(), Mat< eT >::n_cols, diagview< eT >::n_elem, diagview< eT >::n_rows, Mat< eT >::n_rows, and diagview< eT >::row_offset.

00184   {
00185   arma_extra_debug_sigprint();
00186   
00187   arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "matrix subtraction");
00188   
00189   const Mat<eT>& in_m = in.m;
00190   
00191   const u32 in_n_elem     = in.n_elem;
00192   const u32 in_row_offset = in.row_offset;
00193   const u32 in_col_offset = in.col_offset;
00194   
00195   eT* out_mem = out.memptr();
00196   
00197   for(u32 i=0; i<in_n_elem; ++i)
00198     {
00199     out_mem[i] -= in_m.at(i+in_row_offset, i+in_col_offset);
00200     }
00201   }

template<typename eT >
void diagview< eT >::schur_inplace ( Mat< eT > &  out,
const diagview< eT > &  in 
) [inline, static, inherited]

X = Y.submat(...).

Definition at line 209 of file diagview_meat.hpp.

References Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, Mat< eT >::memptr(), Mat< eT >::n_cols, diagview< eT >::n_elem, diagview< eT >::n_rows, Mat< eT >::n_rows, and diagview< eT >::row_offset.

00210   {
00211   arma_extra_debug_sigprint();
00212   
00213   arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "element-wise matrix multiplication");
00214   
00215   const Mat<eT>& in_m = in.m;
00216   
00217   const u32 in_n_elem     = in.n_elem;
00218   const u32 in_row_offset = in.row_offset;
00219   const u32 in_col_offset = in.col_offset;
00220   
00221   eT* out_mem = out.memptr();
00222   
00223   for(u32 i=0; i<in_n_elem; ++i)
00224     {
00225     out_mem[i] *= in_m.at(i+in_row_offset, i+in_col_offset);
00226     }
00227   }

template<typename eT >
void diagview< eT >::div_inplace ( Mat< eT > &  out,
const diagview< eT > &  in 
) [inline, static, inherited]

X /= Y.diagview(...).

Definition at line 235 of file diagview_meat.hpp.

References Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m, Mat< eT >::memptr(), Mat< eT >::n_cols, diagview< eT >::n_elem, diagview< eT >::n_rows, Mat< eT >::n_rows, and diagview< eT >::row_offset.

00236   {
00237   arma_extra_debug_sigprint();
00238   
00239   arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, 1, "element-wise matrix division");
00240   
00241   const Mat<eT>& in_m = in.m;
00242   
00243   const u32 in_n_elem     = in.n_elem;
00244   const u32 in_row_offset = in.row_offset;
00245   const u32 in_col_offset = in.col_offset;
00246   
00247   eT* out_mem = out.memptr();
00248   
00249   for(u32 i=0; i<in_n_elem; ++i)
00250     {
00251     out_mem[i] /= in_m.at(i+in_row_offset, i+in_col_offset);
00252     }
00253   }

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

Definition at line 260 of file diagview_meat.hpp.

References diagview< eT >::col_offset, and diagview< eT >::row_offset.

00261   {
00262   return (*m_ptr).at(i+row_offset, i+col_offset);
00263   }

template<typename eT >
arma_inline eT diagview< eT >::operator[] ( const u32  i  )  const [inline, inherited]

Definition at line 270 of file diagview_meat.hpp.

References diagview< eT >::col_offset, diagview< eT >::m, and diagview< eT >::row_offset.

00271   {
00272   return m.at(i+row_offset, i+col_offset);
00273   }

template<typename eT >
arma_inline eT & diagview< eT >::at ( const u32  in_n_row,
const u32  in_n_col 
) [inline, inherited]

Definition at line 280 of file diagview_meat.hpp.

References diagview< eT >::col_offset, and diagview< eT >::row_offset.

00281   {
00282   return (*m_ptr).at(row+row_offset, row+col_offset);
00283   }

template<typename eT >
arma_inline eT diagview< eT >::at ( const u32  in_n_row,
const u32  in_n_col 
) const [inline, inherited]

Definition at line 290 of file diagview_meat.hpp.

References diagview< eT >::col_offset, diagview< eT >::m, and diagview< eT >::row_offset.

00291   {
00292   return m.at(row+row_offset, row+col_offset);
00293   }

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

Definition at line 300 of file diagview_meat.hpp.

References arma_check(), diagview< eT >::col_offset, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00301   {
00302   arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only");
00303   arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
00304   
00305   return (*m_ptr).at(i+row_offset, i+col_offset);
00306   }

template<typename eT >
arma_inline eT diagview< eT >::operator() ( const u32  i  )  const [inline, inherited]

Definition at line 313 of file diagview_meat.hpp.

References diagview< eT >::col_offset, diagview< eT >::m, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00314   {
00315   arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" );
00316   
00317   return m.at(i+row_offset, i+col_offset);
00318   }

template<typename eT >
arma_inline eT & diagview< eT >::operator() ( const u32  in_n_row,
const u32  in_n_col 
) [inline, inherited]

Definition at line 325 of file diagview_meat.hpp.

References arma_check(), diagview< eT >::col_offset, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00326   {
00327   arma_check( (m_ptr == 0), "diagview::operator(): matrix is read only");
00328   arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
00329   
00330   return (*m_ptr).at(row+row_offset, row+col_offset);
00331   }

template<typename eT >
arma_inline eT diagview< eT >::operator() ( const u32  in_n_row,
const u32  in_n_col 
) const [inline, inherited]

Definition at line 338 of file diagview_meat.hpp.

References diagview< eT >::col_offset, diagview< eT >::m, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00339   {
00340   arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" );
00341   
00342   return m.at(row+row_offset, row+col_offset);
00343   }

template<typename eT >
void diagview< eT >::fill ( const eT  val  )  [inline, inherited]

Definition at line 350 of file diagview_meat.hpp.

References arma_check(), Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00351   {
00352   arma_extra_debug_sigprint();
00353   arma_check( (m_ptr == 0), "diagview::fill(): matrix is read only");
00354   
00355   Mat<eT>& x = (*m_ptr);
00356   
00357   for(u32 i=0; i<n_elem; ++i)
00358     {
00359     x.at(i+row_offset, i+col_offset) = val;
00360     }
00361   }

template<typename eT >
void diagview< eT >::zeros (  )  [inline, inherited]

Definition at line 368 of file diagview_meat.hpp.

References arma_check(), Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00369   {
00370   arma_extra_debug_sigprint();
00371   arma_check( (m_ptr == 0), "diagview::zeros(): matrix is read only");
00372   
00373   Mat<eT>& x = (*m_ptr);
00374   
00375   for(u32 i=0; i<n_elem; ++i)
00376     {
00377     x.at(i+row_offset, i+col_offset) = eT(0);
00378     }
00379   }

template<typename eT >
void diagview< eT >::ones (  )  [inline, inherited]

Definition at line 386 of file diagview_meat.hpp.

References arma_check(), Mat< eT >::at(), diagview< eT >::col_offset, diagview< eT >::m_ptr, diagview< eT >::n_elem, and diagview< eT >::row_offset.

00387   {
00388   arma_extra_debug_sigprint();
00389   arma_check( (m_ptr == 0), "diagview::ones(): matrix is read only");
00390   
00391   Mat<eT>& x = (*m_ptr);
00392   
00393   for(u32 i=0; i<n_elem; ++i)
00394     {
00395     x.at(i+row_offset, i+col_offset) = eT(1);
00396     }
00397   }