Changeset 732
- Timestamp:
- 07/28/14 06:51:58 (22 months ago)
- Location:
- mystic
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
mystic/examples/test_scem.py
r713 r732 9 9 """ 10 10 11 #from mystic.scemtools import *11 from mystic.scemtools import * 12 12 import numpy 13 14 def sort_complex(c, a):15 # this is dumb, because c (i.e., a, are almost sorted)16 # should sue the one below instead.17 D = zip(a,c)18 def mycmp(x,y):19 if x[0] < y[0]:20 return 121 elif x[0] > y[0]:22 return -123 else:24 return 025 D.sort(cmp = mycmp)26 return numpy.array([x[1] for x in D]), [x[0] for x in D]27 28 def myinsert(a, x):29 # a is in descending order30 from bisect import bisect31 return bisect([-i for i in a],-x)32 33 def sort_complex2(c, a):34 """35 - c and a are partially sorted (either the last one is bad, or the first one)36 - pos : 0 (first one out of order)37 -1 (last one out of order)38 """39 from bisect import bisect40 # find where new key is relative to the rest41 if a[0] < a[1]:42 ax, cx = a[0], c[0]43 ind = myinsert(a[1:],ax)44 a[0:ind], a[ind] = a[1:1+ind], ax45 c[0:ind], c[ind] = c[1:1+ind], cx46 elif a[-1] > a[-2]:47 ax,cx = a[-1], c[0]48 ind = myinsert(a[0:],ax)49 a[ind+1:], a[ind] = a[ind:-1], ax50 c[ind+1:], c[ind] = c[ind:-1], cx51 return52 13 53 14 print "Numpy Input" -
mystic/mystic/scemtools.py
r726 r732 104 104 def sort_complex0(c, a): 105 105 # this is dumb, because c (i.e., a, are almost sorted) 106 # should sue the one below instead.106 # should use the one below instead. 107 107 # this is faster than sort_complex 108 108 b = array(a) … … 112 112 def sort_complex(c, a): 113 113 # this is dumb, because c (i.e., a, are almost sorted) 114 # should sue the one below instead.114 # should use the one below instead. 115 115 D = zip(a,c) 116 116 def mycmp(x,y): … … 135 135 -1 (last one out of order) 136 136 """ 137 from bisect import bisect138 137 # find where new key is relative to the rest 139 138 if a[0] < a[1]: … … 156 155 - pos is 0, or -1 157 156 """ 158 from bisect import bisect159 157 if pos == 0: 160 158 at = ak[1:] … … 162 160 at = ak[:-1] 163 161 164 p = bisect(-at, -a)162 p = myinsert(at, a) 165 163 166 164 # not done yet. 167 165 if pos == 0: 168 166 Ck[0:p], ak[p] = Ck[1:p+1], ak[1:p+1] 169 ck[p], ak[p] = c, a167 Ck[p], ak[p] = c, a 170 168 else: 171 169 Ck[0:p], ak[p] = Ck[1:p+1], ak[1:p+1] 172 ck[p], ak[p] = c, a170 Ck[p], ak[p] = c, a 173 171 174 172 return
Note: See TracChangeset
for help on using the changeset viewer.