Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>>> As others already said, using a Numpy array or an array.array object >>> would >>> be more efficient (and even easier - the C code gets a pointer to an >>> array >>> of integers, as usual). >> >> I looked for this in the C API docs but couldn't find anything on how >> to make an array.array pyt

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sun, 28 Dec 2008 01:47:08 -0200, Daniel Fetchinson escribió: As others already said, using a Numpy array or an array.array object would be more efficient (and even easier - the C code gets a pointer to an array of integers, as usual). I looked for this in the C API docs but couldn't

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Ivan Illarionov
On Dec 28, 12:45 am, "Daniel Fetchinson" wrote: > I'm trying to write an extension module in C which contains a single > function with the following prototype: > > void func( int N, int * arg1, int * arg2, int * ret ); > > Here arg1 and arg2 are length N arrays, and the function computes ret > whi

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>>> You MUST check EVERY function call for errors! >> >> Yes, I know :) >> > > Believe me, if you don't, there is a risk of crashing the program. And > they're a lot harder to find and fix. Sure, what I meant by the smiley is just that it was a quick and dirty example, not real code. In a real cod

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> This is the function I have, the corresponding python function will >> take two equal length lists of integers and the C function will >> compute their sum and return the result as a python tuple. >> >> >> static PyObject *func( PyObject * self, PyObject * args ) >> { >> int j, N; >> int

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sun, 28 Dec 2008 00:40:52 -0200, Daniel Fetchinson escribió: You MUST check EVERY function call for errors! Yes, I know :) Believe me, if you don't, there is a risk of crashing the program. And they're a lot harder to find and fix. And check the argument's type (how do you know i

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. >>> With recent versions of PIL, numpy can create an array from an Image very >>> qui

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> This is the function I have, the corresponding python function will >> take two equal length lists of integers and the C function will >> compute their sum and return the result as a python tuple. >> >> >> static PyObject *func( PyObject * self, PyObject * args ) >> { >> int j, N; >> int

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Robert Kern
Daniel Fetchinson wrote: I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. With recent versions of PIL, numpy can create an array from an Image ver

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sat, 27 Dec 2008 22:54:52 -0200, Daniel Fetchinson escribió: This is the function I have, the corresponding python function will take two equal length lists of integers and the C function will compute their sum and return the result as a python tuple. static PyObject *func( PyObject * se

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
On 12/27/08, Robert Kern wrote: > Daniel Fetchinson wrote: > >> I agree that array.array is more efficient than a list but the input >> for my function will come from PIL and PIL returns a list. So I have a >> list to begin with which will be passed to the C function. > > With recent versions of P

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Aaron Brady
On Dec 27, 6:06 pm, Scott David Daniels wrote: > Daniel Fetchinson wrote: > > I have a list to begin with which will be passed to the C function. > >  > I assume converting the list to an array.array and passing that to the C > > > function doesn't make any difference in terms of speed since t

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> I agree that array.array is more efficient than a list but the input >> for my function will come from PIL and PIL returns a list. So I have a >> list to begin with which will be passed to the C function. > > With recent versions of PIL, numpy can create an array from an Image very > quickly, po

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Robert Kern
Daniel Fetchinson wrote: I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. With recent versions of PIL, numpy can create an array from an Image v

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
Daniel Fetchinson wrote: I have a list to begin with which will be passed to the C function. > I assume converting the list to an array.array and passing that to the C function doesn't make any difference in terms of speed since the operation itself will be done in the C function anyway.

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> I have considered using ctypes but for my needs using the C API >> directly seems more reasonable. array.array and numpy.array doesn't >> fit my needs since I need to do long and complicated operations on the >> two (pretty large) integer arrays that would be too slow using >> array.array and nu

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
Daniel Fetchinson wrote: I have considered using ctypes but for my needs using the C API directly seems more reasonable. array.array and numpy.array doesn't fit my needs since I need to do long and complicated operations on the two (pretty large) integer arrays that would be too slow using array.

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> I'm trying to write an extension module in C which contains a single >> function with the following prototype: >> void func( int N, int * arg1, int * arg2, int * ret ); >> Here arg1 and arg2 are length N arrays, and the function computes ret >> which is also an N length array. From python I'

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
Daniel Fetchinson wrote: I'm trying to write an extension module in C which contains a single function with the following prototype: void func( int N, int * arg1, int * arg2, int * ret ); Here arg1 and arg2 are length N arrays, and the function computes ret which is also an N length array. Fr

C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
I'm trying to write an extension module in C which contains a single function with the following prototype: void func( int N, int * arg1, int * arg2, int * ret ); Here arg1 and arg2 are length N arrays, and the function computes ret which is also an N length array. From python I'd like to call th