Coverage for src/pystencilssfg/lang/extractions.py: 100%
8 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 __future__ import annotations
2from typing import Protocol, runtime_checkable
3from abc import abstractmethod
5from .expressions import AugExpr
8@runtime_checkable
9class SupportsFieldExtraction(Protocol):
10 """Protocol for field pointer and indexing extraction.
12 Objects adhering to this protocol are understood to provide expressions
13 for the base pointer, shape, and stride properties of a field.
14 They can therefore be passed to `sfg.map_field <SfgBasicComposer.map_field>`.
15 """
17 # how-to-guide begin
18 @abstractmethod
19 def _extract_ptr(self) -> AugExpr:
20 """Extract the field base pointer.
22 Return an expression which represents the base pointer
23 of this field data structure.
25 :meta public:
26 """
28 @abstractmethod
29 def _extract_size(self, coordinate: int) -> AugExpr | None:
30 """Extract field size in a given coordinate.
32 If ``coordinate`` is valid for this field (i.e. smaller than its dimensionality),
33 return an expression representing the logical size of this field
34 in the given dimension.
35 Otherwise, return `None`.
37 :meta public:
38 """
40 @abstractmethod
41 def _extract_stride(self, coordinate: int) -> AugExpr | None:
42 """Extract field stride in a given coordinate.
44 If ``coordinate`` is valid for this field (i.e. smaller than its dimensionality),
45 return an expression representing the memory linearization stride of this field
46 in the given dimension.
47 Otherwise, return `None`.
49 :meta public:
50 """
53# how-to-guide end
56@runtime_checkable
57class SupportsVectorExtraction(Protocol):
58 """Protocol for component extraction from a vector.
60 Objects adhering to this protocol are understood to provide
61 access to the entries of a vector
62 and can therefore be passed to `sfg.map_vector <SfgBasicComposer.map_vector>`.
63 """
65 @abstractmethod
66 def _extract_component(self, coordinate: int) -> AugExpr: ...