fn_median.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12 
13 
16 
17 
18 template<typename T1>
22  {
24 
25  return Op<T1, op_median>(X.get_ref(), dim, 0);
26  }
27 
28 
29 
31 template<typename eT>
32 inline
34 eT
35 median(const Row<eT>& A)
36  {
38 
39  const uword A_n_elem = A.n_elem;
40 
41  arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
42 
43  return op_median::direct_median(A.mem, A_n_elem);
44  }
45 
46 
47 
49 template<typename eT>
50 inline
52 eT
53 median(const Col<eT>& A)
54  {
56 
57  const uword A_n_elem = A.n_elem;
58 
59  arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
60 
61  return op_median::direct_median(A.mem, A_n_elem);
62  }
63 
64 
65 
67 template<typename T>
68 inline
70 std::complex<T>
71 median(const Row< std::complex<T> >& A)
72  {
74 
75  const uword A_n_elem = A.n_elem;
76 
77  arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
78 
79  uword index1;
80  uword index2;
81  op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem);
82 
83  return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] );
84  }
85 
86 
87 
89 template<typename T>
90 inline
92 std::complex<T>
93 median(const Col< std::complex<T> >& A)
94  {
96 
97  const uword A_n_elem = A.n_elem;
98 
99  arma_debug_check( (A_n_elem == 0), "median(): given object has no elements" );
100 
101  uword index1;
102  uword index2;
103  op_median::direct_cx_median_index(index1, index2, A.mem, A_n_elem);
104 
105  return (index1 == index2) ? A.mem[index1] : op_median::robust_mean( A.mem[index1], A.mem[index2] );
106  }
107 
108 
109 
111 template<typename eT>
112 inline
114 eT
116  {
118 
119  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
120 
121  return op_median::direct_median(A);
122  }
123 
124 
125 
127 template<typename eT>
128 inline
130 eT
132  {
134 
135  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
136 
137  return op_median::direct_median(A.colptr(0), A.n_rows);
138  }
139 
140 
141 
143 template<typename T>
144 inline
146 std::complex<T>
147 median(const subview_row< std::complex<T> >& A)
148  {
150 
151  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
152 
153  uword index1;
154  uword index2;
155  op_median::direct_cx_median_index(index1, index2, A);
156 
157  return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
158  }
159 
160 
161 
163 template<typename T>
164 inline
166 std::complex<T>
167 median(const subview_col< std::complex<T> >& A)
168  {
170 
171  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
172 
173  uword index1;
174  uword index2;
175  op_median::direct_cx_median_index(index1, index2, A);
176 
177  return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
178  }
179 
180 
181 
182 template<typename eT>
183 inline
185 eT
187  {
189 
190  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
191 
192  return op_median::direct_median(A);
193  }
194 
195 
196 
197 template<typename T>
198 inline
200 std::complex<T>
201 median(const diagview< std::complex<T> >& A)
202  {
204 
205  arma_debug_check( (A.n_elem == 0), "median(): given object has no elements" );
206 
207  uword index1;
208  uword index2;
209  op_median::direct_cx_median_index(index1, index2, A);
210 
211  return (index1 == index2) ? A[index1] : op_median::robust_mean(A[index1], A[index2]);
212  }
213 
214 
215 
216 template<typename eT, typename T1>
217 inline
219 eT
221  {
223 
224  const Col<eT> X(A);
225 
226  return median(X);
227  }
228 
229 
230 
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
const uword n_rows
static arma_inline eT robust_mean(const eT A, const eT B)
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
const uword n_elem
u32 uword
Definition: typedef.hpp:85
Class for column vectors (matrices with only one column)
Definition: Col_bones.hpp:20
arma_inline const Op< T1, op_median > median(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Definition: fn_median.hpp:21
#define arma_debug_check
Definition: debug.hpp:1084
arma_inline eT * colptr(const uword in_col)
Class for row vectors (matrices with only one row)
static eT direct_median(std::vector< eT > &X)
find the median value of a std::vector (contents is modified)
static void direct_cx_median_index(uword &out_index1, uword &out_index2, std::vector< arma_cx_median_packet< T > > &X)
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
#define arma_warn_unused
#define arma_inline
const uword n_elem
arma_aligned const eT *const mem
pointer to the memory used by the matrix (memory is read-only)
Definition: Mat_bones.hpp:40
Class for storing data required to extract and set the diagonals of a matrix.


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57