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
659319bd
"README.md" did not exist on "2d925329a8a53ae7a77a402a379dc7261a60a793"
Commit
659319bd
authored
5 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
Correctly print sp.Abs in generated code
parent
b63cb073
No related branches found
No related tags found
1 merge request
!127
Correctly print sp.Abs in generated code
Pipeline
#21075
passed with warnings
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/backends/cbackend.py
+6
-0
6 additions, 0 deletions
pystencils/backends/cbackend.py
pystencils/cpu/vectorization.py
+4
-0
4 additions, 0 deletions
pystencils/cpu/vectorization.py
with
10 additions
and
0 deletions
pystencils/backends/cbackend.py
+
6
−
0
View file @
659319bd
...
@@ -353,6 +353,12 @@ class CustomSympyPrinter(CCodePrinter):
...
@@ -353,6 +353,12 @@ class CustomSympyPrinter(CCodePrinter):
result
=
super
(
CustomSympyPrinter
,
self
).
_print_Piecewise
(
expr
)
result
=
super
(
CustomSympyPrinter
,
self
).
_print_Piecewise
(
expr
)
return
result
.
replace
(
"
\n
"
,
""
)
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
):
def
_print_Type
(
self
,
node
):
return
str
(
node
)
return
str
(
node
)
...
...
This diff is collapsed.
Click to expand it.
pystencils/cpu/vectorization.py
+
4
−
0
View file @
659319bd
...
@@ -176,6 +176,10 @@ def insert_vector_casts(ast_node):
...
@@ -176,6 +176,10 @@ def insert_vector_casts(ast_node):
visit_expr
(
expr
.
args
[
4
]))
visit_expr
(
expr
.
args
[
4
]))
elif
isinstance
(
expr
,
cast_func
):
elif
isinstance
(
expr
,
cast_func
):
return
expr
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
):
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
]
new_args
=
[
visit_expr
(
a
)
for
a
in
expr
.
args
]
arg_types
=
[
get_type_of_expression
(
a
)
for
a
in
new_args
]
arg_types
=
[
get_type_of_expression
(
a
)
for
a
in
new_args
]
...
...
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