Skip to content

Commit ce6da6b

Browse files
authored
Support inv on diagonal matrices from unitranges (#177)
* Support inv on diagonal matrices from unitranges * Don't use == on entire matrix * Check for singular exception
1 parent 0049f1b commit ce6da6b

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteArrays"
22
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
3-
version = "0.14"
3+
version = "0.14.1"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/InfiniteArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Base: *, +, -, /, <, ==, >, \, ≤, ≥, (:), @propagate_inbounds,
88
angle, axes, broadcast, cat_indices,
99
cat_similar, cat_size, checkindex, collect, convert, copy,
1010
cumsum, dataids, diff, div, eltype, fill, findfirst, first, floatrange, getindex, hcat,
11-
in, ind2sub_rs, intersect, isempty, isinf, issorted, last, length, lt, max,
11+
in, ind2sub_rs, intersect, inv, isempty, isinf, issorted, last, length, lt, max,
1212
maximum, minimum, mod, one, ones, parent, parentindices, permutedims, print_matrix, print_matrix_row,
1313
print_matrix_vdots, promote_rule, reinterpret, reshape, reverse, searchsorted,
1414
searchsortedfirst, searchsortedlast, setindex!, show, show_circular, show_delim_array, sign,

src/infrange.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,10 @@ function LinearAlgebra.diag(D::Diagonal{<:Any,<:InfRanges}, k::Integer = 0)
617617
return Zeros{eltype(D)}(size(D,1)) # infinite vector of zeros
618618
end
619619
end
620+
621+
function inv(D::Diagonal{T, <:InfRanges}) where {T}
622+
d = D.diag
623+
idx = findfirst(==(zero(T)), d)
624+
isnothing(idx) || throw(SingularException(idx))
625+
return Diagonal(inv.(d))
626+
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,8 @@ end
12061206
@test @inferred((D -> diag(D,1))(D)) === Zeros{Int}(ℵ₀)
12071207
# test for compile-time evaluation of off-diagonals
12081208
@inferred Val((D -> diag(D,1))(D))
1209+
# Issue #176
1210+
@test inv(D)[1:100,1:100] == Diagonal(inv.(1:∞))[1:100,1:100]
12091211
end
12101212

12111213
@testset "inf padded" begin

0 commit comments

Comments
 (0)