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
69c29833
Commit
69c29833
authored
Nov 28, 2019
by
Stephan Seitz
Browse files
Add option to use `auto` in `SympyAssignment`s
parent
0b8e7e88
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/astnodes.py
View file @
69c29833
...
...
@@ -518,12 +518,13 @@ class LoopOverCoordinate(Node):
class
SympyAssignment
(
Node
):
def
__init__
(
self
,
lhs_symbol
,
rhs_expr
,
is_const
=
True
):
def
__init__
(
self
,
lhs_symbol
,
rhs_expr
,
is_const
=
True
,
use_auto
=
True
):
super
(
SympyAssignment
,
self
).
__init__
(
parent
=
None
)
self
.
_lhs_symbol
=
lhs_symbol
self
.
rhs
=
sp
.
sympify
(
rhs_expr
)
self
.
_is_const
=
is_const
self
.
_is_declaration
=
self
.
__is_declaration
()
self
.
use_auto
=
use_auto
def
__is_declaration
(
self
):
if
isinstance
(
self
.
_lhs_symbol
,
cast_func
):
...
...
pystencils/backends/cbackend.py
View file @
69c29833
...
...
@@ -5,6 +5,7 @@ import numpy as np
import
sympy
as
sp
from
sympy.core
import
S
from
sympy.printing.ccode
import
C89CodePrinter
from
pystencils.astnodes
import
KernelFunction
,
Node
from
pystencils.cpu.vectorization
import
vec_all
,
vec_any
from
pystencils.data_types
import
(
...
...
@@ -229,11 +230,15 @@ class CBackend:
def
_print_SympyAssignment
(
self
,
node
):
if
node
.
is_declaration
:
if
node
.
is_const
:
prefix
=
'const
'
if
node
.
use_auto
:
data_type
=
'auto
'
else
:
prefix
=
''
data_type
=
prefix
+
self
.
_print
(
node
.
lhs
.
dtype
).
replace
(
' const'
,
''
)
+
" "
if
node
.
is_const
:
prefix
=
'const '
else
:
prefix
=
''
data_type
=
prefix
+
self
.
_print
(
node
.
lhs
.
dtype
).
replace
(
' const'
,
''
)
+
" "
return
"%s%s = %s;"
%
(
data_type
,
self
.
sympy_printer
.
doprint
(
node
.
lhs
),
self
.
sympy_printer
.
doprint
(
node
.
rhs
))
...
...
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