From a02677dc1d2a54adb7d845a2a147fbcd540b56a4 Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Tue, 24 Nov 2020 16:34:40 +0100 Subject: [PATCH] - Fix chunks for when length of input is smaller than chunk size. --- README.md | 3 +++ parfor/__init__.py | 4 ++-- setup.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98303c8..20d7a9f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/parfor/__init__.py b/parfor/__init__.py index fac34de..ccc9bb7 100644 --- a/parfor/__init__.py +++ b/parfor/__init__.py @@ -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: diff --git a/setup.py b/setup.py index a5ff993..4a31e1a 100644 --- a/setup.py +++ b/setup.py @@ -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.",