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
Commits
56563511
Commit
56563511
authored
3 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Fix test cases
parent
83c93124
No related branches found
No related tags found
1 merge request
!275
WIP: Revamp the type system
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/backends/cbackend.py
+2
-2
2 additions, 2 deletions
pystencils/backends/cbackend.py
pystencils/typing/leaf_typing.py
+2
-1
2 additions, 1 deletion
pystencils/typing/leaf_typing.py
pystencils_tests/test_simplifications.py
+11
-12
11 additions, 12 deletions
pystencils_tests/test_simplifications.py
with
15 additions
and
15 deletions
pystencils/backends/cbackend.py
+
2
−
2
View file @
56563511
...
...
@@ -495,8 +495,8 @@ class CustomSympyPrinter(CCodePrinter):
known
=
self
.
known_functions
[
arg
.
__class__
.
__name__
.
lower
()]
code
=
self
.
_print
(
arg
)
return
code
.
replace
(
known
,
f
"
{
known
}
f
"
)
elif
isinstance
(
arg
,
sp
.
Pow
)
and
data_type
==
BasicType
(
'
float32
'
):
known
=
[
'
sqrt
'
,
'
cbrt
'
,
'
pow
'
]
elif
isinstance
(
arg
,
(
sp
.
Pow
,
sp
.
exp
)
)
and
data_type
==
BasicType
(
'
float32
'
):
known
=
[
'
sqrt
'
,
'
cbrt
'
,
'
pow
'
,
'
exp
'
]
code
=
self
.
_print
(
arg
)
for
k
in
known
:
if
k
in
code
:
...
...
This diff is collapsed.
Click to expand it.
pystencils/typing/leaf_typing.py
+
2
−
1
View file @
56563511
...
...
@@ -216,7 +216,8 @@ class TypeAdder:
else
:
new_args
.
append
(
a
)
return
expr
.
func
(
*
new_args
)
if
new_args
else
expr
,
collated_type
elif
isinstance
(
expr
,
(
sp
.
Pow
,
InverseTrigonometricFunction
,
TrigonometricFunction
,
HyperbolicFunction
)):
elif
isinstance
(
expr
,
(
sp
.
Pow
,
sp
.
exp
,
InverseTrigonometricFunction
,
TrigonometricFunction
,
HyperbolicFunction
)):
args_types
=
[
self
.
figure_out_type
(
arg
)
for
arg
in
expr
.
args
]
collated_type
=
collate_types
([
t
for
_
,
t
in
args_types
])
new_args
=
[
a
if
t
.
dtype_eq
(
collated_type
)
else
CastFunc
(
a
,
collated_type
)
for
a
,
t
in
args_types
]
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_simplifications.py
+
11
−
12
View file @
56563511
...
...
@@ -4,6 +4,7 @@ import pytest
import
pystencils.config
import
sympy
as
sp
import
pystencils
as
ps
import
numpy
as
np
from
pystencils.simp
import
subexpression_substitution_in_main_assignments
from
pystencils.simp
import
add_subexpressions_for_divisions
...
...
@@ -143,29 +144,27 @@ def test_add_subexpressions_for_field_reads():
@pytest.mark.parametrize
(
'
target
'
,
(
ps
.
Target
.
CPU
,
ps
.
Target
.
GPU
))
@pytest.mark.parametrize
(
'
simplification
'
,
(
True
,
False
))
@pytest.mark.parametrize
(
'
dtype
'
,
(
'
float32
'
,
'
float64
'
))
@pytest.mark.skipif
((
vs
.
major
,
vs
.
minor
,
vs
.
micro
)
==
(
3
,
8
,
2
),
reason
=
"
does not work on python 3.8.2 for some reason
"
)
def
test_sympy_optimizations
(
target
,
simplification
):
def
test_sympy_optimizations
(
target
,
dtype
):
if
target
==
ps
.
Target
.
GPU
:
pytest
.
importorskip
(
"
pycuda
"
)
src
,
dst
=
ps
.
fields
(
'
src, dst:
float32
[2d]
'
)
src
,
dst
=
ps
.
fields
(
f
'
src, dst:
{
dtype
}
[2d]
'
)
# Triggers Sympy's expm1 optimization
# Sympy's expm1 optimization is tedious to use and the behaviour is highly depended on the sympy version. In
# some cases the exp expression has to be encapsulated in brackets or multiplied with 1 or 1.0
# for sympy to work properly ...
assignments
=
ps
.
AssignmentCollection
({
src
[
0
,
0
]:
1.0
*
(
sp
.
exp
(
dst
[
0
,
0
])
-
1
)
})
config
=
pystencils
.
config
.
CreateKernelConfig
(
target
=
target
,
default_
assignment_simplifications
=
simplification
)
config
=
pystencils
.
config
.
CreateKernelConfig
(
target
=
target
,
default_
number_float
=
dtype
)
ast
=
ps
.
create_kernel
(
assignments
,
config
=
config
)
ps
.
show_code
(
ast
)
code
=
ps
.
get_code_str
(
ast
)
if
simplification
:
assert
'
exp
m1
(
'
in
code
el
se
:
assert
'
exp
m1(
'
not
in
code
if
dtype
==
'
float32
'
:
assert
'
exp
f
(
'
in
code
el
if
dtype
==
'
float64
'
:
assert
'
exp
(
'
in
code
@pytest.mark.parametrize
(
'
target
'
,
(
ps
.
Target
.
CPU
,
ps
.
Target
.
GPU
))
...
...
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