Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexander Reinauer
pystencils
Commits
54bd44ef
Commit
54bd44ef
authored
Feb 03, 2020
by
Martin Bauer
Browse files
Merge branch 'abs' into 'master'
Correctly print sp.Abs in generated code See merge request
pycodegen/pystencils!127
parents
a5ab1070
b1e9b1e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/backends/cbackend.py
View file @
54bd44ef
...
...
@@ -361,6 +361,12 @@ class CustomSympyPrinter(CCodePrinter):
result
=
super
(
CustomSympyPrinter
,
self
).
_print_Piecewise
(
expr
)
return
result
.
replace
(
"
\n
"
,
""
)
def
_print_Abs
(
self
,
expr
):
if
expr
.
is_integer
:
return
'abs({0})'
.
format
(
self
.
_print
(
expr
.
args
[
0
]))
else
:
return
'fabs({0})'
.
format
(
self
.
_print
(
expr
.
args
[
0
]))
def
_print_Type
(
self
,
node
):
return
str
(
node
)
...
...
pystencils/cpu/vectorization.py
View file @
54bd44ef
...
...
@@ -176,6 +176,10 @@ def insert_vector_casts(ast_node):
visit_expr
(
expr
.
args
[
4
]))
elif
isinstance
(
expr
,
cast_func
):
return
expr
elif
expr
.
func
is
sp
.
Abs
:
new_arg
=
visit_expr
(
expr
.
args
[
0
])
pw
=
sp
.
Piecewise
((
-
1
*
new_arg
,
new_arg
<
0
),
(
new_arg
,
True
))
return
visit_expr
(
pw
)
elif
expr
.
func
in
handled_functions
or
isinstance
(
expr
,
sp
.
Rel
)
or
isinstance
(
expr
,
BooleanFunction
):
new_args
=
[
visit_expr
(
a
)
for
a
in
expr
.
args
]
arg_types
=
[
get_type_of_expression
(
a
)
for
a
in
new_args
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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