[Numpy-discussion] help with typemapping a C function to use numpy arrays

Rich E reakinator@gmail....
Wed Jan 7 10:43:07 CST 2009


Here is my example, trying to wrap the function sms_spectrumMag that
we have been dealing with:

%apply (int DIM1, float* IN_ARRAY1) {(int sizeInArray, float* pInArray)};
%apply (int DIM1, float* INPLACE_ARRAY1) {(int sizeOutArray, float* pOutArray)};

%inline %{

        void my_spectrumMag( int sizeInArray, float *pInArray, int
sizeOutArray, float *pOutArray)
        {
                sms_spectrumMag(sizeOutArray, pInArray, pOutArray);
        }

%}


at this point,  have the new function my_spectrumMag that wraps
sms_spectrumMag() and provides arguments that can be typemapped using
numpy.i  Now, I don't want to have to call the function
my_spectrumMag() in python, I want to use the original name, I would
like to call the function as:

sms_spectrumMag(numpyArray1, numpyArray2)

But, trying to %rename my_spectrumMag to sms_spectrumMag does not
work, the original sms_spectrumMag gets called in python instead.
Trying to %ignore the original function first as follows removes the
sms_spectrumMag completely from the module and I am left with
my_spectrumMag:

%ignore sms_spectrumMag;
%rename (sms_spectrumMag) my_spectrumMag;


Do you see my problem?


On Wed, Jan 7, 2009 at 8:58 AM, Matthieu Brucher
<matthieu.brucher@gmail.com> wrote:
> 2009/1/6 Rich E <reakinator@gmail.com>:
>> This helped immensely.  I feel like I am getting close to being able
>> to accomplish what I would like with SWIG: producing a python module
>> that can be very 'python-like', while co-existing with the c library
>> that is very 'c-like'.
>>
>> There is one question still remaining though, is it possible to make
>> the wrapped function have the same name still?  Using either
>> my_spectrumMag or spectrumMag means I have to create a number of
>> inconsistencies between the python module and the c library.  It is
>> ideal to ignore (%ignore?) the c sms_spectrumMag and instead use the
>> wrapped one, with the same name.  But my attempts at doing this so far
>> have not compiled because of name conflictions.
>
> Ok course you can. The function is renamed only if you say so. Perhaps
> can you provide a small example of what doesn't work at the moment ?
>
>> Thanks for the help, I think you are doing great things with this
>> numpy interface/typemaps system.
>
> Matthieu
> --
> Information System Engineer, Ph.D.
> Website: http://matthieu-brucher.developpez.com/
> Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the Numpy-discussion mailing list