gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / eigen-stabilise-sparseqr-test.patch
1 From: Tobias Geerinckx-Rice <me@tobias.gr>
2 Date: Mon, 16 Mar 2020 22:51:37 +0000
3 Subject: gnu: eigen: Stabilise sparseqr test.
4
5 Taken verbatim from this[0] upstream commit.
6
7 [0]: https://gitlab.com/libeigen/eigen/-/commit/3b5deeb546d4017b24846f5b0dc3296a50a039fe
8
9 From 3b5deeb546d4017b24846f5b0dc3296a50a039fe Mon Sep 17 00:00:00 2001
10 From: Gael Guennebaud <g.gael@free.fr>
11 Date: Tue, 19 Feb 2019 22:57:51 +0100
12 Subject: [PATCH] bug #899: make sparseqr unit test more stable by 1) trying
13 with larger threshold and 2) relax rank computation for rank-deficient
14 problems.
15
16 ---
17 test/sparseqr.cpp | 31 ++++++++++++++++++++++++++-----
18 1 file changed, 26 insertions(+), 5 deletions(-)
19
20 diff --git a/test/sparseqr.cpp b/test/sparseqr.cpp
21 index 3ffe62314..3576cc626 100644
22 --- a/test/sparseqr.cpp
23 +++ b/test/sparseqr.cpp
24 @@ -43,6 +43,7 @@ int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows
25
26 template<typename Scalar> void test_sparseqr_scalar()
27 {
28 + typedef typename NumTraits<Scalar>::Real RealScalar;
29 typedef SparseMatrix<Scalar,ColMajor> MatrixType;
30 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMat;
31 typedef Matrix<Scalar,Dynamic,1> DenseVector;
32 @@ -91,14 +92,34 @@ template<typename Scalar> void test_sparseqr_scalar()
33 exit(0);
34 return;
35 }
36 -
37 - VERIFY_IS_APPROX(A * x, b);
38 -
39 - //Compare with a dense QR solver
40 +
41 + // Compare with a dense QR solver
42 ColPivHouseholderQR<DenseMat> dqr(dA);
43 refX = dqr.solve(b);
44
45 - VERIFY_IS_EQUAL(dqr.rank(), solver.rank());
46 + bool rank_deficient = A.cols()>A.rows() || dqr.rank()<A.cols();
47 + if(rank_deficient)
48 + {
49 + // rank deficient problem -> we might have to increase the threshold
50 + // to get a correct solution.
51 + RealScalar th = RealScalar(20)*dA.colwise().norm().maxCoeff()*(A.rows()+A.cols()) * NumTraits<RealScalar>::epsilon();
52 + for(Index k=0; (k<16) && !test_isApprox(A*x,b); ++k)
53 + {
54 + th *= RealScalar(10);
55 + solver.setPivotThreshold(th);
56 + solver.compute(A);
57 + x = solver.solve(b);
58 + }
59 + }
60 +
61 + VERIFY_IS_APPROX(A * x, b);
62 +
63 + // For rank deficient problem, the estimated rank might
64 + // be slightly off, so let's only raise a warning in such cases.
65 + if(rank_deficient) ++g_test_level;
66 + VERIFY_IS_EQUAL(solver.rank(), dqr.rank());
67 + if(rank_deficient) --g_test_level;
68 +
69 if(solver.rank()==A.cols()) // full rank
70 VERIFY_IS_APPROX(x, refX);
71 // else
72 --
73 2.24.1
74