Skip to content

Commit 22433fb

Browse files
authored
backport: Three-term ldiv for UpperTriangular AlmostBandedMatrix (#618)
1 parent 0f7958b commit 22433fb

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.61"
3+
version = "0.8.62"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Caching/almostbanded.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,10 @@ for ArrTyp in (:AbstractVector, :AbstractMatrix)
392392
end
393393
u
394394
end
395+
@eval function ldiv!(v::$ArrTyp{T},
396+
U::UpperTriangular{T,<:SubArray{T, 2, <:AlmostBandedMatrix{T}, NTuple{2,UnitRange{Int}}}},
397+
u::$ArrTyp{T}) where T
398+
399+
ldiv!(U, copyto!(v, u))
400+
end
395401
end

src/LinearAlgebra/AlmostBandedMatrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
size(A::AlmostBandedMatrix) = size(A.bands)
3636

3737

38-
function getindex(B::AlmostBandedMatrix,k::Integer,j::Integer)
38+
Base.@propagate_inbounds function getindex(B::AlmostBandedMatrix,k::Integer,j::Integer)
3939
if j > k + bandwidth(B.bands,2)
4040
B.fill[k,j]
4141
else
@@ -44,7 +44,7 @@ function getindex(B::AlmostBandedMatrix,k::Integer,j::Integer)
4444
end
4545

4646
# can only change the bands, not the fill
47-
function setindex!(B::AlmostBandedMatrix,v,k::Integer,j::Integer)
47+
Base.@propagate_inbounds function setindex!(B::AlmostBandedMatrix,v,k::Integer,j::Integer)
4848
B.bands[k,j] = v
4949
end
5050

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using FillArrays
1010
using InfiniteArrays
1111
using Infinities
1212
using LinearAlgebra
13+
using LowRankMatrices
1314
using Random
1415
using SpecialFunctions
1516
using Test
@@ -251,6 +252,11 @@ end
251252
AInt = convert(AbstractArray{Int}, A)
252253
@test AInt isa AbstractArray{Int}
253254
@test AInt == A
255+
256+
bands, fill = BandedMatrix(0=>Float64[1:4;]), LowRankMatrix(Float64[1:4;], Float64[1:4;])
257+
AB = ApproxFunBase.AlmostBandedMatrix(bands, fill)
258+
U = UpperTriangular(view(AB, 1:4, 1:4))
259+
@test ldiv!(U, Float64[1:4;]) == ldiv!(ones(4), U, Float64[1:4;]) == ldiv!(factorize(Array(U)), Float64[1:4;])
254260
end
255261

256262
@testset "DiracDelta sampling" begin

0 commit comments

Comments
 (0)