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
Gwenaël Samain
cython
Commits
fdc6bdfd
Commit
fdc6bdfd
authored
Dec 31, 2014
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly uses same nodes. Added more tests.
parent
28d3b313
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
6 deletions
+57
-6
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+11
-6
tests/run/reversed_iteration.pyx
tests/run/reversed_iteration.pyx
+46
-0
No files found.
Cython/Compiler/Optimize.py
View file @
fdc6bdfd
...
@@ -657,6 +657,7 @@ class IterationTransform(Visitor.EnvTransform):
...
@@ -657,6 +657,7 @@ class IterationTransform(Visitor.EnvTransform):
relation1
,
relation2
=
self
.
_find_for_from_node_relations
(
step_value
<
0
,
reversed
)
relation1
,
relation2
=
self
.
_find_for_from_node_relations
(
step_value
<
0
,
reversed
)
bound2_ref_node
=
None
if
reversed
:
if
reversed
:
bound1
,
bound2
=
bound2
,
bound1
bound1
,
bound2
=
bound2
,
bound1
abs_step
=
abs
(
step_value
)
abs_step
=
abs
(
step_value
)
...
@@ -676,17 +677,18 @@ class IterationTransform(Visitor.EnvTransform):
...
@@ -676,17 +677,18 @@ class IterationTransform(Visitor.EnvTransform):
bound1
.
pos
,
value
=
str
(
bound1_value
),
constant_result
=
bound1_value
,
bound1
.
pos
,
value
=
str
(
bound1_value
),
constant_result
=
bound1_value
,
type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
))
type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
))
else
:
else
:
bound2_ref_node
=
UtilNodes
.
LetRefNode
(
bound2
)
spanning_type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
)
spanning_type
=
PyrexTypes
.
spanning_type
(
bound1
.
type
,
bound2
.
type
)
spanning_step_type
=
PyrexTypes
.
spanning_type
(
spanning_type
,
step
.
type
)
spanning_step_type
=
PyrexTypes
.
spanning_type
(
spanning_type
,
step
.
type
)
if
step_value
<
0
:
if
step_value
<
0
:
begin_value
=
copy
.
deepcopy
(
bound2
)
begin_value
=
bound2_ref_node
end_value
=
copy
.
deepcopy
(
bound1
)
end_value
=
bound1
final_op
=
'-'
final_op
=
'-'
final_node
=
ExprNodes
.
SubNode
final_node
=
ExprNodes
.
SubNode
else
:
else
:
begin_value
=
copy
.
deepcopy
(
bound1
)
begin_value
=
bound1
end_value
=
copy
.
deepcopy
(
bound2
)
end_value
=
bound2_ref_node
final_op
=
'+'
final_op
=
'+'
final_node
=
ExprNodes
.
AddNode
final_node
=
ExprNodes
.
AddNode
...
@@ -694,7 +696,7 @@ class IterationTransform(Visitor.EnvTransform):
...
@@ -694,7 +696,7 @@ class IterationTransform(Visitor.EnvTransform):
bound1
.
pos
,
bound1
.
pos
,
operand1
=
final_node
(
operand1
=
final_node
(
bound1
.
pos
,
bound1
.
pos
,
operand1
=
copy
.
deepcopy
(
bound2
)
,
operand1
=
bound2_ref_node
,
operator
=
final_op
,
operator
=
final_op
,
operand2
=
ExprNodes
.
MulNode
(
operand2
=
ExprNodes
.
MulNode
(
bound1
.
pos
,
bound1
.
pos
,
...
@@ -745,7 +747,10 @@ class IterationTransform(Visitor.EnvTransform):
...
@@ -745,7 +747,10 @@ class IterationTransform(Visitor.EnvTransform):
if
not
bound2
.
is_literal
:
if
not
bound2
.
is_literal
:
# stop bound must be immutable => keep it in a temp var
# stop bound must be immutable => keep it in a temp var
bound2_is_temp
=
True
bound2_is_temp
=
True
bound2
=
UtilNodes
.
LetRefNode
(
bound2
)
if
bound2_ref_node
:
bound2
=
bound2_ref_node
else
:
bound2
=
UtilNodes
.
LetRefNode
(
bound2
)
else
:
else
:
bound2_is_temp
=
False
bound2_is_temp
=
False
...
...
tests/run/reversed_iteration.pyx
View file @
fdc6bdfd
...
@@ -163,6 +163,21 @@ def reversed_range_step3(int a, int b):
...
@@ -163,6 +163,21 @@ def reversed_range_step3(int a, int b):
result
.
append
(
i
)
result
.
append
(
i
)
return
result
,
i
return
result
,
i
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ForInStatNode'
)
def
reversed_range_step3_expr
(
int
a
,
int
b
):
"""
>>> [ i for i in _reversed(range(0, 5, 3)) ]
[3, 0]
>>> reversed_range_step3_expr(0, 5)
([3, 0], 0)
"""
cdef
int
i
=
99
,
c
=
100
result
=
[]
for
i
in
reversed
(
range
(
c
-
c
+
a
+
c
-
c
,
c
-
c
+
b
+
c
-
c
,
3
)):
result
.
append
(
i
)
return
result
,
i
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ForInStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ForInStatNode'
)
def
reversed_range_step3_neg
(
int
a
,
int
b
):
def
reversed_range_step3_neg
(
int
a
,
int
b
):
...
@@ -193,6 +208,21 @@ def reversed_range_step3_neg(int a, int b):
...
@@ -193,6 +208,21 @@ def reversed_range_step3_neg(int a, int b):
result
.
append
(
i
)
result
.
append
(
i
)
return
result
,
i
return
result
,
i
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ForInStatNode'
)
def
reversed_range_step3_neg_expr
(
int
a
,
int
b
):
"""
>>> [ i for i in _reversed(range(5, 0, -3)) ]
[2, 5]
>>> reversed_range_step3_neg_expr(5, 0)
([2, 5], 5)
"""
cdef
int
i
=
99
,
c
=
100
result
=
[]
for
i
in
reversed
(
range
(
c
-
c
+
a
+
c
-
c
,
c
-
c
+
b
+
c
-
c
,
-
3
)):
result
.
append
(
i
)
return
result
,
i
def
reversed_range_step3_py_args
(
a
,
b
):
def
reversed_range_step3_py_args
(
a
,
b
):
"""
"""
>>> [ i for i in _reversed(range(-5, 0, 3)) ]
>>> [ i for i in _reversed(range(-5, 0, 3)) ]
...
@@ -214,6 +244,14 @@ def reversed_range_step3_py_args(a, b):
...
@@ -214,6 +244,14 @@ def reversed_range_step3_py_args(a, b):
[]
[]
>>> reversed_range_step3_py_args(1, 1)
>>> reversed_range_step3_py_args(1, 1)
([], 99)
([], 99)
>>> reversed_range_step3_py_args(set(), 1) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
>>> reversed_range_step3_py_args(1, set()) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
"""
"""
i
=
99
i
=
99
result
=
[]
result
=
[]
...
@@ -242,6 +280,14 @@ def reversed_range_step3_neg_py_args(a, b):
...
@@ -242,6 +280,14 @@ def reversed_range_step3_neg_py_args(a, b):
[]
[]
>>> reversed_range_step3_neg_py_args(1, 1)
>>> reversed_range_step3_neg_py_args(1, 1)
([], 99)
([], 99)
>>> reversed_range_step3_neg_py_args(set(), 1) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
>>> reversed_range_step3_neg_py_args(1, set()) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...integer...
"""
"""
i
=
99
i
=
99
result
=
[]
result
=
[]
...
...
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