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
Tom Harke
pystencils
Commits
c4e92d45
Commit
c4e92d45
authored
Nov 27, 2019
by
Martin Bauer
Browse files
Fix: type of sqrt(int) was int not floating point type
parent
8ca8b2ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/data_types.py
View file @
c4e92d45
...
...
@@ -548,7 +548,13 @@ def get_type_of_expression(expr,
if
vec_args
:
result
=
VectorType
(
result
,
width
=
vec_args
[
0
].
width
)
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
])
elif
isinstance
(
expr
,
sp
.
Expr
):
expr
:
sp
.
Expr
...
...
pystencils_tests/test_types.py
View file @
c4e92d45
import
sympy
as
sp
import
numpy
as
np
import
pystencils
as
ps
from
pystencils
import
data_types
from
pystencils.data_types
import
*
from
pystencils.kernelparameters
import
FieldShapeSymbol
from
pystencils.data_types
import
TypedSymbol
,
get_type_of_expression
,
VectorType
,
collate_types
,
create_type
def
test_parsing
():
...
...
@@ -25,7 +25,6 @@ def test_collation():
def
test_dtype_of_constants
():
# Some come constants are neither of type Integer,Float,Rational and don't have args
# >>> isinstance(pi, Integer)
# False
...
...
@@ -39,13 +38,25 @@ def test_dtype_of_constants():
def
test_assumptions
():
x
=
pystencils
.
fields
(
'x: float32[3d]'
)
x
=
ps
.
fields
(
'x: float32[3d]'
)
assert
x
.
shape
[
0
].
is_nonnegative
assert
(
2
*
x
.
shape
[
0
]).
is_nonnegative
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'
))
+
1
).
is_positive
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
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