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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
bd673cc3
Commit
bd673cc3
authored
Dec 04, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow object indices for typed memoryviews
parent
25361fb6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-0
tests/run/memslice.pyx
tests/run/memslice.pyx
+18
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
bd673cc3
...
...
@@ -2339,6 +2339,7 @@ class IndexNode(ExprNode):
# Whether we are indexing or slicing a memoryviewslice
memslice_index
=
False
memslice_slice
=
False
warned_untyped_idx
=
False
def
__init__
(
self
,
pos
,
index
,
*
args
,
**
kw
):
ExprNode
.
__init__
(
self
,
pos
,
index
=
index
,
*
args
,
**
kw
)
...
...
@@ -2542,6 +2543,11 @@ class IndexNode(ExprNode):
setattr
(
index
,
attr
,
value
)
new_indices
.
append
(
value
)
elif
index
.
type
.
is_int
or
index
.
type
.
is_pyobject
:
if
index
.
type
.
is_pyobject
and
not
self
.
warned_untyped_idx
:
warning
(
index
.
pos
,
"Index should be typed for more "
"efficient access"
,
level
=
2
)
IndexNode
.
warned_untyped_idx
=
True
elif
index
.
type
.
is_int
:
self
.
memslice_index
=
True
index
=
index
.
coerce_to
(
index_type
,
env
)
...
...
tests/run/memslice.pyx
View file @
bd673cc3
...
...
@@ -8,8 +8,6 @@ cimport cython
from
cython
cimport
view
from
cython.parallel
cimport
prange
print
cython
.
array
import
sys
import
re
...
...
@@ -1457,3 +1455,21 @@ def test_memslice_prange(arg):
for
j
in
range
(
src
.
shape
[
1
]):
for
k
in
range
(
src
.
shape
[
2
]):
assert
src
[
i
,
j
,
k
]
==
dst
[
i
,
j
,
k
],
(
src
[
i
,
j
,
k
]
==
dst
[
i
,
j
,
k
])
@
testcase
def
test_object_indices
():
"""
>>> test_object_indices()
0
1
2
"""
cdef
int
array
[
3
]
cdef
int
[:]
myslice
=
array
cdef
int
j
for
i
in
range
(
3
):
myslice
[
i
]
=
i
for
j
in
range
(
3
):
print
myslice
[
j
]
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