annotate armadillo-2.4.4/include/armadillo_bits/fn_median.hpp @ 5:79b343f3e4b8

In thi version the problem of letters assigned to each segment has been solved.
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 13:48:13 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2009-2011 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup fn_median
max@0 15 //! @{
max@0 16
max@0 17
max@0 18 template<typename T1>
max@0 19 arma_inline
max@0 20 const Op<T1, op_median>
max@0 21 median(const Base<typename T1::elem_type,T1>& X, const uword dim = 0)
max@0 22 {
max@0 23 arma_extra_debug_sigprint();
max@0 24
max@0 25 return Op<T1, op_median>(X.get_ref(), dim, 0);
max@0 26 }
max@0 27
max@0 28
max@0 29
max@0 30 //! Immediate 'find the median value of a row vector' operation
max@0 31 template<typename eT>
max@0 32 inline
max@0 33 arma_warn_unused
max@0 34 eT
max@0 35 median(const Row<eT>& A)
max@0 36 {
max@0 37 arma_extra_debug_sigprint();
max@0 38
max@0 39 const uword A_n_elem = A.n_elem;
max@0 40
max@0 41 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
max@0 42
max@0 43 return op_median::direct_median(A.mem, A_n_elem);
max@0 44 }
max@0 45
max@0 46
max@0 47
max@0 48 //! Immediate 'find the median value of a column vector' operation
max@0 49 template<typename eT>
max@0 50 inline
max@0 51 arma_warn_unused
max@0 52 eT
max@0 53 median(const Col<eT>& A)
max@0 54 {
max@0 55 arma_extra_debug_sigprint();
max@0 56
max@0 57 const uword A_n_elem = A.n_elem;
max@0 58
max@0 59 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
max@0 60
max@0 61 return op_median::direct_median(A.mem, A_n_elem);
max@0 62 }
max@0 63
max@0 64
max@0 65
max@0 66 //! Immediate 'find the median value of a row vector' operation (complex number version)
max@0 67 template<typename T>
max@0 68 inline
max@0 69 arma_warn_unused
max@0 70 std::complex<T>
max@0 71 median(const Row< std::complex<T> >& A)
max@0 72 {
max@0 73 arma_extra_debug_sigprint();
max@0 74
max@0 75 const uword A_n_elem = A.n_elem;
max@0 76
max@0 77 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
max@0 78
max@0 79 uword index1;
max@0 80 uword index2;
max@0 81 op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem);
max@0 82
max@0 83 return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] );
max@0 84 }
max@0 85
max@0 86
max@0 87
max@0 88 //! Immediate 'find the median value of a column vector' operation (complex number version)
max@0 89 template<typename T>
max@0 90 inline
max@0 91 arma_warn_unused
max@0 92 std::complex<T>
max@0 93 median(const Col< std::complex<T> >& A)
max@0 94 {
max@0 95 arma_extra_debug_sigprint();
max@0 96
max@0 97 const uword A_n_elem = A.n_elem;
max@0 98
max@0 99 arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
max@0 100
max@0 101 uword index1;
max@0 102 uword index2;
max@0 103 op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem);
max@0 104
max@0 105 return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] );
max@0 106 }
max@0 107
max@0 108
max@0 109
max@0 110 //! find the median value of a subview_row
max@0 111 template<typename eT>
max@0 112 inline
max@0 113 arma_warn_unused
max@0 114 eT
max@0 115 median(const subview_row<eT>& A)
max@0 116 {
max@0 117 arma_extra_debug_sigprint();
max@0 118
max@0 119 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 120
max@0 121 return op_median::direct_median(A);
max@0 122 }
max@0 123
max@0 124
max@0 125
max@0 126 //! find the median value of a subview_col
max@0 127 template<typename eT>
max@0 128 inline
max@0 129 arma_warn_unused
max@0 130 eT
max@0 131 median(const subview_col<eT>& A)
max@0 132 {
max@0 133 arma_extra_debug_sigprint();
max@0 134
max@0 135 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 136
max@0 137 return op_median::direct_median(A.colptr(0), A.n_rows);
max@0 138 }
max@0 139
max@0 140
max@0 141
max@0 142 //! find the median value of a subview_row (complex number version)
max@0 143 template<typename T>
max@0 144 inline
max@0 145 arma_warn_unused
max@0 146 std::complex<T>
max@0 147 median(const subview_row< std::complex<T> >& A)
max@0 148 {
max@0 149 arma_extra_debug_sigprint();
max@0 150
max@0 151 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 152
max@0 153 uword index1;
max@0 154 uword index2;
max@0 155 op_median::direct_cx_median_index(index1, index2, A);
max@0 156
max@0 157 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
max@0 158 }
max@0 159
max@0 160
max@0 161
max@0 162 //! find the median value of a subview_col (complex number version)
max@0 163 template<typename T>
max@0 164 inline
max@0 165 arma_warn_unused
max@0 166 std::complex<T>
max@0 167 median(const subview_col< std::complex<T> >& A)
max@0 168 {
max@0 169 arma_extra_debug_sigprint();
max@0 170
max@0 171 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 172
max@0 173 uword index1;
max@0 174 uword index2;
max@0 175 op_median::direct_cx_median_index(index1, index2, A);
max@0 176
max@0 177 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
max@0 178 }
max@0 179
max@0 180
max@0 181
max@0 182 template<typename eT>
max@0 183 inline
max@0 184 arma_warn_unused
max@0 185 eT
max@0 186 median(const diagview<eT>& A)
max@0 187 {
max@0 188 arma_extra_debug_sigprint();
max@0 189
max@0 190 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 191
max@0 192 return op_median::direct_median(A);
max@0 193 }
max@0 194
max@0 195
max@0 196
max@0 197 template<typename T>
max@0 198 inline
max@0 199 arma_warn_unused
max@0 200 std::complex<T>
max@0 201 median(const diagview< std::complex<T> >& A)
max@0 202 {
max@0 203 arma_extra_debug_sigprint();
max@0 204
max@0 205 arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
max@0 206
max@0 207 uword index1;
max@0 208 uword index2;
max@0 209 op_median::direct_cx_median_index(index1, index2, A);
max@0 210
max@0 211 return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
max@0 212 }
max@0 213
max@0 214
max@0 215
max@0 216 template<typename eT, typename T1>
max@0 217 inline
max@0 218 arma_warn_unused
max@0 219 eT
max@0 220 median(const subview_elem1<eT,T1>& A)
max@0 221 {
max@0 222 arma_extra_debug_sigprint();
max@0 223
max@0 224 const Col<eT> X(A);
max@0 225
max@0 226 return median(X);
max@0 227 }
max@0 228
max@0 229
max@0 230
max@0 231 //! @}