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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
1c5814c2
Commit
1c5814c2
authored
Oct 23, 2022
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
node collection replacements more specific
parent
404f5138
No related branches found
No related tags found
1 merge request
!306
Improve Vectorisation
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/node_collection.py
+7
-5
7 additions, 5 deletions
pystencils/node_collection.py
pystencils_tests/test_vectorization.py
+1
-0
1 addition, 0 deletions
pystencils_tests/test_vectorization.py
with
8 additions
and
5 deletions
pystencils/node_collection.py
+
7
−
5
View file @
1c5814c2
...
@@ -43,14 +43,15 @@ class NodeCollection:
...
@@ -43,14 +43,15 @@ class NodeCollection:
def
evaluate_terms
(
self
):
def
evaluate_terms
(
self
):
evaluate_constant_terms
=
ReplaceOptim
(
evaluate_constant_terms
=
ReplaceOptim
(
lambda
e
:
hasattr
(
e
,
'
is_constant
'
)
and
e
.
is_constant
and
not
e
.
is_integer
,
lambda
e
:
hasattr
(
e
,
'
is_constant
'
)
and
e
.
is_constant
and
not
e
.
is_integer
,
lambda
p
:
p
.
evalf
())
lambda
p
:
p
.
evalf
()
)
evaluate_pow
=
ReplaceOptim
(
evaluate_pow
=
ReplaceOptim
(
lambda
e
:
e
.
is_Pow
and
e
.
exp
.
is_Integer
and
abs
(
e
.
exp
)
<=
8
,
lambda
e
:
e
.
is_Pow
and
e
.
exp
.
is_Integer
and
abs
(
e
.
exp
)
<=
8
,
lambda
p
:
(
lambda
p
:
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
([
p
.
base
]
*
+
p
.
exp
),
evaluate
=
False
))
if
p
.
exp
>
0
else
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
([
p
.
base
]
*
+
p
.
exp
),
evaluate
=
False
)
)
if
p
.
exp
>
0
else
(
DivFunc
(
sp
.
Integer
(
1
),
p
.
base
)
if
p
.
exp
==
-
1
else
DivFunc
(
sp
.
Integer
(
1
),
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
([
p
.
base
]
*
-
p
.
exp
),
evaluate
=
False
)))
DivFunc
(
sp
.
Integer
(
1
),
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
([
p
.
base
]
*
-
p
.
exp
),
evaluate
=
False
)))
)
)
)
)
sympy_optimisations
=
[
evaluate_constant_terms
,
evaluate_pow
]
sympy_optimisations
=
[
evaluate_constant_terms
,
evaluate_pow
]
if
self
.
is_Nodes
:
if
self
.
is_Nodes
:
...
@@ -65,6 +66,7 @@ class NodeCollection:
...
@@ -65,6 +66,7 @@ class NodeCollection:
return
optimize
(
node
,
sympy_optimisations
)
return
optimize
(
node
,
sympy_optimisations
)
else
:
else
:
raise
NotImplementedError
(
f
'
{
node
}
{
type
(
node
)
}
has no valid visitor
'
)
raise
NotImplementedError
(
f
'
{
node
}
{
type
(
node
)
}
has no valid visitor
'
)
self
.
all_assignments
=
[
visitor
(
assignment
)
for
assignment
in
self
.
all_assignments
]
self
.
all_assignments
=
[
visitor
(
assignment
)
for
assignment
in
self
.
all_assignments
]
else
:
else
:
self
.
all_assignments
=
[
Assignment
(
a
.
lhs
,
optimize
(
a
.
rhs
,
sympy_optimisations
))
self
.
all_assignments
=
[
Assignment
(
a
.
lhs
,
optimize
(
a
.
rhs
,
sympy_optimisations
))
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_vectorization.py
+
1
−
0
View file @
1c5814c2
...
@@ -282,6 +282,7 @@ def test_vectorised_pow(instruction_set=instruction_set):
...
@@ -282,6 +282,7 @@ def test_vectorised_pow(instruction_set=instruction_set):
ast
=
ps
.
create_kernel
(
as6
)
ast
=
ps
.
create_kernel
(
as6
)
vectorize
(
ast
,
instruction_set
=
instruction_set
)
vectorize
(
ast
,
instruction_set
=
instruction_set
)
ps
.
show_code
(
ast
)
ast
.
compile
()
ast
.
compile
()
...
...
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
sign in
to comment