Dear Heather,

Please find attached the patch that I am going to apply to r-cran-gnm
in Debian.

With this patch applied, the test now works with both lapack 3.9 and
3.10.

Feel free to use it (or not) for the next release of gnm.

Best wishes,

Le lundi 27 septembre 2021 à 12:01 +0100, Heather Turner a écrit :
> Hi Andreas,
> 
> Thanks for forwarding this bug report and thanks to Sébastien for the 
> detailed and accurate analysis. I will need to submit an update to CRAN, 
> which should be feasible in the next week or two. Is there a deadline that I 
> need to work to?
> 
> Best wishes,
> 
> Heather
> 
> On Mon, Sep 27, 2021, at 10:12 AM, Andreas Tille wrote:
> > Control: tags -1 upstream
> > Control: forwarded -1 Heather Turner <h...@heatherturner.net>
> > 
> > Hi Heather,
> > 
> > the Debian packaged gnm recieved a bug report about a failing test in
> > connection with the upgrade to lapack 3.10.0 on the machine running the
> > test.  Please read the bug report below.
> > 
> > We admit we need your help to solve this issue that might affect
> > other systems as well.
> > 
> > Kind regards
> > 
> >     Andreas.
> > 
> > On Thu, Sep 16, 2021 at 10:59:19AM +0200, Sébastien Villemot wrote:
> > > Package: r-cran-gnm
> > > Version: 1.1-1-2
> > > Severity: serious
> > > Tags: sid bookworm
> > > X-Debbugs-CC: debian...@lists.debian.org
> > > User: debian...@lists.debian.org
> > > Usertags: needs-update
> > > 
> > > Dear Maintainer,
> > > 
> > > Since the upload of lapack 3.10.0-1, the autopkgtest of r-cran-gnm
> > > fails in unstable. See for example:
> > > https://ci.debian.net/data/autopkgtest/unstable/amd64/r/r-cran-gnm/15155026/log.gz
> > > 
> > > More precisely, test-biplot.R fails, because some results have the
> > > opposite sign compared to the one which is expected.
> > > 
> > > My understanding is that this comes from the SVD of barleyMatrix in
> > > that test file, which is different between lapack 3.9 and 3.10.
> > > Mathematically, the SVD is not unique, and lapack 3.10 returns a
> > > different (still valid) solution. More precisely, I verified that one
> > > of the right-singular vector of that matrix has the opposite sign in
> > > lapack 3.10. I also verified that the decomposition is correct by
> > > checking that:
> > > 
> > >   max(abs(barleySVD$u %*% diag(barleySVD$d) %*% t(barleySVD$v) - 
> > > barleyMatrix))
> > > 
> > > is a small value (about 2e-14).
> > > 
> > > Also note that the hardcoded expected values already partially differ 
> > > from those of the original research paper mentioned in that test
> > > (Gabriel (1998): Generalised bilinear regression). More precisely, half
> > > of the values were hardcoded with the opposite sign. It seems that now
> > > all values need to be hardcoded with the opposite sign.
> > > 
> > > The testsuite of r-cran-gnm thus needs to be adapted, by being more
> > > tolerant to such sign changes.
> > > 
> > > N.B. : when trying to reproduce the problem, please ensure that your
> > > lapack alternative (as given by “update-alternatives --display
> > > liblapack.so.3-x86_64-linux-gnu) points to /usr/lib/x86_64-linux-
> > > gnu/lapack/liblapack.so.3, and not to the binary provided by either
> > > openblas or atlas (because these two have not yet been recompiled
> > > against lapack 3.10, and thus do not expose the problem).
> > > 
> > > Best regards,
> > > 
> > > -- 
> > > ⢀⣴⠾⠻⢶⣦⠀  Sébastien Villemot
> > > ⣾⠁⢠⠒⠀⣿⡁  Debian Developer
> > > ⢿⡄⠘⠷⠚⠋⠀  https://sebastien.villemot.name
> > > ⠈⠳⣄⠀⠀⠀⠀  https://www.debian.org
> > > 
> > 
> > 
> > 
> > > _______________________________________________
> > > R-pkg-team mailing list
> > > r-pkg-t...@alioth-lists.debian.net
> > > https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/r-pkg-team
> > 
> > 
> > -- 
> > http://fam-tille.de

