otwrapy.FunctionDecorator

class FunctionDecorator(enableCache=True, doc=None)

Convert an OpenTURNSPythonFunction into a Function.

This class is intended to be used as a decorator.

Parameters:
enableCachebool (Optional)

If True, enable cache of the returned ot.Function

Methods

__call__(wrapper)

Call self as a function.

Notes

I wanted this decorator to work also with Wrapper class, but it only works with ParallelWrapper for the moment. The problem is that, apparently, decorated classes are not picklable, and Wrapper instances must be picklable so that they can be easily distributed with multiprocessing

References

http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ http://www.artima.com/weblogs/viewpost.jsp?thread=240808 http://stackoverflow.com/questions/30714485/why-does-a-decorated-class-looses-its-docstrings http://stackoverflow.com/questions/30711730/decorated-class-looses-acces-to-its-attributes

Examples

In order to always get an ot.Function when instantiating your wrapper, decorate it as follows:

>>> import otwrapy as otw
>>> import openturns as ot
>>> @otw.FunctionDecorator(enableCache=True)
>>> class Wrapper(ot.OpenTURNSPythonFunction):
>>>     pass

Note that a great disadvantage of this decorator is that your wrapper cannot be parallelized afterwards. Only use it if you don’t plan to parallelize your wrapper or if the wrapper itself is parallelized already. However, if you plan to use Parallelizer, there is no need to use this decorator !

__init__(enableCache=True, doc=None)

Methods

__init__([enableCache, doc])