Skip to content

Commit 6046ac2

Browse files
committed
support getindex and setindex! for AbstractBandedMatrix
1 parent 865f560 commit 6046ac2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
1111
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
1212
ClassicalOrthogonalPolynomials = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
1313
InfiniteArrays = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
14+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
1415

1516
[extensions]
1617
PTYQoLLinearAlgebraExt = "LinearAlgebra"
@@ -20,6 +21,7 @@ PTYQoLIntervalSetsExt = "IntervalSets"
2021
PTYQoLQuasiArraysExt = "QuasiArrays"
2122
PTYQoLClassicalOrthogonalPolynomialsExt = "ClassicalOrthogonalPolynomials"
2223
PTYQoLInfiniteArraysExt = "InfiniteArrays"
24+
PTYQoLBandedMatricesExt = "BandedMatrices"
2325

2426
[compat]
2527
julia = "1"

ext/PTYQoLBandedMatricesExt.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module PTYQoLBandedMatricesExt
2+
3+
import BandedMatrices: inbands_getindex, inbands_setindex!, AbstractBandedMatrix, bandwidths, MemoryLayout, BandedLayout
4+
import Base: getindex, setindex!, @propagate_inbounds
5+
6+
@propagate_inbounds function getindex(A::AbstractBandedMatrix, j::Integer, k::Integer)
7+
@boundscheck checkbounds(A, j, k)
8+
l, u = bandwidths(A)
9+
if -l k-j u
10+
inbands_getindex(A, j, k)
11+
else
12+
zero(eltype(A))
13+
end
14+
end
15+
16+
@propagate_inbounds function setindex!(A::AbstractBandedMatrix, v, j::Integer, k::Integer)
17+
@boundscheck checkbounds(A, j, k)
18+
l, u = bandwidths(A)
19+
if -l k-j u
20+
inbands_setindex!(A, v, j, k)
21+
elseif iszero(v)
22+
zero(eltype(A))
23+
else
24+
error("out of band.")
25+
end
26+
end
27+
28+
end

0 commit comments

Comments
 (0)