Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
d0a06963
Commit
d0a06963
authored
Aug 09, 2020
by
Markus Holzer
Browse files
Fixed operation count
parent
e462d7f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
pystencils/sympyextensions.py
View file @
d0a06963
...
...
@@ -481,7 +481,7 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
pass
elif
t
.
func
is
sp
.
Mul
:
if
check_type
(
t
):
result
[
'muls'
]
+=
len
(
t
.
args
)
result
[
'muls'
]
+=
len
(
t
.
args
)
-
1
for
a
in
t
.
args
:
if
a
==
1
or
a
==
-
1
:
result
[
'muls'
]
-=
1
...
...
@@ -509,7 +509,8 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
if
t
.
exp
>=
0
:
result
[
'muls'
]
+=
int
(
t
.
exp
)
-
1
else
:
result
[
'muls'
]
-=
1
if
result
[
'muls'
]
>
0
:
result
[
'muls'
]
-=
1
result
[
'divs'
]
+=
1
result
[
'muls'
]
+=
(
-
int
(
t
.
exp
))
-
1
elif
sp
.
nsimplify
(
t
.
exp
)
==
sp
.
Rational
(
1
,
2
):
...
...
pystencils_tests/test_datahandling.py
View file @
d0a06963
...
...
@@ -116,9 +116,6 @@ def kernel_execution_jacobi(dh, target):
assert
dh
.
is_on_gpu
(
'f'
)
assert
dh
.
is_on_gpu
(
'tmp'
)
with
pytest
.
raises
(
ValueError
):
dh
.
add_array
(
'f'
,
gpu
=
test_gpu
)
stencil_2d
=
[(
1
,
0
),
(
-
1
,
0
),
(
0
,
1
),
(
0
,
-
1
)]
stencil_3d
=
[(
1
,
0
,
0
),
(
-
1
,
0
,
0
),
(
0
,
1
,
0
),
(
0
,
-
1
,
0
),
(
0
,
0
,
1
),
(
0
,
0
,
-
1
)]
stencil
=
stencil_2d
if
dh
.
dim
==
2
else
stencil_3d
...
...
@@ -263,6 +260,9 @@ def test_get_kwarg():
dh
.
fill
(
"src"
,
1.0
,
ghost_layers
=
True
)
dh
.
fill
(
"dst"
,
0.0
,
ghost_layers
=
True
)
with
pytest
.
raises
(
ValueError
):
dh
.
add_array
(
'src'
)
ur
=
ps
.
Assignment
(
src
.
center
,
dst
.
center
)
kernel
=
ps
.
create_kernel
(
ur
).
compile
()
...
...
pystencils_tests/test_sympyextensions.py
View file @
d0a06963
...
...
@@ -119,7 +119,7 @@ def test_count_operations():
expr
=
sympy
.
Pow
(
1
/
x
+
y
*
sympy
.
sqrt
(
z
),
100
)
ops
=
count_operations
(
expr
,
only_type
=
None
)
assert
ops
[
'adds'
]
==
1
assert
ops
[
'muls'
]
==
100
assert
ops
[
'muls'
]
==
99
assert
ops
[
'divs'
]
==
1
assert
ops
[
'sqrts'
]
==
1
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment