Skip to content
Snippets Groups Projects
Commit 65ae5c1d authored by Jean-Baptiste Keck's avatar Jean-Baptiste Keck
Browse files

fix numpy wrapper routines

parent 8b8922dc
No related branches found
No related tags found
2 merge requests!24Resolve "Add python3.x support",!15WIP: Resolve "HySoP with tasks"
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment