Commit 2a5e66ae authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fix #441

parent cf818792
...@@ -408,8 +408,10 @@ class GlobalState(object): ...@@ -408,8 +408,10 @@ class GlobalState(object):
code_layout = [ code_layout = [
'h_code', 'h_code',
'utility_code_proto_before_types', 'utility_code_proto_before_types',
'type_declarations', 'numeric_typedefs', # Let these detailed individual parts stay!,
'utility_code_proto', 'complex_type_declarations', # as the proper solution is to make a full DAG...
'type_declarations', # More coarse-grained blocks would simply hide
'utility_code_proto', # the ugliness, not fix it
'module_declarations', 'module_declarations',
'typeinfo', 'typeinfo',
'before_global_var', 'before_global_var',
......
...@@ -654,8 +654,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -654,8 +654,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_typedef(self, entry, code): def generate_typedef(self, entry, code):
base_type = entry.type.typedef_base_type base_type = entry.type.typedef_base_type
code.putln("") if base_type.is_numeric:
code.putln("typedef %s;" % base_type.declaration_code(entry.cname)) writer = code.globalstate['numeric_typedefs']
else:
writer = code
writer.putln("")
writer.putln("typedef %s;" % base_type.declaration_code(entry.cname))
def sue_header_footer(self, type, kind, name): def sue_header_footer(self, type, kind, name):
if type.typedef_flag: if type.typedef_flag:
......
...@@ -871,6 +871,15 @@ class CComplexType(CNumericType): ...@@ -871,6 +871,15 @@ class CComplexType(CNumericType):
scope = None scope = None
def __init__(self, real_type): def __init__(self, real_type):
while real_type.is_typedef and not real_type.typedef_is_external:
real_type = real_type.typedef_base_type
if real_type.is_typedef and real_type.typedef_is_external:
# The below is not actually used: Coercions are currently disabled
# so that complex types of external types can not be created
self.funcsuffix = "_%s" % real_type.specalization_name()
else:
self.funcsuffix = real_type.math_h_modifier
self.real_type = real_type self.real_type = real_type
CNumericType.__init__(self, real_type.rank + 0.5, real_type.signed) CNumericType.__init__(self, real_type.rank + 0.5, real_type.signed)
self.binops = {} self.binops = {}
...@@ -915,7 +924,8 @@ class CComplexType(CNumericType): ...@@ -915,7 +924,8 @@ class CComplexType(CNumericType):
def assignable_from(self, src_type): def assignable_from(self, src_type):
# Temporary hack/feature disabling, see #441 # Temporary hack/feature disabling, see #441
if not src_type.is_complex and src_type.is_numeric and src_type.is_typedef: if (not src_type.is_complex and src_type.is_numeric and src_type.is_typedef
and src_type.typedef_is_external):
return False return False
else: else:
return super(CComplexType, self).assignable_from(src_type) return super(CComplexType, self).assignable_from(src_type)
...@@ -940,7 +950,7 @@ class CComplexType(CNumericType): ...@@ -940,7 +950,7 @@ class CComplexType(CNumericType):
CFuncType(self, [CFuncTypeArg("self", self, None)]), CFuncType(self, [CFuncTypeArg("self", self, None)]),
pos=None, pos=None,
defining=1, defining=1,
cname="__Pyx_c_conj%s" % self.real_type.math_h_modifier) cname="__Pyx_c_conj%s" % self.funcsuffix)
return True return True
...@@ -956,7 +966,7 @@ class CComplexType(CNumericType): ...@@ -956,7 +966,7 @@ class CComplexType(CNumericType):
utility_code.specialize( utility_code.specialize(
self, self,
real_type = self.real_type.declaration_code(''), real_type = self.real_type.declaration_code(''),
m = self.real_type.math_h_modifier)) m = self.funcsuffix))
return True return True
def create_to_py_utility_code(self, env): def create_to_py_utility_code(self, env):
...@@ -973,7 +983,7 @@ class CComplexType(CNumericType): ...@@ -973,7 +983,7 @@ class CComplexType(CNumericType):
utility_code.specialize( utility_code.specialize(
self, self,
real_type = self.real_type.declaration_code(''), real_type = self.real_type.declaration_code(''),
m = self.real_type.math_h_modifier)) m = self.funcsuffix))
self.from_py_function = "__Pyx_PyComplex_As_" + self.specalization_name() self.from_py_function = "__Pyx_PyComplex_As_" + self.specalization_name()
return True return True
...@@ -984,8 +994,7 @@ class CComplexType(CNumericType): ...@@ -984,8 +994,7 @@ class CComplexType(CNumericType):
pass pass
try: try:
op_name = complex_ops[nargs, op] op_name = complex_ops[nargs, op]
modifier = self.real_type.math_h_modifier self.binops[nargs, op] = func_name = "__Pyx_c_%s%s" % (op_name, self.funcsuffix)
self.binops[nargs, op] = func_name = "__Pyx_c_%s%s" % (op_name, modifier)
return func_name return func_name
except KeyError: except KeyError:
return None return None
...@@ -1045,7 +1054,7 @@ proto=""" ...@@ -1045,7 +1054,7 @@ proto="""
""") """)
complex_type_utility_code = UtilityCode( complex_type_utility_code = UtilityCode(
proto_block='utility_code_proto_before_types', proto_block='complex_type_declarations',
proto=""" proto="""
#if CYTHON_CCOMPLEX #if CYTHON_CCOMPLEX
#ifdef __cplusplus #ifdef __cplusplus
...@@ -1204,7 +1213,6 @@ impl=""" ...@@ -1204,7 +1213,6 @@ impl="""
#endif #endif
""") """)
class CArrayType(CType): class CArrayType(CType):
# base_type CType Element type # base_type CType Element type
# size integer or None Number of elements # size integer or None Number of elements
......
...@@ -123,15 +123,45 @@ def test_conjugate_double(double complex z): ...@@ -123,15 +123,45 @@ def test_conjugate_double(double complex z):
ctypedef double complex cdouble ctypedef double complex cdouble
def test_conjugate_typedef(cdouble z): def test_conjugate_typedef(cdouble z):
"""
>>> test_conjugate_typedef(2+3j)
(2-3j)
"""
return z.conjugate() return z.conjugate()
#ctypedef double mydouble ## cdef extern from "complex_numbers_T305.h":
#def test_coerce_typedef_multiply(mydouble x, double complex z): ## ctypedef double double_really_float "myfloat"
# """ ## ctypedef float float_really_double "mydouble"
# >>> test_coerce_typedef_multiply(3, 1j) ## ctypedef float real_float "myfloat"
# (3j) ## ctypedef double real_double "mydouble"
# """
# return x * z ## def test_conjugate_nosizeassumptions(double_really_float x,
## float_really_double y,
## real_float z, real_double w):
## """
## >>> test_conjugate_nosizeassumptions(1, 1, 1, 1)
## (-1j, -1j, -1j, -1j)
## >>> ["%.2f" % x.imag for x in test_conjugate_nosizeassumptions(2e300, 2e300, 2e300, 2e300)]
## ['-inf', '-2e+300', '-inf', '-2e+300']
## """
## cdef double complex I = 1j
## return ((x*I).conjugate(), (y*I).conjugate(), (z*I).conjugate(), (w*I).conjugate())
ctypedef double mydouble
def test_coerce_typedef_multiply(mydouble x, double complex z):
"""
>>> test_coerce_typedef_multiply(3, 1+1j)
(3+3j)
"""
return x * z
ctypedef int myint
def test_coerce_typedef_multiply_int(myint x, double complex z):
"""
>>> test_coerce_typedef_multiply_int(3, 1+1j)
(3+3j)
"""
return x * z
cpdef double complex complex_retval(): cpdef double complex complex_retval():
""" """
......
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