Read about our upcoming Code of Conduct on this issue

Commit 081e8f0a authored by Pierre Augier's avatar Pierre Augier
Browse files

First commit

parents
syntax: glob
__pycache__
.vscode/
doc/_build/*
doc/**generated/*
doc/**.zip
build/*
dist/*.tar.gz
dist*
.tox/*
.coverage/*
*.egg-info/*
\ No newline at end of file
This diff is collapsed.
develop:
python setup.py develop
black:
black -l 82 fluidpythran
tests:
pytest -s
FluidPythran: Pythran annotations in Python files
=================================================
This pure-Python package will provide few supplementary pythran commands,
namely ``pythran block`` and ``pythran def``.
The Python files have to be "compiled" with the command line tool
`fluidpythran`.
import fluidpythran as fp
class MyClass:
def __init__(self, a, b):
self.a = a
self.b = b
def compute(self, n):
a = self.a
b = self.b
if fp.is_pythranized():
result = fp.use_pythranized_block("block0")
else:
# pythran block (
# float[][] a, b,
# int n
# ) -> result
# pythran block (
# float[][][] a, b,
# int n
# ) -> result
result = 0.0
for _ in range(n):
result += a**2 + b**3
return result
import numpy as np
import fluidpythran as fp
from fluiddyn.util import mpi
# pythran def func(float[][], float[][])
# pythran def func(int[][], float[][])
def func(a, b):
return (a * np.log(b)).max()
func = fp.monkey_patch_function(func)
if __name__ == "__main__":
n0, n1 = 100, 200
a0 = np.random.rand(n0, n1)
a1 = np.random.rand(n0, n1)
result = func(a0, a1)
if mpi.nb_proc > 1:
result = mpi.comm.allreduce(result, op=mpi.MPI.MAX)
mpi.printby0(result)
a0 = (1000 * a0).astype(int)
result = func(a0, a1)
if mpi.nb_proc > 1:
result = mpi.comm.allreduce(result, op=mpi.MPI.MAX)
mpi.printby0(result)
from tokenize import tokenize, untokenize
from io import BytesIO
path = "example_class.py"
with open(path) as file:
code = file.read()
g = tokenize(BytesIO(code.encode('utf-8')).readline)
for toknum, tokval, a, b, c in g:
print((toknum, tokval, a, b, c))
import inspect
from ._version import __version__
__all__ = [
"__version__",
"monkey_patch_function",
"is_pythranized",
"use_pythranized_block",
]
def monkey_patch_function(func):
return func
def is_pythranized():
return False
def use_pythranized_block(name):
frame = inspect.currentframe()
try:
locals_caller = frame.f_back.f_locals
finally:
del frame
raise NotImplementedError
__version__ = "0.0.1"
try:
from pyfiglet import figlet_format
__about__ = figlet_format("fluidpythran v" + __version__, font="big")
except:
__about__ = r"""
/ _| | (_) | | | | | |
| |_| |_ _ _ __| |_ __ _ _| |_| |__ _ __ __ _ _ __
| _| | | | | |/ _` | '_ \| | | | __| '_ \| '__/ _` | '_ \
| | | | |_| | | (_| | |_) | |_| | |_| | | | | | (_| | | | |
|_| |_|\__,_|_|\__,_| .__/ \__, |\__|_| |_|_| \__,_|_| |_|
| | __/ |
|_| |___/
"""
[metadata]
name = fluidpythran
description = Pythran annotations in Python files
long_description = file: README.rst, LICENSE.txt
keywords = pythran
license = CeCILL-B License
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
\ No newline at end of file
from setuptools import setup, find_packages
from runpy import run_path
f"In >=2018, you should use a Python supporting f-strings!"
d = run_path("fluidpythran/_version.py")
__version__ = d["__version__"]
__about__ = d["__about__"]
print(__about__)
setup(version=__version__, packages=find_packages(exclude=["doc"]))
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