nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
154 stars 23 forks source link

MacOS test-car.R failure #1456

Open paciorek opened 1 month ago

paciorek commented 1 month ago

We are now seeing a MacOS test failure on test-car.R. It doesn't actually seem related to 1.2.0 (results below are based on nimble 1.1.0) though I do think it has just arisen. I'm wondering if it is because the runner (test machine) is now Apple Silicon.

Two of the three failures seem trivial - whereas formerly some R vs. C MCMC sample comparisons were identical, now they are different by about machine precision. I'm just adjusting those tests.

The third is troublesome. This is for the "dcar_proper gives correct likelihood with singular Cmatrix". This is a case where Cmatrix is singular, with three zero eigenvalues. eigen (i.e., Lapack) gives back (slightly) complex values. nimEigen (i.e., Eigen) on Linux gives back two NaNs (and one 6e-31) with a run-time warning about complex-valued eigenvector, so presumably behind the scenes the imaginary parts are being discarded. We set the NaNs to zero before passing the eigenvalues to dcar_proper to get a valid logProb.

Now on MacOS, nimEigen gives back all zeroes as the eigenvalues (with no warning about complex eigenvalues), and the logProb is incorrect. I don't know what to make of this. Most of the eigenvalues are real according to eigen() and Linux's nimEigen(). Also I can give it a different input matrix with complex eigenvalues and it gives me back a mix of real numbers (from the eigenvalues whose imaginary parts are 0) and NaNs, with a warning about complex eigenvalues where results match those of eigen(). So something about this particular matrix is causing problems.

Cmatrix is 25x25. If I use the upper 24x24 subset (or any other subset) everything seems fine.

Changing the example to be 4x4 or 6x6 instead of 5x5 (nHabRows, nHabCols) avoids the problem too.

So I am changing to 6x6.

:(

paciorek commented 1 month ago

This has addressed the MacOS test failure. Leaving issue open given there is still a mystery (and possible concern) about Eigen's behavior on MacOS.

danielturek commented 1 month ago

@paciorek This was really puzzling to read. Slightly disconcerting.