Changeset 732


Ignore:
Timestamp:
07/28/14 06:51:58 (22 months ago)
Author:
mmckerns
Message:

fix: update_complex in scemtools for list inputs; clean and move test_scem

Location:
mystic
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • mystic/examples/test_scem.py

    r713 r732  
    99""" 
    1010 
    11 # from mystic.scemtools import * 
     11from mystic.scemtools import * 
    1212import 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 1 
    21         elif x[0] > y[0]: 
    22             return -1 
    23         else: 
    24             return 0 
    25     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 order 
    30     from bisect import bisect 
    31     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 bisect 
    40     # find where new key is relative to the rest 
    41     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], ax 
    45         c[0:ind], c[ind] = c[1:1+ind], cx 
    46     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], ax 
    50         c[ind+1:], c[ind] = c[ind:-1], cx 
    51     return 
    5213 
    5314print "Numpy Input"  
  • mystic/mystic/scemtools.py

    r726 r732  
    104104def sort_complex0(c, a): 
    105105    # 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. 
    107107    # this is faster than sort_complex 
    108108    b = array(a) 
     
    112112def sort_complex(c, a): 
    113113    # 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. 
    115115    D = zip(a,c) 
    116116    def mycmp(x,y): 
     
    135135       -1 (last one out of order) 
    136136    """ 
    137     from bisect import bisect 
    138137    # find where new key is relative to the rest 
    139138    if a[0] < a[1]: 
     
    156155- pos is 0, or -1 
    157156    """ 
    158     from bisect import bisect 
    159157    if pos == 0: 
    160158        at = ak[1:] 
     
    162160        at = ak[:-1] 
    163161 
    164     p = bisect(-at, -a) 
     162    p = myinsert(at, a) 
    165163 
    166164    # not done yet. 
    167165    if pos == 0: 
    168166        Ck[0:p], ak[p] = Ck[1:p+1], ak[1:p+1] 
    169         ck[p], ak[p] = c, a 
     167        Ck[p], ak[p] = c, a 
    170168    else: 
    171169        Ck[0:p], ak[p] = Ck[1:p+1], ak[1:p+1] 
    172         ck[p], ak[p] = c, a 
     170        Ck[p], ak[p] = c, a 
    173171 
    174172    return 
Note: See TracChangeset for help on using the changeset viewer.