Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
fluiddyn
transonic
Commits
1a2b1787083e
Commit
eece272d
authored
Dec 04, 2018
by
Pierre Augier
Browse files
Array definitions: errors and doc
parent
7789c707b861
Changes
2
Hide whitespace changes
Inline
Side-by-side
doc/examples/type_hints.rst
View file @
1a2b1787
...
@@ -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"]
fluidpythran/annotation.py
View file @
1a2b1787
...
@@ -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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment