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
c4e92d45
Commit
c4e92d45
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Fix: type of sqrt(int) was int not floating point type
parent
8ca8b2ee
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/data_types.py
+7
-1
7 additions, 1 deletion
pystencils/data_types.py
pystencils_tests/test_types.py
+18
-7
18 additions, 7 deletions
pystencils_tests/test_types.py
with
25 additions
and
8 deletions
pystencils/data_types.py
+
7
−
1
View file @
c4e92d45
...
@@ -548,7 +548,13 @@ def get_type_of_expression(expr,
...
@@ -548,7 +548,13 @@ def get_type_of_expression(expr,
if
vec_args
:
if
vec_args
:
result
=
VectorType
(
result
,
width
=
vec_args
[
0
].
width
)
result
=
VectorType
(
result
,
width
=
vec_args
[
0
].
width
)
return
result
return
result
elif
isinstance
(
expr
,
(
sp
.
Pow
,
sp
.
Sum
,
sp
.
Product
)):
elif
isinstance
(
expr
,
sp
.
Pow
):
base_type
=
get_type
(
expr
.
args
[
0
])
if
expr
.
exp
.
is_integer
:
return
base_type
else
:
return
collate_types
([
create_type
(
default_float_type
),
base_type
])
elif
isinstance
(
expr
,
(
sp
.
Sum
,
sp
.
Product
)):
return
get_type
(
expr
.
args
[
0
])
return
get_type
(
expr
.
args
[
0
])
elif
isinstance
(
expr
,
sp
.
Expr
):
elif
isinstance
(
expr
,
sp
.
Expr
):
expr
:
sp
.
Expr
expr
:
sp
.
Expr
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_types.py
+
18
−
7
View file @
c4e92d45
import
sympy
as
sp
import
sympy
as
sp
import
numpy
as
np
import
pystencils
as
ps
from
pystencils
import
data_types
from
pystencils
import
data_types
from
pystencils.data_types
import
*
from
pystencils.data_types
import
TypedSymbol
,
get_type_of_expression
,
VectorType
,
collate_types
,
create_type
from
pystencils.kernelparameters
import
FieldShapeSymbol
def
test_parsing
():
def
test_parsing
():
...
@@ -25,7 +25,6 @@ def test_collation():
...
@@ -25,7 +25,6 @@ def test_collation():
def
test_dtype_of_constants
():
def
test_dtype_of_constants
():
# Some come constants are neither of type Integer,Float,Rational and don't have args
# Some come constants are neither of type Integer,Float,Rational and don't have args
# >>> isinstance(pi, Integer)
# >>> isinstance(pi, Integer)
# False
# False
...
@@ -39,13 +38,25 @@ def test_dtype_of_constants():
...
@@ -39,13 +38,25 @@ def test_dtype_of_constants():
def
test_assumptions
():
def
test_assumptions
():
x
=
ps
.
fields
(
'
x: float32[3d]
'
)
x
=
pystencils
.
fields
(
'
x: float32[3d]
'
)
assert
x
.
shape
[
0
].
is_nonnegative
assert
x
.
shape
[
0
].
is_nonnegative
assert
(
2
*
x
.
shape
[
0
]).
is_nonnegative
assert
(
2
*
x
.
shape
[
0
]).
is_nonnegative
assert
(
2
*
x
.
shape
[
0
]).
is_integer
assert
(
2
*
x
.
shape
[
0
]).
is_integer
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))).
is_nonnegative
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))).
is_nonnegative
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))).
is_positive
is
None
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))).
is_positive
is
None
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))
+
1
).
is_positive
assert
(
TypedSymbol
(
'
a
'
,
create_type
(
'
uint64
'
))
+
1
).
is_positive
assert
(
x
.
shape
[
0
]
+
1
).
is_real
assert
(
x
.
shape
[
0
]
+
1
).
is_real
def
test_sqrt_of_integer
():
"""
Regression test for bug where sqrt(3) was classified as integer
"""
f
=
ps
.
fields
(
"
f: [1D]
"
)
tmp
=
sp
.
symbols
(
"
tmp
"
)
assignments
=
[
ps
.
Assignment
(
tmp
,
sp
.
sqrt
(
3
)),
ps
.
Assignment
(
f
[
0
],
tmp
)]
arr
=
np
.
array
([
1
],
dtype
=
np
.
float64
)
kernel
=
ps
.
create_kernel
(
assignments
).
compile
()
kernel
(
f
=
arr
)
assert
1.7
<
arr
[
0
]
<
1.8
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