diff options
Diffstat (limited to 'tests/run/fused_cpp.pyx')
-rw-r--r-- | tests/run/fused_cpp.pyx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/run/fused_cpp.pyx b/tests/run/fused_cpp.pyx index c5a0d7d34..95b326904 100644 --- a/tests/run/fused_cpp.pyx +++ b/tests/run/fused_cpp.pyx @@ -2,6 +2,9 @@ cimport cython from libcpp.vector cimport vector +from libcpp.map cimport map +from libcpp.typeinfo cimport type_info +from cython.operator cimport typeid def test_cpp_specialization(cython.floating element): """ @@ -14,3 +17,74 @@ def test_cpp_specialization(cython.floating element): cdef vector[cython.floating] *v = new vector[cython.floating]() v.push_back(element) print cython.typeof(v), cython.typeof(element), v.at(0) + +cdef fused C: + int + object + +cdef const type_info* tidint = &typeid(int) +def typeid_call(C x): + """ + For GH issue 3203 + >>> typeid_call(1) + True + """ + cdef const type_info* a = &typeid(C) + return a[0] == tidint[0] + +cimport cython + +def typeid_call2(cython.integral x): + """ + For GH issue 3203 + >>> typeid_call2[int](1) + True + """ + cdef const type_info* a = &typeid(cython.integral) + return a[0] == tidint[0] + +cdef fused_ref(cython.integral& x): + return x*2 + +def test_fused_ref(int x): + """ + >>> test_fused_ref(5) + (10, 10) + """ + return fused_ref(x), fused_ref[int](x) + +ctypedef fused nested_fused: + vector[cython.integral] + +cdef vec_of_fused(nested_fused v): + x = v[0] + return cython.typeof(x) + +def test_nested_fused(): + """ + >>> test_nested_fused() + int + long + """ + cdef vector[int] vi = [0,1] + cdef vector[long] vl = [0,1] + print vec_of_fused(vi) + print vec_of_fused(vl) + +ctypedef fused nested_fused2: + map[cython.integral, cython.floating] + +cdef map_of_fused(nested_fused2 m): + for pair in m: + return cython.typeof(pair.first), cython.typeof(pair.second) + +def test_nested_fused2(): + """ + >>> test_nested_fused2() + ('int', 'float') + ('long', 'double') + """ + cdef map[int, float] mif = { 0: 0.0 } + cdef map[long, double] mld = { 0: 0.0 } + print map_of_fused(mif) + print map_of_fused(mld) |