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
Merge requests
!337
Add adjacent direcitons to stencil module
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add adjacent direcitons to stencil module
holzer/pystencils:stencil_util
into
master
Overview
0
Commits
5
Pipelines
5
Changes
2
Merged
Markus Holzer
requested to merge
holzer/pystencils:stencil_util
into
master
1 year ago
Overview
0
Commits
5
Pipelines
5
Changes
2
Expand
0
0
Merge request reports
Compare
master
version 4
66d80dbe
1 year ago
version 3
3ef09900
1 year ago
version 2
a5a3a18c
1 year ago
version 1
5fd6f332
1 year ago
master (base)
and
latest version
latest version
e0d338ee
5 commits,
1 year ago
version 4
66d80dbe
4 commits,
1 year ago
version 3
3ef09900
3 commits,
1 year ago
version 2
a5a3a18c
2 commits,
1 year ago
version 1
5fd6f332
1 commit,
1 year ago
2 files
+
49
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
pystencils/stencil.py
+
34
−
0
Options
@@ -5,6 +5,8 @@ from typing import Sequence
import
numpy
as
np
import
sympy
as
sp
from
pystencils.utils
import
binary_numbers
def
inverse_direction
(
direction
):
"""
Returns inverse i.e. negative of given direction tuple
@@ -293,6 +295,38 @@ def direction_string_to_offset(direction: str, dim: int = 3):
return
offset
[:
dim
]
def
adjacent_directions
(
direction
):
"""
Returns all adjacent directions for a direction as tuple of tuples. This is useful for exmple to find all directions
relevant for neighbour communication.
Args:
direction: tuple representing a direction. For example (0, 1, 0) for the northern side
Examples:
>>>
adjacent_directions
((
0
,
0
,
0
))
((
0
,
0
,
0
),)
>>>
adjacent_directions
((
0
,
1
,
0
))
((
0
,
1
,
0
),)
>>>
adjacent_directions
((
0
,
1
,
1
))
((
0
,
0
,
1
),
(
0
,
1
,
0
),
(
0
,
1
,
1
))
>>>
adjacent_directions
((
-
1
,
-
1
))
((
-
1
,
-
1
),
(
-
1
,
0
),
(
0
,
-
1
))
"""
result
=
set
()
if
all
(
e
==
0
for
e
in
direction
):
result
.
add
(
direction
)
return
tuple
(
result
)
binary_numbers_list
=
binary_numbers
(
len
(
direction
))
for
adjacent_direction
in
binary_numbers_list
:
for
i
,
entry
in
enumerate
(
direction
):
if
entry
==
0
:
adjacent_direction
[
i
]
=
0
if
entry
==
-
1
and
adjacent_direction
[
i
]
==
1
:
adjacent_direction
[
i
]
=
-
1
if
not
all
(
e
==
0
for
e
in
adjacent_direction
):
result
.
add
(
tuple
(
adjacent_direction
))
return
tuple
(
sorted
(
result
))
# -------------------------------------- Visualization -----------------------------------------------------------------
Loading