Skip to content

Commit

Permalink
Merge pull request numba#7622 from sklam/enh/arrayexpr_fortran_loop
Browse files Browse the repository at this point in the history
Support fortran loop ordering for ufunc generation
  • Loading branch information
sklam authored Nov 23, 2022
2 parents 3e96339 + 5967666 commit a5d7dee
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion numba/np/npyimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,23 @@ def numpy_ufunc_kernel(context, builder, sig, args, ufunc, kernel_class):
# assume outputs are all the same size, which numpy requires

loopshape = outputs[0].shape
with cgutils.loop_nest(builder, loopshape, intp=intpty) as loop_indices:

# count the number of C and F layout arrays, respectively
input_layouts = [inp.layout for inp in inputs
if isinstance(inp, _ArrayHelper)]
num_c_layout = len([x for x in input_layouts if x == 'C'])
num_f_layout = len([x for x in input_layouts if x == 'F'])

# Only choose F iteration order if more arrays are in F layout.
# Default to C order otherwise.
# This is a best effort for performance. NumPy has more fancy logic that
# uses array iterators in non-trivial cases.
if num_f_layout > num_c_layout:
order = 'F'
else:
order = 'C'

with cgutils.loop_nest(builder, loopshape, intp=intpty, order=order) as loop_indices:
vals_in = []
for i, (index, arg) in enumerate(zip(indices, inputs)):
index.update_indices(loop_indices, i)
Expand Down

0 comments on commit a5d7dee

Please sign in to comment.