Skip to content
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

Add row/colsupport for InvLayout(TriangularLayout) properly #341

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LazyArrays"
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
version = "2.1.8"
version = "2.1.9"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
21 changes: 20 additions & 1 deletion src/linalg/inv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,23 @@
getindex(L::ApplyMatrix{<:Any,typeof(/)}, k::Integer, j::Integer) = L[k,:][j]


inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A)
inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A)

Check warning on line 187 in src/linalg/inv.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/inv.jl#L187

Added line #L187 was not covered by tests

function colsupport(lay::AbstractInvLayout{TriLay}, A, j) where {S,TriLay<:TriangularLayout{S}}
isempty(j) && return 1:0
B, = arguments(lay, A)
if S == 'U'
return firstindex(B, 2):(maximum(j) - firstindex(B, 2) + 1)

Check warning on line 193 in src/linalg/inv.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/inv.jl#L189-L193

Added lines #L189 - L193 were not covered by tests
else # S == 'L'
return minimum(j):size(B, 2)

Check warning on line 195 in src/linalg/inv.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/inv.jl#L195

Added line #L195 was not covered by tests
end
end
function rowsupport(lay::AbstractInvLayout{TriLay}, A, k) where {S,TriLay<:TriangularLayout{S}}
isempty(k) && return 1:0
B, = arguments(lay, A)
if S == 'U'
return minimum(k):size(B, 1)

Check warning on line 202 in src/linalg/inv.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/inv.jl#L198-L202

Added lines #L198 - L202 were not covered by tests
else # S == 'L'
return firstindex(B, 1):(maximum(k) - firstindex(B, 1) + 1)

Check warning on line 204 in src/linalg/inv.jl

View check run for this annotation

Codecov / codecov/patch

src/linalg/inv.jl#L204

Added line #L204 was not covered by tests
end
end
17 changes: 17 additions & 0 deletions test/bandedtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,21 @@ LinearAlgebra.lmul!(β::Number, A::PseudoBandedMatrix) = (lmul!(β, A.data); A)
end
end

@testset "Issue #329" begin
# Make sure that we aren't giving the incorrect bandwidths
U = UpperTriangular(ApplyArray(inv, brand(5, 5, 1, 2)))
invU = inv(U)
L = LowerTriangular(ApplyArray(inv, brand(10, 10, 3, 4)))
invL = inv(L)
@test colsupport(invU, 1) == 1:1
@test colsupport(invU, 3) == 1:3
@test rowsupport(invU, 1) == 1:5
@test rowsupport(invU, 4) == 4:5
@test rowsupport(invU, 5) == 5:5
@test colsupport(invL, 1) == 1:10
@test colsupport(invL, 5) == 5:10
@test rowsupport(invL, 1) == 1:1
@test rowsupport(invL, 4) == 1:4
end

end # module
26 changes: 25 additions & 1 deletion test/ldivtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,28 @@ end
@test Z \ Y ≈ [-2.0 1.0; 1.5 -0.5]
end

end # module
@testset "Issue #329" begin
U = UpperTriangular(ApplyArray(inv, rand(5, 5)))
invU = inv(U)
L = LowerTriangular(ApplyArray(inv, rand(10, 10)))
invL = inv(L)
@test colsupport(invU, 1) == 1:1
@test colsupport(invU, 3) == 1:3
@test colsupport(invU, 1:3) == 1:3
@test rowsupport(invU, 1) == 1:5
@test rowsupport(invU, 4) == 4:5
@test rowsupport(invU, 5) == 5:5
@test rowsupport(invU, 3:5) == 3:5
@test colsupport(invL, 1) == 1:10
@test colsupport(invL, 5) == 5:10
@test colsupport(invL, 2:4) == 2:10
@test rowsupport(invL, 1) == 1:1
@test rowsupport(invL, 4) == 1:4
@test rowsupport(invL, 2:2:4) == 1:4
@test colsupport(invU, ()) == 1:0
@test rowsupport(invU, ()) == 1:0
@test colsupport(invL, ()) == 1:0
@test rowsupport(invL, ()) == 1:0
end

end # module
Loading