Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils-sfg
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
Package registry
Model registry
Operate
Environments
Terraform modules
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-sfg
Commits
1934248a
Commit
1934248a
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
std::tuple mapping
parent
c5a41e2e
No related branches found
No related tags found
No related merge requests found
Pipeline
#58423
passed
1 year ago
Stage: pretest
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencilssfg/source_concepts/cpp/__init__.py
+7
-2
7 additions, 2 deletions
src/pystencilssfg/source_concepts/cpp/__init__.py
src/pystencilssfg/source_concepts/cpp/std_tuple.py
+53
-0
53 additions, 0 deletions
src/pystencilssfg/source_concepts/cpp/std_tuple.py
with
60 additions
and
2 deletions
src/pystencilssfg/source_concepts/cpp/__init__.py
+
7
−
2
View file @
1934248a
from
.std_mdspan
import
StdMdspan
,
mdspan_ref
from
.std_mdspan
import
StdMdspan
,
mdspan_ref
from
.std_vector
import
StdVector
,
std_vector_ref
from
.std_vector
import
StdVector
,
std_vector_ref
from
.std_tuple
import
StdTuple
,
std_tuple_ref
__all__
=
[
__all__
=
[
"
StdMdspan
"
,
"
StdVector
"
,
"
std_vector_ref
"
,
"
StdMdspan
"
,
"
mdspan_ref
"
"
mdspan_ref
"
,
"
StdVector
"
,
"
std_vector_ref
"
,
"
StdTuple
"
,
"
std_tuple_ref
"
,
]
]
This diff is collapsed.
Click to expand it.
src/pystencilssfg/source_concepts/cpp/std_tuple.py
0 → 100644
+
53
−
0
View file @
1934248a
from
typing
import
Sequence
from
pystencils.typing
import
BasicType
,
TypedSymbol
from
...tree
import
SfgStatements
from
..source_objects
import
SrcVector
from
..source_objects
import
TypedSymbolOrObject
from
...types
import
SrcType
,
cpp_typename
from
...source_components
import
SfgHeaderInclude
class
StdTuple
(
SrcVector
):
def
__init__
(
self
,
identifier
:
str
,
element_types
:
Sequence
[
BasicType
],
const
:
bool
=
False
,
ref
:
bool
=
False
,
):
self
.
_element_types
=
element_types
self
.
_length
=
len
(
element_types
)
elt_type_strings
=
tuple
(
cpp_typename
(
t
)
for
t
in
self
.
_element_types
)
src_type
=
f
"
{
'
const
'
if
const
else
''
}
std::tuple<
{
'
,
'
.
join
(
elt_type_strings
)
}
>
{
'
&
'
if
ref
else
''
}
"
super
().
__init__
(
identifier
,
SrcType
(
src_type
))
@property
def
required_includes
(
self
)
->
set
[
SfgHeaderInclude
]:
return
{
SfgHeaderInclude
(
"
tuple
"
,
system_header
=
True
)}
def
extract_component
(
self
,
destination
:
TypedSymbolOrObject
,
coordinate
:
int
):
if
coordinate
<
0
or
coordinate
>=
self
.
_length
:
raise
ValueError
(
f
"
Index
{
coordinate
}
out-of-bounds for std::tuple with
{
self
.
_length
}
entries.
"
)
if
destination
.
dtype
!=
self
.
_element_types
[
coordinate
]:
raise
ValueError
(
f
"
Cannot extract type
{
destination
.
dtype
}
from std::tuple entry
"
"
of type {self._element_types[coordinate]}
"
)
return
SfgStatements
(
f
"
{
destination
.
dtype
}
{
destination
.
name
}
= std::get<
{
coordinate
}
>(
{
self
.
identifier
}
);
"
,
(
destination
,),
(
self
,),
)
def
std_tuple_ref
(
identifier
:
str
,
components
:
Sequence
[
TypedSymbol
],
const
:
bool
=
True
):
elt_types
=
tuple
(
c
.
dtype
for
c
in
components
)
return
StdTuple
(
identifier
,
elt_types
,
const
=
const
,
ref
=
True
)
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