Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: simplify ListOffsetArray_reduce_nonlocal_outstartsstops #1796

Merged
merged 11 commits into from
Oct 17, 2022
70 changes: 21 additions & 49 deletions kernel-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2328,27 +2328,6 @@ kernels:
automatic-tests: true
manual-tests: []

- name: awkward_ListOffsetArray_reduce_nonlocal_findgaps_64
specializations:
- name: awkward_ListOffsetArray_reduce_nonlocal_findgaps_64
args:
- {name: gaps, type: "List[int64_t]", dir: out}
- {name: parents, type: "Const[List[int64_t]]", dir: in, role: reducer-parents}
- {name: lenparents, type: "int64_t", dir: in, role: reducer-lenparents}
description: null
definition: |
def awkward_ListOffsetArray_reduce_nonlocal_findgaps_64(gaps, parents, lenparents):
k = 0
last = -1
for i in range(lenparents):
parent = parents[i]
if last < parent:
gaps[k] = parent - last
k = k + 1
last = parent
automatic-tests: true
manual-tests: []

- name: awkward_ListOffsetArray_reduce_nonlocal_maxcount_offsetscopy_64
specializations:
- name: awkward_ListOffsetArray_reduce_nonlocal_maxcount_offsetscopy_64
Expand Down Expand Up @@ -2444,43 +2423,36 @@ kernels:
- {name: outstops, type: "List[int64_t]", dir: out}
- {name: distincts, type: "Const[List[int64_t]]", dir: in, role: reducer-distincts}
- {name: lendistincts, type: "int64_t", dir: in, role: reducer-lendistincts}
- {name: gaps, type: "Const[List[int64_t]]", dir: in, role: reducer-gaps}
- {name: outlength, type: "int64_t", dir: in, role: reducer-outlength}
description: null
definition: |
def awkward_ListOffsetArray_reduce_nonlocal_outstartsstops_64(
outstarts, outstops, distincts, lendistincts, gaps, outlength
outstarts, outstops, distincts, lendistincts, outlength
):
maxcount = lendistincts // outlength

j = 0
k = 0
maxdistinct = -2
lasti = -1
for i in range(lendistincts):
if maxdistinct < distincts[i]:
maxdistinct = distincts[i]

extra = (i - lasti) // maxcount
lasti = i

numgappy = gaps[j]
if numgappy < extra:
numgappy = extra

for gappy in range(numgappy):
maxcount = lendistincts if (outlength == 0) else int(lendistincts // outlength)
if outlength > 0 and lendistincts > 0:
# The sublist index
k = 0
i_next_sublist = 0
for i in range(lendistincts):
# Are we now in the next sublist?
if i == i_next_sublist:
# Advance counter
i_next_sublist += maxcount

# Add a new sublist
outstarts[k] = i
outstops[k] = i
k = k + 1
j = j + 1

if distincts[i] != -1:
outstops[k - 1] = i + 1
k += 1

while k < outlength:
outstarts[k] = lendistincts + 1
outstops[k] = lendistincts + 1
k = k + 1
# Expand stop index of previous list
if distincts[i] != -1:
outstops[k - 1] = i + 1
else:
for k in range(outlength):
outstarts[k] = 0
outstops[k] = 0
automatic-tests: true
manual-tests: []

Expand Down
Loading