max@0: // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2009-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup fn_median max@0: //! @{ max@0: max@0: max@0: template max@0: arma_inline max@0: const Op max@0: median(const Base& X, const uword dim = 0) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Op(X.get_ref(), dim, 0); max@0: } max@0: max@0: max@0: max@0: //! Immediate 'find the median value of a row vector' operation max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const Row& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); max@0: max@0: return op_median::direct_median(A.mem, A_n_elem); max@0: } max@0: max@0: max@0: max@0: //! Immediate 'find the median value of a column vector' operation max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const Col& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); max@0: max@0: return op_median::direct_median(A.mem, A_n_elem); max@0: } max@0: max@0: max@0: max@0: //! Immediate 'find the median value of a row vector' operation (complex number version) max@0: template max@0: inline max@0: arma_warn_unused max@0: std::complex max@0: median(const Row< std::complex >& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); max@0: max@0: uword index1; max@0: uword index2; max@0: op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem); max@0: max@0: return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] ); max@0: } max@0: max@0: max@0: max@0: //! Immediate 'find the median value of a column vector' operation (complex number version) max@0: template max@0: inline max@0: arma_warn_unused max@0: std::complex max@0: median(const Col< std::complex >& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword A_n_elem = A.n_elem; max@0: max@0: arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" ); max@0: max@0: uword index1; max@0: uword index2; max@0: op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem); max@0: max@0: return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] ); max@0: } max@0: max@0: max@0: max@0: //! find the median value of a subview_row max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const subview_row& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: return op_median::direct_median(A); max@0: } max@0: max@0: max@0: max@0: //! find the median value of a subview_col max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const subview_col& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: return op_median::direct_median(A.colptr(0), A.n_rows); max@0: } max@0: max@0: max@0: max@0: //! find the median value of a subview_row (complex number version) max@0: template max@0: inline max@0: arma_warn_unused max@0: std::complex max@0: median(const subview_row< std::complex >& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: uword index1; max@0: uword index2; max@0: op_median::direct_cx_median_index(index1, index2, A); max@0: max@0: return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); max@0: } max@0: max@0: max@0: max@0: //! find the median value of a subview_col (complex number version) max@0: template max@0: inline max@0: arma_warn_unused max@0: std::complex max@0: median(const subview_col< std::complex >& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: uword index1; max@0: uword index2; max@0: op_median::direct_cx_median_index(index1, index2, A); max@0: max@0: return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const diagview& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: return op_median::direct_median(A); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: std::complex max@0: median(const diagview< std::complex >& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" ); max@0: max@0: uword index1; max@0: uword index2; max@0: op_median::direct_cx_median_index(index1, index2, A); max@0: max@0: return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: eT max@0: median(const subview_elem1& A) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Col X(A); max@0: max@0: return median(X); max@0: } max@0: max@0: max@0: max@0: //! @}