Commit a099ddbe authored by Mark Florisson's avatar Mark Florisson

Use signature string of fused subtype instead of compound type for def functions

parent 480f6687
......@@ -2296,9 +2296,12 @@ class FusedCFuncDefNode(StatListNode):
Create a copy of the original def or lambda function for specialized
versions.
"""
fused_types = PyrexTypes.unique(
fused_compound_types = PyrexTypes.unique(
[arg.type for arg in self.node.args if arg.type.is_fused])
permutations = PyrexTypes.get_all_specialized_permutations(fused_types)
permutations = PyrexTypes.get_all_specialized_permutations(fused_compound_types)
fused_types = [fused_type
for fused_compound_type in fused_compound_types
for fused_type in fused_compound_type.get_fused_types()]
if self.node.entry in env.pyfunc_entries:
env.pyfunc_entries.remove(self.node.entry)
......
......@@ -780,6 +780,10 @@ class BufferType(BaseType):
def __repr__(self):
return "<BufferType %r>" % self.base
def __str__(self):
cast_str = ', cast=True' if self.cast else ''
return "%s[%s, ndim=%d%s]" % (self.base, self.dtype, self.ndim,
cast_str)
class PyObjectType(PyrexType):
#
......
# mode: run
cimport cython
from cython.view cimport array
from cython cimport integral
from cpython cimport Py_INCREF
from Cython import Shadow as pure_cython
ctypedef char * string_t
# floating = cython.fused_type(float, double) floating
......@@ -249,3 +249,40 @@ def test_sizeof_fused_type(fused_type1 b):
"""
t = sizeof(b), sizeof(fused_type1), sizeof(double)
assert t[0] == t[1] == t[2], t
def get_array(itemsize, format):
result = array((10,), itemsize, format)
result[5] = 5.0
result[6] = 6.0
return result
def test_fused_memslice_dtype(cython.floating[:] array):
"""
Note: the np.ndarray dtype test is in numpy_test
>>> import cython
>>> sorted(test_fused_memslice_dtype.__signatures__)
['double', 'float']
>>> test_fused_memslice_dtype[cython.double](get_array(8, 'd'))
double[:] double[:] 5.0 6.0
>>> test_fused_memslice_dtype[cython.float](get_array(4, 'f'))
float[:] float[:] 5.0 6.0
"""
cdef cython.floating[:] otherarray = array[0:100:1]
print cython.typeof(array), cython.typeof(otherarray), \
array[5], otherarray[6]
# FIXME: broken
#from libcpp.vector cimport vector
#def test_cpp_specialization(cython.floating element):
# """
# >>> import cython
# >>> test_cpp_specialization[cython.float](10.0)
# vector<float> * float 10.0
# >>> test_cpp_specialization[cython.double](10.0)
# vector<double> * double 10.0
# """
# cdef vector[cython.floating] *v = new vector[cython.floating]()
# v.push_back(element)
# print cython.typeof(v), cython.typeof(element), v.at(0)
......@@ -2,6 +2,7 @@
# cannot be named "numpy" in order to not clash with the numpy module!
cimport numpy as np
cimport cython
def little_endian():
cdef int endian_detector = 1
......@@ -35,7 +36,7 @@ try:
[[ 16. 17. 18. 19.]
[ 20. 21. 22. 23.]]]
6.0 0.0 13.0 8.0
>>> obj_array()
[a 1 {}]
a 1 {}
......@@ -502,4 +503,17 @@ def test_point_record():
test[i].y = -i
print repr(test).replace('<', '!').replace('>', '!')
def test_fused_ndarray_dtype(np.ndarray[cython.floating, ndim=1] a):
"""
>>> import cython
>>> sorted(test_fused_ndarray_dtype.__signatures__)
['double', 'float']
>>> test_fused_ndarray_dtype[cython.double](np.arange(10, dtype=np.float64))
ndarray[double, ndim=1] ndarray[double, ndim=1] 5.0 6.0
>>> test_fused_ndarray_dtype[cython.float](np.arange(10, dtype=np.float32))
ndarray[float, ndim=1] ndarray[float, ndim=1] 5.0 6.0
"""
cdef np.ndarray[cython.floating, ndim=1] b = a
print cython.typeof(a), cython.typeof(b), a[5], b[6]
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