diff --git a/hysop/tools/numpywrappers.py b/hysop/tools/numpywrappers.py index d50c769144a95dc684cfe3c7bd58269c567774cb..58ed78a1ca422467f584d34c8598fe1d4fafffe0 100644 --- a/hysop/tools/numpywrappers.py +++ b/hysop/tools/numpywrappers.py @@ -4,9 +4,6 @@ Interface to numpy arrays, with hysop predifined types for int, real ... Those functions are useful to enforce hysop predefined types in numpy arrays. """ -from hysop.constants import HYSOP_REAL, HYSOP_COMPLEX, HYSOP_ORDER -from hysop.constants import HYSOP_INTEGER, HYSOP_INDEX, HYSOP_DIM, HYSOP_BOOL - from hysop.tools.types import check_instance from hysop.deps import np as npw @@ -19,7 +16,7 @@ def __generate_hysop_type_functions(): 'as{type}array': ''' -def __hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): """ Convert the input to an array of dtype HYSOP_{TYPE}. """ @@ -28,7 +25,7 @@ def __hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): ''', 'asany{type}array': ''' -def __hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): """ Convert the input to an array of dtype HYSOP_{TYPE}. """ @@ -37,7 +34,7 @@ def __hysop_array_generated_method(a, order=HYSOP_ORDER, **kargs): ''', '{type}_prod': ''' -def __hysop_array_generated_method(a, axis=None, out=None, **kargs): +def hysop_array_generated_method(a, axis=None, out=None, **kargs): """ Sum of array elements over a given axis. """ @@ -46,7 +43,7 @@ def __hysop_array_generated_method(a, axis=None, out=None, **kargs): ''', '{type}_sum': ''' -def __hysop_array_generated_method(a, axis=None, out=None, **kargs): +def hysop_array_generated_method(a, axis=None, out=None, **kargs): """ Sum of array elements over a given axis. """ @@ -56,7 +53,7 @@ def __hysop_array_generated_method(a, axis=None, out=None, **kargs): '{type}_empty': ''' -def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): """ Return a new array of given shape and type, without initializing entries. """ @@ -66,7 +63,7 @@ def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): '{type}_ones': ''' -def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): """ Return a new array of given shape filled with ones of type HYSOP_{TYPE}. """ @@ -76,7 +73,7 @@ def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): '{type}_zeros': ''' -def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): """ Return a new array of given shape, filled with zeros of type HYSOP_{TYPE}. """ @@ -86,7 +83,7 @@ def __hysop_array_generated_method(shape, order=HYSOP_ORDER, **kargs): '{type}_full': ''' -def __hysop_array_generated_method(shape, fill_value, order=HYSOP_ORDER, **kargs): +def hysop_array_generated_method(shape, fill_value, order=HYSOP_ORDER, **kargs): """ Return a new array of given shape, filled with fill_value of type HYSOP_{TYPE}. """ @@ -100,12 +97,18 @@ def __hysop_array_generated_method(shape, fill_value, order=HYSOP_ORDER, **kargs for ht in hysop_types: for _fname, fdefinition in functions.items(): fname = _fname.format(type=ht, TYPE=ht.upper()) - fdef = fdefinition.format(type=ht, TYPE=ht.upper()) - exec(fdef) - setattr(npw, fname, __hysop_array_generated_method) + fdef = \ +''' +from hysop.constants import HYSOP_REAL, HYSOP_COMPLEX, HYSOP_ORDER +from hysop.constants import HYSOP_INTEGER, HYSOP_INDEX, HYSOP_DIM, HYSOP_BOOL +{} +'''.format(fdefinition.format(type=ht, TYPE=ht.upper())) + namespace = dict() + exec(fdef, namespace) + setattr(npw, fname, namespace['hysop_array_generated_method']) if ht == 'integer': fname = _fname.format(type='int') - setattr(npw, fname, __hysop_array_generated_method) + setattr(npw, fname, namespace['hysop_array_generated_method']) __generate_hysop_type_functions()