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
36444962
Commit
36444962
authored
Oct 25, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable direct assignments to C arrays by transforming to full slice assignment
parent
fd565517
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
7 deletions
+27
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-5
tests/run/carray_coercion.pyx
tests/run/carray_coercion.pyx
+15
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
36444962
...
...
@@ -1860,7 +1860,6 @@ class NameNode(AtomicExprNode):
def
is_lvalue
(
self
):
return
(
self
.
entry
.
is_variable
and
not
self
.
entry
.
type
.
is_array
and
not
self
.
entry
.
is_readonly
)
or
(
self
.
entry
.
is_cfunction
and
...
...
@@ -11247,7 +11246,7 @@ class CoerceFromPyTypeNode(CoercionNode):
return
self
def
is_ephemeral
(
self
):
return
self
.
type
.
is_ptr
and
self
.
arg
.
is_ephemeral
()
return
(
self
.
type
.
is_ptr
and
not
self
.
type
.
is_array
)
and
self
.
arg
.
is_ephemeral
()
def
generate_result_code
(
self
,
code
):
code
.
putln
(
self
.
type
.
from_py_call_code
(
...
...
Cython/Compiler/Nodes.py
View file @
36444962
...
...
@@ -4750,14 +4750,20 @@ class SingleAssignmentNode(AssignmentNode):
self
.
lhs
.
memslice_broadcast
=
True
self
.
rhs
.
memslice_broadcast
=
True
is_index_node
=
isinstance
(
self
.
lhs
,
ExprNodes
.
IndexNode
)
if
(
is_index_node
and
not
self
.
rhs
.
type
.
is_memoryviewslice
and
(
self
.
lhs
.
memslice_slice
or
self
.
lhs
.
is_memslice_copy
)
and
(
self
.
lhs
.
type
.
dtype
.
assignable_from
(
self
.
rhs
.
type
)
or
self
.
rhs
.
type
.
is_pyobject
)):
if
(
self
.
lhs
.
is_subscript
and
not
self
.
rhs
.
type
.
is_memoryviewslice
and
(
self
.
lhs
.
memslice_slice
or
self
.
lhs
.
is_memslice_copy
)
and
(
self
.
lhs
.
type
.
dtype
.
assignable_from
(
self
.
rhs
.
type
)
or
self
.
rhs
.
type
.
is_pyobject
)):
# scalar slice assignment
self
.
lhs
.
is_memslice_scalar_assignment
=
True
dtype
=
self
.
lhs
.
type
.
dtype
elif
self
.
lhs
.
type
.
is_array
:
if
not
isinstance
(
self
.
lhs
,
(
ExprNodes
.
IndexNode
,
ExprNodes
.
SliceIndexNode
)):
# cannot assign to C array, only to its full slice
self
.
lhs
=
ExprNodes
.
SliceIndexNode
(
self
.
lhs
.
pos
,
base
=
self
.
lhs
,
start
=
None
,
stop
=
None
)
self
.
lhs
=
self
.
lhs
.
analyse_target_types
(
env
)
dtype
=
self
.
lhs
.
type
else
:
dtype
=
self
.
lhs
.
type
...
...
tests/run/carray_coercion.pyx
View file @
36444962
...
...
@@ -96,6 +96,21 @@ def to_int_array(x):
Traceback (most recent call last):
IndexError: too many values found during array assignment, expected 3
"""
cdef
int
[
3
]
v
=
x
return
v
[
0
],
v
[
1
],
v
[
2
]
def
to_int_array_slice
(
x
):
"""
>>> to_int_array_slice([1, 2, 3])
(1, 2, 3)
>>> to_int_array_slice([1, 2])
Traceback (most recent call last):
IndexError: not enough values found during array assignment, expected 3, got 2
>>> to_int_array_slice([1, 2, 3, 4])
Traceback (most recent call last):
IndexError: too many values found during array assignment, expected 3
"""
cdef
int
[
3
]
v
v
[:]
=
x
[:
3
]
assert
v
[
0
]
==
x
[
0
]
...
...
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