Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 903d3b44 authored by Pierre Augier's avatar Pierre Augier
Browse files

Fix bugs: compile fluidsim!

parent 6e22623956af
import numpy as np
from transonic import boost
from transonic import boost, Array
A = Array[float, "2d"]
@boost
class Transmitter:
freq: float
arr: A
def __init__(self, freq):
self.freq = float(freq)
self.arr = np.ones((2, 2))
@boost
def __call__(self, inp: "float[]"):
"""My docstring"""
return inp * np.exp(np.arange(len(inp)) * self.freq * 1j)
return inp * np.exp(np.arange(len(inp)) * self.freq * 1j), self.arr
if __name__ == "__main__":
......
......@@ -5,12 +5,19 @@ import beniget
from transonic.log import logger
from .util import filter_code_typevars, get_annotations
from .util import (
filter_code_typevars,
get_annotations,
print_dumped,
print_unparsed,
)
from .capturex import CaptureX
from .blocks_if import get_block_definitions
from .parser import parse_code
from . import extast
__all__ = ["print_dumped", "print_unparsed"]
def compute_ancestors_chains(module_node):
......@@ -129,8 +136,15 @@ def analyse_aot(code):
]
# remove the decorator (boost) to compute the code dependance
# + do not consider the class annotations
for def_node in def_nodes:
def_node.decorator_list = []
if isinstance(def_node, ast.ClassDef):
def_node.body = [
node
for node in def_node.body
if not isinstance(node, ast.AnnAssign)
]
blocks_for_capturex = [block.ast_code for block in blocks]
......@@ -146,7 +160,7 @@ def analyse_aot(code):
code_dependance = capturex.make_code_external()
debug(code_dependance)
debug("parse_code")
signatures_p = parse_code(code)
annotations["comments"] = {}
......
......@@ -2,6 +2,7 @@ from textwrap import dedent
import gast as ast
from transonic.analyses import extast
import astunparse
def print_dumped(source):
......@@ -13,7 +14,7 @@ def print_dumped(source):
node = module
else:
node = source
print(ast.dump(node))
print(astunparse.dump(node))
def print_unparsed(node):
......
......@@ -42,7 +42,7 @@ def produce_new_code_method(fdef, class_def):
g = tokenize(BytesIO(src.encode("utf-8")).readline)
for toknum, tokval, a, b, c in g:
logger.debug((tok_name[toknum], tokval))
# logger.debug((tok_name[toknum], tokval))
if using_self == "self":
if toknum == OP and tokval == ".":
......@@ -130,10 +130,10 @@ def produce_code_for_method(
else:
raise
pythran_signatures = "\n"
pythran_signatures = set()
for types_string_signature in types_string_signatures:
pythran_signatures += (
pythran_signatures.add(
"# pythran export "
+ name_new_func
+ "("
......@@ -144,7 +144,7 @@ def produce_code_for_method(
if jit:
new_code = "from transonic import jit\n\n@jit\n" + new_code
python_code = pythran_signatures + "\n" + new_code
python_code = "\n".join(sorted(pythran_signatures)) + "\n" + new_code
str_self_dot_attributes = ", ".join("self." + attr for attr in attributes)
args_func = [arg.id for arg in fdef.args.args[1:]]
......@@ -205,8 +205,7 @@ def make_pythran_code(path_py):
for func_name, fdef in boosted_dicts["functions"].items():
# args = [name.id for name in fdef.args.args]
signatures_func = []
signatures_func = set()
try:
ann = annotations["functions"][func_name]
......@@ -216,7 +215,7 @@ def make_pythran_code(path_py):
typess = compute_pythran_types_from_valued_types(ann.values())
for types in typess:
signatures_func.append(
signatures_func.add(
f"# pythran export {func_name}({', '.join(types)})"
)
......@@ -226,11 +225,11 @@ def make_pythran_code(path_py):
typess = compute_pythran_types_from_valued_types(ann.values())
for types in typess:
signatures_func.append(
signatures_func.add(
f"# pythran export {func_name}({', '.join(types)})"
)
code.append("\n".join(signatures_func))
code.append("\n".join(sorted(signatures_func)))
code.append(get_code_function(fdef))
......@@ -255,16 +254,16 @@ def make_pythran_code(path_py):
code.append(code_for_meth)
for block in blocks:
signatures_block = []
signatures_block = set()
for ann in block.signatures:
typess = compute_pythran_types_from_valued_types(ann.values())
for types in typess:
signatures_block.append(
signatures_block.add(
f"# pythran export {block.name}({', '.join(types)})"
)
code.extend(signatures_block)
code.extend(sorted(signatures_block))
str_variables = ", ".join(block.signatures[0].keys())
......
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