Op_mean

Classes

class  op_mean
 Class for finding mean values of a matrix. More...

Functions

template<typename eT >
static eT op_mean::direct_mean (const eT *const X, const u32 N)
 find the mean value of an array
template<typename eT >
static eT op_mean::direct_mean (const subview< eT > &X)
 find the mean value of a subview
template<typename eT >
static eT op_mean::direct_mean (const diagview< eT > &X)
 find the mean value of a diagview
template<typename T1 >
static void op_mean::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_mean > &in)
 For each row or for each column, find the mean value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the means are found, is set via the mean() function.

Function Documentation

template<typename eT >
eT op_mean::direct_mean ( const eT *const   X,
const u32  N 
) [inline, static, inherited]

find the mean value of an array

Definition at line 25 of file op_mean_meat.hpp.

Referenced by apply(), and mean().

00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   eT val = eT(0);
00030   
00031   for(u32 i=0; i<n_elem; ++i)
00032     {
00033     val += X[i];
00034     }
00035   
00036   return val / eT(n_elem);
00037   }

template<typename eT >
eT op_mean::direct_mean ( const subview< eT > &  X  )  [inline, static, inherited]

find the mean value of a subview

Definition at line 45 of file op_mean_meat.hpp.

References subview< eT >::n_elem.

00046   {
00047   arma_extra_debug_sigprint();
00048   
00049   eT val = eT(0);
00050   
00051   for(u32 i=0; i<X.n_elem; ++i)
00052     {
00053     val += X[i];
00054     }
00055   
00056   return val / eT(X.n_elem);
00057   }

template<typename eT >
eT op_mean::direct_mean ( const diagview< eT > &  X  )  [inline, static, inherited]

find the mean value of a diagview

Definition at line 65 of file op_mean_meat.hpp.

References diagview< eT >::n_elem.

00066   {
00067   arma_extra_debug_sigprint();
00068   
00069   eT val = eT(0);
00070   
00071   for(u32 i=0; i<X.n_elem; ++i)
00072     {
00073     val += X[i];
00074     }
00075   
00076   return val / eT(X.n_elem);
00077   }

template<typename T1 >
void op_mean::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_mean > &  in 
) [inline, static, inherited]

For each row or for each column, find the mean value. The result is stored in a dense matrix that has either one column or one row. The dimension, for which the means are found, is set via the mean() function.

Definition at line 88 of file op_mean_meat.hpp.

References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_mean(), unwrap_check< T1 >::M, Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().

00089   {
00090   arma_extra_debug_sigprint();
00091   
00092   typedef typename T1::elem_type eT;
00093   
00094   const unwrap_check<T1> tmp(in.m, out);
00095   const Mat<eT>& X = tmp.M;
00096   
00097   arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements" );
00098   
00099   const u32 dim = in.aux_u32_a;
00100   arma_debug_check( (dim > 1), "mean(): incorrect usage. dim must be 0 or 1");
00101   
00102   
00103   if(dim == 0)
00104     {
00105     arma_extra_debug_print("op_mean::apply(), dim = 0");
00106     
00107     out.set_size(1, X.n_cols);
00108     
00109     for(u32 col=0; col<X.n_cols; ++col)
00110       {
00111       out[col] = op_mean::direct_mean( X.colptr(col), X.n_rows );
00112       }
00113     }
00114   else
00115   if(dim == 1)
00116     {
00117     arma_extra_debug_print("op_mean::apply(), dim = 1");
00118     
00119     out.set_size(X.n_rows, 1);
00120     
00121     for(u32 row=0; row<X.n_rows; ++row)
00122       {
00123       eT val = eT(0);
00124       
00125       for(u32 col=0; col<X.n_cols; ++col)
00126         {
00127         val += X.at(row,col);
00128         }
00129       
00130       out[row] = val / eT(X.n_cols);
00131       
00132       }
00133     
00134     }
00135   
00136   }