Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencils_autodiff
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
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
pycodegen
pystencils_autodiff
Commits
af798d17
Commit
af798d17
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Enable use of custom printer for classes with printer variable
parent
d3c15dd7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#19313
failed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils_autodiff/framework_integration/printer.py
+6
-0
6 additions, 0 deletions
src/pystencils_autodiff/framework_integration/printer.py
tests/test_module_printing.py
+22
-3
22 additions, 3 deletions
tests/test_module_printing.py
with
28 additions
and
3 deletions
src/pystencils_autodiff/framework_integration/printer.py
+
6
−
0
View file @
af798d17
...
@@ -15,6 +15,12 @@ class FrameworkIntegrationPrinter(pystencils.backends.cbackend.CBackend):
...
@@ -15,6 +15,12 @@ class FrameworkIntegrationPrinter(pystencils.backends.cbackend.CBackend):
super
().
__init__
(
sympy_printer
=
None
,
super
().
__init__
(
sympy_printer
=
None
,
dialect
=
'
c
'
)
dialect
=
'
c
'
)
def
_print
(
self
,
node
):
from
pystencils_autodiff.framework_integration.astnodes
import
JinjaCppFile
if
isinstance
(
node
,
JinjaCppFile
):
node
.
printer
=
self
return
super
().
_print
(
node
)
def
_print_WrapperFunction
(
self
,
node
):
def
_print_WrapperFunction
(
self
,
node
):
super_result
=
super
().
_print_KernelFunction
(
node
)
super_result
=
super
().
_print_KernelFunction
(
node
)
return
super_result
.
replace
(
'
FUNC_PREFIX
'
,
''
)
return
super_result
.
replace
(
'
FUNC_PREFIX
'
,
''
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_module_printing.py
+
22
−
3
View file @
af798d17
...
@@ -8,11 +8,12 @@
...
@@ -8,11 +8,12 @@
"""
"""
import
pytest
import
pytest
import
sympy
import
pystencils
import
pystencils
import
sympy
from
pystencils_autodiff
import
create_backward_assignments
from
pystencils_autodiff
import
create_backward_assignments
from
pystencils_autodiff.backends.astnodes
import
PybindModule
,
TensorflowModule
,
TorchModule
from
pystencils_autodiff.backends.astnodes
import
PybindModule
,
TensorflowModule
,
TorchModule
from
pystencils_autodiff.framework_integration.printer
import
FrameworkIntegrationPrinter
try
:
try
:
from
pystencils.interpolation_astnodes
import
TextureCachedField
from
pystencils.interpolation_astnodes
import
TextureCachedField
...
@@ -101,5 +102,23 @@ def test_module_printing_globals():
...
@@ -101,5 +102,23 @@ def test_module_printing_globals():
print
(
module
)
print
(
module
)
if
__name__
==
"
__main__
"
:
def
test_custom_printer
():
test_module_printing_globals
()
class
DoesNotLikeTorchPrinter
(
FrameworkIntegrationPrinter
):
def
_print_TorchModule
(
self
,
node
):
return
'
Error: I don
\'
t like Torch
'
z
,
y
,
x
=
pystencils
.
fields
(
"
z, y, x: [20,40]
"
)
forward_assignments
=
pystencils
.
AssignmentCollection
({
z
[
0
,
0
]:
x
[
0
,
0
]
*
sympy
.
log
(
TextureCachedField
(
x
).
at
(
sympy
.
Matrix
((
0.43
,
3
)))
*
y
[
0
,
0
])
})
backward_assignments
=
create_backward_assignments
(
forward_assignments
)
forward_ast
=
pystencils
.
create_kernel
(
forward_assignments
)
forward_ast
.
function_name
=
'
forward
'
backward_ast
=
pystencils
.
create_kernel
(
backward_assignments
)
backward_ast
.
function_name
=
'
backward
'
module
=
TorchModule
(
"
hallo
"
,
[
forward_ast
,
backward_ast
])
print
(
DoesNotLikeTorchPrinter
()(
module
))
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