Segfault with rWishart in R 2.15.1
On 04/07/2012 08:35, peter dalgaard wrote:
On Jul 4, 2012, at 03:12 , Michael Braun wrote:
I just upgraded to R 2.15.1, and I am getting a segmentation fault when using the rWishart function (from the stats package) to sample moderately-size matrices. Here is the output when I run R within gdb. 720 appears to be the dimensionality cut-off. Anything smaller works fine. Anything larger crashes.
x=rWishart(1,700,diag(700)) // this works x=rWishart(1,720,diag(720))
Error: C stack usage is too close to the limit
x=rWishart(1,722,diag(722))
That'll be due to allocating memory off the C stack with alloca(). Please file a bug report on this (nothing to do with Mac, much less with the age of your computer). In a tight spot, you can run R from the terminal after raising the C stack limit with, say, "ulimit -s 32768", but of course the trouble returns at twice the matrix size. Notice that there are really two issues here. One is that the R_CheckStack() safeguards are failing. The other is why we're using stack allocation in the first place.
They are related: the R_CheckStack() safeguards were being used incorrectly. alloca() is important for frequent small allocations (not the case here): the safeguards are only designed to work for repeated small allocations (< 100kB, well under 5% of the stack). I have experimented with a pre-alloca check in the past, and it seems this would be a better protection against misuse, and I'll trial that in R-devel.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595