@@ -209,7 +209,13 @@ def make_alloc(loop_orders, dtype, sub, fortran="0"):
209
209
)
210
210
211
211
212
- def make_loop (loop_orders , dtypes , loop_tasks , sub , openmp = None ):
212
+ def make_loop (
213
+ loop_orders : list [tuple [int | str , ...]],
214
+ dtypes : list ,
215
+ loop_tasks : list ,
216
+ sub : dict [str , str ],
217
+ openmp : bool = False ,
218
+ ):
213
219
"""
214
220
Make a nested loop over several arrays and associate specific code
215
221
to each level of nesting.
@@ -227,7 +233,7 @@ def make_loop(loop_orders, dtypes, loop_tasks, sub, openmp=None):
227
233
string is code to be executed before the ith loop starts, the second
228
234
one contains code to be executed just before going to the next element
229
235
of the ith dimension.
230
- The last element if loop_tasks is a single string, containing code
236
+ The last element of loop_tasks is a single string, containing code
231
237
to be executed at the very end.
232
238
sub : dictionary
233
239
Maps 'lv#' to a suitable variable name.
@@ -260,7 +266,7 @@ def loop_over(preloop, code, indices, i):
260
266
}}
261
267
"""
262
268
263
- preloops = {}
269
+ preloops : dict [ int , str ] = {}
264
270
for i , (loop_order , dtype ) in enumerate (zip (loop_orders , dtypes , strict = True )):
265
271
for j , index in enumerate (loop_order ):
266
272
if index != "x" :
@@ -277,16 +283,8 @@ def loop_over(preloop, code, indices, i):
277
283
278
284
s = ""
279
285
280
- for i , (pre_task , task ), indices in reversed (
281
- list (
282
- zip (
283
- range (len (loop_tasks ) - 1 ),
284
- loop_tasks ,
285
- list (zip (* loop_orders , strict = True )),
286
- strict = False ,
287
- )
288
- )
289
- ):
286
+ tasks_indices = zip (loop_tasks [:- 1 ], zip (* loop_orders , strict = True ), strict = True )
287
+ for i , ((pre_task , task ), indices ) in reversed (list (enumerate (tasks_indices ))):
290
288
s = loop_over (preloops .get (i , "" ) + pre_task , s + task , indices , i )
291
289
292
290
s += loop_tasks [- 1 ]
0 commit comments