Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
412b5227
Commit
412b5227
authored
Oct 26, 2015
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix prange() end condition for (stop - start) % step != 0.
parent
dc00a176
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
CHANGES.rst
CHANGES.rst
+10
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
tests/run/sequential_parallel.pyx
tests/run/sequential_parallel.pyx
+28
-0
No files found.
CHANGES.rst
View file @
412b5227
...
...
@@ -2,6 +2,16 @@
Cython Changelog
================
0.23.5 (2015-xx-yy)
===================
Bugs fixed
----------
* Fix prange() to behave identically to range(). The end condition was
miscalculated when the range was not exactly divisible by the step.
0.23.4 (2015-10-10)
===================
...
...
Cython/Compiler/Nodes.py
View file @
412b5227
...
...
@@ -8541,7 +8541,7 @@ class ParallelRangeNode(ParallelStatNode):
self
.
control_flow_var_code_point
=
code
.
insertion_point
()
# Note: nsteps is private in an outer scope if present
code
.
putln
(
"%(nsteps)s = (%(stop)s - %(start)s) / %(step)s;"
%
fmt_dict
)
code
.
putln
(
"%(nsteps)s = (%(stop)s - %(start)s
+ %(step)s - %(step)s/abs(%(step)s)
) / %(step)s;"
%
fmt_dict
)
# The target iteration variable might not be initialized, do it only if
# we are executing at least 1 iteration, otherwise we should leave the
...
...
tests/run/sequential_parallel.pyx
View file @
412b5227
...
...
@@ -46,6 +46,34 @@ def test_descending_prange():
return
sum
def
test_prange_matches_range
(
int
start
,
int
stop
,
int
step
):
"""
>>> test_prange_matches_range(0, 8, 3)
>>> test_prange_matches_range(0, 9, 3)
>>> test_prange_matches_range(0, 10, 3)
>>> test_prange_matches_range(0, 10, -3)
>>> test_prange_matches_range(0, -10, -3)
>>> test_prange_matches_range(1, -10, -3)
>>> test_prange_matches_range(2, -10, -3)
>>> test_prange_matches_range(3, -10, -3)
"""
cdef
int
i
,
range_last
,
prange_last
prange_set
=
set
()
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
,
num_threads
=
3
):
prange_last
=
i
with
gil
:
prange_set
.
add
(
i
)
range_set
=
set
(
range
(
start
,
stop
,
step
))
assert
range_set
==
prange_set
,
"missing: %s extra %s"
%
(
sorted
(
range_set
-
prange_set
),
sorted
(
prange_set
-
range_set
))
for
ii
in
range
(
start
,
stop
,
step
):
range_last
=
ii
if
range_set
:
assert
prange_last
==
i
assert
range_last
==
prange_last
def
test_propagation
():
"""
>>> test_propagation()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment