On Mon, Aug 18, 2008 at 6:24 PM, Bill Page <[EMAIL PROTECTED]> wrote: > > On Mon, Aug 18, 2008 at 12:06 PM, Ondrej Certik wrote: >> >> On Mon, Aug 18, 2008 at 5:51 PM, Bill Page wrote: >>> ... >>> There is supposed to be an "easy" way to call programs compiled >>> with ECL from C (and thus via some suitable wrapper from Python >>> or from Cython), but I have yet to see this demonstrated. Even in >>> this case there remains the problem of conversion of data structures >>> which is likely to add back some (hopefully small part) of the overhead >>> that you removed by eliminating pexpect. >> >> Just like with sympy or ginac. Just holding the pointer to the >> expression in ginac or sympy. >> > > I don't understand what "just holding the point to expression" has to > do with the conversions that are done when I type something like > > sage: axiom(x^2+1) > > and hope to get the result back in Sage as something Sage understands > natively as a polynomial.
Just like the proposed symbolics with ginac, you just let ginac construct and hold the expression and operate it from Python/Cython. But you want more than that, right? Well, each conversion looses time. >> I think if any program wants to be successful, it's a good idea >> to figure out how to call it from C without (much) overhead. Imho. >> > > Maybe. But again I think it depends how you intend to achieve > "success". It is not so easy to call Python code from a C mainline > program either, is it? Thanks to Cython, it is very easy to call my Python implementation of something from pure C. And it's fast, for example: http://freehg.sympy.org/u/certik/csympy/file/991e40db913e/basic.c line 841: 841 import_csympy(); 842 coeff = multi(m, n, &len); multi is implemented here http://freehg.sympy.org/u/certik/csympy/file/991e40db913e/csympy.pyx: 146 from multinomial import multinomial_coefficients 147 148 149 cdef api sympyint *multi(int m, int n, int *list_len): 150 r = multinomial_coefficients(m, n) 151 cdef int len2 = len(r) 152 list_len[0] = len2 153 l = [] 154 for k, v in r.iteritems(): 155 l.extend(k) 156 l.append(v) 157 cdef sympyint *cl = <sympyint*> malloc(len(l)*sizeof(sympyint)) 158 for i in range(len(l)): 159 try: 160 cl[i] = l[i] 161 except OverflowError: 162 print "Overflow occured, using 'cl[i] = 2'." 163 print l[i] 164 cl[i] = 2 165 return cl So you see it calls pure Python function and just converts the dictionary it returns to a C array of integers. Ondrej --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
