Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils-sfg
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
pycodegen
pystencils-sfg
Commits
36c55793
Commit
36c55793
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
add define_once and custom generators; made define variadic
parent
b89a3ab8
No related branches found
No related tags found
No related merge requests found
Pipeline
#58817
passed
1 year ago
Stage: pretest
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencilssfg/composer/basic_composer.py
+15
-3
15 additions, 3 deletions
src/pystencilssfg/composer/basic_composer.py
src/pystencilssfg/composer/custom.py
+11
-0
11 additions, 0 deletions
src/pystencilssfg/composer/custom.py
with
26 additions
and
3 deletions
src/pystencilssfg/composer/basic_composer.py
+
15
−
3
View file @
36c55793
...
...
@@ -6,6 +6,7 @@ import numpy as np
from
pystencils
import
Field
,
TypedSymbol
from
pystencils.astnodes
import
KernelFunction
from
.custom
import
CustomGenerator
from
..tree
import
(
SfgCallTreeNode
,
SfgKernelCallNode
,
...
...
@@ -53,14 +54,25 @@ class SfgBasicComposer:
"""
self
.
_ctx
.
append_to_prelude
(
content
)
def
define
(
self
,
definition
:
str
):
"""
Add a custom definition to the generated header file.
"""
self
.
_ctx
.
add_definition
(
definition
)
def
define
(
self
,
*
definitions
:
str
):
"""
Add custom definitions to the generated header file.
"""
for
d
in
definitions
:
self
.
_ctx
.
add_definition
(
d
)
def
define_once
(
self
,
*
definitions
:
str
):
"""
Same as `define`, but only adds definitions only if the same code string was not already added.
"""
for
definition
in
definitions
:
if
all
(
d
!=
definition
for
d
in
self
.
_ctx
.
definitions
()):
self
.
_ctx
.
add_definition
(
definition
)
def
namespace
(
self
,
namespace
:
str
):
"""
Set the inner code namespace. Throws an exception if a namespace was already set.
"""
self
.
_ctx
.
set_namespace
(
namespace
)
def
generate
(
self
,
generator
:
CustomGenerator
):
"""
Invokes a custom code generator with the underlying context.
"""
generator
.
generate
(
self
.
_ctx
)
@property
def
kernels
(
self
)
->
SfgKernelNamespace
:
"""
The default kernel namespace. Add kernels like:
...
...
This diff is collapsed.
Click to expand it.
src/pystencilssfg/composer/custom.py
0 → 100644
+
11
−
0
View file @
36c55793
from
abc
import
ABC
,
abstractmethod
from
..context
import
SfgContext
class
CustomGenerator
(
ABC
):
"""
Abstract base class for custom code generators that may be passed to
[SfgComposer.generate][pystencilssfg.SfgComposer.generate].
"""
@abstractmethod
def
generate
(
self
,
ctx
:
SfgContext
)
->
None
:
...
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