Dear Support,

These are probably truly Cython questions which I am appending below,
but I am using it in the notebook so I figured I would ask here...
Thanks for any help, I truly appreciate it, given that I know very
little C.

The context is Cythonizing sage.plot.plot.float_to_html; the speedup
in the (not full) test case I did get to work was from .125 ms per
loop to .0124 ms per loop, so my hope was this would provide a good
test case to learn Cython as well as actually speed something up, in
this case rainbow().

- kcrisman

1) I have the following in one notebook cell.

%cython
cdef extern from "stdio.h":
    int sprintf(char *, char *,...)

cdef extern from "string.h":
    char * strcat(char *, char *)

def weirdfunc1(int x):
    cdef int n1
    cdef char * output1
    n1 = sprintf(output1,"%x",x)
    return n1

def weirdfunc2(int x):
    cdef char * z='0'
    cdef int n2
    cdef char * output2
    n2 = sprintf(output2,"%x",x)
    return strcat(z,output2)

2) calling weirdfunc1 hangs forever.  I think this must have something
to do with the string stuff at
http://docs.cython.org/docs/language_basics.html#caveats-when-using-a-python-string-in-a-c-context
but I can't for the life of me figure out what is going on.  Sometimes
when I do a variation on where the *s are placed or what I have it
return (print, just n1, etc.) I get lucky and it does what it should
(namely, return the hex representation of x), but I have not been able
to figure this out systematically.

3) calling weirdfunc2 hangs too, but even when I've correctly gotten
the combinations of * and other things so that it doesn't hang (which
I couldn't recreate for this post, unfortunately), it seems to
"remember" the value of z - that is, if I call the function twice, it
appends the hex rep of the new input x to the previous output, as
often as I like.  In Python, explicitly saying z='0' at the beginning
is enough to "reset" z, correct?  But there must be something about C
variables that won't allow that, perhaps having to do with compile vs.
interpret.  In any case, I can't figure out what to do in order to
"start over" with z='0'.
--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to