fn_stddev.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup fn_stddev
00017 //! @{
00018 
00019 
00020 
00021 template<typename T1>
00022 inline
00023 Mat<typename T1::pod_type>
00024 stddev(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, const u32 dim = 0)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   const unwrap<T1> A_tmp(X.get_ref());
00029 
00030   // if T1 is a complex matrix,
00031   // pod_type is the underlying type used by std::complex;
00032   // otherwise pod_type is the same as elem_type
00033   
00034   typedef typename T1::elem_type  in_eT;
00035   typedef typename T1::pod_type  out_eT;
00036 
00037   const Mat<in_eT>& A = A_tmp.M;
00038   
00039   Mat<out_eT> out;
00040   
00041   op_stddev::apply(out, A, norm_type, dim);
00042   
00043   return out;
00044   }
00045 
00046 
00047 
00048 //! Immediate 'find the standard deviation of a row vector' operation
00049 template<typename eT>
00050 inline
00051 eT
00052 stddev(const Row<eT>& A, const u32 norm_type = 0)
00053   {
00054   arma_extra_debug_sigprint();
00055   
00056   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00057   
00058   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00059   }
00060 
00061 
00062 
00063 //! Immediate 'find the standard deviation of a row vector' operation (version for complex numbers)
00064 template<typename T>
00065 inline
00066 T
00067 stddev(const Row< std::complex<T> >& A, const u32 norm_type = 0)
00068   {
00069   arma_extra_debug_sigprint();
00070   
00071   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00072   
00073   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00074   }
00075 
00076 
00077 
00078 //! Immediate 'find the standard deviation of a column vector' operation
00079 template<typename eT>
00080 inline
00081 eT
00082 stddev(const Col<eT>& A, const u32 norm_type = 0)
00083   {
00084   arma_extra_debug_sigprint();
00085   
00086   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00087   
00088   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00089   }
00090 
00091 
00092 
00093 //! Immediate 'find the standard deviation of a column vector' operation (version for complex numbers)
00094 template<typename T>
00095 inline
00096 T
00097 stddev(const Col< std::complex<T> >& A, const u32 norm_type = 0)
00098   {
00099   arma_extra_debug_sigprint();
00100   
00101   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00102   
00103   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00104   }
00105 
00106 
00107 
00108 //! find the standard deviation of a subview_row
00109 template<typename eT>
00110 inline
00111 eT
00112 stddev(const subview_row<eT>& A, const u32 norm_type = 0)
00113   {
00114   arma_extra_debug_sigprint();
00115   
00116   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00117   
00118   return std::sqrt( op_var::direct_var(A, norm_type) );
00119   }
00120 
00121 
00122 
00123 //! find the standard deviation of a subview_row (version for complex numbers)
00124 template<typename T>
00125 inline
00126 T
00127 stddev(const subview_row< std::complex<T> >& A, const u32 norm_type = 0)
00128   {
00129   arma_extra_debug_sigprint();
00130   
00131   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00132   
00133   return std::sqrt( op_var::direct_var(A, norm_type) );
00134   }
00135 
00136 
00137 
00138 //! find the standard deviation of a subview_col
00139 template<typename eT>
00140 inline
00141 eT
00142 stddev(const subview_col<eT>& A, const u32 norm_type = 0)
00143   {
00144   arma_extra_debug_sigprint();
00145   
00146   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00147   
00148   return std::sqrt( op_var::direct_var(A, norm_type) );
00149   }
00150 
00151 
00152 
00153 //! find the standard deviation of a subview_col (version for complex numbers)
00154 template<typename T>
00155 inline
00156 T
00157 stddev(const subview_col< std::complex<T> >& A, const u32 norm_type = 0)
00158   {
00159   arma_extra_debug_sigprint();
00160   
00161   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00162   
00163   return std::sqrt( op_var::direct_var(A, norm_type) );
00164   }
00165 
00166 
00167 
00168 //! find the standard deviation of a diagview
00169 template<typename eT>
00170 inline
00171 eT
00172 stddev(const diagview<eT>& A, const u32 norm_type = 0)
00173   {
00174   arma_extra_debug_sigprint();
00175   
00176   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00177   
00178   return std::sqrt( op_var::direct_var(A, norm_type) );
00179   }
00180 
00181 
00182 
00183 //! find the standard deviation of a diagview (version for complex numbers)
00184 template<typename T>
00185 inline
00186 T
00187 stddev(const diagview< std::complex<T> >& A, const u32 norm_type = 0)
00188   {
00189   arma_extra_debug_sigprint();
00190   
00191   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00192   
00193   return std::sqrt( op_var::direct_var(A, norm_type) );
00194   }
00195 
00196 
00197 
00198 //! @}