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
Markus Holzer
pystencils
Commits
3bb88ad1
Commit
3bb88ad1
authored
Nov 17, 2021
by
Markus Holzer
Browse files
Fixed integer square root
parent
43393627
Pipeline
#35668
passed with stages
in 20 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/backends/cbackend.py
View file @
3bb88ad1
...
...
@@ -444,7 +444,7 @@ class CustomSympyPrinter(CCodePrinter):
def
_print_Pow
(
self
,
expr
):
"""Don't use std::pow function, for small integer exponents, write as multiplication"""
if
not
expr
.
free_symbols
:
return
self
.
_typed_number
(
expr
.
evalf
(),
get_type_of_expression
(
expr
))
return
self
.
_typed_number
(
expr
.
evalf
(),
get_type_of_expression
(
expr
.
base
))
if
expr
.
exp
.
is_integer
and
expr
.
exp
.
is_number
and
0
<
expr
.
exp
<
8
:
return
f
"(
{
self
.
_print
(
sp
.
Mul
(
*
[
expr
.
base
]
*
expr
.
exp
,
evaluate
=
False
))
}
)"
...
...
pystencils_tests/test_types.py
View file @
3bb88ad1
...
...
@@ -87,10 +87,25 @@ def test_sqrt_of_integer():
assignments
=
[
ps
.
Assignment
(
tmp
,
sp
.
sqrt
(
3
)),
ps
.
Assignment
(
f
[
0
],
tmp
)]
arr
=
np
.
array
([
1
],
dtype
=
np
.
float64
)
arr
_double
=
np
.
array
([
1
],
dtype
=
np
.
float64
)
kernel
=
ps
.
create_kernel
(
assignments
).
compile
()
kernel
(
f
=
arr
)
assert
1.7
<
arr
[
0
]
<
1.8
kernel
(
f
=
arr_double
)
assert
1.7
<
arr_double
[
0
]
<
1.8
f
=
ps
.
fields
(
"f: float32[1D]"
)
tmp
=
sp
.
symbols
(
"tmp"
)
assignments
=
[
ps
.
Assignment
(
tmp
,
sp
.
sqrt
(
3
)),
ps
.
Assignment
(
f
[
0
],
tmp
)]
arr_single
=
np
.
array
([
1
],
dtype
=
np
.
float32
)
config
=
ps
.
CreateKernelConfig
(
data_type
=
"float32"
)
kernel
=
ps
.
create_kernel
(
assignments
,
config
=
config
).
compile
()
kernel
(
f
=
arr_single
)
code
=
ps
.
get_code_str
(
kernel
.
ast
)
assert
"1.7320508075688772f"
in
code
assert
1.7
<
arr_single
[
0
]
<
1.8
def
test_integer_comparision
():
...
...
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