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
61800b73
Commit
61800b73
authored
6 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
pystencils type system: distinction between static and reinterpret cast
parent
2d925329
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backends/cbackend.py
+5
-2
5 additions, 2 deletions
backends/cbackend.py
data_types.py
+5
-0
5 additions, 0 deletions
data_types.py
transformations.py
+3
-3
3 additions, 3 deletions
transformations.py
with
13 additions
and
5 deletions
backends/cbackend.py
+
5
−
2
View file @
61800b73
...
@@ -12,7 +12,7 @@ from pystencils.integer_functions import bitwise_xor, bit_shift_right, bit_shift
...
@@ -12,7 +12,7 @@ from pystencils.integer_functions import bitwise_xor, bit_shift_right, bit_shift
bitwise_or
,
modulo_ceil
bitwise_or
,
modulo_ceil
from
pystencils.astnodes
import
Node
,
KernelFunction
from
pystencils.astnodes
import
Node
,
KernelFunction
from
pystencils.data_types
import
create_type
,
PointerType
,
get_type_of_expression
,
VectorType
,
cast_func
,
\
from
pystencils.data_types
import
create_type
,
PointerType
,
get_type_of_expression
,
VectorType
,
cast_func
,
\
vector_memory_access
vector_memory_access
,
reinterpret_cast_func
__all__
=
[
'
generate_c
'
,
'
CustomCodeNode
'
,
'
PrintNode
'
,
'
get_headers
'
,
'
CustomSympyPrinter
'
]
__all__
=
[
'
generate_c
'
,
'
CustomCodeNode
'
,
'
PrintNode
'
,
'
get_headers
'
,
'
CustomSympyPrinter
'
]
...
@@ -251,7 +251,10 @@ class CustomSympyPrinter(CCodePrinter):
...
@@ -251,7 +251,10 @@ class CustomSympyPrinter(CCodePrinter):
}
}
if
hasattr
(
expr
,
'
to_c
'
):
if
hasattr
(
expr
,
'
to_c
'
):
return
expr
.
to_c
(
self
.
_print
)
return
expr
.
to_c
(
self
.
_print
)
if
isinstance
(
expr
,
cast_func
):
if
isinstance
(
expr
,
reinterpret_cast_func
):
arg
,
data_type
=
expr
.
args
return
"
*((%s)(& %s))
"
%
(
PointerType
(
data_type
,
restrict
=
False
),
self
.
_print
(
arg
))
elif
isinstance
(
expr
,
cast_func
):
arg
,
data_type
=
expr
.
args
arg
,
data_type
=
expr
.
args
if
isinstance
(
arg
,
sp
.
Number
):
if
isinstance
(
arg
,
sp
.
Number
):
return
self
.
_typed_number
(
arg
,
data_type
)
return
self
.
_typed_number
(
arg
,
data_type
)
...
...
This diff is collapsed.
Click to expand it.
data_types.py
+
5
−
0
View file @
61800b73
...
@@ -56,6 +56,11 @@ class vector_memory_access(cast_func):
...
@@ -56,6 +56,11 @@ class vector_memory_access(cast_func):
nargs
=
(
4
,)
nargs
=
(
4
,)
# noinspection PyPep8Naming
class
reinterpret_cast_func
(
cast_func
):
pass
# noinspection PyPep8Naming
# noinspection PyPep8Naming
class
pointer_arithmetic_func
(
sp
.
Function
,
Boolean
):
class
pointer_arithmetic_func
(
sp
.
Function
,
Boolean
):
@property
@property
...
...
This diff is collapsed.
Click to expand it.
transformations.py
+
3
−
3
View file @
61800b73
...
@@ -10,8 +10,8 @@ from sympy.tensor import IndexedBase
...
@@ -10,8 +10,8 @@ from sympy.tensor import IndexedBase
from
pystencils.assignment
import
Assignment
from
pystencils.assignment
import
Assignment
from
pystencils.assignment_collection.nestedscopes
import
NestedScopes
from
pystencils.assignment_collection.nestedscopes
import
NestedScopes
from
pystencils.field
import
Field
,
FieldType
from
pystencils.field
import
Field
,
FieldType
from
pystencils.data_types
import
TypedSymbol
,
PointerType
,
StructType
,
get_base_type
,
cast_func
,
\
from
pystencils.data_types
import
TypedSymbol
,
PointerType
,
StructType
,
get_base_type
,
reinterpret_
cast_func
,
\
pointer_arithmetic_func
,
get_type_of_expression
,
collate_types
,
create_type
cast_func
,
pointer_arithmetic_func
,
get_type_of_expression
,
collate_types
,
create_type
from
pystencils.kernelparameters
import
FieldPointerSymbol
from
pystencils.kernelparameters
import
FieldPointerSymbol
from
pystencils.slicing
import
normalize_slice
from
pystencils.slicing
import
normalize_slice
import
pystencils.astnodes
as
ast
import
pystencils.astnodes
as
ast
...
@@ -427,7 +427,7 @@ def resolve_field_accesses(ast_node, read_only_field_names=set(),
...
@@ -427,7 +427,7 @@ def resolve_field_accesses(ast_node, read_only_field_names=set(),
if
isinstance
(
get_base_type
(
field_access
.
field
.
dtype
),
StructType
):
if
isinstance
(
get_base_type
(
field_access
.
field
.
dtype
),
StructType
):
new_type
=
field_access
.
field
.
dtype
.
get_element_type
(
field_access
.
index
[
0
])
new_type
=
field_access
.
field
.
dtype
.
get_element_type
(
field_access
.
index
[
0
])
result
=
cast_func
(
result
,
new_type
)
result
=
reinterpret_
cast_func
(
result
,
new_type
)
return
visit_sympy_expr
(
result
,
enclosing_block
,
sympy_assignment
)
return
visit_sympy_expr
(
result
,
enclosing_block
,
sympy_assignment
)
else
:
else
:
...
...
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