$search
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2009-2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00016 00017 00022 template<typename T1> 00023 inline 00024 void 00025 op_stddev::apply(Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_stddev>& in) 00026 { 00027 arma_extra_debug_sigprint(); 00028 00029 typedef typename T1::elem_type in_eT; 00030 typedef typename T1::pod_type out_eT; 00031 00032 const unwrap_check_mixed<T1> tmp(in.m, out); 00033 const Mat<in_eT>& X = tmp.M; 00034 00035 const uword norm_type = in.aux_uword_a; 00036 const uword dim = in.aux_uword_b; 00037 00038 arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); 00039 arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" ); 00040 00041 const uword X_n_rows = X.n_rows; 00042 const uword X_n_cols = X.n_cols; 00043 00044 if(dim == 0) 00045 { 00046 arma_extra_debug_print("op_stddev::apply(), dim = 0"); 00047 00048 arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" ); 00049 00050 out.set_size(1, X_n_cols); 00051 00052 out_eT* out_mem = out.memptr(); 00053 00054 for(uword col=0; col<X_n_cols; ++col) 00055 { 00056 out_mem[col] = std::sqrt( op_var::direct_var( X.colptr(col), X_n_rows, norm_type ) ); 00057 } 00058 } 00059 else 00060 if(dim == 1) 00061 { 00062 arma_extra_debug_print("op_stddev::apply(), dim = 1"); 00063 00064 arma_debug_check( (X_n_cols == 0), "stddev(): given object has zero columns" ); 00065 00066 out.set_size(X_n_rows, 1); 00067 00068 podarray<in_eT> tmp(X_n_cols); 00069 00070 in_eT* tmp_mem = tmp.memptr(); 00071 out_eT* out_mem = out.memptr(); 00072 00073 for(uword row=0; row<X_n_rows; ++row) 00074 { 00075 tmp.copy_row(X, row); 00076 00077 out_mem[row] = std::sqrt( op_var::direct_var( tmp_mem, X_n_cols, norm_type) ); 00078 } 00079 } 00080 } 00081 00082 00083 00085