Skip to content

Commit 2551b75

Browse files
authored
Dl/newblockarrays (#53)
* Move over to new BlockArrays * basic functionbality * Some tests passing * BlockSkyline tests * basic BandedBlockBandedMatrix * Block skyline tests pass * Tests almost pass * Up to misc tests * tests pass!! * blockedrange * support backends that just support block interface * CumsumBlockRange -> BlockedUnitRange * _cumsum -> _blocklengs2blocklasts * Update BlockBandedMatrices.jl * Julia v1.2 minmum * work on memory layout
1 parent 1c3b9d4 commit 2551b75

21 files changed

+491
-578
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 1.0
8-
- 1.1
9-
- 1.2
7+
- 1.2
8+
- 1.3
109
- nightly
1110
matrix:
1211
allow_failures:

Project.toml

Lines changed: 3 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.6"
3+
version = "0.7"
44

55
[deps]
66
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
@@ -19,8 +19,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1919

2020
[compat]
2121
BandedMatrices = "0.14"
22-
BlockArrays = "0.10"
22+
BlockArrays = "0.11"
2323
FillArrays = "0.8"
2424
ArrayLayouts = "0.1"
2525
MatrixFactorizations = "0.2"
26-
julia = "1"
26+
julia = "1.2"

appveyor.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
environment:
22
matrix:
3-
- julia_version: 1
4-
- julia_version: 1.1
5-
- julia_version: 1.2
3+
- julia_version: 1.2
4+
- julia_version: 1.3
65
- julia_version: nightly
76

87
platform:

src/AbstractBlockBandedMatrix.jl

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
####
2+
# Matrix memory layout traits
3+
#
4+
# if MemoryLayout(A) returns BandedColumnMajor, you must override
5+
# pointer and leadingdimension
6+
# in addition to the banded matrix interface
7+
####
8+
9+
abstract type AbstractBlockBandedLayout <: MemoryLayout end
10+
11+
struct BandedBlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
12+
struct BandedBlockBandedRows{LAY} <: AbstractBlockBandedLayout end
13+
struct BlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
14+
struct BlockBandedRows{LAY} <: AbstractBlockBandedLayout end
15+
16+
const BandedBlockBandedColumnMajor = BandedBlockBandedColumns{ColumnMajor}
17+
const BandedBlockBandedRowMajor = BandedBlockBandedColumns{RowMajor}
18+
const BlockBandedColumnMajor = BlockBandedColumns{ColumnMajor}
19+
const BlockBandedRowMajor = BlockBandedColumns{RowMajor}
20+
21+
transposelayout(::BandedBlockBandedColumnMajor) = BandedBlockBandedRowMajor()
22+
transposelayout(::BandedBlockBandedRowMajor) = BandedBlockBandedColumnMajor()
23+
transposelayout(::BlockBandedColumnMajor) = BlockBandedRowMajor()
24+
transposelayout(::BlockBandedRowMajor) = BlockBandedColumnMajor()
25+
conjlayout(::Type{<:Complex}, M::AbstractBlockBandedLayout) = ConjLayout(M)
26+
27+
28+
129
# AbstractBandedMatrix must implement
230

331
# A BlockBandedMatrix is a BlockMatrix, but is not a BandedMatrix
@@ -9,7 +37,7 @@ abstract type AbstractBlockBandedMatrix{T} <: AbstractBlockMatrix{T} end
937
1038
Returns a tuple containing the upper and lower blockbandwidth of `A`.
1139
"""
12-
blockbandwidths(A::AbstractMatrix) = (nblocks(A,1)-1 , nblocks(A,2)-1)
40+
blockbandwidths(A::AbstractMatrix) = (blocksize(A,1)-1 , blocksize(A,2)-1)
1341

1442
"""
1543
blockbandwidth(A,i)
@@ -29,9 +57,9 @@ blockbandrange(A::AbstractMatrix) = -blockbandwidth(A,1):blockbandwidth(A,2)
2957

3058
# start/stop indices of the i-th column/row, bounded by actual matrix size
3159
@inline blockcolstart(A::AbstractVecOrMat, i::Integer) = Block(max(i-colblockbandwidth(A,2)[i], 1))
32-
@inline blockcolstop(A::AbstractVecOrMat, i::Integer) = Block(max(min(i+colblockbandwidth(A,1)[i], nblocks(A, 1)), 0))
60+
@inline blockcolstop(A::AbstractVecOrMat, i::Integer) = Block(max(min(i+colblockbandwidth(A,1)[i], blocksize(A, 1)), 0))
3361
@inline blockrowstart(A::AbstractVecOrMat, i::Integer) = Block(max(i-rowblockbandwidth(A,1)[i], 1))
34-
@inline blockrowstop(A::AbstractVecOrMat, i::Integer) = Block(max(min(i+rowblockbandwidth(A,2)[i], nblocks(A, 2)), 0))
62+
@inline blockrowstop(A::AbstractVecOrMat, i::Integer) = Block(max(min(i+rowblockbandwidth(A,2)[i], blocksize(A, 2)), 0))
3563

3664
for Func in (:blockcolstart, :blockcolstop, :blockrowstart, :blockrowstop)
3765
@eval $Func(A, i::Block{1}) = $Func(A, Int(i))
@@ -46,8 +74,8 @@ end
4674
@inline blockrowlength(A::AbstractVecOrMat, i) = max(Int(blockrowstop(A, i)) - Int(blockrowstart(A, i)) + 1, 0)
4775

4876
# this gives the block bandwidth in each block column/row
49-
@inline colblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), nblocks(A,2))
50-
@inline rowblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), nblocks(A,1))
77+
@inline colblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), blocksize(A,2))
78+
@inline rowblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), blocksize(A,1))
5179

