Skip to content

Commit

Permalink
Specialized fused indices
Browse files Browse the repository at this point in the history
  • Loading branch information
markflorisson committed Jun 14, 2012
1 parent 23b8ea6 commit 27d1dcf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cython/Compiler/ExprNodes.py
Expand Up @@ -2805,6 +2805,9 @@ def parse_indexed_fused_cdef(self, env):
self.is_fused_index = False
return

for i, type in enumerate(specific_types):
specific_types[i] = type.specialize_fused(env)

fused_types = base_type.get_fused_types()
if len(specific_types) > len(fused_types):
return error(self.pos, "Too many types specified")
Expand Down
6 changes: 6 additions & 0 deletions Cython/Compiler/PyrexTypes.py
Expand Up @@ -57,6 +57,12 @@ def get_fused_types(self, result=None, seen=None, subtypes=None):

return None

def specialize_fused(self, env):
if env.fused_to_specific:
return self.specialize(env.fused_to_specific)

return self

def _get_fused_types(self):
"""
Add this indirection for the is_fused property to allow overriding
Expand Down
15 changes: 15 additions & 0 deletions tests/run/fused_types.pyx
Expand Up @@ -282,3 +282,18 @@ def test_cython_numeric(cython.numeric arg):
double complex (10+1j)
"""
print cython.typeof(arg), arg

cdef fused ints_t:
int
long

cdef _test_index_fused_args(cython.floating f, ints_t i):
print cython.typeof(f), cython.typeof(i)

def test_index_fused_args(cython.floating f, ints_t i):
"""
>>> import cython
>>> test_index_fused_args[cython.double, cython.int](2.0, 3)
double int
"""
_test_index_fused_args[cython.floating, ints_t](f, i)

0 comments on commit 27d1dcf

Please sign in to comment.