Skip to content

Commit

Permalink
Make split return an iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchanial committed Jan 26, 2015
1 parent 899b30f commit 4fe1575
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pyoperators/utils/misc.py
Expand Up @@ -761,13 +761,13 @@ def settingerr(*args, **keywords):

def split(n, m, rank=None):
"""
Return an iterator through the slices that partition a list of n elements
in m almost same-size groups. If a rank is provided, only the slice
for the rank is returned.
Iterate through the slices that partition a list of n elements in m almost
same-size groups. If a rank is provided, only the slice for the rank
is returned.
Example
-------
>>> split(1000, 2)
>>> tuple(split(1000, 2))
(slice(0, 500, None), slice(500, 1000, None))
>>> split(1000, 2, 1)
slice(500, 1000, None)
Expand All @@ -787,7 +787,7 @@ def generator():
start += work
rank += 1

return tuple(generator())
return generator()


def strelapsed(t0, msg='Elapsed time'):
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.py
Expand Up @@ -372,7 +372,7 @@ def test_settingerr():

def test_split():
def func(n, m):
slices = split(n, m)
slices = tuple(split(n, m))
assert_eq(len(slices), m)
x = np.zeros(n, int)
for s in slices:
Expand Down

0 comments on commit 4fe1575

Please sign in to comment.