annotate armadillo-3.900.4/include/armadillo_bits/op_stddev_meat.hpp @ 84:55a047986812 tip

Update library URI so as not to be document-local
author Chris Cannam
date Wed, 22 Apr 2020 14:21:57 +0100
parents 1ec0e2823891
children
rev   line source
Chris@49 1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
Chris@49 2 // Copyright (C) 2009-2011 Conrad Sanderson
Chris@49 3 //
Chris@49 4 // This Source Code Form is subject to the terms of the Mozilla Public
Chris@49 5 // License, v. 2.0. If a copy of the MPL was not distributed with this
Chris@49 6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
Chris@49 7
Chris@49 8
Chris@49 9 //! \addtogroup op_stddev
Chris@49 10 //! @{
Chris@49 11
Chris@49 12
Chris@49 13 //! \brief
Chris@49 14 //! For each row or for each column, find the standard deviation.
Chris@49 15 //! The result is stored in a dense matrix that has either one column or one row.
Chris@49 16 //! The dimension for which the standard deviations are found is set via the stddev() function.
Chris@49 17 template<typename T1>
Chris@49 18 inline
Chris@49 19 void
Chris@49 20 op_stddev::apply(Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_stddev>& in)
Chris@49 21 {
Chris@49 22 arma_extra_debug_sigprint();
Chris@49 23
Chris@49 24 typedef typename T1::elem_type in_eT;
Chris@49 25 typedef typename T1::pod_type out_eT;
Chris@49 26
Chris@49 27 const unwrap_check_mixed<T1> tmp(in.m, out);
Chris@49 28 const Mat<in_eT>& X = tmp.M;
Chris@49 29
Chris@49 30 const uword norm_type = in.aux_uword_a;
Chris@49 31 const uword dim = in.aux_uword_b;
Chris@49 32
Chris@49 33 arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1");
Chris@49 34 arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" );
Chris@49 35
Chris@49 36 const uword X_n_rows = X.n_rows;
Chris@49 37 const uword X_n_cols = X.n_cols;
Chris@49 38
Chris@49 39 if(dim == 0)
Chris@49 40 {
Chris@49 41 arma_extra_debug_print("op_stddev::apply(), dim = 0");
Chris@49 42
Chris@49 43 arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" );
Chris@49 44
Chris@49 45 out.set_size(1, X_n_cols);
Chris@49 46
Chris@49 47 out_eT* out_mem = out.memptr();
Chris@49 48
Chris@49 49 for(uword col=0; col<X_n_cols; ++col)
Chris@49 50 {
Chris@49 51 out_mem[col] = std::sqrt( op_var::direct_var( X.colptr(col), X_n_rows, norm_type ) );
Chris@49 52 }
Chris@49 53 }
Chris@49 54 else
Chris@49 55 if(dim == 1)
Chris@49 56 {
Chris@49 57 arma_extra_debug_print("op_stddev::apply(), dim = 1");
Chris@49 58
Chris@49 59 arma_debug_check( (X_n_cols == 0), "stddev(): given object has zero columns" );
Chris@49 60
Chris@49 61 out.set_size(X_n_rows, 1);
Chris@49 62
Chris@49 63 podarray<in_eT> dat(X_n_cols);
Chris@49 64
Chris@49 65 in_eT* dat_mem = dat.memptr();
Chris@49 66 out_eT* out_mem = out.memptr();
Chris@49 67
Chris@49 68 for(uword row=0; row<X_n_rows; ++row)
Chris@49 69 {
Chris@49 70 dat.copy_row(X, row);
Chris@49 71
Chris@49 72 out_mem[row] = std::sqrt( op_var::direct_var( dat_mem, X_n_cols, norm_type) );
Chris@49 73 }
Chris@49 74 }
Chris@49 75 }
Chris@49 76
Chris@49 77
Chris@49 78
Chris@49 79 //! @}
Chris@49 80