- Fix chunks for when length of input is smaller than chunk size.

This commit is contained in:
Wim Pomp
2020-11-24 16:34:40 +01:00
parent 2ddf73ed0f
commit a02677dc1d
3 changed files with 6 additions and 3 deletions

View File

@@ -11,6 +11,9 @@ Tested on linux on python 2.7 and 3.8 and on Windows and OSX on python 3.8.
- Using dill instead of pickle: a lot more objects can be used when parallelizing
- Progress bars are built-in
## Installation
pip install parfor
## Usage
Parfor decorates a functions and returns the result of that function evaluated in parallel for each iteration of
an iterator.

View File

@@ -118,8 +118,8 @@ def chunks(n, *args):
""" Yield successive n-sized chunks from lists. """
A = len(args)==1
N = len(args[0])
n = int(round(N/round(N/n)))
for i in range(0, N, n):
n = int(round(N/max(1, round(N/n))))
for i in range(0, N, n) if N else []:
if A:
yield args[0][i:i+n]
else:

View File

@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="parfor",
version="2020.09.4",
version="2020.11.24",
author="Wim Pomp",
author_email="wimpomp@gmail.com",
description="A package to mimic the use of parfor as done in Matlab.",