Posts for the month of May 2012

OT function decorator


Here is an easier way to pass python functions to openturns

First define once this decorator for python functions (could be proposed in a future version):

def FunctionDecorator(n, p):
  class otfunc(OpenTURNSPythonFunction):
    def __init__(self, func):
      OpenTURNSPythonFunction.__init__(self, n, p) 
      self.__class__.__name__ = func.__name__
      self._exec = func 
  return otfunc

Then apply it to your function by adding this one line:

@FunctionDecorator(2, 1)
    Y = [ X[0] + X[1] ]    
    return Y

Then use it through OpenTURNS as usual:

myFunc = NumericalMathFunction( SIMPLEFUNC )

This is open for discussion ...