-- 
⢀⣴⠾⠻⢶⣦⠀  Sébastien Villemot
⣾⠁⢠⠒⠀⣿⡁  Debian Developer
⢿⡄⠘⠷⠚⠋⠀  https://sebastien.villemot.name
⠈⠳⣄⠀⠀⠀⠀  https://www.debian.org

Description: Fix test-biplot.R with lapack 3.10
 With lapack 3.10, test-biplot.R fails, because some results have the
 opposite sign compared to the one which is expected.
 .
 This comes from the SVD of barleyMatrix in that test file, which is different
 between lapack 3.9 and 3.10. Mathematically, the SVD is not unique, and lapack
 3.10 returns a different (still valid) solution.
 .
 This patch accomodates sign differences in the columns of the test matrices,
 so that the test passes with both lapack 3.9 and lapack 3.10.
Author: Sébastien Villemot <sebast...@debian.org>
Bug-Debian: https://bugs.debian.org/994457
Forwarded: no
Last-Update: 2021-10-11
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/tests/testthat/test-biplot.R
+++ b/tests/testthat/test-biplot.R
@@ -6,6 +6,15 @@ set.seed(1)
 
 # Gabriel, K R (1998). Generalised bilinear regression. Biometrika 85, 689–700.
 
+expect_equivalent_up_to_column_sign <- function(A, B)
+{
+  ok <- nrow(A) == nrow(B) && ncol(A) == ncol(B)
+  if (ok)
+    for (j in 1:ncol(A))
+      ok <- ok && (all(A[,j] == B[,j]) || all(A[,j] == -B[,j]))
+  expect(ok, "Matrices are not equivalent up to column sign")
+}
+
 test_that("biplot model as expected for barley data", {
     biplotModel <- gnm(y ~ -1 + instances(Mult(site, variety), 2),
                        family = wedderburn, data = barley, verbose = FALSE)
@@ -22,16 +31,16 @@ test_that("biplot model as expected for
     colnames(A) <- colnames(B) <- paste("Component", 1:2)
     # compare vs matrices in Gabriel (1998): allow for sign change
     # 3rd element in fit is 1.425 vs 1.42 in paper
-    expect_equivalent(round(A, 2), 
-                      matrix(c(4.19, 2.76, 1.43, 1.85, 1.27, 
-                               1.16, 1.02, 0.65, -0.15, 
-                               -0.39, -0.34, -0.05, 0.33, 0.16, 
-                               0.4, 0.73, 1.46, 2.13), nrow = 9))
-    expect_equivalent(round(B, 2), 
-                      matrix(c(-2.07, -3.06, -2.96, -1.81, -1.56,
-                               -1.89, -1.18, -0.85, -0.97, -0.60,
-                               -0.97, -0.51, -0.33, -0.50, -0.08, 
-                               1.08, 0.41, 1.15, 1.27, 1.40), nrow = 10))
+    expect_equivalent_up_to_column_sign(round(A, 2), 
+                                        matrix(c(4.19, 2.76, 1.43, 1.85, 1.27, 
+                                                 1.16, 1.02, 0.65, -0.15, 
+                                                 -0.39, -0.34, -0.05, 0.33, 0.16, 
+                                                 0.4, 0.73, 1.46, 2.13), nrow = 9))
+    expect_equivalent_up_to_column_sign(round(B, 2), 
+                                        matrix(c(-2.07, -3.06, -2.96, -1.81, -1.56,
+                                                 -1.89, -1.18, -0.85, -0.97, -0.60,
+                                                 -0.97, -0.51, -0.33, -0.50, -0.08, 
+                                                 1.08, 0.41, 1.15, 1.27, 1.40), nrow = 10))
     # chi-square statistic approx equal to that reported
     expect_equal(round(sum(residuals(biplotModel, type = "pearson")^2)), 54)
     expect_equal(df.residual(biplotModel), 56)

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to