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
e867d1f6
Commit
e867d1f6
authored
4 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Added test cases for stencil
parent
6aa28a4b
No related branches found
No related tags found
1 merge request
!168
Extend testsuite
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/stencil.py
+5
-0
5 additions, 0 deletions
pystencils/stencil.py
pystencils_tests/test_staggered_kernel.py
+10
-0
10 additions, 0 deletions
pystencils_tests/test_staggered_kernel.py
pystencils_tests/test_stencils.py
+29
-0
29 additions, 0 deletions
pystencils_tests/test_stencils.py
with
44 additions
and
0 deletions
pystencils/stencil.py
+
5
−
0
View file @
e867d1f6
...
@@ -34,6 +34,8 @@ def is_valid(stencil, max_neighborhood=None):
...
@@ -34,6 +34,8 @@ def is_valid(stencil, max_neighborhood=None):
True
True
>>>
is_valid
([(
2
,
0
),
(
1
,
0
)],
max_neighborhood
=
1
)
>>>
is_valid
([(
2
,
0
),
(
1
,
0
)],
max_neighborhood
=
1
)
False
False
>>>
is_valid
([(
2
,
0
),
(
1
,
0
)],
max_neighborhood
=
2
)
True
"""
"""
expected_dim
=
len
(
stencil
[
0
])
expected_dim
=
len
(
stencil
[
0
])
for
d
in
stencil
:
for
d
in
stencil
:
...
@@ -67,8 +69,11 @@ def have_same_entries(s1, s2):
...
@@ -67,8 +69,11 @@ def have_same_entries(s1, s2):
Examples:
Examples:
>>>
stencil1
=
[(
1
,
0
),
(
-
1
,
0
),
(
0
,
1
),
(
0
,
-
1
)]
>>>
stencil1
=
[(
1
,
0
),
(
-
1
,
0
),
(
0
,
1
),
(
0
,
-
1
)]
>>>
stencil2
=
[(
-
1
,
0
),
(
0
,
-
1
),
(
1
,
0
),
(
0
,
1
)]
>>>
stencil2
=
[(
-
1
,
0
),
(
0
,
-
1
),
(
1
,
0
),
(
0
,
1
)]
>>>
stencil3
=
[(
-
1
,
0
),
(
0
,
-
1
),
(
1
,
0
)]
>>>
have_same_entries
(
stencil1
,
stencil2
)
>>>
have_same_entries
(
stencil1
,
stencil2
)
True
True
>>>
have_same_entries
(
stencil1
,
stencil3
)
False
"""
"""
if
len
(
s1
)
!=
len
(
s2
):
if
len
(
s1
)
!=
len
(
s2
):
return
False
return
False
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_staggered_kernel.py
+
10
−
0
View file @
e867d1f6
...
@@ -4,6 +4,7 @@ import sympy as sp
...
@@ -4,6 +4,7 @@ import sympy as sp
import
pytest
import
pytest
import
pystencils
as
ps
import
pystencils
as
ps
from
pystencils
import
x_staggered_vector
,
TypedSymbol
class
TestStaggeredDiffusion
:
class
TestStaggeredDiffusion
:
...
@@ -96,3 +97,12 @@ def test_staggered_loop_cutting():
...
@@ -96,3 +97,12 @@ def test_staggered_loop_cutting():
assignments
=
[
ps
.
Assignment
(
j
.
staggered_access
(
"
SW
"
),
1
)]
assignments
=
[
ps
.
Assignment
(
j
.
staggered_access
(
"
SW
"
),
1
)]
ast
=
ps
.
create_staggered_kernel
(
assignments
,
target
=
dh
.
default_target
)
ast
=
ps
.
create_staggered_kernel
(
assignments
,
target
=
dh
.
default_target
)
assert
not
ast
.
atoms
(
ps
.
astnodes
.
Conditional
)
assert
not
ast
.
atoms
(
ps
.
astnodes
.
Conditional
)
def
test_staggered_vector
():
dim
=
2
v
=
x_staggered_vector
(
dim
)
ctr0
=
TypedSymbol
(
'
ctr_0
'
,
'
int
'
,
nonnegative
=
True
)
ctr1
=
TypedSymbol
(
'
ctr_1
'
,
'
int
'
,
nonnegative
=
True
)
expected_result
=
sp
.
Matrix
(
tuple
((
ctr0
+
0.5
,
ctr1
+
0.5
)))
assert
v
==
expected_result
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pystencils_tests/test_stencils.py
+
29
−
0
View file @
e867d1f6
import
pystencils
as
ps
import
pystencils
as
ps
import
sympy
as
sp
from
pystencils.stencil
import
coefficient_list
,
plot_expression
def
test_coefficient_list
():
f
=
ps
.
fields
(
"
f: double[1D]
"
)
expr
=
2
*
f
[
1
]
+
3
*
f
[
-
1
]
coff
=
coefficient_list
(
expr
)
assert
coff
==
[
3
,
0
,
2
]
plot_expression
(
expr
,
matrix_form
=
True
)
f
=
ps
.
fields
(
"
f: double[3D]
"
)
expr
=
2
*
f
[
1
,
0
,
0
]
+
3
*
f
[
0
,
-
1
,
0
]
coff
=
coefficient_list
(
expr
)
assert
coff
==
[[[
0
,
3
,
0
],
[
0
,
0
,
2
],
[
0
,
0
,
0
]]]
expr
=
2
*
f
[
1
,
0
,
0
]
+
3
*
f
[
0
,
-
1
,
0
]
+
4
*
f
[
0
,
0
,
1
]
coff
=
coefficient_list
(
expr
,
matrix_form
=
True
)
assert
coff
[
0
]
==
sp
.
zeros
(
3
,
3
)
# in 3D plot only works if there are entries on every of the three 2D planes. In the above examples z-1 was empty
expr
=
2
*
f
[
1
,
0
,
0
]
+
1
*
f
[
0
,
-
1
,
0
]
+
1
*
f
[
0
,
0
,
1
]
+
f
[
0
,
0
,
-
1
]
plot_expression
(
expr
)
def
test_plot_expression
():
f
=
ps
.
fields
(
"
f: double[2D]
"
)
plot_expression
(
2
*
f
[
1
,
0
]
+
3
*
f
[
0
,
-
1
],
matrix_form
=
True
)
\ No newline at end of file
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