Changeset 598 for branches/decorate/wrapper.py
- Timestamp:
- 11/21/12 19:22:46 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/wrapper.py
r594 r598 113 113 The function's input will be mapped to the given discrete set 114 114 115 >>> @d ecorate([1.0, 2.0])115 >>> @discrete([1.0, 2.0]) 116 116 ... def identity(x): 117 117 ... return x … … 154 154 155 155 156 #FIXME: the following should preserve the input type 157 def __clip_bound(x, amin, amax): 158 return max(min(x, amax), amin) 159 clip_bound = vectorize(__clip_bound) 160 161 def __bounce_bound(x, amin, amax): 162 if not x <= amax: 163 x = amax-(amax-amin)*((x-amax)/(x+amax)) 164 if not x >= amin: 165 x = amin+(amax-amin)*((amin-x)/(amin+x)) 166 return x 167 bounce_bound = vectorize(__bounce_bound) 168 169 def __target_bound(x, amin, amax, target): 170 if not x <= amax: 171 x = min(target, amax) 172 if not x >= amin: 173 x = max(target, amin) 174 return x 175 target_bound = vectorize(__target_bound) 176 177 """ 178 def _clip_bound(x, amin, amax): 179 return [__clip_bound(xi,li,ui) for xi,li,ui in zip(x,amin,amax)] 180 181 def _bounce_bound(x, amin, amax): 182 return [__bounce_bound(xi,li,ui) for xi,li,ui in zip(x,amin,amax)] 183 184 def _target_bound(x, amin, amax, target): 185 return [__target_bound(xi,li,ui,target) for xi,li,ui in zip(x,amin,amax)] 186 """ 187 188 def clip_bounded(min, max): 189 def dec(f): 190 def func(x, *args, **kwds): 191 return f(clip_bound(x, min, max), *args, **kwds) 192 return func 193 return dec 194 195 def bounce_bounded(min, max): 196 def dec(f): 197 def func(x, *args, **kwds): 198 return f(bounce_bound(x, min, max), *args, **kwds) 199 return func 200 return dec 201 202 def target_bounded(min, max, target): 203 def dec(f): 204 def func(x, *args, **kwds): 205 return f(target_bound(x, min, max, target), *args, **kwds) 206 return func 207 return dec 208 209 156 210 # EOF
Note: See TracChangeset
for help on using the changeset viewer.