From: Bastian A. <An...@gm...> - 2008-05-06 21:17:42
|
On Tue, 06 May 2008 05:18:04 +0200 Soeren Sonnenburg wrote: > 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? Yes it is working for int. In R we have the typemap %typemap(scoercein) int, int *, int & %{ $input = as($input, "integer"); %} and on the C side of things INTEGER(ng)[0] > > 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. %{ %} . > I don't think this will solve all problems, when going in the other direction (C->R) starting with an unsigned int => 2^31 a cast to "integer" will not have the desired result. Bastian -- Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger |