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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Sebastian Bindgen
pystencils
Commits
dab3371d
Commit
dab3371d
authored
4 years ago
by
Dominik Ernst
Committed by
Markus Holzer
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
count_operations: fix to not count integer expressions for addresses/constants as real operations
parent
99257435
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/sympyextensions.py
+11
-6
11 additions, 6 deletions
pystencils/sympyextensions.py
pystencils_tests/test_simplification_strategy.py
+1
-1
1 addition, 1 deletion
pystencils_tests/test_simplification_strategy.py
with
12 additions
and
7 deletions
pystencils/sympyextensions.py
+
11
−
6
View file @
dab3371d
...
@@ -10,7 +10,8 @@ from sympy.functions import Abs
...
@@ -10,7 +10,8 @@ from sympy.functions import Abs
from
sympy.core.numbers
import
Zero
from
sympy.core.numbers
import
Zero
from
pystencils.assignment
import
Assignment
from
pystencils.assignment
import
Assignment
from
pystencils.data_types
import
cast_func
,
get_base_type
,
get_type_of_expression
from
pystencils.data_types
import
cast_func
,
get_type_of_expression
,
PointerType
from
pystencils.kernelparameters
import
FieldPointerSymbol
T
=
TypeVar
(
'
T
'
)
T
=
TypeVar
(
'
T
'
)
...
@@ -445,7 +446,6 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
...
@@ -445,7 +446,6 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
result
=
{
'
adds
'
:
0
,
'
muls
'
:
0
,
'
divs
'
:
0
,
'
sqrts
'
:
0
,
result
=
{
'
adds
'
:
0
,
'
muls
'
:
0
,
'
divs
'
:
0
,
'
sqrts
'
:
0
,
'
fast_sqrts
'
:
0
,
'
fast_inv_sqrts
'
:
0
,
'
fast_div
'
:
0
}
'
fast_sqrts
'
:
0
,
'
fast_inv_sqrts
'
:
0
,
'
fast_div
'
:
0
}
if
isinstance
(
term
,
Sequence
):
if
isinstance
(
term
,
Sequence
):
for
element
in
term
:
for
element
in
term
:
r
=
count_operations
(
element
,
only_type
)
r
=
count_operations
(
element
,
only_type
)
...
@@ -455,16 +455,18 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
...
@@ -455,16 +455,18 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
elif
isinstance
(
term
,
Assignment
):
elif
isinstance
(
term
,
Assignment
):
term
=
term
.
rhs
term
=
term
.
rhs
if
hasattr
(
term
,
'
evalf
'
):
term
=
term
.
evalf
()
def
check_type
(
e
):
def
check_type
(
e
):
if
only_type
is
None
:
if
only_type
is
None
:
return
True
return
True
if
isinstance
(
e
,
FieldPointerSymbol
)
and
only_type
==
"
real
"
:
return
only_type
==
"
int
"
try
:
try
:
base_type
=
get_base_type
(
get_type_of_expression
(
e
)
)
base_type
=
get_type_of_expression
(
e
)
except
ValueError
:
except
ValueError
:
return
False
return
False
if
isinstance
(
base_type
,
PointerType
):
return
only_type
==
'
int
'
if
only_type
==
'
int
'
and
(
base_type
.
is_int
()
or
base_type
.
is_uint
()):
if
only_type
==
'
int
'
and
(
base_type
.
is_int
()
or
base_type
.
is_uint
()):
return
True
return
True
if
only_type
==
'
real
'
and
(
base_type
.
is_float
()):
if
only_type
==
'
real
'
and
(
base_type
.
is_float
()):
...
@@ -515,6 +517,9 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
...
@@ -515,6 +517,9 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
result
[
'
muls
'
]
+=
(
-
int
(
t
.
exp
))
-
1
result
[
'
muls
'
]
+=
(
-
int
(
t
.
exp
))
-
1
elif
sp
.
nsimplify
(
t
.
exp
)
==
sp
.
Rational
(
1
,
2
):
elif
sp
.
nsimplify
(
t
.
exp
)
==
sp
.
Rational
(
1
,
2
):
result
[
'
sqrts
'
]
+=
1
result
[
'
sqrts
'
]
+=
1
elif
sp
.
nsimplify
(
t
.
exp
)
==
-
sp
.
Rational
(
1
,
2
):
result
[
"
sqrts
"
]
+=
1
result
[
"
divs
"
]
+=
1
else
:
else
:
warnings
.
warn
(
f
"
Cannot handle exponent
{
t
.
exp
}
of sp.Pow node
"
)
warnings
.
warn
(
f
"
Cannot handle exponent
{
t
.
exp
}
of sp.Pow node
"
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_simplification_strategy.py
+
1
−
1
View file @
dab3371d
...
@@ -30,7 +30,7 @@ def test_simplification_strategy():
...
@@ -30,7 +30,7 @@ def test_simplification_strategy():
result
=
strategy
(
ac
)
result
=
strategy
(
ac
)
assert
result
.
operation_count
[
'
adds
'
]
==
7
assert
result
.
operation_count
[
'
adds
'
]
==
7
assert
result
.
operation_count
[
'
muls
'
]
==
5
assert
result
.
operation_count
[
'
muls
'
]
==
4
assert
result
.
operation_count
[
'
divs
'
]
==
0
assert
result
.
operation_count
[
'
divs
'
]
==
0
# Trigger display routines, such that they are at least executed
# Trigger display routines, such that they are at least executed
...
...
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