Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
bec36bb2
Commit
bec36bb2
authored
Jan 20, 2020
by
Stephan Seitz
Browse files
Rename: get_code -> get_code_obj
parent
1e7a179a
Pipeline
#21179
passed with stage
in 3 minutes and 16 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/__init__.py
View file @
bec36bb2
...
...
@@ -5,7 +5,7 @@ from . import stencil as stencil
from
.assignment
import
Assignment
,
assignment_from_stencil
from
.data_types
import
TypedSymbol
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
.kernel_decorator
import
kernel
from
.kernelcreation
import
create_indexed_kernel
,
create_kernel
,
create_staggered_kernel
...
...
@@ -25,7 +25,7 @@ __all__ = ['Field', 'FieldType', 'fields',
'TypedSymbol'
,
'make_slice'
,
'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'
,
'Assignment'
,
'assignment_from_stencil'
,
...
...
pystencils/display_utils.py
View file @
bec36bb2
...
...
@@ -35,7 +35,7 @@ def highlight_cpp(code: str):
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)
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):
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
):
code
=
get_code
(
ast
,
custom_backend
)
code
=
get_code
_obj
(
ast
,
custom_backend
)
try
:
from
IPython.display
import
display
...
...
pystencils_tests/test_jacobi_cbackend.py
View file @
bec36bb2
import
numpy
as
np
from
pystencils
import
get_code
from
pystencils
import
get_code
_obj
from
pystencils.astnodes
import
Block
,
KernelFunction
,
SympyAssignment
from
pystencils.cpu
import
make_python_function
from
pystencils.field
import
Field
...
...
@@ -36,7 +36,7 @@ def test_jacobi_fixed_field_size():
error
=
np
.
sum
(
np
.
abs
(
dst_field_py
-
dst_field_c
))
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
code_display
.
_repr_html_
()
...
...
pystencils_tests/test_sum_prod.py
View file @
bec36bb2
...
...
@@ -30,7 +30,7 @@ def test_sum():
})
ast
=
pystencils
.
create_kernel
(
assignments
)
code
=
str
(
pystencils
.
show
_code
(
ast
))
code
=
str
(
pystencils
.
get
_code
_obj
(
ast
))
kernel
=
ast
.
compile
()
print
(
code
)
...
...
@@ -58,11 +58,11 @@ def test_sum_use_float():
})
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
()
print
(
code
)
print
(
pystencils
.
show
_code
(
ast
))
print
(
pystencils
.
get
_code
_obj
(
ast
))
assert
'float sum'
in
code
array
=
np
.
zeros
((
10
,),
np
.
float32
)
...
...
@@ -89,7 +89,7 @@ def test_product():
})
ast
=
pystencils
.
create_kernel
(
assignments
)
code
=
str
(
pystencils
.
show
_code
(
ast
)
)
code
=
pystencils
.
get
_code
_str
(
ast
)
kernel
=
ast
.
compile
()
print
(
code
)
...
...
pystencils_tests/test_sympy_optimizations.py
View file @
bec36bb2
...
...
@@ -18,7 +18,7 @@ def test_sympy_optimizations():
assignments
=
optimize_assignments
(
assignments
,
optims_pystencils_cpu
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
target
)
code
=
str
(
pystencils
.
show
_code
(
ast
)
)
code
=
pystencils
.
get
_code
_str
(
ast
)
assert
'expm1('
in
code
...
...
@@ -35,7 +35,7 @@ def test_evaluate_constant_terms():
assignments
=
optimize_assignments
(
assignments
,
optims_pystencils_cpu
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
target
)
code
=
str
(
pystencils
.
show
_code
(
ast
)
)
code
=
pystencils
.
get
_code
_str
(
ast
)
assert
'cos('
not
in
code
print
(
code
)
...
...
@@ -55,6 +55,6 @@ def test_do_not_evaluate_constant_terms():
optimize_assignments
(
assignments
,
optimizations
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
target
)
code
=
str
(
pystencils
.
show
_code
(
ast
)
)
code
=
pystencils
.
get
_code
_str
(
ast
)
assert
'cos('
in
code
print
(
code
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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