# Could \`svd!\` support option \`check=false\` like \`lu!\` and other factorizations?

**URL:** https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386
**Category:** Numerics
**Tags:** question, linearalgebra
**Created:** [April 24, 2025, 8:36pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386 "2025-04-24T20:36:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [April 24, 2025, 8:36pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/1 "2025-04-24T20:36:57Z")

</div>

The `check=false` option present in `lu!`, `bunchkaufman!` and other factorization routines is super useful to handle exceptions efficiently. Unfortunately, the `svd!` doesn’t have this option and I am getting `LinearAlgebra.LAPACKException(1)` in the middle of a very complicated routine.

What is the recommended method to emulate the `check=false` behavior with `svd!`? I am assuming that a `throw-catch` block will compromise type stability and performance. Is that right?

Any help is appreciated.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [April 24, 2025, 9:10pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/2 "2025-04-24T21:10:52Z")

</div>

yeah probably just needs a PR to LinearAlgebra. The other check=false options were mostly added for LinearSolve.jl which doesn’t use SVD as much so no one made the PR.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [April 24, 2025, 11:00pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/3 "2025-04-24T23:00:23Z")

</div>

@Oscar_Smith any chance you could help with this PR? I am not familiar with the LinearAlgebra.jl conventions and internal LAPACK calls.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [April 24, 2025, 11:10pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/4 "2025-04-24T23:10:09Z")

</div>

Sure! basically what you want to do is figure out what line inspects the Lapack exception code and turns it into a Julia exception, and then modify it to make it do that only if `check=true`. [check kwarg for factorizations by fredrikekre · Pull Request #27336 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/27336) should give you a decent template (since this implemented it for lots of other factorizations)

---

<div class="post-metadata">

### Author: ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)
#### Post date: [April 25, 2025, 6:33am UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/5 "2025-04-25T06:33:37Z")

</div>

The SVD is a little different from LU and Cholesky. In theory, the algorithm shouldn’t fail for any matrix with finite elements so the error here is actually considered a bug in LAPACK, see [Possible bug in `dgesdd` routine · Issue #672 · Reference-LAPACK/lapack · GitHub](https://github.com/Reference-LAPACK/lapack/issues/672). Hence, I’m not sure it is a good idea to extend `check` to cover a case that is actually a bug.

I think the issue might be isolated to the divide-and-conquer algorithm so you might be able to completely avoid the issue by setting `alg=QRIteration()`.

If you can isolate the matrix, ideally after it has been transformed to a bidiagonal, it would be useful if you could share it in the linked issue.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [April 25, 2025, 12:17pm UTC](https://discourse.julialang.org/t/could-svd-support-option-check-false-like-lu-and-other-factorizations/128386/6 "2025-04-25T12:17:38Z")

</div>

Thank you @andreasnoack , I added the MWE to the linked issue:

> <https://github.com/Reference-LAPACK/lapack/issues/672#issuecomment-2830265027>
>
> I believe I found a bug in \`LAPACK\` in \`svd(.)\` / \`dgesdd\` function:
> 
> \### Prob…lem description
> R routine \`svd(.)\` from \`LAPACK\` crashes in \`dgesdd\` on a full rank matrix with dimensions 5344x263. 
> 
> \### Problem replication
> \`\`\`
> library(Rfssa)
> load\_github\_data("https://github.com/SzymonNowakowski/DMRnet/blob/testing\_branch/data/crashes\_svd.RData")
> svd(crashes\_svd)
> \`\`\` 
> \`\`\`
> Error in La.svd(x, nu, nv) : error code 1 from Lapack routine 'dgesdd'
> \`\`\`
> 
> But \`crashes\_svd\` is a full rank matrix, it should decompose in \`svd(.)\`:
> 
> \`\> qr(crashes\_svd)$rank\`
> \`\[1\] 263\`
> \`\> dim(crashes\_svd)\`
> \`\[1\] 5344 263\`
> \*\*EDIT 07/04/2022:\*\*
> ~The above example (a matrix 5344x263) is minimal to reproduce the bug - If you remove a row or a column from that matrix, \`svd(.)\` successfully decomposes a resulting matrix into SVD components.~
> I have verified, that (in general) removing random rows or columns of that special matrix makes it pass the SVD, but one can also remove them in a \*certain order\*, obtaining a sequence of matrices failing SVD computation:
> 
> \`\`\`{r code}
> crashes\_svd\_col \<- crashes\_svd\[, -51\] #removing the 51st column
> svd(crashes\_svd\_col)
> \# Error in La.svd(x, nu, nv) : error code 1 from Lapack routine 'dgesdd'
> crashes\_svd \<- crashes\_svd\[-393,\] #removing a sequence of rows: 393, 962, 642
> svd(crashes\_svd)
> \# Error in La.svd(x, nu, nv) : error code 1 from Lapack routine 'dgesdd'
> crashes\_svd \<- crashes\_svd\[-962,\]
> svd(crashes\_svd)
> \# Error in La.svd(x, nu, nv) : error code 1 from Lapack routine 'dgesdd'
> crashes\_svd \<- crashes\_svd\[-642,\]
> svd(crashes\_svd)
> \# Error in La.svd(x, nu, nv) : error code 1 from Lapack routine 'dgesdd'
> \`\`\`
> 
> \*\*END OF EDIT 07/04/2022\*\*
> 
> \### Software versions
> \#### Windows 7, \`R\` 4.2.0, \`LAPACK\` 3.10.0:
> \`\> La\_version()\`
> \`\[1\] "3.10.0"\`
> \`\> print(sessionInfo())\`
> \`\`\`
> R version 4.2.0 (2022-04-22 ucrt)
> Platform: x86\_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
> \`\`\`
> \#### Windows 7, \`R\` 4.1.0, \`LAPACK\` 3.9.0:
> \`\> La\_version()\`
> \`\[1\] "3.9.0"\`
> \`\> print(sessionInfo())\`
> \`\`\`
> R version 4.1.0 (2021-05-18)
> Platform: x86\_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
> \`\`\`
> \#### Ubuntu 20.04, \`R\` 4.1.2, \`LAPACK\` 3.9.0:
> \`\> La\_version()\`
> \`\[1\] "3.9.0"\`
> \`\> print(sessionInfo())\`
> \`\`\`
> R version 4.1.2 (2021-11-01)
> Platform: x86\_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 20.04.2 LTS
> \`\`\`
> 
> 
> 
> \*\*Checklist\*\*
> 
> \- \[x\] I've included a minimal example to reproduce the issue
> \- \[\] I'd be willing to make a PR to solve this issue

I also confirm that the option `alg=LinearAlgebra.QRIteration()` solved the issue.
