Ignore:
Timestamp:
07/31/14 11:08:02 (22 months ago)
Author:
mmckerns
Message:

simplified internal reducer state to always use arraylike; added wrap_reducer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/abstract_solver.py

    r727 r737  
    7878import numpy 
    7979from numpy import inf, shape, asarray, absolute, asfarray 
    80 from mystic.tools import wrap_function, wrap_nested 
     80from mystic.tools import wrap_function, wrap_nested, wrap_reducer 
    8181from mystic.tools import wrap_bounds, wrap_penalty, reduced 
    8282 
     
    146146        self._constraints     = lambda x: x 
    147147        self._penalty         = lambda x: 0.0 
    148         self._reducer         = (None, False) 
     148        self._reducer         = None 
    149149        self._cost            = (None, None) 
    150150        self._termination     = lambda x, *ar, **kw: False if len(ar) < 1 or ar[0] is False or kw.get('info',True) == False else '' #XXX: better default ? 
     
    220220      (e.g. lambda x,y: x+y), taking two scalars and producing a scalar.""" 
    221221        if not reducer: 
    222             self._reducer = (None, True) 
     222            self._reducer = None 
    223223        elif not callable(reducer): 
    224224            raise TypeError, "'%s' is not a callable function" % reducer 
    225         else: #XXX: check for format: x' = reducer(x) ? 
    226             self._reducer = (reducer, arraylike) #XXX: bool(arraylike) ? 
     225        elif not arraylike: 
     226            self._reducer = wrap_reducer(reducer)    
     227        else: #XXX: check if is arraylike? 
     228            self._reducer = reducer 
    227229        return 
    228230 
     
    578580        cost = wrap_penalty(cost, self._penalty) 
    579581        cost = wrap_nested(cost, self._constraints) 
    580         if self._reducer[0]: 
    581             cost = reduced(*self._reducer)(cost) #XXX: decorated? as wrap_*? 
     582        if self._reducer: 
     583           #cost = reduced(*self._reducer)(cost) # was self._reducer = (f,bool) 
     584            cost = reduced(self._reducer, arraylike=True)(cost) 
    582585        # hold on to the 'wrapped' cost function 
    583586        self._cost = (cost, ExtraArgs) 
Note: See TracChangeset for help on using the changeset viewer.