diff --git a/Project.toml b/Project.toml index dcf111f..9767e53 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/linalg/inv.jl b/src/linalg/inv.jl index 33b5591..e49e636 100644 --- a/src/linalg/inv.jl +++ b/src/linalg/inv.jl @@ -184,4 +184,23 @@ getindex(L::ApplyMatrix{<:Any,typeof(/)}, k::Integer, ::Colon) = permutedims(L.a getindex(L::ApplyMatrix{<:Any,typeof(/)}, k::Integer, j::Integer) = L[k,:][j] -inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A) \ No newline at end of file +inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A) + +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) + else # S == 'L' + return minimum(j):size(B, 2) + 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) + else # S == 'L' + return firstindex(B, 1):(maximum(k) - firstindex(B, 1) + 1) + end +end \ No newline at end of file diff --git a/test/bandedtests.jl b/test/bandedtests.jl index 4eb3de0..f3711d6 100644 --- a/test/bandedtests.jl +++ b/test/bandedtests.jl @@ -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 \ No newline at end of file diff --git a/test/ldivtests.jl b/test/ldivtests.jl index 94573bf..1086692 100644 --- a/test/ldivtests.jl +++ b/test/ldivtests.jl @@ -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 \ No newline at end of file