Skip to content
Snippets Groups Projects
Commit bec36bb2 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Rename: get_code -> get_code_obj

parent 1e7a179a
1 merge request!132let show_code display/print code
...@@ -5,7 +5,7 @@ from . import stencil as stencil ...@@ -5,7 +5,7 @@ from . import stencil as stencil
from .assignment import Assignment, assignment_from_stencil from .assignment import Assignment, assignment_from_stencil
from .data_types import TypedSymbol from .data_types import TypedSymbol
from .datahandling import create_data_handling from .datahandling import create_data_handling
from .display_utils import show_code, get_code, get_code_str, to_dot from .display_utils import show_code, get_code_obj, get_code_str, to_dot
from .field import Field, FieldType, fields from .field import Field, FieldType, fields
from .kernel_decorator import kernel from .kernel_decorator import kernel
from .kernelcreation import create_indexed_kernel, create_kernel, create_staggered_kernel from .kernelcreation import create_indexed_kernel, create_kernel, create_staggered_kernel
...@@ -25,7 +25,7 @@ __all__ = ['Field', 'FieldType', 'fields', ...@@ -25,7 +25,7 @@ __all__ = ['Field', 'FieldType', 'fields',
'TypedSymbol', 'TypedSymbol',
'make_slice', 'make_slice',
'create_kernel', 'create_indexed_kernel', 'create_staggered_kernel', 'create_kernel', 'create_indexed_kernel', 'create_staggered_kernel',
'show_code', 'to_dot', 'get_code', 'get_code_str', 'show_code', 'to_dot', 'get_code_obj', 'get_code_str',
'AssignmentCollection', 'AssignmentCollection',
'Assignment', 'Assignment',
'assignment_from_stencil', 'assignment_from_stencil',
......
...@@ -35,7 +35,7 @@ def highlight_cpp(code: str): ...@@ -35,7 +35,7 @@ def highlight_cpp(code: str):
return HTML(highlight(code, CppLexer(), HtmlFormatter())) return HTML(highlight(code, CppLexer(), HtmlFormatter()))
def get_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None): def get_code_obj(ast: Union[KernelFunction, KernelWrapper], custom_backend=None):
"""Returns an object to display generated code (C/C++ or CUDA) """Returns an object to display generated code (C/C++ or CUDA)
Can either be displayed as HTML in Jupyter notebooks or printed as normal string. Can either be displayed as HTML in Jupyter notebooks or printed as normal string.
...@@ -68,11 +68,11 @@ def get_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None): ...@@ -68,11 +68,11 @@ def get_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None):
def get_code_str(ast, custom_backend=None): def get_code_str(ast, custom_backend=None):
return str(get_code(ast, custom_backend)) return str(get_code_obj(ast, custom_backend))
def show_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None): def show_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None):
code = get_code(ast, custom_backend) code = get_code_obj(ast, custom_backend)
try: try:
from IPython.display import display from IPython.display import display
......
import numpy as np import numpy as np
from pystencils import get_code from pystencils import get_code_obj
from pystencils.astnodes import Block, KernelFunction, SympyAssignment from pystencils.astnodes import Block, KernelFunction, SympyAssignment
from pystencils.cpu import make_python_function from pystencils.cpu import make_python_function
from pystencils.field import Field from pystencils.field import Field
...@@ -36,7 +36,7 @@ def test_jacobi_fixed_field_size(): ...@@ -36,7 +36,7 @@ def test_jacobi_fixed_field_size():
error = np.sum(np.abs(dst_field_py - dst_field_c)) error = np.sum(np.abs(dst_field_py - dst_field_c))
np.testing.assert_allclose(error, 0.0, atol=1e-13) np.testing.assert_allclose(error, 0.0, atol=1e-13)
code_display = get_code(ast_node) code_display = get_code_obj(ast_node)
assert 'for' in str(code_display) assert 'for' in str(code_display)
assert 'for' in code_display._repr_html_() assert 'for' in code_display._repr_html_()
......
...@@ -30,7 +30,7 @@ def test_sum(): ...@@ -30,7 +30,7 @@ def test_sum():
}) })
ast = pystencils.create_kernel(assignments) ast = pystencils.create_kernel(assignments)
code = str(pystencils.show_code(ast)) code = str(pystencils.get_code_obj(ast))
kernel = ast.compile() kernel = ast.compile()
print(code) print(code)
...@@ -58,11 +58,11 @@ def test_sum_use_float(): ...@@ -58,11 +58,11 @@ def test_sum_use_float():
}) })
ast = pystencils.create_kernel(assignments, data_type=create_type('float32')) ast = pystencils.create_kernel(assignments, data_type=create_type('float32'))
code = str(pystencils.show_code(ast)) code = str(pystencils.get_code_obj(ast))
kernel = ast.compile() kernel = ast.compile()
print(code) print(code)
print(pystencils.show_code(ast)) print(pystencils.get_code_obj(ast))
assert 'float sum' in code assert 'float sum' in code
array = np.zeros((10,), np.float32) array = np.zeros((10,), np.float32)
...@@ -89,7 +89,7 @@ def test_product(): ...@@ -89,7 +89,7 @@ def test_product():
}) })
ast = pystencils.create_kernel(assignments) ast = pystencils.create_kernel(assignments)
code = str(pystencils.show_code(ast)) code = pystencils.get_code_str(ast)
kernel = ast.compile() kernel = ast.compile()
print(code) print(code)
......
...@@ -18,7 +18,7 @@ def test_sympy_optimizations(): ...@@ -18,7 +18,7 @@ def test_sympy_optimizations():
assignments = optimize_assignments(assignments, optims_pystencils_cpu) assignments = optimize_assignments(assignments, optims_pystencils_cpu)
ast = pystencils.create_kernel(assignments, target=target) ast = pystencils.create_kernel(assignments, target=target)
code = str(pystencils.show_code(ast)) code = pystencils.get_code_str(ast)
assert 'expm1(' in code assert 'expm1(' in code
...@@ -35,7 +35,7 @@ def test_evaluate_constant_terms(): ...@@ -35,7 +35,7 @@ def test_evaluate_constant_terms():
assignments = optimize_assignments(assignments, optims_pystencils_cpu) assignments = optimize_assignments(assignments, optims_pystencils_cpu)
ast = pystencils.create_kernel(assignments, target=target) ast = pystencils.create_kernel(assignments, target=target)
code = str(pystencils.show_code(ast)) code = pystencils.get_code_str(ast)
assert 'cos(' not in code assert 'cos(' not in code
print(code) print(code)
...@@ -55,6 +55,6 @@ def test_do_not_evaluate_constant_terms(): ...@@ -55,6 +55,6 @@ def test_do_not_evaluate_constant_terms():
optimize_assignments(assignments, optimizations) optimize_assignments(assignments, optimizations)
ast = pystencils.create_kernel(assignments, target=target) ast = pystencils.create_kernel(assignments, target=target)
code = str(pystencils.show_code(ast)) code = pystencils.get_code_str(ast)
assert 'cos(' in code assert 'cos(' in code
print(code) print(code)
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