Skip to content

Commit

Permalink
Support inv on diagonal matrices from unitranges (#177)
Browse files Browse the repository at this point in the history
* Support inv on diagonal matrices from unitranges

* Don't use == on entire matrix

* Check for singular exception
  • Loading branch information
DanielVandH authored Jun 17, 2024
1 parent 0049f1b commit ce6da6b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.14"
version = "0.14.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Base: *, +, -, /, <, ==, >, \, ≤, ≥, (:), @propagate_inbounds,
angle, axes, broadcast, cat_indices,
cat_similar, cat_size, checkindex, collect, convert, copy,
cumsum, dataids, diff, div, eltype, fill, findfirst, first, floatrange, getindex, hcat,
in, ind2sub_rs, intersect, isempty, isinf, issorted, last, length, lt, max,
in, ind2sub_rs, intersect, inv, isempty, isinf, issorted, last, length, lt, max,
maximum, minimum, mod, one, ones, parent, parentindices, permutedims, print_matrix, print_matrix_row,
print_matrix_vdots, promote_rule, reinterpret, reshape, reverse, searchsorted,
searchsortedfirst, searchsortedlast, setindex!, show, show_circular, show_delim_array, sign,
Expand Down
7 changes: 7 additions & 0 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,10 @@ function LinearAlgebra.diag(D::Diagonal{<:Any,<:InfRanges}, k::Integer = 0)
return Zeros{eltype(D)}(size(D,1)) # infinite vector of zeros
end
end

function inv(D::Diagonal{T, <:InfRanges}) where {T}
d = D.diag
idx = findfirst(==(zero(T)), d)
isnothing(idx) || throw(SingularException(idx))
return Diagonal(inv.(d))
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,8 @@ end
@test @inferred((D -> diag(D,1))(D)) === Zeros{Int}(ℵ₀)
# test for compile-time evaluation of off-diagonals
@inferred Val((D -> diag(D,1))(D))
# Issue #176
@test inv(D)[1:100,1:100] == Diagonal(inv.(1:∞))[1:100,1:100]
end

@testset "inf padded" begin
Expand Down

2 comments on commit ce6da6b

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/109178

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.1 -m "<description of version>" ce6da6bfd20efeef235fa49c8d176e05fbeb80f5
git push origin v0.14.1

Please sign in to comment.