On Apr 2, 2009, at 11:51 AM, Tom H. wrote:

> I can't use simple integer arrays in Cython.   The following simple
> program:
>
> %cython
> # --- vectormultiply.pyx ---
>
> def vectormultiply(int a):
>   cdef int b[1]
>   b[0] = a
>   return b
>
> gives the following sage compiling error.   I've tried following some
> online examples but can't get this program to compile without errors.
> Any suggestions?

Your function vectormultiply is a Python function, so it must return  
a Python object. Conversions from ints, doubles, etc. to Python  
objects are provided, but b is an int[] which has no Python counterpart.

In any case, this also would be an error in C, as b is allocated on  
the call stack, and so it's memory is reclaimed as soon as the  
function exits. You can use b all you want, but there is no way to  
return it without converting it to something else. (You could make it  
a list, e.g. "[b[i] for i from 0 <= i < n]" where n is the length of b.)

- Robert


--~--~---------~--~----~------------~-------~--~----~
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