Commit b997c4ae authored by Mark Florisson's avatar Mark Florisson

Allow attribute specializations and add some tests

parent 315efe4c
......@@ -2738,7 +2738,7 @@ class IndexNode(ExprNode):
specific_types = []
positions = []
if self.index.is_name:
if self.index.is_name or self.index.is_attribute:
positions.append(self.index.pos)
specific_types.append(self.index.analyse_as_type(env))
elif isinstance(self.index, TupleNode):
......
......@@ -1785,7 +1785,7 @@ class AnalyseExpressionsTransform(CythonTransform):
"""
self.visit_Node(node)
if node.is_fused_index and node.type is not PyrexTypes.error_type:
if node.is_fused_index and not node.type.is_error:
node = node.base
elif node.memslice_ellipsis_noop:
# memoryviewslice[...] expression, drop the IndexNode
......@@ -1798,7 +1798,8 @@ class AnalyseExpressionsTransform(CythonTransform):
#print node.dump()
#return node
type = node.obj.type
if type.is_extension_type and should_apply_numpy_hack(type):
if (not node.type.is_error and type.is_extension_type and
should_apply_numpy_hack(type)):
node = numpy_transform_attribute_node(node)
self.visitchildren(node)
......
......@@ -516,4 +516,56 @@ def test_fused_ndarray_dtype(np.ndarray[cython.floating, ndim=1] a):
cdef np.ndarray[cython.floating, ndim=1] b = a
print cython.typeof(a), cython.typeof(b), a[5], b[6]
double_array = np.linspace(0, 1, 100)
int32_array = np.arange(100, dtype=np.int32)
cdef fused fused_external:
np.int32_t
np.int64_t
np.float32_t
np.float64_t
def test_fused_external(np.ndarray[fused_external, ndim=1] a):
"""
>>> import cython
>>> print sorted(test_fused_external.__signatures__)
['float32_t', 'float64_t', 'int32_t', 'int64_t']
>>> test_fused_external["float64_t"](double_array)
float64
>>> test_fused_external["int32_t"](int32_array)
int32
>>> test_fused_external(np.arange(100)) # fix in next release
Traceback (most recent call last):
File "/Users/mark/source/py/osx/lib/python2.7/doctest.py", line 1248, in __run
compileflags, 1) in test.globs
File "<doctest numpy_test.__test__.test_fused_external (line 525)[5]>", line 1, in <module>
File "numpy_test.pyx", line 525, in numpy_test.__pyx_fused_cpdef (numpy_test.cpp:10264)
TypeError: No matching signature found
"""
print a.dtype
cdef fused fused_buffers:
np.ndarray[np.int32_t, ndim=1]
np.int64_t[::1]
def test_fused_buffers(fused_buffers arg):
"""
>>> sorted(test_fused_buffers.__signatures__)
"""
cpdef _fused_cpdef_buffers(np.ndarray[fused_external] a):
print a.dtype
def test_fused_cpdef_buffers():
"""
>>> test_fused_cpdef_buffers()
"""
_fused_cpdef_buffers[np.int32_t](int32_array)
cdef np.ndarray[np.int32_t] typed_array = int32_array
_fused_cpdef_buffers(typed_array)
include "numpy_common.pxi"
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