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
hyteg
pystencils
Commits
ad9cba7c
Commit
ad9cba7c
authored
2 years ago
by
Markus Holzer
Committed by
Christoph Alt
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve FLOP counting function
parent
dee98bb8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/sympyextensions.py
+3
-1
3 additions, 1 deletion
pystencils/sympyextensions.py
pystencils_tests/test_sympyextensions.py
+25
-0
25 additions, 0 deletions
pystencils_tests/test_sympyextensions.py
with
28 additions
and
1 deletion
pystencils/sympyextensions.py
+
3
−
1
View file @
ad9cba7c
...
...
@@ -639,8 +639,10 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr], List[Assignment]],
for
child_term
,
condition
in
t
.
args
:
visit
(
child_term
)
visit_children
=
False
elif
isinstance
(
t
,
sp
.
Rel
):
elif
isinstance
(
t
,
(
sp
.
Rel
,
sp
.
UnevaluatedExpr
)
):
pass
elif
isinstance
(
t
,
DivFunc
):
result
[
"
divs
"
]
+=
1
else
:
warnings
.
warn
(
f
"
Unknown sympy node of type
{
str
(
t
.
func
)
}
counting will be inaccurate
"
)
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_sympyextensions.py
+
25
−
0
View file @
ad9cba7c
...
...
@@ -15,6 +15,7 @@ from pystencils.sympyextensions import scalar_product
from
pystencils.sympyextensions
import
kronecker_delta
from
pystencils
import
Assignment
from
pystencils.functions
import
DivFunc
from
pystencils.fast_approximation
import
(
fast_division
,
fast_inv_sqrt
,
fast_sqrt
,
insert_fast_divisions
,
insert_fast_sqrts
)
...
...
@@ -163,6 +164,30 @@ def test_count_operations():
assert
ops
[
'
divs
'
]
==
1
assert
ops
[
'
sqrts
'
]
==
1
expr
=
DivFunc
(
x
,
y
)
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'
divs
'
]
==
1
expr
=
DivFunc
(
x
+
z
,
y
+
z
)
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'
adds
'
]
==
2
assert
ops
[
'
divs
'
]
==
1
expr
=
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
[
x
]
*
100
,
evaluate
=
False
))
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'
muls
'
]
==
99
expr
=
DivFunc
(
1
,
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
[
x
]
*
100
,
evaluate
=
False
)))
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'
divs
'
]
==
1
assert
ops
[
'
muls
'
]
==
99
expr
=
DivFunc
(
y
+
z
,
sp
.
UnevaluatedExpr
(
sp
.
Mul
(
*
[
x
]
*
100
,
evaluate
=
False
)))
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'
adds
'
]
==
1
assert
ops
[
'
divs
'
]
==
1
assert
ops
[
'
muls
'
]
==
99
def
test_common_denominator
():
x
=
sympy
.
symbols
(
'
x
'
)
...
...
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