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. |
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 24 of file op_mean_meat.hpp.
Referenced by apply(), and mean().
00025 { 00026 arma_extra_debug_sigprint(); 00027 00028 eT val = eT(0); 00029 00030 for(u32 i=0; i<n_elem; ++i) 00031 { 00032 val += X[i]; 00033 } 00034 00035 return val / eT(n_elem); 00036 }
eT op_mean::direct_mean | ( | const subview< eT > & | X | ) | [inline, static, inherited] |
find the mean value of a subview
Definition at line 44 of file op_mean_meat.hpp.
References subview< eT >::n_elem.
00045 { 00046 arma_extra_debug_sigprint(); 00047 00048 eT val = eT(0); 00049 00050 for(u32 i=0; i<X.n_elem; ++i) 00051 { 00052 val += X[i]; 00053 } 00054 00055 return val / eT(X.n_elem); 00056 }
eT op_mean::direct_mean | ( | const diagview< eT > & | X | ) | [inline, static, inherited] |
find the mean value of a diagview
Definition at line 64 of file op_mean_meat.hpp.
References diagview< eT >::n_elem.
00065 { 00066 arma_extra_debug_sigprint(); 00067 00068 eT val = eT(0); 00069 00070 for(u32 i=0; i<X.n_elem; ++i) 00071 { 00072 val += X[i]; 00073 } 00074 00075 return val / eT(X.n_elem); 00076 }
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 87 of file op_mean_meat.hpp.
References Mat< eT >::at(), Op< T1, op_type >::aux_u32_a, Mat< eT >::colptr(), direct_mean(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().
00088 { 00089 arma_extra_debug_sigprint(); 00090 00091 typedef typename T1::elem_type eT; 00092 00093 const unwrap_check<T1> tmp(in.m, out); 00094 const Mat<eT>& X = tmp.M; 00095 00096 arma_debug_check( (X.n_elem == 0), "op_mean::apply(): given matrix has no elements" ); 00097 00098 const u32 dim = in.aux_u32_a; 00099 arma_debug_check( (dim > 1), "op_mean::apply(): incorrect usage. dim must be 0 or 1"); 00100 00101 00102 if(dim == 0) 00103 { 00104 arma_extra_debug_print("op_mean::apply(), dim = 0"); 00105 00106 out.set_size(1, X.n_cols); 00107 00108 for(u32 col=0; col<X.n_cols; ++col) 00109 { 00110 out[col] = op_mean::direct_mean( X.colptr(col), X.n_rows ); 00111 } 00112 } 00113 else 00114 if(dim == 1) 00115 { 00116 arma_extra_debug_print("op_mean::apply(), dim = 1"); 00117 00118 out.set_size(X.n_rows, 1); 00119 00120 for(u32 row=0; row<X.n_rows; ++row) 00121 { 00122 eT val = eT(0); 00123 00124 for(u32 col=0; col<X.n_cols; ++col) 00125 { 00126 val += X.at(row,col); 00127 } 00128 00129 out[row] = val / eT(X.n_cols); 00130 00131 } 00132 00133 } 00134 00135 }