Skip to content

Commit 343c13d

Browse files
authored
Add (row/col)support for inv(Triangular) (#334)
* row/colsupport * Dropped an import * bump
1 parent f2ed399 commit 343c13d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/linalg/inv.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,17 @@ getindex(L::ApplyMatrix{<:Any,typeof(/)}, k::Integer, ::Colon) = permutedims(L.a
184184
getindex(L::ApplyMatrix{<:Any,typeof(/)}, k::Integer, j::Integer) = L[k,:][j]
185185

186186

187-
inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A)
187+
inv_layout(::LazyLayouts, _, A) = ApplyArray(inv, A)
188+
189+
###
190+
# row/colsupport triangular
191+
###
192+
function colsupport(lay::AbstractInvLayout{<:TriangularLayout}, A, j)
193+
B, = arguments(lay, A)
194+
return colsupport(B, j)
195+
end
196+
197+
function rowsupport(lay::AbstractInvLayout{<:TriangularLayout}, A, k)
198+
B, = arguments(lay, A)
199+
return rowsupport(B, k)
200+
end

test/ldivtests.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module LdivRdivTests
22

3-
using LazyArrays, LinearAlgebra, FillArrays, Test
3+
using LazyArrays, LinearAlgebra, FillArrays, Test, ArrayLayouts
4+
import ArrayLayouts: rowsupport, colsupport
45
import LazyArrays: InvMatrix, ApplyBroadcastStyle, LdivStyle, Applied, LazyLayout, simplifiable
56
import Base.Broadcast: materialize
67

@@ -180,4 +181,20 @@ end
180181
@test Z \ Y [-2.0 1.0; 1.5 -0.5]
181182
end
182183

184+
@testset "Issue #329" begin
185+
for op in (UpperTriangular, UnitUpperTriangular)
186+
A = UpperTriangular(ApplyArray(inv, rand(5, 5)))
187+
B = inv(A)
188+
@test colsupport.(Ref(B), 1:5) == Base.OneTo.(1:5)
189+
@test rowsupport.(Ref(B), 1:5) == range.(1:5, 5)
190+
end
191+
192+
for op in (LowerTriangular, UnitLowerTriangular)
193+
A = LowerTriangular(ApplyArray(inv, rand(15, 15)))
194+
B = inv(A)
195+
@test colsupport.(Ref(B), 1:15) == range.(1:15, 15)
196+
@test rowsupport.(Ref(B), 1:15) == Base.OneTo.(1:15)
197+
end
198+
end
199+
183200
end # module

0 commit comments

Comments
 (0)