Skip to content

Commit

Permalink
Move SparseArrays to an extension (#163)
Browse files Browse the repository at this point in the history
* Move SparseArrays to an extension

* bump version to v0.12.3
  • Loading branch information
jishnub authored Jul 27, 2023
1 parent cb486f9 commit 056560c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockBandedMatrices"
uuid = "ffab5731-97b5-5995-9138-79e8c1846df0"
version = "0.12.2"
version = "0.12.3"

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

[weakdeps]
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[extensions]
BlockBandedMatricesSparseArraysExt = "SparseArrays"

[compat]
Aqua = "0.6"
ArrayLayouts = "1"
Expand All @@ -24,7 +30,8 @@ julia = "1.6"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Random", "Test"]
test = ["Aqua", "Random", "SparseArrays", "Test"]
27 changes: 27 additions & 0 deletions ext/BlockBandedMatricesSparseArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module BlockBandedMatricesSparseArraysExt

using BlockBandedMatrices
using BandedMatrices
using BandedMatrices: _banded_rowval, _banded_colval, _banded_nzval
using BlockArrays: blockaxes, blockcolsupport
import SparseArrays: sparse

function sparse(A::BandedBlockBandedMatrix)
i = Vector{Int}()
j = Vector{Int}()
z = Vector{eltype(A)}()
for J = blockaxes(A,2), K = blockcolsupport(A, J)
B = view(A, K, J)
= _banded_rowval(B)
= _banded_colval(B)
= _banded_nzval(B)
.+= first(axes(A,1)[K])-1
.+= first(axes(A,2)[J])-1
append!(i, ĩ)
append!(j, j̃)
append!(z, z̃)
end
sparse(i, j, z, size(A)...)
end

end
18 changes: 0 additions & 18 deletions src/BandedBlockBandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,6 @@ axes(A::BandedBlockBandedMatrix) = (A.raxis, axes(A.data,2))

bandedblockbandeddata(A::BandedBlockBandedMatrix) = A.data

function sparse(A::BandedBlockBandedMatrix)
i = Vector{Int}()
j = Vector{Int}()
z = Vector{eltype(A)}()
for J = blockaxes(A,2), K = blockcolsupport(A, J)
B = view(A, K, J)
= _banded_rowval(B)
= _banded_colval(B)
= _banded_nzval(B)
.+= first(axes(A,1)[K])-1
.+= first(axes(A,2)[J])-1
append!(i, ĩ)
append!(j, j̃)
append!(z, z̃)
end
sparse(i, j, z, size(A)...)
end

################################
# BandedBlockBandedMatrix Interface #
################################
Expand Down
10 changes: 6 additions & 4 deletions src/BlockBandedMatrices.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module BlockBandedMatrices
using BlockArrays, BandedMatrices, ArrayLayouts, FillArrays, SparseArrays, MatrixFactorizations
using BlockArrays, BandedMatrices, ArrayLayouts, FillArrays, MatrixFactorizations
using LinearAlgebra

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

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

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

if !isdefined(Base, :get_extension)
include("../ext/BlockBandedMatricesSparseArraysExt.jl")
end

end # module

2 comments on commit 056560c

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/88445

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.3 -m "<description of version>" 056560c5c960c3f295aba6ec7ce8a675e82d6da6
git push origin v0.12.3

Please sign in to comment.