scope = None
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
CNumericType.__init__(self, real_type.rank + 0.5, real_type.signed)
self.binops = {}
self.from_parts = "%s_from_parts" % self.specalization_name()
self.default_value = "%s(0, 0)" % self.from_parts
-
+
def __eq__(self, other):
if isinstance(self, CComplexType) and isinstance(other, CComplexType):
return self.real_type == other.real_type
def __hash__(self):
return ~hash(self.real_type)
-
+
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
if for_display:
def assignable_from(self, src_type):
# Temporary hack/feature disabling, see #441
- if not src_type.is_complex and src_type.is_numeric and src_type.is_typedef:
- return False
+ if (not src_type.is_complex and src_type.is_numeric and src_type.is_typedef
+ and src_type.typedef_is_external):
+ return False
else:
return super(CComplexType, self).assignable_from(src_type)
CFuncType(self, [CFuncTypeArg("self", self, None)]),
pos=None,
defining=1,
- cname="__Pyx_c_conj%s" % self.real_type.math_h_modifier)
+ cname="__Pyx_c_conj%s" % self.funcsuffix)
return True
utility_code.specialize(
self,
real_type = self.real_type.declaration_code(''),
- m = self.real_type.math_h_modifier))
+ m = self.funcsuffix))
return True
def create_to_py_utility_code(self, env):
utility_code.specialize(
self,
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()
return True
pass
try:
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, modifier)
+ self.binops[nargs, op] = func_name = "__Pyx_c_%s%s" % (op_name, self.funcsuffix)
return func_name
except KeyError:
return None
""")
complex_type_utility_code = UtilityCode(
-proto_block='utility_code_proto_before_types',
+proto_block='complex_type_declarations',
proto="""
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#endif
""")
-
class CArrayType(CType):
# base_type CType Element type
# size integer or None Number of elements
ctypedef double complex cdouble
def test_conjugate_typedef(cdouble z):
+ """
+ >>> test_conjugate_typedef(2+3j)
+ (2-3j)
+ """
return z.conjugate()
-#ctypedef double mydouble
-#def test_coerce_typedef_multiply(mydouble x, double complex z):
-# """
-# >>> test_coerce_typedef_multiply(3, 1j)
-# (3j)
-# """
-# return x * z
+## cdef extern from "complex_numbers_T305.h":
+## ctypedef double double_really_float "myfloat"
+## ctypedef float float_really_double "mydouble"
+## ctypedef float real_float "myfloat"
+## ctypedef double real_double "mydouble"
+
+## 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():
"""