[PyKDE] ANN: eric3 v 3.5.0 released

Phil Thompson phil at riverbankcomputing.co.uk
Sun Oct 3 22:35:54 BST 2004


On Sunday 03 October 2004 5:30 pm, jul wrote:
> Hi there,
>
> First, cheers Detlev!
> Great job :)
>
> Now, I have a question about SIP....
> That is one week I'm trying to wrap a C function for Python with the
> famous SWIG wrapper, but without success....
> Basically, I would just like to pass an array coming from Python
> Numarray  into my C function which takes a pointer on array and the
> dimension in arguments.
> This is certainly a school example, but I didn't find the way with SWIG.
> As it is the first C function I'm trying to wrap, I wonder if I can use
> SIP to do this.....
>
> Example of C functionI would like to wrap:
>
> / * C function in "my_module.c" (sums  all elements of a 1D array) */
> double sum(double *p,int dim){
> double s=0.;
> int i;
>
> for(i=0;i<dim;i++){
>   s=s+*p;
>   p++;
>   }
> return s;
> }
>
>
> What I would like in Python:
> $ python
>
>  >>> import my_module, Numeric as N
>  >>> a=N.array([1,2,3])
>  >>> my_module.sum(a)
>
> 6.0
>
> Can SIP do that ?

Yes, but you will have to provide most of the implementation in the form of 
handwritten code because you can't automate the pointer handling. SIP will 
usefully take care of the rest of the code - creating the module etc. I 
assume that the Numarray module provides you with a C API with which you can 
access the array elements.

Phil




More information about the PyQt mailing list