Changeset 725

Show
Ignore:
Timestamp:
08/09/10 23:56:58 (1 year ago)
Author:
dmitrey
Message:

some FD changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PythonPackages/FuncDesigner/FuncDesigner/examples/nlp1.py

    r460 r725  
    1212#r = p.maximize('ralg') 
    1313print(r.xf) 
     14print a(r.xf) 
    1415a_opt,  b_opt, c_opt = r(a, b, c) 
    1516# or any of the following:  
  • PythonPackages/FuncDesigner/FuncDesigner/ooFun.py

    r724 r725  
    522522    """                                                getFunc                                             """ 
    523523    def _getFunc(self, *args, **kwargs): 
     524        Args = args 
    524525        if len(args) == 0 and len(kwargs) == 0: 
    525526            raise FuncDesignerException('at least one argument is required') 
     
    527528            if type(args[0]) != str: 
    528529                assert not isinstance(args[0], oofun), "you can't invoke oofun on another one oofun" 
    529                  
     530                x = args[0] 
     531                if isinstance(x, dict) and not isinstance(x, ooPoint):  
     532                    x = ooPoint(x) 
     533                    Args = (x,)+args[1:] 
    530534                if self.is_oovar: 
    531535                    if isinstance(x, dict): 
    532536                        tmp = x.get(self, None) 
    533537                        if tmp is not None: 
    534                             return tmp #if type(tmp)==ndarray else asfarray(tmp
     538                            return float(tmp) if isscalar(tmp) or type(tmp)==ndarray else array(tmp, 'float'
    535539                        elif self.name in x: 
    536540                            return asfarray(x[self.name]) 
     
    552556                return self 
    553557                 
    554         return self._getFuncCalcEngine(*args, **kwargs) 
     558        return self._getFuncCalcEngine(*Args, **kwargs) 
    555559 
    556560 
  • PythonPackages/FuncDesigner/FuncDesigner/ooPoint.py

    r724 r725  
    88 
    99from misc import FuncDesignerException 
    10 from numpy import asfarray, ndarray 
     10from numpy import asfarray, ndarray, isscalar 
    1111 
    1212class ooPoint(dict): 
     
    1414    def __init__(self, *args, **kwargs): 
    1515        if args: 
    16             items = [(key, asfarray(val) if type(val) != ndarray else val) for key, val in args[0]] if not isinstance(args[0], dict) else args[0].items() 
     16            if not isinstance(args[0], dict): 
     17                items = [(key, asfarray(val) if not isscalar(val) else float(val)) for key, val in args[0]]  
     18            else: 
     19                items = [(key, asfarray(val) if not isscalar(val) else float(val)) for key, val in args[0].items()]  
    1720        elif kwargs: 
    18             items = [(key, asfarray(val) if type(val) != ndarray else val) for key, val in kwargs.items()] 
     21            items = [(key, asfarray(val) if not isscalar(val) else float(val)) for key, val in kwargs.items()] 
    1922        else: 
    2023            raise FuncDesignerException('incorrect oopoint constructor arguments') 
     
    2326         
    2427        for key, val in items: 
     28            assert type(val) not in [list, ndarray] or type(val[0]) != int 
    2529            if 'size' in key.__dict__ and type(key.size) == int and Len(val)  != key.size:  
    2630                s = 'incorrect size for oovar %s: %d is required, %d is obtained' % (self.name, self.size, Size)