test_linalg_pseudoinverse fails intermittently on CI
The single-precision s_square_pseudoinverse test fails about 0.2% of the time, because it uses random matrices and an absolute tolerance. This was raised in #1178 (whose title is about loadtxt). One recent failure: https://github.com/fortran-lang/stdlib/actions/runs/43647773400 (CI_windows, MINGW64, master, 2026-11-14); the next master run passed.
The test fills a with random_number (no fixed seed) and requires that no element of a - a*inva*a or inva - inva*a*inva exceeds tol = 1000*sqrt(epsilon). The second residual grows with norm(inva), about 1/sigma_min, so an ill-conditioned matrix fails it.
I repeated those checks on 200000 random 10x10 single-precision matrices: 412 failed, with no pinv error. The first 10 failures all had a condition number above about 1.7e4 and all failed the second check.
Options:
- Build the matrix as
U*diag(s)*V^Twith random orthogonalUandVand a chosens. The condition number is then known, the exactpinvis known, and a rank-deficient case is a direct test. - Check a norm of the residual, relative to
norm(inva), instead of every element (suggested in #1178). - The smallest change: make the matrix better conditioned, for example by adding a multiple of the identity (also suggested in #1178).
The failure message also ends in Success!, because it prints state%print() from a state that was ok. It could report the largest residual instead.
Drafted with Claude's assistance.
- I reviewed the test source and the CI log of the failed run.
- My loop reproduces the checks, not the test itself, and covers only real single precision on Windows with gfortran. I did not check the other kinds or the matrix from the CI failure.
This has been a long standing issue in the CI, if you manage to fix it properly that would be greatly appreciated!