Commit cd594eb1 authored by Stefan Behnel's avatar Stefan Behnel

Support 1-dim memory view types in type annotations (requires support in...

Support 1-dim memory view types in type annotations (requires support in SliceIndexNode, where we previously only had it in IndexNode).
parent df5a3352
......@@ -3403,6 +3403,7 @@ class IndexNode(_IndexingBaseNode):
elif self.index.is_slice or self.index.is_sequence_constructor:
# memory view
from . import MemoryView
env.use_utility_code(MemoryView.view_utility_code)
axes = [self.index] if self.index.is_slice else list(self.index.args)
return PyrexTypes.MemoryViewSliceType(base_type, MemoryView.get_axes_specs(env, axes))
else:
......@@ -4830,6 +4831,24 @@ class SliceIndexNode(ExprNode):
self.is_temp = 1
return self
def analyse_as_type(self, env):
base_type = self.base.analyse_as_type(env)
if base_type and not base_type.is_pyobject:
if not self.start and not self.stop:
# memory view
from . import MemoryView
env.use_utility_code(MemoryView.view_utility_code)
none_node = NoneNode(self.pos)
slice_node = SliceNode(
self.pos,
start=none_node,
stop=none_node,
step=none_node,
)
return PyrexTypes.MemoryViewSliceType(
base_type, MemoryView.get_axes_specs(env, [slice_node]))
return None
nogil_check = Node.gil_error
gil_message = "Slicing Python object"
......
# mode: run
# tag: pep484, numpy
##, warnings
import cython
import numpy
def one_dim(a: cython.double[:]):
"""
>>> a = numpy.ones((10,), numpy.double)
>>> one_dim(a)
(2.0, 1)
"""
a[0] *= 2
return a[0], a.ndim
def one_dim_ccontig(a: cython.double[::1]):
"""
>>> a = numpy.ones((10,), numpy.double)
>>> one_dim_ccontig(a)
(2.0, 1)
"""
a[0] *= 2
return a[0], a.ndim
def two_dim(a: cython.double[:,:]):
"""
>>> a = numpy.ones((10, 10), numpy.double)
>>> two_dim(a)
(3.0, 1.0, 2)
"""
a[0,0] *= 3
return a[0,0], a[0,1], a.ndim
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