-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support inv on diagonal matrices from unitranges #177
Conversation
Won't this change the behavior from throwing a |
Technically yes, although this julia> A = Diagonal((0:∞) .+ (0:∞)) # force non-infrange type
ℵ₀×ℵ₀ Diagonal{Int64, LazyArrays.BroadcastVector{Int64, typeof(+), Tuple{InfiniteArrays.InfUnitRange{Int64}, InfiniteArrays.InfUnitRange{Int64}}}} with indices OneToInf()×OneToInf():
0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ …
⋅ 2 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ 4 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ 6 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 8 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 10 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ …
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 12 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 14 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 16 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 18 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 20 ⋅ ⋅ ⋅ ⋅ ⋅ …
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 22 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 24 ⋅ ⋅ ⋅
⋮ ⋮ ⋮ ⋮ ⋱
julia> inv(A)
ℵ₀×ℵ₀ Diagonal{Float64, LazyArrays.BroadcastVector{Float64, typeof(inv), Tuple{LazyArrays.BroadcastVector{Int64, typeof(+), Tuple{InfiniteArrays.InfUnitRange{Int64}, InfiniteArrays.InfUnitRange{Int64}}}}}} with indices OneToInf()×OneToInf():
Inf ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ …
⋅ 0.5 ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ 0.25 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ 0.166667 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 0.125 ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 0.1 ⋅ …
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.0833333
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ …
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋮ ⋮ |
Should a change like this go to |
I wasn't too sure, the method in function inv(D::Diagonal{T, <:InfRanges}) where {T}
d = D.diag
idx = findfirst(==(zero(T)), d) # iszero is broken for infranges
isnothing(idx) || throw(SingularException(idx))
return Diagonal(inv.(d))
end I do agree that having to special case is a bit annoying but I don't think such a change would get through to LinearAlgebra |
In any case, we can add it here, as we would still need it on older versions of Julia |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #177 +/- ##
==========================================
- Coverage 86.00% 84.97% -1.03%
==========================================
Files 6 6
Lines 743 752 +9
==========================================
Hits 639 639
- Misses 104 113 +9 ☔ View full report in Codecov by Sentry. |
Test failure seems spurious |
Fixes #176