Changeset 628 for branches


Ignore:
Timestamp:
12/31/12 10:58:48 (3 years ago)
Author:
mmckerns
Message:

discrete decorator for ndarrays; updated test_wrapper for discrete

Location:
branches/decorate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/decorate/test_wrapper.py

    r609 r628  
    133133 
    134134  assert discrete_squared(5.6) == 5.5**2 
    135   assert all(discrete_squared([1, 3]) == asarray([1.0, 3.5])**2) 
     135  assert all(discrete_squared(asarray([1, 3])) == asarray([1.0, 3.5])**2) 
    136136  discrete_squared.samples([1.0, 7.0]) 
    137137  assert discrete_squared(5.6) == 7.0**2 
  • branches/decorate/wrapper.py

    r627 r628  
    4141 
    4242 
    43 from numpy import asarray, any, inf, vectorize, choose, zeros, ones 
     43from numpy import asarray, any, inf, vectorize, choose, zeros, ones, ndarray 
    4444def bounded(min=None, max=None): 
    4545    """impose an infinite barrier box constraint on a function 
     
    139139    samples = [asarray(samples)] 
    140140    samples[0].sort() 
     141    index = [index] 
    141142 
    142143    #XXX: refactor to use points_factory(samples) 
     
    164165    def dec(f): 
    165166        def func(x, *args, **kwds): 
    166             xtype = type(x) 
     167            if isinstance(x, ndarray): xtype = asarray 
     168            else: xtype = type(x) 
    167169            arglo, arghi = argnear(x) 
    168170            xp = near(x, samples[0][arglo], samples[0][arghi]) 
    169171            # create a choice array from given indices 
    170172            #FIXME: better ways to do the following 
    171             if index is None:  
     173            if index[0] is None:  
    172174                mask = ones(xp.size, dtype=bool) 
    173175            else: 
    174176                mask = zeros(xp.size, dtype=bool) 
    175                 try: mask[sorted(index)] = True 
     177                try: mask[sorted(index[0])] = True 
    176178                except IndexError: pass 
    177179            xp = xtype(choose(mask, (x,xp))) 
Note: See TracChangeset for help on using the changeset viewer.