Chris@49: // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) Chris@49: // Copyright (C) 2009-2011 Conrad Sanderson Chris@49: // Chris@49: // This Source Code Form is subject to the terms of the Mozilla Public Chris@49: // License, v. 2.0. If a copy of the MPL was not distributed with this Chris@49: // file, You can obtain one at http://mozilla.org/MPL/2.0/. Chris@49: Chris@49: Chris@49: //! \addtogroup op_stddev Chris@49: //! @{ Chris@49: Chris@49: Chris@49: //! \brief Chris@49: //! For each row or for each column, find the standard deviation. Chris@49: //! The result is stored in a dense matrix that has either one column or one row. Chris@49: //! The dimension for which the standard deviations are found is set via the stddev() function. Chris@49: template Chris@49: inline Chris@49: void Chris@49: op_stddev::apply(Mat& out, const mtOp& in) Chris@49: { Chris@49: arma_extra_debug_sigprint(); Chris@49: Chris@49: typedef typename T1::elem_type in_eT; Chris@49: typedef typename T1::pod_type out_eT; Chris@49: Chris@49: const unwrap_check_mixed tmp(in.m, out); Chris@49: const Mat& X = tmp.M; Chris@49: Chris@49: const uword norm_type = in.aux_uword_a; Chris@49: const uword dim = in.aux_uword_b; Chris@49: Chris@49: arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); Chris@49: arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" ); Chris@49: Chris@49: const uword X_n_rows = X.n_rows; Chris@49: const uword X_n_cols = X.n_cols; Chris@49: Chris@49: if(dim == 0) Chris@49: { Chris@49: arma_extra_debug_print("op_stddev::apply(), dim = 0"); Chris@49: Chris@49: arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" ); Chris@49: Chris@49: out.set_size(1, X_n_cols); Chris@49: Chris@49: out_eT* out_mem = out.memptr(); Chris@49: Chris@49: for(uword col=0; col dat(X_n_cols); Chris@49: Chris@49: in_eT* dat_mem = dat.memptr(); Chris@49: out_eT* out_mem = out.memptr(); Chris@49: Chris@49: for(uword row=0; row