To accept one 1D-Numpy array and return another

View: New views
10 Messages — Rating Filter:   Alert me  

To accept one 1D-Numpy array and return another

by Jose Guzman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear swig-user group!

I am new to Swig and after a couple of successfully performed tests (the
numpyi. pdf document helped a lot), I decided to create a "simple"
function which receives a 1D NumPy array and returns ANOTHER. The simple
question is... is there any way to create a function which accept a
vector and returns another vector?

something like
 >>>mymodule.myfunc(inputarray)
 >>> array([ 20.25,  12.25,   6.25,   2.25,   0.25,   0.25,   2.25,  
6.25, 12.25,  20.25])


The only solution I found was the following.


My C function is defined as follows:

void sse(double *vec, int n); // actually I wanted to use void sse
(double *invec, double *outvec, int size);

Then I use In-Place arrays:

%apply (double *INPLACE_ARRAY1, int DIM1) { (double *vec, int n)}

and modify the function to receive only one array which is gonna be
transformed. After that I modified my function

%pythoncode{

def ssem(list):
    a = np.array(list,dtype=float)
    sse(a)
    return a
}

Now I have only to use ssem in stead of sse. :(

Is there any better/simple way to do it?

Thanks a lot in advance!!!

Jose.



------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: To accept one 1D-Numpy array and return another

by Josh Cherry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, 3 Jul 2009, Jose Guzman wrote:

> %pythoncode{
>
> def ssem(list):
>    a = np.array(list,dtype=float)
>    sse(a)
>    return a
> }
>
> Now I have only to use ssem in stead of sse. :(

You could %rename sse to, say, _sse, and call your python function "sse"
(and have it call _sse), to get around that annoyance.

Josh


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: To accept one 1D-Numpy array and return another

by Jose Guzman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Josh Cherry wrote:

>
>
> On Fri, 3 Jul 2009, Jose Guzman wrote:
>
>> %pythoncode{
>>
>> def ssem(list):
>>    a = np.array(list,dtype=float)
>>    sse(a)
>>    return a
>> }
>>
>> Now I have only to use ssem in stead of sse. :(
>
> You could %rename sse to, say, _sse, and call your python function
> "sse" (and have it call _sse), to get around that annoyance.
>
> Josh
>
This was a very clever idea indeed. The only thing is that now my C
function is called _sse, but it is OK.

Thanks a lot Josh!

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: To accept one 1D-Numpy array and return another

by Josh Cherry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, 6 Jul 2009, Jose Guzman wrote:

> Josh Cherry wrote:
>> You could %rename sse to, say, _sse, and call your python function "sse"
>> (and have it call _sse), to get around that annoyance.
>>
>> Josh
>>
> This was a very clever idea indeed. The only thing is that now my C function
> is called _sse, but it is OK.

To make sure we're clear, I was suggesting that you use SWIG's %rename
directive.  So you shouldn't have to change the name of the actual C
function.

Josh


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: To accept one 1D-Numpy array and return another

by Jose Guzman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, not it is solved


%rename (_sse) sse;

def sse(list):

    a=np.array(list,dtype=float)
    _sse(a)
    return a

}

Josh Cherry wrote:

>
>
> On Mon, 6 Jul 2009, Jose Guzman wrote:
>
>> Josh Cherry wrote:
>>> You could %rename sse to, say, _sse, and call your python function
>>> "sse" (and have it call _sse), to get around that annoyance.
>>>
>>> Josh
>>>
>> This was a very clever idea indeed. The only thing is that now my C
>> function is called _sse, but it is OK.
>
> To make sure we're clear, I was suggesting that you use SWIG's %rename
> directive.  So you shouldn't have to change the name of the actual C
> function.
>
> Josh
>


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Suppress warning 511 for std::vector

by Geoffrey Philbrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have keywords enabled and I'm getting many warning 511 messages for
std::vector. How do I suppress these just for the std::vector template? I
tried the following with no luck.

%warnfilter(511) std::vector;
%warnfilter(511) std::vector<>;
%warnfilter(511) std::vector<*>;


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Suppress warning 511 for std::vector

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Geoffrey Philbrick writes:
>
> I have keywords enabled and I'm getting many warning 511 messages for
> std::vector. How do I suppress these just for the std::vector template? I
> tried the following with no luck.
>
> %warnfilter(511) std::vector;
> %warnfilter(511) std::vector<>;
> %warnfilter(511) std::vector<*>;

There are overloaded methods in both std::vector and in a helper wrapper called
swig::SwigPyIterator, so you need:

%warnfilter(511) std::vector;
%warnfilter(511) swig::SwigPyIterator;

William


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Suppress warning 511 for std::vector

by Geoffrey Philbrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, but still no luck. Here are the statements in the interface file:

%warnfilter(511) std::vector;
%warnfilter(511) swig::SwigPyIterator;
%include std_vector.i

This did get rid of warnings generated at
   std_vector.i:93 (%std_vector_methods(vector);)
but not the ones generated at:
   std_vector.i:134 (%std_vector_methods_val(vector);)

Here are the warning messages:

swig/1.3.31/python/pyiterators.swg:376: Warning(511): Can't use keyword
arguments with overloaded functions.
swig/1.3.31/python/pyiterators.swg:377: Warning(511): Can't use keyword
arguments with overloaded functions.
swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
with overloaded functions.
swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
with overloaded functions.
swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
with overloaded functions.

...

-----Original Message-----
From: William S Fulton [mailto:wsf@...]
Sent: Thursday, July 09, 2009 7:38 AM
To: swig-user@...
Subject: Re: [Swig-user] Suppress warning 511 for std::vector

Geoffrey Philbrick writes:
>
> I have keywords enabled and I'm getting many warning 511 messages for
> std::vector. How do I suppress these just for the std::vector template? I
> tried the following with no luck.
>
> %warnfilter(511) std::vector;
> %warnfilter(511) std::vector<>;
> %warnfilter(511) std::vector<*>;

There are overloaded methods in both std::vector and in a helper wrapper
called
swig::SwigPyIterator, so you need:

%warnfilter(511) std::vector;
%warnfilter(511) swig::SwigPyIterator;

William


----------------------------------------------------------------------------
--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize

details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Suppress warning 511 for std::vector

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You are using an old version of SWIG. PySwigIterator is now
SwigPyIterator to conform to Python naming recommendations. With this
old version you need:

%warnfilter(511) std::vector;
%warnfilter(511) swig::PySwigIterator;

William
Geoffrey Philbrick wrote:

> Thanks, but still no luck. Here are the statements in the interface file:
>
> %warnfilter(511) std::vector;
> %warnfilter(511) swig::SwigPyIterator;
> %include std_vector.i
>
> This did get rid of warnings generated at
>    std_vector.i:93 (%std_vector_methods(vector);)
> but not the ones generated at:
>    std_vector.i:134 (%std_vector_methods_val(vector);)
>
> Here are the warning messages:
>
> swig/1.3.31/python/pyiterators.swg:376: Warning(511): Can't use keyword
> arguments with overloaded functions.
> swig/1.3.31/python/pyiterators.swg:377: Warning(511): Can't use keyword
> arguments with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
> with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
> with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword arguments
> with overloaded functions.
>
> ...
>
> -----Original Message-----
> From: William S Fulton [mailto:wsf@...]
> Sent: Thursday, July 09, 2009 7:38 AM
> To: swig-user@...
> Subject: Re: [Swig-user] Suppress warning 511 for std::vector
>
> Geoffrey Philbrick writes:
>> I have keywords enabled and I'm getting many warning 511 messages for
>> std::vector. How do I suppress these just for the std::vector template? I
>> tried the following with no luck.
>>
>> %warnfilter(511) std::vector;
>> %warnfilter(511) std::vector<>;
>> %warnfilter(511) std::vector<*>;
>
> There are overloaded methods in both std::vector and in a helper wrapper
> called
> swig::SwigPyIterator, so you need:
>
> %warnfilter(511) std::vector;
> %warnfilter(511) swig::SwigPyIterator;
>
> William
>
>
> ----------------------------------------------------------------------------
> --
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
>
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Swig-user mailing list
> Swig-user@...
> https://lists.sourceforge.net/lists/listinfo/swig-user
>
>


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Suppress warning 511 for std::vector

by Geoffrey Philbrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've upgraded to the latest version of swig (1.3.39), and I'm still getting
dozens of warnings from lines 130 and 133 of std_vector.i. I will appreciate
any suggestions on solving this.

Thank you.

swig/1.3.39/std/std_vector.i:130: Warning(511): Can't use keyword arguments
with overloaded functions.
swig/1.3.39/std/std_vector.i:133: Warning(511): Can't use keyword arguments
with overloaded functions.

-----Original Message-----
From: William S Fulton [mailto:wsf@...]
Sent: Thursday, July 09, 2009 4:00 PM
To: Geoffrey Philbrick
Cc: swig-user@...
Subject: Re: [Swig-user] Suppress warning 511 for std::vector

You are using an old version of SWIG. PySwigIterator is now
SwigPyIterator to conform to Python naming recommendations. With this
old version you need:

%warnfilter(511) std::vector;
%warnfilter(511) swig::PySwigIterator;

William
Geoffrey Philbrick wrote:

> Thanks, but still no luck. Here are the statements in the interface file:
>
> %warnfilter(511) std::vector;
> %warnfilter(511) swig::SwigPyIterator;
> %include std_vector.i
>
> This did get rid of warnings generated at
>    std_vector.i:93 (%std_vector_methods(vector);)
> but not the ones generated at:
>    std_vector.i:134 (%std_vector_methods_val(vector);)
>
> Here are the warning messages:
>
> swig/1.3.31/python/pyiterators.swg:376: Warning(511): Can't use keyword
> arguments with overloaded functions.
> swig/1.3.31/python/pyiterators.swg:377: Warning(511): Can't use keyword
> arguments with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword
arguments
> with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword
arguments
> with overloaded functions.
> swig/1.3.31/std/std_vector.i:134: Warning(511): Can't use keyword
arguments

> with overloaded functions.
>
> ...
>
> -----Original Message-----
> From: William S Fulton [mailto:wsf@...]
> Sent: Thursday, July 09, 2009 7:38 AM
> To: swig-user@...
> Subject: Re: [Swig-user] Suppress warning 511 for std::vector
>
> Geoffrey Philbrick writes:
>> I have keywords enabled and I'm getting many warning 511 messages for
>> std::vector. How do I suppress these just for the std::vector template? I
>> tried the following with no luck.
>>
>> %warnfilter(511) std::vector;
>> %warnfilter(511) std::vector<>;
>> %warnfilter(511) std::vector<*>;
>
> There are overloaded methods in both std::vector and in a helper wrapper
> called
> swig::SwigPyIterator, so you need:
>
> %warnfilter(511) std::vector;
> %warnfilter(511) swig::SwigPyIterator;
>
> William
>
>
>
----------------------------------------------------------------------------
> --
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full
prize
>
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Swig-user mailing list
> Swig-user@...
> https://lists.sourceforge.net/lists/listinfo/swig-user
>
>



------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user