Skip to content

Commit 056560c

Browse files
authored
Move SparseArrays to an extension (#163)
* Move SparseArrays to an extension * bump version to v0.12.3
1 parent cb486f9 commit 056560c

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

Project.toml

Lines changed: 9 additions & 2 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.12.2"
3+
version = "0.12.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -12,6 +12,12 @@ MatrixFactorizations = "a3b82374-2e81-5b9e-98ce-41277c0e4c87"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1414

15+
[weakdeps]
16+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
17+
18+
[extensions]
19+
BlockBandedMatricesSparseArraysExt = "SparseArrays"
20+
1521
[compat]
1622
Aqua = "0.6"
1723
ArrayLayouts = "1"
@@ -24,7 +30,8 @@ julia = "1.6"
2430
[extras]
2531
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2632
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
33+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2734
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2835

2936
[targets]
30-
test = ["Aqua", "Random", "Test"]
37+
test = ["Aqua", "Random", "SparseArrays", "Test"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module BlockBandedMatricesSparseArraysExt
2+
3+
using BlockBandedMatrices
4+
using BandedMatrices
5+
using BandedMatrices: _banded_rowval, _banded_colval, _banded_nzval
6+
using BlockArrays: blockaxes, blockcolsupport
7+
import SparseArrays: sparse
8+
9+
function sparse(A::BandedBlockBandedMatrix)
10+
i = Vector{Int}()
11+
j = Vector{Int}()
12+
z = Vector{eltype(A)}()
13+
for J = blockaxes(A,2), K = blockcolsupport(A, J)
14+
B = view(A, K, J)
15+
= _banded_rowval(B)
16+
= _banded_colval(B)
17+
= _banded_nzval(B)
18+
.+= first(axes(A,1)[K])-1
19+
.+= first(axes(A,2)[J])-1
20+
append!(i, ĩ)
21+
append!(j, j̃)
22+
append!(z, z̃)
23+
end
24+
sparse(i, j, z, size(A)...)
25+
end
26+
27+
end

src/BandedBlockBandedMatrix.jl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,6 @@ axes(A::BandedBlockBandedMatrix) = (A.raxis, axes(A.data,2))
257257

258258
bandedblockbandeddata(A::BandedBlockBandedMatrix) = A.data
259259

260-
function sparse(A::BandedBlockBandedMatrix)
261-
i = Vector{Int}()
262-
j = Vector{Int}()
263-
z = Vector{eltype(A)}()
264-
for J = blockaxes(A,2), K = blockcolsupport(A, J)
265-
B = view(A, K, J)
266-
= _banded_rowval(B)
267-
= _banded_colval(B)
268-
= _banded_nzval(B)
269-
.+= first(axes(A,1)[K])-1
270-
.+= first(axes(A,2)[J])-1
271-
append!(i, ĩ)
272-
append!(j, j̃)
273-
append!(z, z̃)
274-
end
275-
sparse(i, j, z, size(A)...)
276-
end
277-
278260
################################
279261
# BandedBlockBandedMatrix Interface #
280262
################################

src/BlockBandedMatrices.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module BlockBandedMatrices
2-
using BlockArrays, BandedMatrices, ArrayLayouts, FillArrays, SparseArrays, MatrixFactorizations
2+
using BlockArrays, BandedMatrices, ArrayLayouts, FillArrays, MatrixFactorizations
33
using LinearAlgebra
44

55
import Base: getindex, setindex!, checkbounds, @propagate_inbounds, convert,
@@ -19,7 +19,6 @@ import LinearAlgebra.BLAS: BlasInt, BlasFloat, @blasfunc, BlasComplex, BlasReal
1919
import LinearAlgebra.LAPACK: chktrans, chkdiag, chklapackerror, checksquare, chkstride1,
2020
chkuplo
2121
import MatrixFactorizations: ql, ql!, _ql, QLPackedQ, AdjQRPackedQLayout, AdjQLPackedQLayout, QR, QRPackedQ
22-
import SparseArrays: sparse
2322

2423
import ArrayLayouts: BlasMatLmulVec, MatLmulVec, MatLmulMat,
2524
triangularlayout, UpperTriangularLayout, TriangularLayout, MatLdivVec,
@@ -42,8 +41,7 @@ import BandedMatrices: isbanded, bandwidths, bandwidth, banded_getindex, colrang
4241
BandedLayout, BandedColumnMajor, BandedColumns, bandedcolumns,
4342
BandedSubBandedMatrix, bandeddata,
4443
_BandedMatrix, colstart, colstop, rowstart, rowstop,
45-
BandedStyle, _fill_lmul!, bandshift,
46-
_banded_colval, _banded_rowval, _banded_nzval # for sparse
44+
BandedStyle, _fill_lmul!, bandshift
4745

4846
export BandedBlockBandedMatrix, BlockBandedMatrix, BlockSkylineMatrix, blockbandwidth, blockbandwidths,
4947
subblockbandwidth, subblockbandwidths, Ones, Zeros, Fill, Block, BlockTridiagonal, BlockBidiagonal, isblockbanded
@@ -68,4 +66,8 @@ include("interfaceimpl.jl")
6866
include("triblockbanded.jl")
6967
include("adjtransblockbanded.jl")
7068

69+
if !isdefined(Base, :get_extension)
70+
include("../ext/BlockBandedMatricesSparseArraysExt.jl")
71+
end
72+
7173
end # module

0 commit comments

Comments
 (0)