Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 template<typename eT>
00026 inline
00027 void
00028 op_stddev::apply(Mat< typename get_pod_type<eT>::result >& out, const Mat<eT>& X, const u32 norm_type, const u32 dim)
00029 {
00030 arma_extra_debug_sigprint();
00031
00032 arma_debug_check( (X.n_elem == 0), "stddev(): given matrix has no elements" );
00033
00034 arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1");
00035 arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" );
00036
00037 if(dim == 0)
00038 {
00039 arma_extra_debug_print("op_stddev::apply(), dim = 0");
00040
00041 out.set_size(1, X.n_cols);
00042
00043 for(u32 col=0; col<X.n_cols; ++col)
00044 {
00045 out[col] = std::sqrt( op_var::direct_var( X.colptr(col), X.n_rows, norm_type ) );
00046 }
00047 }
00048 else
00049 if(dim == 1)
00050 {
00051 arma_extra_debug_print("op_stddev::apply(), dim = 1");
00052
00053 const u32 n_rows = X.n_rows;
00054 const u32 n_cols = X.n_cols;
00055
00056 out.set_size(n_rows, 1);
00057
00058 podarray<eT> tmp(n_cols);
00059
00060 eT* tmp_mem = tmp.memptr();
00061
00062 for(u32 row=0; row<n_rows; ++row)
00063 {
00064 for(u32 col=0; col<n_cols; ++col)
00065 {
00066 tmp_mem[col] = X.at(row,col);
00067 }
00068
00069 out[row] = std::sqrt( op_var::direct_var(tmp_mem, n_cols, norm_type) );
00070 }
00071
00072 }
00073
00074 }
00075
00076
00077
00078