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
8555b2f3553d
Commit
dcc68cef
authored
Oct 02, 2018
by
Pierre Augier
Browse files
Use a decorator for functions
parent
ccc03e767733
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/create_pythran_file.py
View file @
8555b2f3
from
fluidpythran
import
create_pythran_file
path
=
"example_class.py"
path
=
"example_class
ic
.py"
create_pythran_file
(
path
)
\ No newline at end of file
doc/example_classic.py
View file @
8555b2f3
...
...
@@ -12,14 +12,11 @@ fp = FluidPythran()
# pythran def func(float[][], float[][])
# pythran def func(int[][], float[][])
@
fp
.
pythranize
def
func
(
a
,
b
):
return
(
a
*
np
.
log
(
b
)).
max
()
func
=
fp
.
monkey_patch_function
(
func
)
if
__name__
==
"__main__"
:
n0
,
n1
=
100
,
200
...
...
fluidpythran/__init__.py
View file @
8555b2f3
import
inspect
import
importlib
import
os
from
._version
import
__version__
...
...
@@ -17,7 +18,7 @@ __all__ = [
class
FluidPythran
:
def
__init__
(
self
,
use_pythran
=
True
):
if
not
use_pythran
:
if
not
use_pythran
or
"FLUIDPYTHRAN_COMPILING"
in
os
.
environ
:
self
.
is_pythranized
=
False
return
...
...
@@ -35,8 +36,8 @@ class FluidPythran:
self
.
module_pythran
,
"arguments_blocks"
)
def
monkey_patch_function
(
self
,
func
):
def
pythranize
(
self
,
func
):
"""Decorator used for functions"""
if
self
.
is_pythranized
:
return
getattr
(
self
.
module_pythran
,
func
.
__name__
)
else
:
...
...
fluidpythran/toolchain.py
View file @
8555b2f3
from
tokenize
import
tokenize
,
untokenize
,
COMMENT
,
INDENT
,
DEDENT
,
STRING
,
NAME
from
token
import
tok_name
from
io
import
BytesIO
import
os
# from token import tok_name
from
io
import
BytesIO
import
inspect
from
runpy
import
run_path
from
pathlib
import
Path
import
black
...
...
@@ -119,7 +120,10 @@ def create_pythran_code(path_py):
code_pythran
=
"
\n
"
+
"
\n
"
.
join
(
imports
)
+
"
\n
"
os
.
environ
[
"FLUIDPYTHRAN_COMPILING"
]
=
"1"
mod
=
run_path
(
path_py
)
del
os
.
environ
[
"FLUIDPYTHRAN_COMPILING"
]
for
name_func
in
functions
:
signatures
=
signatures_func
[
name_func
]
for
signature
in
signatures
:
...
...
@@ -128,6 +132,10 @@ def create_pythran_code(path_py):
func
=
mod
[
name_func
]
code
=
inspect
.
getsource
(
func
)
code
=
"
\n
"
.
join
(
line
for
line
in
code
.
split
(
"
\n
"
)
if
".pythranize"
not
in
line
)
code_pythran
+=
f
"
\n
{
code
}
\n\n
"
variables_types_block
=
{}
...
...
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