$search
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2009-2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00016 00017 00018 00019 template<typename T1> 00020 arma_inline 00021 const Op<T1, op_mean> 00022 mean(const Base<typename T1::elem_type,T1>& X, const uword dim = 0) 00023 { 00024 arma_extra_debug_sigprint(); 00025 00026 return Op<T1, op_mean>(X.get_ref(), dim, 0); 00027 } 00028 00029 00030 00032 template<typename eT> 00033 inline 00034 arma_warn_unused 00035 eT 00036 mean(const Row<eT>& A) 00037 { 00038 arma_extra_debug_sigprint(); 00039 00040 const uword A_n_elem = A.n_elem; 00041 00042 arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" ); 00043 00044 return op_mean::direct_mean(A.mem, A_n_elem); 00045 } 00046 00047 00048 00050 template<typename eT> 00051 inline 00052 arma_warn_unused 00053 eT 00054 mean(const Col<eT>& A) 00055 { 00056 arma_extra_debug_sigprint(); 00057 00058 const uword A_n_elem = A.n_elem; 00059 00060 arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" ); 00061 00062 return op_mean::direct_mean(A.mem, A_n_elem); 00063 } 00064 00065 00066 00070 template<typename T1> 00071 inline 00072 arma_warn_unused 00073 typename T1::elem_type 00074 mean(const Op<T1, op_mean>& in) 00075 { 00076 arma_extra_debug_sigprint(); 00077 arma_extra_debug_print("mean(): two consecutive mean() calls detected"); 00078 00079 typedef typename T1::elem_type eT; 00080 00081 const unwrap<T1> tmp1(in.m); 00082 const Mat<eT>& X = tmp1.M; 00083 00084 const uword X_n_elem = X.n_elem; 00085 00086 arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); 00087 00088 return op_mean::direct_mean(X.mem, X_n_elem); 00089 } 00090 00091 00092 00093 template<typename T1> 00094 arma_inline 00095 const Op< Op<T1, op_mean>, op_mean> 00096 mean(const Op<T1, op_mean>& in, const uword dim) 00097 { 00098 arma_extra_debug_sigprint(); 00099 00100 return Op< Op<T1, op_mean>, op_mean>(in, dim, 0); 00101 } 00102 00103 00104 00105 template<typename eT> 00106 inline 00107 arma_warn_unused 00108 eT 00109 mean(const subview_row<eT>& A) 00110 { 00111 arma_extra_debug_sigprint(); 00112 00113 arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); 00114 00115 const eT mu = accu(A) / eT(A.n_cols); 00116 00117 return is_finite(mu) ? mu : op_mean::direct_mean_robust(A); 00118 } 00119 00120 00121 00122 template<typename eT> 00123 inline 00124 arma_warn_unused 00125 eT 00126 mean(const subview_col<eT>& A) 00127 { 00128 arma_extra_debug_sigprint(); 00129 00130 arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); 00131 00132 return op_mean::direct_mean(A.colptr(0), A.n_rows); 00133 } 00134 00135 00136 00137 template<typename eT> 00138 inline 00139 arma_warn_unused 00140 eT 00141 mean(const Op<subview<eT>, op_mean>& in) 00142 { 00143 arma_extra_debug_sigprint(); 00144 arma_extra_debug_print("mean(): two consecutive mean() calls detected"); 00145 00146 const subview<eT>& X = in.m; 00147 00148 arma_debug_check( (X.n_elem == 0), "mean(): given object has no elements" ); 00149 00150 return op_mean::direct_mean(X); 00151 } 00152 00153 00154 00155 template<typename eT> 00156 inline 00157 arma_warn_unused 00158 eT 00159 mean(const diagview<eT>& A) 00160 { 00161 arma_extra_debug_sigprint(); 00162 00163 arma_debug_check( (A.n_elem == 0), "mean(): given object has no elements" ); 00164 00165 return op_mean::direct_mean(A); 00166 } 00167 00168 00169 00170 template<typename eT, typename T1> 00171 inline 00172 arma_warn_unused 00173 eT 00174 mean(const subview_elem1<eT,T1>& A) 00175 { 00176 arma_extra_debug_sigprint(); 00177 00178 const Mat<eT> X(A); 00179 00180 const uword X_n_elem = X.n_elem; 00181 00182 arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); 00183 00184 return op_mean::direct_mean(X.mem, X_n_elem); 00185 } 00186 00187 00188