Skip to content

Commit

Permalink
Merge pull request #9 from JinchengHeRyan/app
Browse files Browse the repository at this point in the history
accelerated multiprocess task assignment in recording retrieval
  • Loading branch information
realzza authored May 5, 2022
2 parents b10e964 + e87eec5 commit 5057e31
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from typing import List


def average(L, n) -> List[int]:
"""
average the list the most possible
"""
if (L / n) == int(L / n):
k = int(L / n)
ans = [k] * n
else:
k = int(L / n)
a = L - k * n
ans = [k + 1] * a + [k] * (n - a)
return ans


def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
to_return = []
portion = len(lst) // n
for i in range(0, n):
if i == (n - 1):
last_port = lst[portion*i:]
diff = len(last_port) - portion

for j in range(diff):
to_return[j].append(last_port[j])

last_port = last_port[diff:]
to_return.append(last_port)

else:
to_return.append(lst[portion*i: portion*(i+1)])
return to_return
num_list = average(len(lst), n)
offset = 0
for num in num_list:
to_return.append(lst[offset : offset + num])
offset += num
return to_return

0 comments on commit 5057e31

Please sign in to comment.