op_stddev_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12 
13 
16 
17 
22 template<typename T1>
23 inline
24 void
26  {
28 
29  typedef typename T1::elem_type in_eT;
30  typedef typename T1::pod_type out_eT;
31 
32  const unwrap_check_mixed<T1> tmp(in.m, out);
33  const Mat<in_eT>& X = tmp.M;
34 
35  const uword norm_type = in.aux_uword_a;
36  const uword dim = in.aux_uword_b;
37 
38  arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1");
39  arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" );
40 
41  const uword X_n_rows = X.n_rows;
42  const uword X_n_cols = X.n_cols;
43 
44  if(dim == 0)
45  {
46  arma_extra_debug_print("op_stddev::apply(), dim = 0");
47 
48  arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" );
49 
50  out.set_size(1, X_n_cols);
51 
52  out_eT* out_mem = out.memptr();
53 
54  for(uword col=0; col<X_n_cols; ++col)
55  {
56  out_mem[col] = std::sqrt( op_var::direct_var( X.colptr(col), X_n_rows, norm_type ) );
57  }
58  }
59  else
60  if(dim == 1)
61  {
62  arma_extra_debug_print("op_stddev::apply(), dim = 1");
63 
64  arma_debug_check( (X_n_cols == 0), "stddev(): given object has zero columns" );
65 
66  out.set_size(X_n_rows, 1);
67 
68  podarray<in_eT> tmp(X_n_cols);
69 
70  in_eT* tmp_mem = tmp.memptr();
71  out_eT* out_mem = out.memptr();
72 
73  for(uword row=0; row<X_n_rows; ++row)
74  {
75  tmp.copy_row(X, row);
76 
77  out_mem[row] = std::sqrt( op_var::direct_var( tmp_mem, X_n_cols, norm_type) );
78  }
79  }
80  }
81 
82 
83 
85 
const Mat< eT1 > M
Definition: unwrap.hpp:275
arma_hot void copy_row(const Mat< eT > &A, const uword row)
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
Definition: Mat_meat.hpp:4024
arma_aligned uword aux_uword_b
storage of auxiliary data, uword format
Definition: mtOp_bones.hpp:43
A lightweight array for POD types. If the amount of memory requested is small, the stack is used...
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: mtOp_bones.hpp:39
arma_inline const eOp< T1, eop_sqrt > sqrt(const Base< typename T1::elem_type, T1 > &A)
Definition: fn_elem.hpp:403
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
#define arma_extra_debug_print
Definition: debug.hpp:1118
arma_inline arma_warn_unused eT * colptr(const uword in_col)
returns a pointer to array of eTs for a specified column; no bounds check
Definition: Mat_meat.hpp:4000
u32 uword
Definition: typedef.hpp:85
#define arma_debug_check
Definition: debug.hpp:1084
static eT direct_var(const eT *const X, const uword N, const uword norm_type=0)
find the variance of an array
Definition: op_var_meat.hpp:22
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
arma_inline eT * memptr()
Dense matrix class.
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: mtOp_bones.hpp:42
static void apply(Mat< typename T1::pod_type > &out, const mtOp< typename T1::pod_type, T1, op_stddev > &in)
For each row or for each column, find the standard deviation. The result is stored in a dense matrix ...


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:58