fn_median.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_median
00018 //! @{
00019 
00020 
00021 template<typename T1>
00022 arma_inline
00023 const Op<T1, op_median>
00024 median(const Base<typename T1::elem_type,T1>& X, const u32 dim = 0)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   return Op<T1, op_median>(X.get_ref(), dim, 0);
00029   }
00030 
00031 
00032 //! Immediate 'find the median value of a row vector' operation
00033 template<typename eT>
00034 inline
00035 arma_warn_unused
00036 eT
00037 median(const Row<eT>& A)
00038   {
00039   arma_extra_debug_sigprint();
00040   
00041   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00042   
00043   return op_median::direct_median(A.mem, A.n_elem);
00044   }
00045 
00046 
00047 
00048 //! Immediate 'find the median value of a column vector' operation
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   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00058   
00059   return op_median::direct_median(A.mem, A.n_elem);
00060   }
00061 
00062 
00063 
00064 //! Immediate 'find the median value of a row vector' operation (complex number version)
00065 template<typename T>
00066 inline
00067 arma_warn_unused
00068 std::complex<T>
00069 median(const Row< std::complex<T> >& A)
00070   {
00071   arma_extra_debug_sigprint();
00072   
00073   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00074   
00075   u32 index1;
00076   u32 index2;
00077   op_median::direct_cx_median_index(index1, index2, A.mem, A.n_elem);
00078   
00079   return (A.mem[index1] + A.mem[index2]) / T(2);
00080   }
00081 
00082 
00083 
00084 //! Immediate 'find the median value of a column vector' operation (complex number version)
00085 template<typename T>
00086 inline
00087 arma_warn_unused
00088 std::complex<T>
00089 median(const Col< std::complex<T> >& A)
00090   {
00091   arma_extra_debug_sigprint();
00092   
00093   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00094   
00095   u32 index1;
00096   u32 index2;
00097   op_median::direct_cx_median_index(index1, index2, A.mem, A.n_elem);
00098   
00099   return (A.mem[index1] + A.mem[index2]) / T(2);
00100   }
00101 
00102 
00103 
00104 //! find the median value of a subview_row
00105 template<typename eT>
00106 inline
00107 arma_warn_unused
00108 eT
00109 median(const subview_row<eT>& A)
00110   {
00111   arma_extra_debug_sigprint();
00112   
00113   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00114   
00115   return op_median::direct_median(A);
00116   }
00117 
00118 
00119 
00120 //! find the median value of a subview_col
00121 template<typename eT>
00122 inline
00123 arma_warn_unused
00124 eT
00125 median(const subview_col<eT>& A)
00126   {
00127   arma_extra_debug_sigprint();
00128   
00129   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00130   
00131   return op_median::direct_median(A);
00132   }
00133 
00134 
00135 
00136 //! find the median value of a subview_row (complex number version)
00137 template<typename T>
00138 inline
00139 arma_warn_unused
00140 std::complex<T>
00141 median(const subview_row< std::complex<T> >& A)
00142   {
00143   arma_extra_debug_sigprint();
00144   
00145   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00146   
00147   u32 index1;
00148   u32 index2;
00149   op_median::direct_cx_median_index(index1, index2, A);
00150   
00151   return (A[index1] + A[index2]) / T(2);
00152   }
00153 
00154 
00155 
00156 //! find the median value of a subview_col (complex number version)
00157 template<typename T>
00158 inline
00159 arma_warn_unused
00160 std::complex<T>
00161 median(const subview_col< std::complex<T> >& A)
00162   {
00163   arma_extra_debug_sigprint();
00164   
00165   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00166   
00167   u32 index1;
00168   u32 index2;
00169   op_median::direct_cx_median_index(index1, index2, A);
00170   
00171   return (A[index1] + A[index2]) / T(2);
00172   }
00173 
00174 
00175 
00176 template<typename eT>
00177 inline
00178 arma_warn_unused
00179 eT
00180 median(const diagview<eT>& A)
00181   {
00182   arma_extra_debug_sigprint();
00183   
00184   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00185   
00186   return op_median::direct_median(A);
00187   }
00188 
00189 
00190 
00191 template<typename T>
00192 inline
00193 arma_warn_unused
00194 std::complex<T>
00195 median(const diagview< std::complex<T> >& A)
00196   {
00197   arma_extra_debug_sigprint();
00198   
00199   arma_debug_check( (A.n_elem == 0), "median(): given vector has no elements" );
00200   
00201   u32 index1;
00202   u32 index2;
00203   op_median::direct_cx_median_index(index1, index2, A);
00204   
00205   return (A[index1] + A[index2]) / T(2);
00206   }
00207 
00208 
00209 
00210 //! @}