Skip to content

Commit f9dfe2a

Browse files
authored
Fix stack overflow w/ OneTo axes (#74)
1 parent 93469a9 commit f9dfe2a

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

Project.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockBandedMatrices"
22
uuid = "ffab5731-97b5-5995-9138-79e8c1846df0"
3-
version = "0.8.5"
3+
version = "0.8.6"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -11,11 +11,9 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1111
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1212
MatrixFactorizations = "a3b82374-2e81-5b9e-98ce-41277c0e4c87"
1313
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
14-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1514
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
1615
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1716
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
18-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1917

2018
[compat]
2119
ArrayLayouts = "0.3.3"
@@ -24,3 +22,10 @@ BlockArrays = "0.12.7"
2422
FillArrays = "0.8.10"
2523
MatrixFactorizations = "0.4.1"
2624
julia = "1.2"
25+
26+
[extras]
27+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
28+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
29+
30+
[targets]
31+
test = ["Random", "Test"]

src/BandedBlockBandedMatrix.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ end
310310
BI,BJ = findblockindex.(axes(A), (i,j))
311311
if -A.l Int(block(BJ)-block(BI))  A.u
312312
V = view(A, block(BI),block(BJ))
313-
@inbounds V[blockindex(BI),blockindex(BJ)] = convert(T, v)::T
313+
@inbounds V[blockindex(BI),blockindex(BJ)] = convert(T, v)::T
314314
elseif !iszero(v)
315315
throw(BandError(A))
316316
end
@@ -462,13 +462,13 @@ function blockbandwidths(V::SubArray{<:Any,2,<:Any,<:Tuple{<:BlockSlice{<:BlockR
462462
end
463463

464464

465-
const BandedBlockBandedBlock{T, BLOCKS, RAXIS} = SubArray{T,2,BandedBlockBandedMatrix{T, BLOCKS, RAXIS},<:Tuple{<:BlockSlice1,<:BlockSlice1},false}
465+
const BandedBlockBandedBlock{T, BLOCKS, RAXIS} = SubArray{T,2,BandedBlockBandedMatrix{T, BLOCKS, RAXIS},<:Tuple{<:BlockSlice{Block1},<:BlockSlice{Block1}},false}
466466

467467

468468
BroadcastStyle(::Type{<: BandedBlockBandedBlock}) = BandedStyle()
469469

470470

471-
function inblockbands(V::SubArray{<:Any,2,<:AbstractMatrix,<:Tuple{<:BlockSlice1,<:BlockSlice1},false})
471+
function inblockbands(V::SubArray{<:Any,2,<:AbstractMatrix,<:Tuple{<:BlockSlice{Block1},<:BlockSlice{Block1}},false})
472472
A = parent(V)
473473
K_sl, J_sl = parentindices(V)
474474
K, J = K_sl.block, J_sl.block
@@ -502,7 +502,7 @@ parentblocks2Int(V::BandedBlockBandedBlock)::Tuple{Int,Int} = Int(first(parentin
502502
######################################
503503
# BandedMatrix interface for Blocks #
504504
######################################
505-
@inline function bandwidths(V::SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice1,BlockSlice1}}) where T
505+
@inline function bandwidths(V::SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{Block1},BlockSlice{Block1}}}) where T
506506
inblockbands(V) && return subblockbandwidths(parent(V))
507507
(-720,-720)
508508
end

src/BlockBandedMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import LinearAlgebra.LAPACK: chktrans, chkdiag, liblapack, chklapackerror, check
2121
import MatrixFactorizations: ql, ql!, _ql, QLPackedQ, AdjQRPackedQLayout, AdjQLPackedQLayout, QR, QRPackedQ
2222
import SparseArrays: sparse
2323

24-
import ArrayLayouts: BlasMatLmulVec,
24+
import ArrayLayouts: BlasMatLmulVec, MatLmulVec, MatLmulMat,
2525
triangularlayout, UpperTriangularLayout, TriangularLayout, MatLdivVec,
2626
triangulardata, sublayout, sub_materialize,
2727
AbstractColumnMajor, DenseColumnMajor, ColumnMajor,

src/blockskylineqr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ _qr(lay::AbstractBlockBandedLayout, ax::Tuple{AbstractUnitRange{Int},AbstractUni
7373
_ql(::AbstractBlockBandedLayout, _, A) = ql!(BlockBandedMatrix(A, (blockbandwidth(A,1)+blockbandwidth(A,2),blockbandwidth(A,2))))
7474
_factorize(::AbstractBlockBandedLayout, _, A) = qr(A)
7575

76-
function materialize!(Mul::Lmul{<:AdjQRPackedQLayout{<:AbstractBlockBandedLayout}})
76+
function materialize!(Mul::MatLmulVec{<:AdjQRPackedQLayout{<:AbstractBlockBandedLayout}})
7777
adjQ,Bin = Mul.A,Mul.B
7878
Q = parent(adjQ)
7979
A = Q.factors
@@ -91,7 +91,7 @@ function materialize!(Mul::Lmul{<:AdjQRPackedQLayout{<:AbstractBlockBandedLayout
9191
end
9292
Bin
9393
end
94-
function materialize!(Mul::Lmul{<:AdjQLPackedQLayout{<:AbstractBlockBandedLayout}})
94+
function materialize!(Mul::MatLmulVec{<:AdjQLPackedQLayout{<:AbstractBlockBandedLayout}})
9595
Q = parent(Mul.A)
9696
A = Q.factors
9797
l,u = blockbandwidths(A)
@@ -111,7 +111,7 @@ end
111111

112112
# avoid LinearALgebra Strided obsession
113113

114-
for Typ in (:StridedVector, :StridedMatrix, :AbstractVector, :AbstractMatrix)
114+
for Typ in (:StridedVector, :StridedMatrix, :AbstractVector, :AbstractMatrix, :LayoutMatrix)
115115
@eval function ldiv!(A::QR{<:Any,<:BlockSkylineMatrix}, B::$Typ)
116116
lmul!(adjoint(A.Q), B)
117117
M,N = blocksize(A.factors)

test/test_bandedblockbanded.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ import BlockBandedMatrices: _BandedBlockBandedMatrix, blockcolsupport, blockrows
470470
@test bandwidths(V2) == (-1,1)
471471
@test BandedMatrix(V2) == A[3:3,5:6]
472472
end
473+
474+
@testset "OneTo axes" begin
475+
ret = BandedBlockBandedMatrix{Int}(undef, (Base.OneTo(5),Base.OneTo(5)), (0,0), (1,1))
476+
V = view(ret, Block(1,1))
477+
@test bandwidths(V) == (1,1)
478+
A = brand(5,5,1,1)
479+
B = BandedBlockBandedMatrix(A)
480+
@test A == B
481+
@test subblockbandwidths(B) == (1,1)
482+
@test blockbandwidths(B) == (0,0)
483+
end
473484
end
474485

475486
if false # turned off since tests have check-bounds=yes

test/test_misc.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,4 @@ end
3131
@test_throws DimensionMismatch A+I
3232
A = BlockTridiagonal(fill([1 2; 1 2],3), fill([3 4; 3 4],4), fill([4 5; 4 5],3))
3333
@test A+I == I+A == mortar(Tridiagonal(fill([1 2; 1 2],3), fill([4 4; 3 5],4), fill([4 5; 4 5],3))) == Matrix(A) + I
34-
end
35-
36-
34+
end

0 commit comments

Comments
 (0)