Skip to content

Commit

Permalink
refactor inv to also work for lu (#1267)
Browse files Browse the repository at this point in the history
* refactor inv to also work for lu

* handle non-square case like LA

* bump v1.9.7

* test non-square case
  • Loading branch information
lxvm authored Jul 2, 2024
1 parent 12fd8f7 commit 778a563
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StaticArrays"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.9.6"
version = "1.9.7"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
11 changes: 9 additions & 2 deletions src/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ end
if prod(S) 14*14
quote
@_inline_meta
LUp = lu(A)
LUp.U \ (LUp.L \ typeof(A)(I)[LUp.p,:])
inv(lu(A))
end
else
:(@_inline_meta; similar_type(A)(inv(Matrix(A))))
end
end

function inv(LUp::LU)
if !(LUp.L isa LowerTriangular)
checksquare(LUp.L)
checksquare(LUp.U)
end
LUp.U \ (LUp.L \ typeof(parent(LUp.L))(I)[LUp.p,:])
end
8 changes: 8 additions & 0 deletions test/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ end
@test inv(A) inv(SA)
end

@testset "LU to inverse" for sz in (5, 8, 15), typ in (Float64, Complex{Float64})
A = rand(typ, sz, sz)
SA = SMatrix{sz,sz,typ}(A)
@test inv(lu(A)) inv(lu(SA))
@test_throws DimensionMismatch inv(lu(SMatrix{sz,sz+1,typ}(rand(typ, sz, sz+1))))
@test_throws DimensionMismatch inv(lu(SMatrix{sz+1,sz,typ}(rand(typ, sz+1, sz))))
end

#-------------------------------------------------------------------------------
# More comprehensive but qualitative testing for inv() accuracy
#=
Expand Down

2 comments on commit 778a563

@mateuszbaran
Copy link
Collaborator

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/110312

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 v1.9.7 -m "<description of version>" 778a56353b5f2314b5a80eaded0c99c5d4981fb1
git push origin v1.9.7

Please sign in to comment.