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
!23
Seeding of RNG
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Seeding of RNG
rng_seed
into
test_martin
Overview
2
Commits
3
Pipelines
1
Changes
4
Closed
Michael Kuron
requested to merge
rng_seed
into
test_martin
5 years ago
Overview
2
Commits
3
Pipelines
1
Changes
4
Expand
For
lbmpy!2 (closed)
0
0
Merge request reports
Compare
test_martin
version 5
7d06580f
5 years ago
version 4
7d06580f
5 years ago
version 3
7d06580f
5 years ago
version 2
7d06580f
5 years ago
version 1
7d06580f
5 years ago
test_martin (base)
and
latest version
latest version
7d06580f
3 commits,
5 years ago
version 5
7d06580f
3 commits,
5 years ago
version 4
7d06580f
3 commits,
5 years ago
version 3
7d06580f
3 commits,
5 years ago
version 2
7d06580f
3 commits,
5 years ago
version 1
7d06580f
1 commit,
5 years ago
4 files
+
52
−
23
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
pystencils/simp/assignment_collection.py
+
43
−
10
Options
@@ -4,7 +4,23 @@ from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Set,
import
sympy
as
sp
from
pystencils.assignment
import
Assignment
from
pystencils.sympyextensions
import
count_operations
,
fast_subs
,
sort_assignments_topologically
from
pystencils.astnodes
import
Node
from
pystencils.sympyextensions
import
count_operations
,
fast_subs
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
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
for
a
in
assignment_list
]
class
AssignmentCollection
:
@@ -205,17 +221,15 @@ class AssignmentCollection:
Returns:
New AssignmentCollection where substitutions have been applied, self is not altered.
"""
if
substitute_on_lhs
:
new_subexpressions
=
[
fast_subs
(
eq
,
substitutions
)
for
eq
in
self
.
subexpressions
]
new_equations
=
[
fast_subs
(
eq
,
substitutions
)
for
eq
in
self
.
main_assignments
]
else
:
new_subexpressions
=
[
Assignment
(
eq
.
lhs
,
fast_subs
(
eq
.
rhs
,
substitutions
))
for
eq
in
self
.
subexpressions
]
new_equations
=
[
Assignment
(
eq
.
lhs
,
fast_subs
(
eq
.
rhs
,
substitutions
))
for
eq
in
self
.
main_assignments
]
transform
=
transform_lhs_and_rhs
if
substitute_on_lhs
else
transform_rhs
transformed_subexpressions
=
transform
(
self
.
subexpressions
,
fast_subs
,
substitutions
)
transformed_assignments
=
transform
(
self
.
main_assignments
,
fast_subs
,
substitutions
)
if
add_substitutions_as_subexpressions
:
new_subexpressions
=
[
Assignment
(
b
,
a
)
for
a
,
b
in
substitutions
.
items
()]
+
new_subexpressions
new_subexpressions
=
sort_assignments_topologically
(
new_subexpressions
)
return
self
.
copy
(
new_equations
,
new_subexpressions
)
transformed_subexpressions
=
[
Assignment
(
b
,
a
)
for
a
,
b
in
substitutions
.
items
()]
+
transformed_subexpressions
transformed_subexpressions
=
sort_assignments_topologically
(
transformed_subexpressions
)
return
self
.
copy
(
transformed_assignments
,
transformed_subexpressions
)
def
new_merged
(
self
,
other
:
'
AssignmentCollection
'
)
->
'
AssignmentCollection
'
:
"""
Returns a new collection which contains self and other. Subexpressions are renamed if they clash.
"""
@@ -377,3 +391,22 @@ class SymbolGen:
name
=
"
{}_{}
"
.
format
(
self
.
_symbol
,
self
.
_ctr
)
self
.
_ctr
+=
1
return
sp
.
Symbol
(
name
)
def
sort_assignments_topologically
(
assignments
:
Sequence
[
Union
[
Assignment
,
Node
]])
->
List
[
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
):
symbols
=
[
e1
.
lhs
]
elif
isinstance
(
e1
,
Node
):
symbols
=
e1
.
symbols_defined
else
:
symbols
=
[]
for
lhs
in
symbols
:
for
c2
,
e2
in
enumerate
(
assignments
):
if
isinstance
(
e2
,
Assignment
)
and
lhs
in
e2
.
rhs
.
free_symbols
:
edges
.
append
((
c1
,
c2
))
elif
isinstance
(
e2
,
Node
)
and
lhs
in
e2
.
undefined_symbols
:
edges
.
append
((
c1
,
c2
))
return
[
assignments
[
i
]
for
i
in
sp
.
topological_sort
((
range
(
len
(
assignments
)),
edges
))]
Loading