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