Ticket #5572: fast_callable_complex.patch

File fast_callable_complex.patch, 4.4 KB (added by jason, 10 years ago)

apply on top of previous patch

  • sage/ext/gen_interpreters.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1272108947 18000
    # Node ID a174dc47b48b398e307bb6524f733199f72374e4
    # Parent  360ebd327e26af75f436bc1e818478d3a927ba9f
    imported patch gen_interpreters.py
    
    diff -r 360ebd327e26 -r a174dc47b48b sage/ext/gen_interpreters.py
    a b  
    585585        """
    586586        return je("{{ c }} = CDE_to_dz({{ py }})", c=c, py=py)
    587587
    588 ty_double_complex = StorageTypeDoubleComplex('double_complex')
     588ty_double_complex = StorageTypeDoubleComplex('double complex')
    589589
    590590class StorageTypePython(StorageTypeAssignable):
    591591    r"""
     
    22912291        self.mc_py_constants = MemoryChunkConstants('py_constants', ty_python)
    22922292        # See comment for RDFInterpreter
    22932293        self.err_return = '-1094648119105371'
    2294         self.adjust_retval = "dz_to_CDE"
    22952294        self.chunks = [self.mc_args, self.mc_constants, self.mc_py_constants,
    22962295                       self.mc_stack,
    22972296                       self.mc_code]
     
    23032302#include <complex.h>
    23042303#include "wrapper_cdf.h"
    23052304
    2306 typedef double complex double_complex;
    2307 
    23082305"""
    23092306        self.pxd_header = """
    23102307# This is to work around a header ordering bug in Cython < 0.11
    23112308# (Pari is included from sage.rings.complex_double.)
    2312 cdef extern from "pari/paricfg.h":
    2313     pass
    2314 cdef extern from "pari/pari.h":
    2315     pass
    2316 cdef extern from "pari/paripriv.h":
    2317     pass
     2309#cdef extern from "pari/paricfg.h":
     2310#    pass
     2311#cdef extern from "pari/pari.h":
     2312#    pass
     2313#cdef extern from "pari/paripriv.h":
     2314#    pass
    23182315
    2319 # Cython does not (yet) support complex numbers natively, so this is a bit hackish. 
    2320 cdef extern from "complex.h":
    2321     ctypedef double double_complex "double complex"
     2316#cdef extern from "complex.h":
     2317#    #pass
     2318#    creal
     2319#    cimag
    23222320"""
    23232321        self.pyx_header = """
    23242322from sage.rings.complex_double cimport ComplexDoubleElement
     
    23292327
    23302328# Cython does not (yet) support complex numbers natively, so this is a bit hackish. 
    23312329cdef extern from "complex.h":
    2332     ctypedef double double_complex "double complex"
    2333     cdef double creal(double_complex)
    2334     cdef double cimag(double_complex)
    2335     cdef double_complex _Complex_I
     2330    cdef double creal(double complex)
     2331    cdef double cimag(double complex)
     2332#    ctypedef double double_complex "double complex"
     2333#    cdef double complex _Complex_I
    23362334
    2337 cdef inline double_complex CDE_to_dz(zz):
     2335cdef inline double complex CDE_to_dz(zz):
    23382336    cdef ComplexDoubleElement z = <ComplexDoubleElement>(zz if isinstance(zz, ComplexDoubleElement) else CDF(zz))
    2339     return z._complex.dat[0] + _Complex_I * z._complex.dat[1]
     2337    return z
     2338#    return z._complex.dat[0] + z._complex.dat[1]j
    23402339
    2341 cdef inline ComplexDoubleElement dz_to_CDE(double_complex dz):
     2340cpdef inline ComplexDoubleElement dz_to_CDE(double complex dz):
    23422341    cdef ComplexDoubleElement z = <ComplexDoubleElement>PY_NEW(ComplexDoubleElement)
    23432342    z._complex.dat[0] = creal(dz)
    23442343    z._complex.dat[1] = cimag(dz)
    23452344    return z
    23462345
     2346cpdef inline ComplexDoubleElement dz_to_complex(double complex dz):
     2347    return complex(creal(dz), cimag(dz))
     2348
    23472349cdef public bint cdf_py_call_helper(object fn,
    23482350                                    int n_args,
    2349                                     double_complex* args, double_complex* retval) except 0:
     2351                                    double complex* args, double complex* retval) except 0:
    23502352    py_args = []
    23512353    cdef int i
    23522354    for i from 0 <= i < n_args:
     
    23902392            instrs.append(instr_unary(name, pg('S',  'S'), "c%s(i0)" % name))
    23912393        self.instr_descs = instrs
    23922394        self._set_opcodes()
     2395        self.extra_class_members = "cdef object _domain\n"
     2396        self.extra_members_initialize = "self._domain = args['domain']\n"
     2397        #self.adjust_retval = "dz_to_CDE"
     2398        self.adjust_retval = 'self._domain'
    23932399
    23942400
    23952401class RRInterpreter(StackInterpreter):
     
    38533859             
    38543860    Extension('sage.ext.interpreters.wrapper_cdf',
    38553861              sources = ['sage/ext/interpreters/wrapper_cdf.pyx',
    3856                          'sage/ext/interpreters/interp_cdf.c']
    3857               ),
     3862                         'sage/ext/interpreters/interp_cdf.c'],
     3863              extra_compile_args=["-std=c99"]),
    38583864
    38593865    Extension('sage.ext.interpreters.wrapper_rr',
    38603866              sources = ['sage/ext/interpreters/wrapper_rr.pyx',