@@ -1873,10 +1873,18 @@ def _type_getitem(self, args):
18731873 return self .pass_states .typingctx .resolve_function_type (fnty , tuple (args ), {})
18741874
18751875
1876- def _make_index_var (typemap , scope , index_vars , body_block ):
1876+ def _make_index_var (typemap , scope , index_vars , body_block , force_tuple = False ):
1877+ """ When generating a SetItem call to an array in a parfor, the general
1878+ strategy is to generate a tuple if the array is more than 1 dimension.
1879+ If it is 1 dimensional then you can use a simple variable. This routine
1880+ is also used when converting pndindex to parfor but pndindex requires a
1881+ tuple even if the iteration space is 1 dimensional. The pndindex use of
1882+ this function will use force_tuple to make the output index a tuple even
1883+ if it is one dimensional.
1884+ """
18771885 ndims = len (index_vars )
18781886 loc = body_block .loc
1879- if ndims > 1 :
1887+ if ndims > 1 or force_tuple :
18801888 tuple_var = ir .Var (scope , mk_unique_var (
18811889 "$parfor_index_tuple_var" ), loc )
18821890 typemap [tuple_var .name ] = types .containers .UniTuple (
@@ -2446,11 +2454,20 @@ def find_mask_from_size(size_var):
24462454 in_arr , mask_var , mask_typ , mask_indices = result
24472455 else :
24482456 in_arr = args [0 ]
2449- size_vars = equiv_set .get_shape (in_arr
2450- if mask_indices is None else mask_var )
2451- index_vars , loops = _mk_parfor_loops (
2452- pass_states .typemap , size_vars , scope , loc ,
2453- )
2457+ assert (isinstance (in_arr , ir .Var ))
2458+ in_arr_typ = pass_states .typemap [in_arr .name ]
2459+ if isinstance (in_arr_typ , types .Integer ):
2460+ index_var = ir .Var (scope , mk_unique_var ("parfor_index" ), loc )
2461+ pass_states .typemap [index_var .name ] = types .uintp
2462+ loops = [LoopNest (index_var , 0 , in_arr , 1 )]
2463+ index_vars = [index_var ]
2464+ else :
2465+ size_vars = equiv_set .get_shape (in_arr
2466+ if mask_indices is None else mask_var )
2467+ index_vars , loops = _mk_parfor_loops (
2468+ pass_states .typemap , size_vars , scope , loc ,
2469+ )
2470+ assert (len (loops ) > 0 )
24542471 orig_index = index_vars
24552472 if mask_indices :
24562473 # replace mask indices if required;
@@ -2462,6 +2479,7 @@ def find_mask_from_size(size_var):
24622479 body_block = ir .Block (scope , loc )
24632480 index_var , index_var_typ = _make_index_var (
24642481 pass_states .typemap , scope , index_vars , body_block ,
2482+ force_tuple = True
24652483 )
24662484 body = body_block .body + first_body_block .body
24672485 first_body_block .body = body
0 commit comments