fn_var.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup fn_var
00018 //! @{
00019 
00020 
00021 
00022 template<typename T1>
00023 inline
00024 Mat<typename T1::pod_type>
00025 var(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, const u32 dim = 0)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   typedef typename T1::elem_type  in_eT;
00030   typedef typename T1::pod_type  out_eT;
00031 
00032   const unwrap<T1>      tmp(X.get_ref());
00033   const Mat<in_eT>& A = tmp.M;
00034 
00035   Mat<out_eT> out;
00036   
00037   op_var::apply(out, A, norm_type, dim);
00038   
00039   return out;
00040   }
00041 
00042 
00043 
00044 //! Immediate 'find the variance of a row vector' operation
00045 template<typename eT>
00046 inline
00047 arma_warn_unused
00048 typename get_pod_type<eT>::result
00049 var(const Row<eT>& A, const u32 norm_type = 0)
00050   {
00051   arma_extra_debug_sigprint();
00052   
00053   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00054   
00055   return op_var::direct_var(A.mem, A.n_elem, norm_type);
00056   }
00057 
00058 
00059 
00060 //! Immediate 'find the variance of a column vector' operation
00061 template<typename eT>
00062 inline
00063 arma_warn_unused
00064 typename get_pod_type<eT>::result
00065 var(const Col<eT>& A, const u32 norm_type = 0)
00066   {
00067   arma_extra_debug_sigprint();
00068   
00069   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00070   
00071   return op_var::direct_var(A.mem, A.n_elem, norm_type);
00072   }
00073 
00074 
00075 
00076 template<typename eT>
00077 inline
00078 arma_warn_unused
00079 typename get_pod_type<eT>::result
00080 var(const subview_row<eT>& A, const u32 norm_type = 0)
00081   {
00082   arma_extra_debug_sigprint();
00083   
00084   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00085   
00086   return op_var::direct_var(A, norm_type);
00087   }
00088 
00089 
00090 
00091 template<typename eT>
00092 inline
00093 arma_warn_unused
00094 typename get_pod_type<eT>::result
00095 var(const subview_col<eT>& A, const u32 norm_type = 0)
00096   {
00097   arma_extra_debug_sigprint();
00098   
00099   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00100   
00101   return op_var::direct_var(A, norm_type);
00102   }
00103 
00104 
00105 
00106 template<typename eT>
00107 inline
00108 arma_warn_unused
00109 typename get_pod_type<eT>::result
00110 var(const diagview<eT>& A, const u32 norm_type = 0)
00111   {
00112   arma_extra_debug_sigprint();
00113   
00114   arma_debug_check( (A.n_elem == 0), "var(): given vector has no elements" );
00115   
00116   return op_var::direct_var(A, norm_type);
00117   }
00118 
00119 
00120 
00121 //! @}