[Rd] patch for random.c

Berwin A Turlach statba at nus.edu.sg
Wed Mar 5 13:26:24 CET 2008


G'day Martin,

On Mon, 3 Mar 2008 10:16:45 +0100
Martin Maechler <maechler at stat.math.ethz.ch> wrote:

> >>>>> "BAT" == Berwin A Turlach <statba at nus.edu.sg>
> >>>>>     on Fri, 29 Feb 2008 18:19:40 +0800 writes:
>
>     BAT> while looking for some inspiration of how to organise some
>     BAT> code, I studied the code of random.c and noticed that for
>     BAT> distributions with 2 or 3 parameters the user is not warned
>     BAT> if NAs are created while such a warning is issued for
>     BAT> distributions with 1 parameter. [...] The attached patch
>     BAT> rectifies this.  [...]
>
> I cannot imagine a design reason for that.  If there was, it
> should have been mentioned as a comment in the C code.
> 
> I'll commit your patch (if it passes the checks).

Sorry, I was a bit in a hurry when writing the e-mail, so I forgot to
mention that the source code modified by this patch compiles and passes
"make check FORCE=FORCE" on my machine.

And in my hurry, I also posted from my NUS account, without realising
it, which forced you to intervene as moderator and to approve the
posting.  My apologies for the extra work.  But this gave me the idea
to also subscribe to r-devel with my NUS account and configure the
subscriptions so that I only receive e-mail at my UWA account.  Thus,
hopefully, you will not have to intervene again.  (Which this e-mail
should test.)
 
>     BAT> BTW, there are other places in the code were NAs can be
>     BAT> created but no warning is issued.  E.g:
> 
>     >> rexp(2, rate=numeric())
>     BAT> [1] NA NA
>     >> rnorm(2, mean=numeric())
>     BAT> [1] NA NA
> 
>     BAT> I wonder whether a warning should be issued in this case
>     BAT> too.  
> 
> Yes, "should in principle".
> 
> If you feel like finding another elegant patch...

Well, elegance is in the eye of the beholder. :-)  I attach two
patches.  One that adds warning messages at the other places where NAs
can be generated.

The second one in additiona rearranges the code a bit such that in the
case when all the "vectors" that contain the parameter values of the
distribution, from which one wants to simulate, are of length one some
unnecessary calculations is taken out of the for loop.  I am not sure
how much time is actually saved in this situation, but I belong to the
school that things such kind of optimisation should be done. :)  If you
think it bloats the code too much (or duplicates things too much
leading to hard to maintain code), then feel free to ignore this second
patch. 


> Thank you Berwin, for your contribution!

My pleasure.

Cheers,

	Berwin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: R-patch2
Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20080305/d21ea9a8/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: R-patch3
Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20080305/d21ea9a8/attachment-0001.pl 


More information about the R-devel mailing list