Commit da2a3963 authored by Mark Florisson's avatar Mark Florisson

Fix BufferType's assignable_from & some tests

parent 29d68530
......@@ -2578,7 +2578,7 @@ def __pyx_fused_cpdef(signatures, args, kwargs):
candidates = []
for sig in signatures:
match_found = filter(None, dest_sig)
match_found = [x for x in dest_sig if x]
for src_type, dst_type in zip(sig.strip('()').split(', '), dest_sig):
if dst_type is not None and match_found:
match_found = src_type == dst_type
......
......@@ -791,14 +791,21 @@ class BufferType(BaseType):
cast_str)
def assignable_from(self, other_type):
return self.same_as(other_type) or other_type.is_pyobject
if other_type.is_buffer:
return (self.same_as(other_type, compare_base=False) and
self.base.assignable_from(other_type.base))
def same_as(self, other_type):
return (other_type.is_buffer and
self.dtype.same_as(other_type.dtype) and
return self.base.assignable_from(other_type)
def same_as(self, other_type, compare_base=True):
if not other_type.is_buffer:
return other_type.same_as(self.base)
return (self.dtype.same_as(other_type.dtype) and
self.ndim == other_type.ndim and
self.mode == other_type.mode and
self.cast == other_type.cast) or self.base.same_as(other_type)
self.cast == other_type.cast and
(not compare_base or self.base.same_as(other_type.base)))
class PyObjectType(PyrexType):
......
......@@ -528,7 +528,7 @@ cdef fused fused_external:
def test_fused_external(np.ndarray[fused_external, ndim=1] a):
"""
>>> import cython
>>> print sorted(test_fused_external.__signatures__)
>>> sorted(test_fused_external.__signatures__)
['float32_t', 'float64_t', 'int32_t', 'int64_t']
>>> test_fused_external["float64_t"](double_array)
......@@ -539,10 +539,7 @@ def test_fused_external(np.ndarray[fused_external, ndim=1] a):
>>> 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
......@@ -554,6 +551,7 @@ cdef fused fused_buffers:
def test_fused_buffers(fused_buffers arg):
"""
>>> sorted(test_fused_buffers.__signatures__)
['int64_t[::1]', 'ndarray[int32_t,ndim=1]']
"""
cpdef _fused_cpdef_buffers(np.ndarray[fused_external] a):
......@@ -562,6 +560,8 @@ cpdef _fused_cpdef_buffers(np.ndarray[fused_external] a):
def test_fused_cpdef_buffers():
"""
>>> test_fused_cpdef_buffers()
int32
int32
"""
_fused_cpdef_buffers[np.int32_t](int32_array)
......
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