Coverage for src/pystencilssfg/lang/cpp/std_tuple.py: 81%
16 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-04 07:16 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-04 07:16 +0000
1from pystencils.types import UserTypeSpec, create_type
3from ...lang import SupportsVectorExtraction, AugExpr, cpptype
6class StdTuple(AugExpr, SupportsVectorExtraction):
7 _template = cpptype("std::tuple< {ts} >", "<tuple>")
9 def __init__(
10 self,
11 *element_types: UserTypeSpec,
12 const: bool = False,
13 ref: bool = False,
14 ):
15 self._element_types = tuple(create_type(t) for t in element_types)
16 self._length = len(element_types)
17 elt_type_strings = tuple(t.c_string() for t in self._element_types)
19 dtype = self._template(ts=", ".join(elt_type_strings), const=const, ref=ref)
20 super().__init__(dtype)
22 def get(self, idx: int | str) -> AugExpr:
23 return AugExpr.format("std::get< {} >({})", idx, self)
25 def _extract_component(self, coordinate: int) -> AugExpr:
26 if coordinate < 0 or coordinate >= self._length:
27 raise ValueError(
28 f"Index {coordinate} out-of-bounds for std::tuple with {self._length} entries."
29 )
31 return self.get(coordinate)