Skip to content

Commit 84d8624

Browse files
authored
Overload bandedrowsdata for SubArray (#487)
* Overload bandedrowsdata for SubArray * fix negative bands and add tests
1 parent 4cacec3 commit 84d8624

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

.github/workflows/downstream.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- {repo: ApproxFunBase.jl, group: JuliaApproximation}
4545
- {repo: ApproxFun.jl, group: JuliaApproximation}
4646
- {repo: InfiniteLinearAlgebra.jl, group: JuliaLinearAlgebra}
47+
- {repo: ClassicalOrthogonalPolynomials.jl, group: JuliaApproximation}
4748

4849
steps:
4950
- uses: actions/checkout@v5

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "1.10.0"
3+
version = "1.10.1"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/banded/BandedMatrix.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,14 @@ BandedMatrix(A::AbstractMatrix) = _BandedMatrix(MemoryLayout(A), A)
266266
_BandedMatrix(::BandedColumns, A::AbstractMatrix) = _BandedMatrix(copy(bandeddata(A)), axes(A,1), bandwidths(A)...)
267267
function _BandedMatrix(::BandedRows, A::AbstractMatrix)
268268
bdata = bandedrowsdata(A)
269-
data = similar(bdata, eltype(bdata), reverse(size(bdata)))
270-
u, ℓ = bandwidths(A)
269+
m,ν = size(bdata)
270+
ℓ,u = bandwidths(A)
271+
data = similar(bdata, eltype(bdata), ν, size(A,2))
271272
n = size(A, 2)
272-
for j in axes(A, 1), i in max(1, j - u):min(n, j + )
273-
data[ + 1 + j - i, i] = bdata[j, u+1+i-j]
273+
for j in axes(A, 1), i in max(1, j - ):min(n, j + u)
274+
data[u + 1 + j - i, i] = bdata[j, +1+i-j]
274275
end
275-
return _BandedMatrix(data, axes(A, 1), bandwidths(A)...)
276+
return _BandedMatrix(data, axes(A, 1), ℓ, u)
276277
end
277278
function _BandedMatrix(::DiagonalLayout, A::AbstractMatrix{T}) where T
278279
m,n = size(A)

src/interfaceimpl.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ end
3232

3333
bandedrowsdata(Ac::Transpose) = permutedims(bandeddata(parent(Ac)))
3434
bandedrowsdata(Ac::Adjoint{<:Real}) = permutedims(bandeddata(parent(Ac)))
35+
bandedrowsdata(V::SubArray) = permutedims(bandeddata(view(parent(parent(V)), reverse(parentindices(V))...)))
3536

3637
# treat subinds as banded
3738
sublayout(::DiagonalLayout{L}, inds::Type) where L = sublayout(bandedcolumns(L()), inds)

test/test_banded.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,18 @@ include("mymatrix.jl")
608608
@test BandedMatrix(B) == B
609609
@test BandedMatrix(B) !== B
610610
@test BandedMatrices.bandeddata(BandedMatrix(B)) !== BandedMatrices.bandeddata(A)
611+
612+
@test BandedMatrix(view(B,2:4, 3:5)) == B[2:4,3:5] == [B[k,j] for k=2:4,j=3:5]
613+
end
614+
615+
for V in (view(BandedMatrix((1 => ones(4),), (10, 10))', 1:5, 1:4),
616+
view(BandedMatrix((1 => ones(4),), (10, 10))', 1:3, 1:5),
617+
view(BandedMatrix((-1 => ones(4),), (10, 10))', 1:5, 1:4),
618+
view(BandedMatrix((-1 => ones(4),), (10, 10))', 1:3, 1:5),
619+
view(BandedMatrix((-1 => ones(4), 1 => ones(9)), (10, 10))', 1:3, 1:5))
620+
@test BandedMatrix(V) == V
611621
end
622+
612623
end
613624
end
614625

0 commit comments

Comments
 (0)