5280
@inline colblockbandwidth(bs, i::Int) = colblockbandwidths(bs)[i]
5381
@inline rowblockbandwidth(bs, i::Int) = rowblockbandwidths(bs)[i]
@@ -88,25 +116,35 @@ const BlockSlice1 = BlockSlice{Block{1,Int}}
88116
# RaggedMatrix interface
89117
######################################
90118

119+
@inline colstart(A::AbstractBlockBandedMatrix, i::Integer) =
120+
first(axes(A,1)[blockcolstart(A,findblock(axes(A,2),i))])
91121

92-
93-
@inline function colstart(A::AbstractBlockBandedMatrix, i::Integer)
94-
bs = A.block_sizes.block_sizes
95-
bs.cumul_sizes[1][Int(blockcolstart(A, _find_block(bs, 2, i)[1]))]
96-
end
97122
@inline function colstop(A::AbstractBlockBandedMatrix, i::Integer)
98-
bs = A.block_sizes.block_sizes
99-
bs.cumul_sizes[1][Int(blockcolstop(A, _find_block(bs, 2, i)[1]))+1]-1
100-
end
101-
@inline function rowstart(A::AbstractBlockBandedMatrix, i::Integer)
102-
bs = A.block_sizes.block_sizes
103-
bs.cumul_sizes[2][Int(blockrowstart(A, _find_block(bs, 1, i)[1]))]
123+
CS = blockcolstop(A,findblock(axes(A,2),i))
124+
CS == Block(0) && return 0
125+
last(axes(A,1)[CS])
104126
end
127+
128+
@inline rowstart(A::AbstractBlockBandedMatrix, i::Integer) =
129+
first(axes(A,2)[blockrowstart(A,findblock(axes(A,1),i))])
130+
105131
@inline function rowstop(A::AbstractBlockBandedMatrix, i::Integer)
106-
bs = A.block_sizes.block_sizes
107-
bs.cumul_sizes[2][Int(blockrowstop(A, _find_block(bs, 1, i)[1]))+1]-1
132+
CS = blockrowstop(A,findblock(axes(A,1),i))
133+
CS == Block(0) && return 0
134+
last(axes(A,2)[CS])
108135
end
109136

137+
@inline blockbanded_colsupport(A, j::Integer) = colrange(A, j)
138+
@inline blockbanded_rowsupport(A, j::Integer) = rowrange(A, j)
139+
140+
@inline blockbanded_rowsupport(A, j) = isempty(j) ? (1:0) : rowstart(A,minimum(j)):rowstop(A,maximum(j))
141+
@inline blockbanded_colsupport(A, j) = isempty(j) ? (1:0) : colstart(A,minimum(j)):colstop(A,maximum(j))
142+
143+
@inline colsupport(::AbstractBlockBandedLayout, A, j) = blockbanded_colsupport(A, j)
144+
@inline rowsupport(::AbstractBlockBandedLayout, A, j) = blockbanded_rowsupport(A, j)
145+
146+
147+
110148
# default implementation loops over all indices, including zeros
111149
function fill!(A::AbstractBlockBandedMatrix, val::Any)
112150
iszero(val) || throw(BandError(A))

0 commit comments

Comments
 (0)