Skip to content

Conversation

@Antoinemarteau
Copy link
Contributor

@Antoinemarteau Antoinemarteau commented May 2, 2025

I suggest documenting that inv(::AbstractMatrix) throws on (numerically) singular matrices, this is different from inv(::Number) that returns Inf.

inv( 0. )    # Inf, no exception
inv( [0;;] ) # SingularException 

I guess documenting this would mean that inv guarantees to return a matrix with only finite (isfinite) entries if the argument has only finite entries, but I don't know if the implementation guarantees it / if this should be tested ?

@Antoinemarteau
Copy link
Contributor Author

Antoinemarteau commented May 2, 2025

Also, inv(M) where M = [Nan;;] currently returns [Nan;;], but then M*inv(M) == Matrix(I,1,1) is false, so what is returned isn't an inverse and the documentation doesn't specify it.

Should this be also documented, or fixed to throw a SingularExcteption ? On one hand [Nan;;] do not have a zero eigenvalue like SingularException says, but it isn't invertible either.

Other inconsistencies with NaN:

julia> M = [NaN 1; 1 0;]

julia> inv(M) 
ERROR: ArgumentError: matrix contains Infs or NaNs
... 

julia> M = [NaN 0; 0 1;]

julia> inv(M)
2×2 Matrix{Float64}:
 NaN    NaN
   0.0    1.0

julia> Matrix(I,2,2) == inv(M)*M
false

@ViralBShah
Copy link
Member

Welcome @Antoinemarteau !

@ViralBShah ViralBShah merged commit 58003a5 into JuliaLang:master May 8, 2025
1 of 2 checks passed
@codecov
Copy link

codecov bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.74%. Comparing base (a305c67) to head (05b703b).
Report is 20 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1331      +/-   ##
==========================================
- Coverage   93.76%   93.74%   -0.03%     
==========================================
  Files          34       34              
  Lines       15751    15751              
==========================================
- Hits        14769    14765       -4     
- Misses        982      986       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah ViralBShah added the backport 1.12 Change should be backported to release-1.12 label May 11, 2025
@jishnub jishnub mentioned this pull request May 12, 2025
27 tasks
jishnub added a commit that referenced this pull request May 26, 2025
Backported PRs:
- [x] #1209 <!-- Remove `LinearAlgebra` qualifications in `cholesky.jl`
-->
- [x] #1230 <!-- Avoid materializing `diag` in `Diagonal` `kron` -->
- [x] #1240 <!-- Reduce `stable_muladdmul` branches in `generic
matvecmul!` -->
- [x] #1247 <!-- fix dispatch to herk -->
- [x] #1255 <!-- use smaller matrix size in `peakflops` on 32-bit -->
- [x] #1310 <!-- Only `@noinline` error path in `matmul_size_check` -->
- [x] #1267 <!-- Refine column ranges in `_isbanded_impl` -->
- [x] #1320 <!-- Copy matrices in `triu`/`tril` if no zero exists for
the `eltype` -->
- [x] #1324 <!-- Fix empty `Tridiagonal` broadcast -->
- [x] #1327 <!-- `iszero` check in hessenberg setindex -->
- [x] #1326 <!-- Fix multiplication with empty `HessenbergQ` -->
- [x] #1332 <!-- Unwrap triangular matrices in broadcast -->
- [x] #1337 <!-- Change `1:size` to `axes` in bidiag mul -->
- [x] #1342 <!-- `Char` uplo in `Bidiagonal` constructor -->
- [x] #1344 <!-- Update the docstring of ldiv! -->
- [x] #1335 <!-- Test: prune old LA based on ENV variable -->
- [x] #1346 <!-- Fix scaling unit triangular matrices -->
- [x] #1355 <!-- Add compat notice for `diagview` -->
- [x] #1349 <!-- Prune `LinearAlgebra` module in ambiguity test -->

Contains multiple commits, manual intervention needed:
- [x] #1238 <!-- Ensure positive-definite matrix in lapack posv test -->
- [x] #1298 <!-- Add `diagm` example -->
- [x] #1312 <!-- WIP: Try use method deletion instead of custom sysimage
-->
- [x] #1333 <!-- Make `fillstored!` public -->
- [x] #1331 <!-- Document SingularException throw for
inv(::AbstractMatrix) -->
- [x] #1350 <!-- Fix copy for partly initialized unit triangular -->

Non-merged PRs with backport label:
- [x] #1352 <!-- log for dense diagonal matrix with negative elements
-->
- [ ] #1305 <!-- Bounds-checking in triangular indexing branches -->

---------

Co-authored-by: Mateus Araújo <[email protected]>
Co-authored-by: Jeff Bezanson <[email protected]>
Co-authored-by: Steven G. Johnson <[email protected]>
Co-authored-by: WalterMadelim <[email protected]>
Co-authored-by: Kristoffer Carlsson <[email protected]>
Co-authored-by: Daniel Karrasch <[email protected]>
Co-authored-by: Michael Abbott <[email protected]>
@jishnub jishnub removed the backport 1.12 Change should be backported to release-1.12 label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants