Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group-connectivity-pub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radek Hušek
group-connectivity-pub
Commits
a9ad147e
Commit
a9ad147e
authored
7 years ago
by
Radek Hušek
Browse files
Options
Downloads
Patches
Plain Diff
parmap.py: add doctests
parent
b9eeee86
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
parmap.py
+22
-1
22 additions, 1 deletion
parmap.py
with
22 additions
and
1 deletion
parmap.py
+
22
−
1
View file @
a9ad147e
...
...
@@ -6,7 +6,15 @@ import multiprocessing
from
itertools
import
chain
def
chunkme
(
X
,
chunksize
):
"""
Return items generated by X in chunks (lists) of size chunksize.
"""
"""
Return items generated by X in chunks (lists) of size chunksize.
EXAMPLE:
>>>
list
(
chunkme
(
range
(
20
),
7
))
[[
0
,
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
,
13
],
[
14
,
15
,
16
,
17
,
18
,
19
]]
>>>
list
(
chunkme
(
range
(
0
),
2
))
[]
"""
chunk
=
[]
for
x
in
X
:
chunk
.
append
(
x
)
...
...
@@ -62,6 +70,11 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
in_order -- if True, input sequence may be reordered during processing
multimap -- if True, f is expected to return an Iterable and flattening is done
out_chunksize -- size of chunks send from workers to consumer
EXAMPLES:
>>>
list
(
parmap
(
lambda
x
:
x
+
1
,
range
(
10
)))
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
"""
if
nprocs
is
None
:
nprocs
=
multiprocessing
.
cpu_count
()
...
...
@@ -127,3 +140,11 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
return
chain
.
from_iterable
(
get_chunk
())
if
__name__
==
"
__main__
"
:
import
doctest
(
f
,
t
)
=
doctest
.
testmod
()
print
"
%s: %i tests of %i failed.
"
%
(
__file__
,
f
,
t
)
if
f
>
0
:
exit
(
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment