Commit eece272d authored by Pierre Augier's avatar Pierre Augier
Browse files

Array definitions: errors and doc

parent 7789c707b861
...@@ -19,4 +19,17 @@ If you don't like generic templating, you can also just write ...@@ -19,4 +19,17 @@ If you don't like generic templating, you can also just write
.. literalinclude:: type_hints_notemplate.py .. literalinclude:: type_hints_notemplate.py
Yes, this one is neat! Yes, this one is neat!
\ No newline at end of file
Note that one can also just write Pythran type-string in type annotations::
@pythran_def
def myfunc(a: "float[3, :]", b: float):
...
Note that if you only need one dimension, array types can be defined like
this::
from fluidpythran import array
A = Array[float, "2d"]
...@@ -177,24 +177,35 @@ class ArrayMeta(type): ...@@ -177,24 +177,35 @@ class ArrayMeta(type):
def __getitem__(self, parameters): def __getitem__(self, parameters):
if not isinstance(parameters, tuple):
parameters = (parameters,)
dtype = None dtype = None
ndim = None ndim = None
params_filtered = [] params_filtered = []
for param in parameters: for param in parameters:
if isinstance(param, (Type, type)): if isinstance(param, (Type, type)):
if dtype is not None: if dtype is not None:
raise ValueError raise ValueError(
"Array should be defined with only one variable defining "
"the types. For more than one type, use "
"for example Type(float, int)"
)
dtype = param dtype = param
if isinstance(param, NDim): if isinstance(param, NDim):
if ndim is not None: if ndim is not None:
raise ValueError raise ValueError(
"Array should be defined with only "
"one NDim. For more than one dimension, use "
"for example NDim(2, 3)."
)
ndim = param ndim = param
if ( if (
isinstance(param, str) isinstance(param, str)
and param[-1] == "d" and param[-1] == "d"
and param[0].isnumeric() and param[:-1].isnumeric()
): ):
try: try:
tmp = int(param[:-1]) tmp = int(param[:-1])
...@@ -202,7 +213,11 @@ class ArrayMeta(type): ...@@ -202,7 +213,11 @@ class ArrayMeta(type):
pass pass
else: else:
if ndim is not None: if ndim is not None:
raise ValueError raise ValueError(
"Array should be defined with only "
"one string fixing the number of dimension. "
"Use for example NDim(2, 3)."
)
param = ndim = NDim( param = ndim = NDim(
tmp, _fp=_get_fluidpythran_calling_module() tmp, _fp=_get_fluidpythran_calling_module()
) )
...@@ -212,6 +227,12 @@ class ArrayMeta(type): ...@@ -212,6 +227,12 @@ class ArrayMeta(type):
params_filtered.append(param) params_filtered.append(param)
if dtype is None:
raise ValueError("No way to determine the dtype of the array")
if ndim is None:
raise ValueError("No way to determine the ndim of the array")
parameters = {p.__name__: p for p in params_filtered} parameters = {p.__name__: p for p in params_filtered}
ArrayBis = type( ArrayBis = type(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment