Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Hönig
pystencils
Commits
130619f9
Commit
130619f9
authored
3 years ago
by
Jan Hönig
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
354fede8
No related branches found
No related tags found
No related merge requests found
Pipeline
#40439
failed
3 years ago
Stage: pretest
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/display_utils.py
+43
-0
43 additions, 0 deletions
pystencils/display_utils.py
pystencils_tests/test_show_assembly.py
+8
-0
8 additions, 0 deletions
pystencils_tests/test_show_assembly.py
with
51 additions
and
0 deletions
pystencils/display_utils.py
+
43
−
0
View file @
130619f9
...
@@ -70,6 +70,32 @@ def get_code_obj(ast: Union[KernelFunction, KernelWrapper], custom_backend=None)
...
@@ -70,6 +70,32 @@ def get_code_obj(ast: Union[KernelFunction, KernelWrapper], custom_backend=None)
return
CodeDisplay
(
ast
)
return
CodeDisplay
(
ast
)
def
get_assembly_obj
(
ast
:
Union
[
KernelFunction
,
KernelWrapper
]):
"""
Returns an object to display generated assembly code (C/C++)
Can either be displayed as HTML in Jupyter notebooks or printed as normal string.
"""
from
pystencils.backends.cbackend
import
generate_c
if
isinstance
(
ast
,
KernelWrapper
):
ast
=
ast
.
ast
code
=
generate_c
(
ast
,
dialect
=
ast
.
backend
)
class
AssemlbyDisplay
:
def
__init__
(
self
,
assembly
):
self
.
assembly
=
assembly
def
_repr_html
(
self
):
return
''
def
__str__
(
self
):
return
''
def
__repr__
(
self
):
return
''
return
AssemlbyDisplay
(
assembly
)
def
get_code_str
(
ast
,
custom_backend
=
None
):
def
get_code_str
(
ast
,
custom_backend
=
None
):
return
str
(
get_code_obj
(
ast
,
custom_backend
))
return
str
(
get_code_obj
(
ast
,
custom_backend
))
...
@@ -102,3 +128,20 @@ def show_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None):
...
@@ -102,3 +128,20 @@ def show_code(ast: Union[KernelFunction, KernelWrapper], custom_backend=None):
console
.
print
(
syntax
)
console
.
print
(
syntax
)
except
ImportError
:
except
ImportError
:
print
(
code
)
print
(
code
)
def
show_assembly
(
ast
:
Union
[
KernelFunction
,
KernelWrapper
]):
code
=
get_assembly_obj
(
ast
)
if
_isnotebook
():
from
IPython.display
import
display
display
(
code
)
else
:
try
:
import
rich.syntax
import
rich.console
syntax
=
rich
.
syntax
.
Syntax
(
str
(
code
),
"
c++
"
,
theme
=
"
monokai
"
,
line_numbers
=
True
)
console
=
rich
.
console
.
Console
()
console
.
print
(
syntax
)
except
ImportError
:
print
(
code
)
This diff is collapsed.
Click to expand it.
pystencils_tests/test_show_assembly.py
0 → 100644
+
8
−
0
View file @
130619f9
import
pytest
import
sympy
as
sp
import
pystencils
as
ps
def
test_simple
():
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment