fn_var.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_var
00017 //! @{
00018 
00019 
00020 
00021 template<typename T1>
00022 inline
00023 Mat<typename T1::pod_type>
00024 var(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_var::apply(out, A, norm_type, dim);
00042   
00043   return out;
00044   }
00045 
00046 
00047 
00048 //! Immediate 'find the variance of a row vector' operation
00049 template<typename eT>
00050 inline
00051 eT
00052 var(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 op_var::direct_var(A.mem, A.n_elem, norm_type);
00059   }
00060 
00061 
00062 
00063 //! Immediate 'find the variance of a row vector' operation (version for complex numbers)
00064 template<typename T>
00065 inline
00066 T
00067 var(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 op_var::direct_var(A.mem, A.n_elem, norm_type);
00074   }
00075 
00076 
00077 
00078 //! Immediate 'find the variance of a column vector' operation
00079 template<typename eT>
00080 inline
00081 eT
00082 var(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 op_var::direct_var(A.mem, A.n_elem, norm_type);
00089   }
00090 
00091 
00092 
00093 //! Immediate 'find the variance of a column vector' operation (version for complex numbers)
00094 template<typename T>
00095 inline
00096 T
00097 var(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 op_var::direct_var(A.mem, A.n_elem, norm_type);
00104   }
00105 
00106 
00107 
00108 template<typename eT>
00109 inline
00110 eT
00111 var(const subview_row<eT>& A, const u32 norm_type = 0)
00112   {
00113   arma_extra_debug_sigprint();
00114   
00115   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00116   
00117   return op_var::direct_var(A, norm_type);
00118   }
00119 
00120 
00121 
00122 template<typename T>
00123 inline
00124 T
00125 var(const subview_row< std::complex<T> >& A, const u32 norm_type = 0)
00126   {
00127   arma_extra_debug_sigprint();
00128   
00129   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00130   
00131   return op_var::direct_var(A, norm_type);
00132   }
00133 
00134 
00135 
00136 template<typename eT>
00137 inline
00138 eT
00139 var(const subview_col<eT>& A, const u32 norm_type = 0)
00140   {
00141   arma_extra_debug_sigprint();
00142   
00143   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00144   
00145   return op_var::direct_var(A, norm_type);
00146   }
00147 
00148 
00149 
00150 template<typename T>
00151 inline
00152 T
00153 var(const subview_col< std::complex<T> >& A, const u32 norm_type = 0)
00154   {
00155   arma_extra_debug_sigprint();
00156   
00157   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00158   
00159   return op_var::direct_var(A, norm_type);
00160   }
00161 
00162 
00163 
00164 template<typename eT>
00165 inline
00166 eT
00167 var(const diagview<eT>& A, const u32 norm_type = 0)
00168   {
00169   arma_extra_debug_sigprint();
00170   
00171   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00172   
00173   return op_var::direct_var(A, norm_type);
00174   }
00175 
00176 
00177 
00178 template<typename T>
00179 inline
00180 T
00181 var(const diagview< std::complex<T> >& A, const u32 norm_type = 0)
00182   {
00183   arma_extra_debug_sigprint();
00184   
00185   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00186   
00187   return op_var::direct_var(A, norm_type);
00188   }
00189 
00190 
00191 
00192 //! @}