From 6f060c90fcbb276b9d53c684a92e92ffa14f49d7 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Thu, 15 Oct 2009 10:35:20 +0200 Subject: [PATCH] complexvar.conjugate() support --- Cython/Compiler/PyrexTypes.py | 19 ++++++++++++++++--- tests/run/complex_numbers_T305.pyx | 16 ++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index f6474f85..f1636daa 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -871,9 +871,22 @@ class CComplexType(CNumericType): def attributes_known(self): if self.scope is None: import Symtab - self.scope = Symtab.StructOrUnionScope(self.specalization_name()) - self.scope.declare_var("real", self.real_type, None, "real") - self.scope.declare_var("imag", self.real_type, None, "imag") + self.scope = scope = Symtab.CClassScope( + '', + None, + visibility="extern") + scope.parent_type = self + + + scope.declare_var("real", self.real_type, None, "real", is_cdef=True) + scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True) + entry = scope.declare_cfunction( + "conjugate", + CFuncType(self, [CFuncTypeArg("self", self, None)]), + pos=None, + defining=1, + cname="__Pyx_c_conj%s" % self.real_type.math_h_modifier) + return True def create_declaration_utility_code(self, env): diff --git a/tests/run/complex_numbers_T305.pyx b/tests/run/complex_numbers_T305.pyx index 231a4762..71846397 100644 --- a/tests/run/complex_numbers_T305.pyx +++ b/tests/run/complex_numbers_T305.pyx @@ -58,9 +58,11 @@ __doc__ = u""" >>> test_real_imag_assignment(1.5, -3.5) (1.5-3.5j) -## XXX not implemented yet! -## >>> test_conjugate(1+2j) -## (1-2j) + >>> test_conjugate(2+3j) + (2-3j) + + >>> test_conjugate_double(2+3j) + (2-3j) """ #cdef extern from "complex.h": @@ -109,6 +111,8 @@ def test_real_imag_assignment(object a, double b): z.imag = b return z -## XXX not implemented yet! -## def test_conjugate(float complex z): -## return z.conjugate() +def test_conjugate(float complex z): + return z.conjugate() + +def test_conjugate_double(double complex z): + return z.conjugate() -- 2.26.2