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

1from __future__ import annotations 

2from typing import Protocol, runtime_checkable 

3from abc import abstractmethod 

4 

5from .expressions import AugExpr 

6 

7 

8@runtime_checkable 

9class SupportsFieldExtraction(Protocol): 

10 """Protocol for field pointer and indexing extraction. 

11 

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 """ 

16 

17 # how-to-guide begin 

18 @abstractmethod 

19 def _extract_ptr(self) -> AugExpr: 

20 """Extract the field base pointer. 

21 

22 Return an expression which represents the base pointer 

23 of this field data structure. 

24 

25 :meta public: 

26 """ 

27 

28 @abstractmethod 

29 def _extract_size(self, coordinate: int) -> AugExpr | None: 

30 """Extract field size in a given coordinate. 

31 

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`. 

36 

37 :meta public: 

38 """ 

39 

40 @abstractmethod 

41 def _extract_stride(self, coordinate: int) -> AugExpr | None: 

42 """Extract field stride in a given coordinate. 

43 

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`. 

48 

49 :meta public: 

50 """ 

51 

52 

53# how-to-guide end 

54 

55 

56@runtime_checkable 

57class SupportsVectorExtraction(Protocol): 

58 """Protocol for component extraction from a vector. 

59 

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 """ 

64 

65 @abstractmethod 

66 def _extract_component(self, coordinate: int) -> AugExpr: ...