Changeset 629 for branches


Ignore:
Timestamp:
12/31/12 11:35:48 (3 years ago)
Author:
mmckerns
Message:

enable discrete decorator to handle negative index; updated corresponding test

Location:
branches/decorate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/decorate/test_wrapper.py

    r628 r629  
    136136  discrete_squared.samples([1.0, 7.0]) 
    137137  assert discrete_squared(5.6) == 7.0**2 
     138  discrete_squared.index([0, -1]) 
     139  assert all(discrete_squared(asarray([0, 3, 6])) == asarray([1.0, 3.0, 7.0])**2) 
    138140 
    139141 
  • branches/decorate/wrapper.py

    r628 r629  
    147147        samples[0] = alist 
    148148 
     149    def _index(alist=None): 
     150        index[0] = alist 
     151 
    149152    #XXX: refactor to use argnear_factory(samples) 
    150153    def _argnear(xi): 
     
    175178            else: 
    176179                mask = zeros(xp.size, dtype=bool) 
    177                 try: mask[sorted(index[0])] = True 
     180                try: mask[sorted(index[0], key=abs)] = True 
    178181                except IndexError: pass 
    179182            xp = xtype(choose(mask, (x,xp))) 
    180183            return f(xp, *args, **kwds) 
    181184        func.samples = _points 
     185        func.index = _index 
    182186        return func 
    183187    return dec 
Note: See TracChangeset for help on using the changeset viewer.