1
+ from __future__ import annotations
2
+
3
+
1
4
"""
2
5
.. currentmodule:: arraycontext
3
6
30
33
THE SOFTWARE.
31
34
"""
32
35
33
- from typing import Any , Dict
36
+ from typing import Any
34
37
35
38
import numpy as np
36
39
39
42
40
43
from arraycontext .container .traversal import rec_map_array_container , with_array_context
41
44
from arraycontext .context import (
45
+ Array ,
42
46
ArrayContext ,
43
47
ArrayOrContainerOrScalar ,
44
48
ArrayOrContainerOrScalarT ,
@@ -62,10 +66,12 @@ class NumpyArrayContext(ArrayContext):
62
66
63
67
.. automethod:: __init__
64
68
"""
69
+
70
+ _loopy_transform_cache : dict [lp .TranslationUnit , lp .ExecutorBase ]
71
+
65
72
def __init__ (self ) -> None :
66
73
super ().__init__ ()
67
- self ._loopy_transform_cache : \
68
- Dict [lp .TranslationUnit , lp .TranslationUnit ] = {}
74
+ self ._loopy_transform_cache = {}
69
75
70
76
array_types = (NumpyNonObjectArray ,)
71
77
@@ -88,17 +94,18 @@ def to_numpy(self,
88
94
) -> NumpyOrContainerOrScalar :
89
95
return array
90
96
91
- def call_loopy (self , t_unit , ** kwargs ):
97
+ def call_loopy (
98
+ self ,
99
+ t_unit : lp .TranslationUnit , ** kwargs : Any
100
+ ) -> dict [str , Array ]:
92
101
t_unit = t_unit .copy (target = lp .ExecutableCTarget ())
93
102
try :
94
- t_unit = self ._loopy_transform_cache [t_unit ]
103
+ executor = self ._loopy_transform_cache [t_unit ]
95
104
except KeyError :
96
- orig_t_unit = t_unit
97
- t_unit = self .transform_loopy_program (t_unit )
98
- self ._loopy_transform_cache [orig_t_unit ] = t_unit
99
- del orig_t_unit
105
+ executor = self .transform_loopy_program (t_unit ).executor ()
106
+ self ._loopy_transform_cache [t_unit ] = executor
100
107
101
- _ , result = t_unit (** kwargs )
108
+ _ , result = executor (** kwargs )
102
109
103
110
return result
104
111
0 commit comments