comparison pymedcouple @ 11:4c7d7ff28a0e

Rename mid_idx to medc_idx
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Fri, 16 Jan 2015 09:24:40 -0500
parents 3d145bcc8694
children c81f6d263897
comparison
equal deleted inserted replaced
10:3d145bcc8694 11:4c7d7ff28a0e
151 L = [0]*n_plus 151 L = [0]*n_plus
152 R = [n_minus - 1]*n_plus 152 R = [n_minus - 1]*n_plus
153 153
154 Ltot = 0 154 Ltot = 0
155 Rtot = n_minus*n_plus 155 Rtot = n_minus*n_plus
156 mid_idx = (Rtot-1)//2 156 medc_idx = (Rtot-1)//2
157 157
158 # kth pair algorithm (Johnson & Mizoguchi) 158 # kth pair algorithm (Johnson & Mizoguchi)
159 while Rtot - Ltot > n_plus: 159 while Rtot - Ltot > n_plus:
160 160
161 # First, compute the median inside the given bounds 161 # First, compute the median inside the given bounds
189 189
190 # Check on which side of those bounds the desired median of 190 # Check on which side of those bounds the desired median of
191 # the whole matrix may be. 191 # the whole matrix may be.
192 sumP = sum(P) + len(P) 192 sumP = sum(P) + len(P)
193 sumQ = sum(Q) 193 sumQ = sum(Q)
194 194
195 if mid_idx <= sumP - 1: 195 if medc_idx <= sumP - 1:
196 R = P 196 R = P
197 Rtot = sumP 197 Rtot = sumP
198 else: 198 else:
199 if mid_idx > sumQ - 1: 199 if medc_idx > sumQ - 1:
200 L = Q 200 L = Q
201 Ltot = sumQ 201 Ltot = sumQ
202 else: 202 else:
203 return Am 203 return Am
204 204
210 for j in xrange(l, r + 1): 210 for j in xrange(l, r + 1):
211 A.append(h_kern(i, j)) 211 A.append(h_kern(i, j))
212 A.sort() 212 A.sort()
213 A.reverse() 213 A.reverse()
214 214
215 Am = A[mid_idx - Ltot] 215 Am = A[medc_idx - Ltot]
216
216 return Am 217 return Am
217 218
218 219
219 def signum(x): 220 def signum(x):
220 if x > 0: 221 if x > 0: