Skip to content

Commit a318431

Browse files
Merge pull request #34 from JuliaDiffEq/blockarrays
fix for BlockBandedMatrix no longer using BlockArrays
2 parents eb25d87 + 7ebe54d commit a318431

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

src/ArrayInterface.jl

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -425,62 +425,63 @@ function __init__()
425425
end
426426

427427
@require BlockBandedMatrices="ffab5731-97b5-5995-9138-79e8c1846df0" begin
428-
function findstructralnz(x::BlockBandedMatrices.BlockBandedMatrix)
429-
l,u=BlockBandedMatrices.blockbandwidths(x)
430-
nrowblock=BlockBandedMatrices.blocksize(x,1)
431-
ncolblock=BlockBandedMatrices.blocksize(x,2)
432-
rowsizes=BlockBandedMatrices.blocklengths(axes(x,1))
433-
colsizes=BlockBandedMatrices.blocklengths(axes(x,2))
434-
BlockBandedMatrixIndex(nrowblock,ncolblock,rowsizes,colsizes,l,u)
435-
end
428+
@require BlockArrays="8e7c35d0-a365-5155-bbbb-fb81a777f24e" begin
429+
function findstructralnz(x::BlockBandedMatrices.BlockBandedMatrix)
430+
l,u=BlockBandedMatrices.blockbandwidths(x)
431+
nrowblock=BlockBandedMatrices.blocksize(x,1)
432+
ncolblock=BlockBandedMatrices.blocksize(x,2)
433+
rowsizes=BlockArrays.blocklengths(axes(x,1))
434+
colsizes=BlockArrays.blocklengths(axes(x,2))
435+
BlockBandedMatrixIndex(nrowblock,ncolblock,rowsizes,colsizes,l,u)
436+
end
436437

437-
function findstructralnz(x::BlockBandedMatrices.BandedBlockBandedMatrix)
438-
l,u=BlockBandedMatrices.blockbandwidths(x)
439-
lambda,mu=BlockBandedMatrices.subblockbandwidths(x)
440-
nrowblock=BlockBandedMatrices.blocksize(x,1)
441-
ncolblock=BlockBandedMatrices.blocksize(x,2)
442-
rowsizes=BlockBandedMatrices.blocklengths(axes(x,1))
443-
colsizes=BlockBandedMatrices.blocklengths(axes(x,2))
444-
BandedBlockBandedMatrixIndex(nrowblock,ncolblock,rowsizes,colsizes,l,u,lambda,mu)
445-
end
438+
function findstructralnz(x::BlockBandedMatrices.BandedBlockBandedMatrix)
439+
l,u=BlockBandedMatrices.blockbandwidths(x)
440+
lambda,mu=BlockBandedMatrices.subblockbandwidths(x)
441+
nrowblock=BlockBandedMatrices.blocksize(x,1)
442+
ncolblock=BlockBandedMatrices.blocksize(x,2)
443+
rowsizes=BlockArrays.blocklengths(axes(x,1))
444+
colsizes=BlockArrays.blocklengths(axes(x,2))
445+
BandedBlockBandedMatrixIndex(nrowblock,ncolblock,rowsizes,colsizes,l,u,lambda,mu)
446+
end
446447

