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
d8b19074
Commit
d8b19074
authored
Nov 08, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop C array unpacking back into C instead of going back and forth through Python list coercion
parent
3ae163a6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
16 deletions
+43
-16
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+18
-15
tests/run/arrayassign.pyx
tests/run/arrayassign.pyx
+25
-1
No files found.
Cython/Compiler/Nodes.py
View file @
d8b19074
...
@@ -4830,19 +4830,16 @@ class SingleAssignmentNode(AssignmentNode):
...
@@ -4830,19 +4830,16 @@ class SingleAssignmentNode(AssignmentNode):
def
unroll
(
self
,
node
,
target_size
,
env
):
def
unroll
(
self
,
node
,
target_size
,
env
):
from
.
import
ExprNodes
,
UtilNodes
from
.
import
ExprNodes
,
UtilNodes
if
node
.
type
.
is_ctuple
:
if
node
.
type
.
size
==
target_size
:
base
=
node
base
=
node
start_node
=
None
start_node
=
stop_node
=
step_node
=
check_node
=
None
stop_node
=
None
step_node
=
None
if
node
.
type
.
is_ctuple
:
check_node
=
None
slice_size
=
node
.
type
.
size
else
:
error
(
self
.
pos
,
"Unpacking type %s requires exactly %s arguments."
%
(
node
.
type
,
node
.
type
.
size
))
return
elif
node
.
type
.
is_ptr
:
elif
node
.
type
.
is_ptr
or
node
.
type
.
is_array
:
while
isinstance
(
node
,
ExprNodes
.
SliceIndexNode
)
and
not
(
node
.
start
or
node
.
stop
):
base
=
node
=
node
.
base
if
isinstance
(
node
,
ExprNodes
.
SliceIndexNode
):
if
isinstance
(
node
,
ExprNodes
.
SliceIndexNode
):
base
=
node
.
base
base
=
node
.
base
start_node
=
node
.
start
start_node
=
node
.
start
...
@@ -4875,19 +4872,25 @@ class SingleAssignmentNode(AssignmentNode):
...
@@ -4875,19 +4872,25 @@ class SingleAssignmentNode(AssignmentNode):
try
:
try
:
slice_size
=
(
get_const
(
stop_node
,
None
)
-
get_const
(
start_node
,
0
))
/
get_const
(
step_node
,
1
)
slice_size
=
(
get_const
(
stop_node
,
None
)
-
get_const
(
start_node
,
0
))
/
get_const
(
step_node
,
1
)
if
target_size
!=
slice_size
:
error
(
self
.
pos
,
"Assignment to/from slice of wrong length, expected %d, got %d"
%
(
slice_size
,
target_size
))
except
ValueError
:
except
ValueError
:
error
(
self
.
pos
,
"C array assignment currently requires known endpoints"
)
error
(
self
.
pos
,
"C array assignment currently requires known endpoints"
)
return
return
check_node
=
None
elif
node
.
type
.
is_array
:
slice_size
=
node
.
type
.
size
if
not
isinstance
(
slice_size
,
(
int
,
long
)):
return
# might still work when coercing to Python
else
:
else
:
return
return
else
:
else
:
return
return
if
slice_size
!=
target_size
:
error
(
self
.
pos
,
"Assignment to/from slice of wrong length, expected %s, got %s"
%
(
slice_size
,
target_size
))
return
items
=
[]
items
=
[]
base
=
UtilNodes
.
LetRefNode
(
base
)
base
=
UtilNodes
.
LetRefNode
(
base
)
refs
=
[
base
]
refs
=
[
base
]
...
...
tests/run/arrayassign.pyx
View file @
d8b19074
...
@@ -162,7 +162,12 @@ def test_starred_from_array():
...
@@ -162,7 +162,12 @@ def test_starred_from_array():
return
x
,
y
,
z
return
x
,
y
,
z
@
cython
.
test_fail_if_path_exists
(
'//ParallelAssignmentNode//CoerceToPyTypeNode'
,
'//ParallelAssignmentNode//CoerceFromPyTypeNode'
,
)
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
'//ParallelAssignmentNode'
,
'//ReturnStatNode//CoerceToPyTypeNode'
'//ReturnStatNode//CoerceToPyTypeNode'
)
)
def
test_multiple_from_array
():
def
test_multiple_from_array
():
...
@@ -170,7 +175,6 @@ def test_multiple_from_array():
...
@@ -170,7 +175,6 @@ def test_multiple_from_array():
>>> test_multiple_from_array()
>>> test_multiple_from_array()
(1, 2, 3)
(1, 2, 3)
"""
"""
# FIXME: copy currently goes through a Python list, even though we infer the right target types
cdef
int
[
3
]
a
cdef
int
[
3
]
a
a
[
0
]
=
1
a
[
0
]
=
1
a
[
1
]
=
2
a
[
1
]
=
2
...
@@ -179,6 +183,26 @@ def test_multiple_from_array():
...
@@ -179,6 +183,26 @@ def test_multiple_from_array():
return
x
,
y
,
z
return
x
,
y
,
z
@
cython
.
test_fail_if_path_exists
(
'//ParallelAssignmentNode//CoerceToPyTypeNode'
)
@
cython
.
test_assert_path_exists
(
'//ParallelAssignmentNode'
,
'//ReturnStatNode//CoerceToPyTypeNode'
)
def
test_multiple_from_array_full_slice
():
"""
>>> test_multiple_from_array_full_slice()
(1, 2, 3)
"""
cdef
int
[
3
]
a
a
[
0
]
=
1
a
[
1
]
=
2
a
[
2
]
=
3
x
,
y
,
z
=
a
[:]
return
x
,
y
,
z
@
cython
.
test_fail_if_path_exists
(
@
cython
.
test_fail_if_path_exists
(
'//ParallelAssignmentNode//CoerceToPyTypeNode'
'//ParallelAssignmentNode//CoerceToPyTypeNode'
)
)
...
...
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