fn_mean.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_mean
00017 //! @{
00018 
00019 
00020 
00021 template<typename T1>
00022 inline
00023 const Op<T1, op_mean>
00024 mean(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   return Op<T1, op_mean>(X.get_ref(), dim, 0);
00029   }
00030 
00031 
00032 
00033 //! Immediate 'find the mean value of a row vector' operation
00034 template<typename eT>
00035 inline
00036 eT
00037 mean(const Row<eT>& A)
00038   {
00039   arma_extra_debug_sigprint();
00040   
00041   arma_debug_check( (A.n_elem == 0), "mean(): given vector has no elements" );
00042   
00043   return op_mean::direct_mean(A.mem, A.n_elem);
00044   }
00045 
00046 
00047 
00048 //! Immediate 'find the mean value of a column vector' operation
00049 template<typename eT>
00050 inline
00051 eT
00052 mean(const Col<eT>& A)
00053   {
00054   arma_extra_debug_sigprint();
00055   
00056   arma_debug_check( (A.n_elem == 0), "mean(): given vector has no elements" );
00057   
00058   return op_mean::direct_mean(A.mem, A.n_elem);
00059   }
00060 
00061 
00062 
00063 //! \brief
00064 //! Immediate 'find mean value' operation,
00065 //! invoked, for example, by: mean(mean(A))
00066 template<typename T1>
00067 inline
00068 typename T1::elem_type
00069 mean(const Op<T1, op_mean>& in)
00070   {
00071   arma_extra_debug_sigprint();
00072   arma_extra_debug_print("mean(): two consecutive mean() calls detected");
00073   
00074   typedef typename T1::elem_type eT;
00075   
00076   const unwrap<T1> tmp1(in.m);
00077   const Mat<eT>& X = tmp1.M;
00078   
00079   arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements" );
00080   
00081   return op_mean::direct_mean(X.mem, X.n_elem);
00082   }
00083 
00084 
00085 
00086 template<typename T1>
00087 inline
00088 const Op< Op<T1, op_mean>, op_mean>
00089 mean(const Op<T1, op_mean>& in, const u32 dim)
00090   {
00091   arma_extra_debug_sigprint();
00092   
00093   return Op< Op<T1, op_mean>, op_mean>(in, dim, 0);
00094   }
00095 
00096 
00097 
00098 template<typename eT>
00099 inline
00100 eT
00101 mean(const subview_row<eT>& A)
00102   {
00103   arma_extra_debug_sigprint();
00104   
00105   arma_debug_check( (A.n_elem == 0), "mean(): given vector has no elements" );
00106   
00107   return op_mean::direct_mean(A);
00108   }
00109 
00110 
00111 
00112 template<typename eT>
00113 inline
00114 eT
00115 mean(const subview_col<eT>& A)
00116   {
00117   arma_extra_debug_sigprint();
00118   
00119   arma_debug_check( (A.n_elem == 0), "mean(): given vector has no elements" );
00120   
00121   return op_mean::direct_mean(A);
00122   }
00123 
00124 
00125 
00126 template<typename eT>
00127 inline
00128 eT
00129 mean(const Op<subview<eT>, op_mean>& in)
00130   {
00131   arma_extra_debug_sigprint();
00132   arma_extra_debug_print("mean(): two consecutive mean() calls detected");
00133   
00134   const subview<eT>& X = in.m;
00135   
00136   arma_debug_check( (X.n_elem == 0), "mean(): given matrix has no elements" );
00137   
00138   return op_mean::direct_mean(X);
00139   }
00140 
00141 
00142 
00143 template<typename eT>
00144 inline
00145 eT
00146 mean(const diagview<eT>& A)
00147   {
00148   arma_extra_debug_sigprint();
00149   
00150   arma_debug_check( (A.n_elem == 0), "mean(): given vector has no elements" );
00151   
00152   return op_mean::direct_mean(A);
00153   }
00154 
00155 
00156 
00157 //! @}