Skip to content

Commit bfaaf0b

Browse files
authored
Add copy for BandedBlockBandedMatrix (#102)
* Add copy for BandedBlockBandedMatrix * add converts * Update test_bandedblockbanded.jl * turn of doc test
1 parent b1095a9 commit bfaaf0b

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.10.0"
3+
version = "0.10.1"
44

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

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Documenter, BlockBandedMatrices
33
makedocs(
44
modules = [BlockBandedMatrices],
55
sitename = "BlockBandedMatrices.jl",
6-
strict = VERSION.major == 1 && sizeof(Int) == 8, # only strict mode on 1.0 and Int64
6+
strict = false, # VERSION.major == 1 && sizeof(Int) == 8, # only strict mode on 1.0 and Int64
77
pages = Any[
88
"Home" => "index.md"
99
]

src/BandedBlockBandedMatrix.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ BandedBlockBandedMatrix(A::AbstractMatrix{T}) where T = BandedBlockBandedMatrix{
220220
BandedBlockBandedMatrix(A::AbstractMatrix, rdims::AbstractVector{Int}, cdims::AbstractVector{Int}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
221221
BandedBlockBandedMatrix(A, (blockedrange(rdims), blockedrange(cdims)), lu, λμ)
222222

223+
copy(B::BandedBlockBandedMatrix) = _BandedBlockBandedMatrix(copy(B.data), B.raxis, blockbandwidths(B), subblockbandwidths(B))
224+
AbstractArray{T}(B::BandedBlockBandedMatrix) where T = _BandedBlockBandedMatrix(AbstractArray{T}(B.data), B.raxis, blockbandwidths(B), subblockbandwidths(B))
225+
AbstractMatrix{T}(B::BandedBlockBandedMatrix) where T = _BandedBlockBandedMatrix(AbstractMatrix{T}(B.data), B.raxis, blockbandwidths(B), subblockbandwidths(B))
226+
convert(::Type{AbstractArray{T}}, B::BandedBlockBandedMatrix) where T = _BandedBlockBandedMatrix(convert(AbstractArray{T},B.data), B.raxis, blockbandwidths(B), subblockbandwidths(B))
227+
convert(::Type{AbstractMatrix{T}}, B::BandedBlockBandedMatrix) where T = _BandedBlockBandedMatrix(convert(AbstractMatrix{T},B.data), B.raxis, blockbandwidths(B), subblockbandwidths(B))
228+
convert(::Type{AbstractArray{T}}, B::BandedBlockBandedMatrix{T}) where T = B
229+
convert(::Type{AbstractMatrix{T}}, B::BandedBlockBandedMatrix{T}) where T = B
230+
231+
223232
similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::NTuple{2,AbstractUnitRange{Int}}) where T =
224233
BandedBlockBandedMatrix{T}(undef, axes, blockbandwidths(A), subblockbandwidths(A))
225234

src/BlockBandedMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Base: getindex, setindex!, checkbounds, @propagate_inbounds, convert,
77
unsafe_convert, fill!, length, first, last,
88
eltype, getindex, to_indices, to_index,
99
reindex, _maybetail, tail, @_propagate_inbounds_meta,
10-
==, axes, copyto!, similar, OneTo
10+
==, axes, copy, copyto!, similar, OneTo
1111

1212
import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, DefaultArrayStyle, Broadcasted, broadcasted,
1313
materialize, materialize!

test/test_bandedblockbanded.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using BlockArrays, BandedMatrices, BlockBandedMatrices, FillArrays, SparseArrays, Test, ArrayLayouts , LinearAlgebra
2-
import BlockBandedMatrices: _BandedBlockBandedMatrix, blockcolsupport, blockrowsupport, colsupport, rowsupport,
2+
import BlockBandedMatrices: _BandedBlockBandedMatrix, blockcolsupport, blockrowsupport, colsupport, rowsupport,
33
isbandedblockbanded, bandeddata, BandedBlockBandedColumns
44
import ArrayLayouts: RangeCumsum
55

@@ -300,7 +300,7 @@ import ArrayLayouts: RangeCumsum
300300
@test B isa BandedBlockBandedMatrix
301301
@test blockbandwidths(V) == blockbandwidths(B) == (2,0)
302302
@test subblockbandwidths(V) == subblockbandwidths(B) == subblockbandwidths(A) == (λ,μ)
303-
@test B == V == A[Block.(2:3), Block.(3:4)]
303+
@test B == V == A[Block.(2:3), Block.(3:4)]
304304

305305
@test A[Block.(2:3), Block.(3:4)] isa BandedBlockBandedMatrix
306306

@@ -504,6 +504,18 @@ import ArrayLayouts: RangeCumsum
504504
A = _BandedBlockBandedMatrix(data, rows,cols, (l,u), (λ,μ))
505505
@test A == BandedBlockBandedMatrix(A, (2,1), (2,1)) == BandedBlockBandedMatrix{Float64}(A, (2,1), (2,1))
506506
end
507+
508+
@testset "convert" begin
509+
l , u = 1,1
510+
λ , μ = 1,1
511+
N = M = 4
512+
cols = rows = 1:N
513+
data = reshape(collect(1:+μ+1)*(l+u+1)*sum(cols)), ((λ+μ+1)*(l+u+1), sum(cols)))
514+
A = _BandedBlockBandedMatrix(data, rows,cols, (l,u), (λ,μ))
515+
@test AbstractArray{Float64}(A) == AbstractMatrix{Float64}(A) == AbstractArray{Int}(A) == AbstractMatrix{Int}(A) == copy(A) == A
516+
@test convert(AbstractArray{Float64}, A) == convert(AbstractMatrix{Float64}, A) == A
517+
@test convert(AbstractArray{Int}, A) convert(AbstractMatrix{Int}, A) A
518+
end
507519
end
508520

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

0 commit comments

Comments
 (0)