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
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
Show more breadcrumbs
pycodegen
pystencils
Commits
8b30de1d
Commit
8b30de1d
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Plain Diff
Merge branch 'avoid-jinja2-dependency' into 'master'
Fix
#10
: Avoid jinja2 dependency Closes
#10
See merge request
!18
parents
6942ed0b
74236fab
No related branches found
No related tags found
1 merge request
!18
Fix #10: Avoid jinja2 dependency
Pipeline
#16981
passed with warnings
5 years ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/astnodes.py
+2
-3
2 additions, 3 deletions
pystencils/astnodes.py
pystencils/backends/cbackend.py
+9
-16
9 additions, 16 deletions
pystencils/backends/cbackend.py
pystencils_tests/test_destructuring_field_class.py
+6
-7
6 additions, 7 deletions
pystencils_tests/test_destructuring_field_class.py
with
17 additions
and
26 deletions
pystencils/astnodes.py
+
2
−
3
View file @
8b30de1d
import
uuid
from
typing
import
Any
,
List
,
Optional
,
Sequence
,
Set
,
Union
import
jinja2
import
sympy
as
sp
from
pystencils.data_types
import
TypedSymbol
,
cast_func
,
create_type
...
...
@@ -673,7 +672,7 @@ class DestructuringBindingsForFieldClass(Node):
FieldShapeSymbol
:
"
shape[%i]
"
,
FieldStrideSymbol
:
"
stride[%i]
"
}
CLASS_NAME_TEMPLATE
=
jinja2
.
Template
(
"
PyStencilsField<{
{
dtype
}
}, {
{
ndim
}
}>
"
)
CLASS_NAME_TEMPLATE
=
"
PyStencilsField<{dtype}, {ndim}>
"
@property
def
fields_accessed
(
self
)
->
Set
[
'
ResolvedFieldAccess
'
]:
...
...
@@ -703,7 +702,7 @@ class DestructuringBindingsForFieldClass(Node):
undefined_field_symbols
=
self
.
symbols_defined
corresponding_field_names
=
{
s
.
field_name
for
s
in
undefined_field_symbols
if
hasattr
(
s
,
'
field_name
'
)}
corresponding_field_names
|=
{
s
.
field_names
[
0
]
for
s
in
undefined_field_symbols
if
hasattr
(
s
,
'
field_names
'
)}
return
{
TypedSymbol
(
f
,
self
.
CLASS_NAME_TEMPLATE
.
render
(
dtype
=
field_map
[
f
].
dtype
,
ndim
=
field_map
[
f
].
ndim
)
+
'
&
'
)
return
{
TypedSymbol
(
f
,
self
.
CLASS_NAME_TEMPLATE
.
format
(
dtype
=
field_map
[
f
].
dtype
,
ndim
=
field_map
[
f
].
ndim
)
+
'
&
'
)
for
f
in
corresponding_field_names
}
|
\
(
self
.
body
.
undefined_symbols
-
undefined_field_symbols
)
...
...
This diff is collapsed.
Click to expand it.
pystencils/backends/cbackend.py
+
9
−
16
View file @
8b30de1d
from
collections
import
namedtuple
from
typing
import
Set
import
jinja2
import
sympy
as
sp
from
sympy.core
import
S
from
sympy.printing.ccode
import
C89CodePrinter
...
...
@@ -9,11 +8,12 @@ from sympy.printing.ccode import C89CodePrinter
from
pystencils.astnodes
import
KernelFunction
,
Node
from
pystencils.cpu.vectorization
import
vec_all
,
vec_any
from
pystencils.data_types
import
(
PointerType
,
VectorType
,
address_of
,
cast_func
,
create_type
,
get_type_of_expression
,
reinterpret_cast_func
,
vector_memory_access
)
PointerType
,
VectorType
,
address_of
,
cast_func
,
create_type
,
get_type_of_expression
,
reinterpret_cast_func
,
vector_memory_access
)
from
pystencils.fast_approximation
import
fast_division
,
fast_inv_sqrt
,
fast_sqrt
from
pystencils.integer_functions
import
(
bit_shift_left
,
bit_shift_right
,
bitwise_and
,
bitwise_or
,
bitwise_xor
,
int_div
,
int_power_of_2
,
modulo_ceil
)
bit_shift_left
,
bit_shift_right
,
bitwise_and
,
bitwise_or
,
bitwise_xor
,
int_div
,
int_power_of_2
,
modulo_ceil
)
from
pystencils.kernelparameters
import
FieldPointerSymbol
try
:
...
...
@@ -271,18 +271,11 @@ class CBackend:
for
u
in
undefined_field_symbols
]
destructuring_bindings
.
sort
()
# only for code aesthetics
template
=
jinja2
.
Template
(
"""
{
{% for binding in bindings -%}
{{ binding | indent(3) }}
{% endfor -%}
{{ block | indent(3) }}
}
"""
)
code
=
template
.
render
(
bindings
=
destructuring_bindings
,
block
=
self
.
_print
(
node
.
body
))
return
code
return
"
{
\n
"
+
self
.
_indent
+
\
(
"
\n
"
+
self
.
_indent
).
join
(
destructuring_bindings
)
+
\
"
\n
"
+
self
.
_indent
+
\
(
"
\n
"
+
self
.
_indent
).
join
(
self
.
_print
(
node
.
body
).
splitlines
())
+
\
"
\n
}
"
# ------------------------------------------ Helper function & classes -------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_destructuring_field_class.py
+
6
−
7
View file @
8b30de1d
import
sympy
import
jinja2
import
pystencils
from
pystencils.astnodes
import
DestructuringBindingsForFieldClass
from
pystencils.kernelparameters
import
FieldPointerSymbol
,
FieldShapeSymbol
,
FieldStrideSymbol
from
pystencils.kernelparameters
import
FieldPointerSymbol
,
FieldShapeSymbol
,
FieldStrideSymbol
def
test_destructuring_field_class
():
...
...
@@ -28,12 +25,13 @@ class DestructuringEmojiClass(DestructuringBindingsForFieldClass):
FieldShapeSymbol
:
"
😳_%i
"
,
FieldStrideSymbol
:
"
🥵_%i
"
}
CLASS_NAME_TEMPLATE
=
jinja2
.
Template
(
"
🤯<{{ dtype }}, {{ ndim }}>
"
)
CLASS_NAME_TEMPLATE
=
"
🤯<{dtype}, {ndim}>
"
def
__init__
(
self
,
node
):
super
().
__init__
(
node
)
self
.
headers
=
[]
def
test_destructuring_alternative_field_class
():
z
,
x
,
y
=
pystencils
.
fields
(
"
z, y, x: [2d]
"
)
...
...
@@ -44,6 +42,7 @@ def test_destructuring_alternative_field_class():
ast
.
body
=
DestructuringEmojiClass
(
ast
.
body
)
print
(
pystencils
.
show_code
(
ast
))
def
main
():
test_destructuring_field_class
()
test_destructuring_alternative_field_class
()
...
...
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