« Return to Thread: typemaps in R

Re: typemaps in R

by Soeren Sonnenburg-9 :: Rate this Message:

Reply to Author | View in Thread

On Tue, 2008-05-06 at 00:50 +0200, Bastian Angermann wrote:
> Hi,
>
> the typemaps for mapping unsigned int to an appropriate type in
> R seem to be broken.

Yeah well R does not have anything except bool, integer, double - so
this mapping is quite arbitrary / IMHO unclear what should be done.

> I am trying to wrap a class with constructor
> Erdos_Renyi_Network(unsigned int ng, double af,double prob);
> Calling network <- Erdos_Renyi_Network(ng=10,af=0.5,p=0.1) results in:
> Error in Erdos_Renyi_Network(ng = 10, af = 0.5, p = 0.1) :
>   REAL() can only be applied to a 'numeric', not a 'integer'

BTW, would it work when you used an int instead of an unsigned int?

> Reviewing the output generated by SWIG reveals that the unsigned int argument is cast into an "integer":
>   ng = as(ng, "integer");
> but the C++ code calls:
> arg1 = static_cast< unsigned int >(REAL(ng)[0]);
> for the same argument.
>
> Could this be fixed by changing line 45,46 in rtypes.swg to
> %typemap(scoercein) unsigned int, unsigned int *, unsigned int &
>   %{  $input = as($input, "numeric");     %} ?
> This removes be cast to "integer" done in R and things seem to work, but I don't know if I am introducing other bugs by this "fix".

In my eyes this cast is broken anyway... just consider $input is a
matrix, doing as($input, ... ) will turn it into a vector. I tend to say
that that the code doing the REAL(ng)[0] should be changed to generate a
INTEGER(ng)[0] and that this scoercein typemap shouldn't do anythin,
i.e. %{ %} .

Soeren

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: typemaps in R

LightInTheBox - Buy quality products at wholesale price