447-
has_sparsestruct(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
448-
has_sparsestruct(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
449-
is_structured(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
450-
is_structured(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
451-
fast_matrix_colors(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
452-
fast_matrix_colors(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
453-
454-
function matrix_colors(A::BlockBandedMatrices.BlockBandedMatrix)
455-
l,u=BlockBandedMatrices.blockbandwidths(A)
456-
blockwidth=l+u+1
457-
nblock=BlockBandedMatrices.blocksize(A,2)
458-
cols=blocklengths(axes(A,2))
459-
blockcolors=_cycle(1:blockwidth,nblock)
460-
#the reserved number of colors of a block is the maximum length of columns of blocks with the same block color
461-
ncolors=[maximum(cols[i:blockwidth:nblock]) for i in 1:blockwidth]
462-
endinds=cumsum(ncolors)
463-
startinds=[endinds[i]-ncolors[i]+1 for i in 1:blockwidth]
464-
colors=[(startinds[blockcolors[i]]:endinds[blockcolors[i]])[1:cols[i]] for i in 1:nblock]
465-
vcat(colors...)
466-
end
448+
has_sparsestruct(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
449+
has_sparsestruct(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
450+
is_structured(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
451+
is_structured(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
452+
fast_matrix_colors(::Type{<:BlockBandedMatrices.BlockBandedMatrix}) = true
453+
fast_matrix_colors(::Type{<:BlockBandedMatrices.BandedBlockBandedMatrix}) = true
454+
455+
function matrix_colors(A::BlockBandedMatrices.BlockBandedMatrix)
456+
l,u=BlockBandedMatrices.blockbandwidths(A)
457+
blockwidth=l+u+1
458+
nblock=BlockBandedMatrices.blocksize(A,2)
459+
cols=BlockArrays.blocklengths(axes(A,2))
460+
blockcolors=_cycle(1:blockwidth,nblock)
461+
#the reserved number of colors of a block is the maximum length of columns of blocks with the same block color
462+
ncolors=[maximum(cols[i:blockwidth:nblock]) for i in 1:blockwidth]
463+
endinds=cumsum(ncolors)
464+
startinds=[endinds[i]-ncolors[i]+1 for i in 1:blockwidth]
465+
colors=[(startinds[blockcolors[i]]:endinds[blockcolors[i]])[1:cols[i]] for i in 1:nblock]
466+
vcat(colors...)
467+
end
467468

468-
function matrix_colors(A::BlockBandedMatrices.BandedBlockBandedMatrix)
469-
l,u=BlockBandedMatrices.blockbandwidths(A)
470-
lambda,mu=BlockBandedMatrices.subblockbandwidths(A)
471-
blockwidth=l+u+1
472-
subblockwidth=lambda+mu+1
473-
nblock=BlockBandedMatrices.blocksize(A,2)
474-
cols=blocklengths(axes(A,2))
475-
blockcolors=_cycle(1:blockwidth,nblock)
476-
#the reserved number of colors of a block is the min of subblockwidth and the largest length of columns of blocks with the same block color
477-
ncolors=[min(subblockwidth,maximum(cols[i:blockwidth:nblock])) for i in 1:min(blockwidth,nblock)]
478-
endinds=cumsum(ncolors)
479-
startinds=[endinds[i]-ncolors[i]+1 for i in 1:min(blockwidth,nblock)]
480-
colors=[_cycle(startinds[blockcolors[i]]:endinds[blockcolors[i]],cols[i]) for i in 1:nblock]
481-
vcat(colors...)
469+
function matrix_colors(A::BlockBandedMatrices.BandedBlockBandedMatrix)
470+
l,u=BlockBandedMatrices.blockbandwidths(A)
471+
lambda,mu=BlockBandedMatrices.subblockbandwidths(A)
472+
blockwidth=l+u+1
473+
subblockwidth=lambda+mu+1
474+
nblock=BlockBandedMatrices.blocksize(A,2)
475+
cols=BlockArrays.blocklengths(axes(A,2))
476+
blockcolors=_cycle(1:blockwidth,nblock)
477+
#the reserved number of colors of a block is the min of subblockwidth and the largest length of columns of blocks with the same block color
478+
ncolors=[min(subblockwidth,maximum(cols[i:blockwidth:nblock])) for i in 1:min(blockwidth,nblock)]
479+
endinds=cumsum(ncolors)
480+
startinds=[endinds[i]-ncolors[i]+1 for i in 1:min(blockwidth,nblock)]
481+
colors=[_cycle(startinds[blockcolors[i]]:endinds[blockcolors[i]],cols[i]) for i in 1:nblock]
482+
vcat(colors...)
483+
end
482484
end
483-
484485
end
485486
end
486487

0 commit comments

Comments
 (0)