Skip to content

Dl/newblockarrays #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ os:
- linux
- osx
julia:
- 1.0
- 1.1
- 1.2
- 1.2
- 1.3
- nightly
matrix:
allow_failures:
Expand Down
6 changes: 3 additions & 3 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.6"
version = "0.7"

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

[compat]
BandedMatrices = "0.14"
BlockArrays = "0.10"
BlockArrays = "0.11"
FillArrays = "0.8"
ArrayLayouts = "0.1"
MatrixFactorizations = "0.2"
julia = "1"
julia = "1.2"
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
environment:
matrix:
- julia_version: 1
- julia_version: 1.1
- julia_version: 1.2
- julia_version: 1.2
- julia_version: 1.3
- julia_version: nightly

platform:
Expand Down
74 changes: 56 additions & 18 deletions src/AbstractBlockBandedMatrix.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
####
# Matrix memory layout traits
#
# if MemoryLayout(A) returns BandedColumnMajor, you must override
# pointer and leadingdimension
# in addition to the banded matrix interface
####

abstract type AbstractBlockBandedLayout <: MemoryLayout end

struct BandedBlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
struct BandedBlockBandedRows{LAY} <: AbstractBlockBandedLayout end
struct BlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
struct BlockBandedRows{LAY} <: AbstractBlockBandedLayout end

const BandedBlockBandedColumnMajor = BandedBlockBandedColumns{ColumnMajor}
const BandedBlockBandedRowMajor = BandedBlockBandedColumns{RowMajor}
const BlockBandedColumnMajor = BlockBandedColumns{ColumnMajor}
const BlockBandedRowMajor = BlockBandedColumns{RowMajor}

transposelayout(::BandedBlockBandedColumnMajor) = BandedBlockBandedRowMajor()
transposelayout(::BandedBlockBandedRowMajor) = BandedBlockBandedColumnMajor()
transposelayout(::BlockBandedColumnMajor) = BlockBandedRowMajor()
transposelayout(::BlockBandedRowMajor) = BlockBandedColumnMajor()
conjlayout(::Type{<:Complex}, M::AbstractBlockBandedLayout) = ConjLayout(M)



# AbstractBandedMatrix must implement

# A BlockBandedMatrix is a BlockMatrix, but is not a BandedMatrix
Expand All @@ -9,7 +37,7 @@ abstract type AbstractBlockBandedMatrix{T} <: AbstractBlockMatrix{T} end

Returns a tuple containing the upper and lower blockbandwidth of `A`.
"""
blockbandwidths(A::AbstractMatrix) = (nblocks(A,1)-1 , nblocks(A,2)-1)
blockbandwidths(A::AbstractMatrix) = (blocksize(A,1)-1 , blocksize(A,2)-1)

"""
blockbandwidth(A,i)
Expand All @@ -29,9 +57,9 @@ blockbandrange(A::AbstractMatrix) = -blockbandwidth(A,1):blockbandwidth(A,2)

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

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

# this gives the block bandwidth in each block column/row
@inline colblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), nblocks(A,2))
@inline rowblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), nblocks(A,1))
@inline colblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), blocksize(A,2))
@inline rowblockbandwidths(A::AbstractMatrix) = Fill.(blockbandwidths(A), blocksize(A,1))

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

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


@inline function colstart(A::AbstractBlockBandedMatrix, i::Integer)
bs = A.block_sizes.block_sizes
bs.cumul_sizes[1][Int(blockcolstart(A, _find_block(bs, 2, i)[1]))]
end
@inline function colstop(A::AbstractBlockBandedMatrix, i::Integer)
bs = A.block_sizes.block_sizes
bs.cumul_sizes[1][Int(blockcolstop(A, _find_block(bs, 2, i)[1]))+1]-1
end
@inline function rowstart(A::AbstractBlockBandedMatrix, i::Integer)
bs = A.block_sizes.block_sizes
bs.cumul_sizes[2][Int(blockrowstart(A, _find_block(bs, 1, i)[1]))]
CS = blockcolstop(A,findblock(axes(A,2),i))
CS == Block(0) && return 0
last(axes(A,1)[CS])
end

@inline rowstart(A::AbstractBlockBandedMatrix, i::Integer) =
first(axes(A,2)[blockrowstart(A,findblock(axes(A,1),i))])

@inline function rowstop(A::AbstractBlockBandedMatrix, i::Integer)
bs = A.block_sizes.block_sizes
bs.cumul_sizes[2][Int(blockrowstop(A, _find_block(bs, 1, i)[1]))+1]-1
CS = blockrowstop(A,findblock(axes(A,1),i))
CS == Block(0) && return 0
last(axes(A,2)[CS])
end

@inline blockbanded_colsupport(A, j::Integer) = colrange(A, j)
@inline blockbanded_rowsupport(A, j::Integer) = rowrange(A, j)

@inline blockbanded_rowsupport(A, j) = isempty(j) ? (1:0) : rowstart(A,minimum(j)):rowstop(A,maximum(j))
@inline blockbanded_colsupport(A, j) = isempty(j) ? (1:0) : colstart(A,minimum(j)):colstop(A,maximum(j))

@inline colsupport(::AbstractBlockBandedLayout, A, j) = blockbanded_colsupport(A, j)
@inline rowsupport(::AbstractBlockBandedLayout, A, j) = blockbanded_rowsupport(A, j)



# default implementation loops over all indices, including zeros
function fill!(A::AbstractBlockBandedMatrix, val::Any)
iszero(val) || throw(BandError(A))
Expand Down
Loading