- Timestamp:
- 12/31/12 10:58:48 (3 years ago)
- Location:
- branches/decorate
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/test_wrapper.py
r609 r628 133 133 134 134 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) 136 136 discrete_squared.samples([1.0, 7.0]) 137 137 assert discrete_squared(5.6) == 7.0**2 -
branches/decorate/wrapper.py
r627 r628 41 41 42 42 43 from numpy import asarray, any, inf, vectorize, choose, zeros, ones 43 from numpy import asarray, any, inf, vectorize, choose, zeros, ones, ndarray 44 44 def bounded(min=None, max=None): 45 45 """impose an infinite barrier box constraint on a function … … 139 139 samples = [asarray(samples)] 140 140 samples[0].sort() 141 index = [index] 141 142 142 143 #XXX: refactor to use points_factory(samples) … … 164 165 def dec(f): 165 166 def func(x, *args, **kwds): 166 xtype = type(x) 167 if isinstance(x, ndarray): xtype = asarray 168 else: xtype = type(x) 167 169 arglo, arghi = argnear(x) 168 170 xp = near(x, samples[0][arglo], samples[0][arghi]) 169 171 # create a choice array from given indices 170 172 #FIXME: better ways to do the following 171 if index is None:173 if index[0] is None: 172 174 mask = ones(xp.size, dtype=bool) 173 175 else: 174 176 mask = zeros(xp.size, dtype=bool) 175 try: mask[sorted(index )] = True177 try: mask[sorted(index[0])] = True 176 178 except IndexError: pass 177 179 xp = xtype(choose(mask, (x,xp)))
Note: See TracChangeset
for help on using the changeset viewer.