Commit bd673cc3 authored by Mark Florisson's avatar Mark Florisson

Allow object indices for typed memoryviews

parent 25361fb6
......@@ -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)
......
......@@ -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]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment