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