$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 template<typename T1> 00019 arma_inline 00020 const Op<T1, op_median> 00021 median(const Base<typename T1::elem_type,T1>& X, const uword dim = 0) 00022 { 00023 arma_extra_debug_sigprint(); 00024 00025 return Op<T1, op_median>(X.get_ref(), dim, 0); 00026 } 00027 00028 00029 00031 template<typename eT> 00032 inline 00033 arma_warn_unused 00034 eT 00035 median(const Row<eT>& A) 00036 { 00037 arma_extra_debug_sigprint(); 00038 00039 const uword A_n_elem = A.n_elem; 00040 00041 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); 00042 00043 return op_median::direct_median(A.mem, A_n_elem); 00044 } 00045 00046 00047 00049 template<typename eT> 00050 inline 00051 arma_warn_unused 00052 eT 00053 median(const Col<eT>& A) 00054 { 00055 arma_extra_debug_sigprint(); 00056 00057 const uword A_n_elem = A.n_elem; 00058 00059 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); 00060 00061 return op_median::direct_median(A.mem, A_n_elem); 00062 } 00063 00064 00065 00067 template<typename T> 00068 inline 00069 arma_warn_unused 00070 std::complex<T> 00071 median(const Row< std::complex<T> >& A) 00072 { 00073 arma_extra_debug_sigprint(); 00074 00075 const uword A_n_elem = A.n_elem; 00076 00077 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); 00078 00079 uword index1; 00080 uword index2; 00081 op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem); 00082 00083 return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] ); 00084 } 00085 00086 00087 00089 template<typename T> 00090 inline 00091 arma_warn_unused 00092 std::complex<T> 00093 median(const Col< std::complex<T> >& A) 00094 { 00095 arma_extra_debug_sigprint(); 00096 00097 const uword A_n_elem = A.n_elem; 00098 00099 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); 00100 00101 uword index1; 00102 uword index2; 00103 op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem); 00104 00105 return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] ); 00106 } 00107 00108 00109 00111 template<typename eT> 00112 inline 00113 arma_warn_unused 00114 eT 00115 median(const subview_row<eT>& A) 00116 { 00117 arma_extra_debug_sigprint(); 00118 00119 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00120 00121 return op_median::direct_median(A); 00122 } 00123 00124 00125 00127 template<typename eT> 00128 inline 00129 arma_warn_unused 00130 eT 00131 median(const subview_col<eT>& A) 00132 { 00133 arma_extra_debug_sigprint(); 00134 00135 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00136 00137 return op_median::direct_median(A.colptr(0), A.n_rows); 00138 } 00139 00140 00141 00143 template<typename T> 00144 inline 00145 arma_warn_unused 00146 std::complex<T> 00147 median(const subview_row< std::complex<T> >& A) 00148 { 00149 arma_extra_debug_sigprint(); 00150 00151 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00152 00153 uword index1; 00154 uword index2; 00155 op_median::direct_cx_median_index(index1, index2, A); 00156 00157 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); 00158 } 00159 00160 00161 00163 template<typename T> 00164 inline 00165 arma_warn_unused 00166 std::complex<T> 00167 median(const subview_col< std::complex<T> >& A) 00168 { 00169 arma_extra_debug_sigprint(); 00170 00171 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00172 00173 uword index1; 00174 uword index2; 00175 op_median::direct_cx_median_index(index1, index2, A); 00176 00177 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); 00178 } 00179 00180 00181 00182 template<typename eT> 00183 inline 00184 arma_warn_unused 00185 eT 00186 median(const diagview<eT>& A) 00187 { 00188 arma_extra_debug_sigprint(); 00189 00190 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00191 00192 return op_median::direct_median(A); 00193 } 00194 00195 00196 00197 template<typename T> 00198 inline 00199 arma_warn_unused 00200 std::complex<T> 00201 median(const diagview< std::complex<T> >& A) 00202 { 00203 arma_extra_debug_sigprint(); 00204 00205 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); 00206 00207 uword index1; 00208 uword index2; 00209 op_median::direct_cx_median_index(index1, index2, A); 00210 00211 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); 00212 } 00213 00214 00215 00216 template<typename eT, typename T1> 00217 inline 00218 arma_warn_unused 00219 eT 00220 median(const subview_elem1<eT,T1>& A) 00221 { 00222 arma_extra_debug_sigprint(); 00223 00224 const Col<eT> X(A); 00225 00226 return median(X); 00227 } 00228 00229 00230