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
0fd71fbf
Commit
0fd71fbf
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs recently introduced in topological sort generalizations
parent
bd49f37e
No related branches found
No related tags found
No related merge requests found
Pipeline
#17098
passed
5 years ago
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/simp/assignment_collection.py
+3
-3
3 additions, 3 deletions
pystencils/simp/assignment_collection.py
pystencils/simp/simplifications.py
+5
-4
5 additions, 4 deletions
pystencils/simp/simplifications.py
with
8 additions
and
7 deletions
pystencils/simp/assignment_collection.py
+
3
−
3
View file @
0fd71fbf
...
...
@@ -5,7 +5,7 @@ import sympy as sp
from
pystencils.assignment
import
Assignment
from
pystencils.simp.simplifications
import
(
sort_assignments_topologically
,
sympy_cse_on_assignment_list
,
sort_assignments_topologically
,
transform_lhs_and_rhs
,
transform_rhs
)
from
pystencils.sympyextensions
import
count_operations
,
fast_subs
...
...
@@ -85,9 +85,9 @@ class AssignmentCollection:
def
topological_sort
(
self
,
sort_subexpressions
:
bool
=
True
,
sort_main_assignments
:
bool
=
True
)
->
None
:
"""
Sorts subexpressions and/or main_equations topologically to make sure symbol usage comes after definition.
"""
if
sort_subexpressions
:
self
.
subexpressions
=
s
ympy_cse_on_assignment_list
(
self
.
subexpressions
)
self
.
subexpressions
=
s
ort_assignments_topologically
(
self
.
subexpressions
)
if
sort_main_assignments
:
self
.
main_assignments
=
s
ympy_cse_on_assignment_list
(
self
.
main_assignments
)
self
.
main_assignments
=
s
ort_assignments_topologically
(
self
.
main_assignments
)
# ---------------------------------------------- Properties -------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
pystencils/simp/simplifications.py
+
5
−
4
View file @
0fd71fbf
...
...
@@ -13,12 +13,13 @@ def sort_assignments_topologically(assignments: Sequence[Union[Assignment, Node]
"""
Sorts assignments in topological order, such that symbols used on rhs occur first on a lhs
"""
edges
=
[]
for
c1
,
e1
in
enumerate
(
assignments
):
if
isinstance
(
e1
,
Assignment
):
if
hasattr
(
e1
,
'
lhs
'
)
and
hasattr
(
e1
,
'
rhs
'
):
symbols
=
[
e1
.
lhs
]
elif
isinstance
(
e1
,
Node
):
symbols
=
e1
.
symbols_defined
else
:
symbols
=
[]
raise
NotImplementedError
(
"
Cannot sort topologically. Object of type
"
+
type
(
e1
)
+
"
cannot be handled.
"
)
for
lhs
in
symbols
:
for
c2
,
e2
in
enumerate
(
assignments
):
if
isinstance
(
e2
,
Assignment
)
and
lhs
in
e2
.
rhs
.
free_symbols
:
...
...
@@ -155,14 +156,14 @@ def transform_rhs(assignment_list, transformation, *args, **kwargs):
"""
Applies a transformation function on the rhs of each element of the passed assignment list
If the list also contains other object, like AST nodes, these are ignored.
Additional parameters are passed to the transformation function
"""
return
[
Assignment
(
a
.
lhs
,
transformation
(
a
.
rhs
,
*
args
,
**
kwargs
))
if
isinstance
(
a
,
Assignment
)
else
a
return
[
Assignment
(
a
.
lhs
,
transformation
(
a
.
rhs
,
*
args
,
**
kwargs
))
if
hasattr
(
a
,
'
lhs
'
)
and
hasattr
(
a
,
'
rhs
'
)
else
a
for
a
in
assignment_list
]
def
transform_lhs_and_rhs
(
assignment_list
,
transformation
,
*
args
,
**
kwargs
):
return
[
Assignment
(
transformation
(
a
.
lhs
,
*
args
,
**
kwargs
),
transformation
(
a
.
rhs
,
*
args
,
**
kwargs
))
if
isinstance
(
a
,
Assignment
)
else
a
if
hasattr
(
a
,
'
lhs
'
)
and
hasattr
(
a
,
'
rhs
'
)
else
a
for
a
in
assignment_list
]
...
...
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