Skip to content

Preserving band structure in concatenations #480

@andreasvarga

Description

@andreasvarga

Is any way to preserve the band structure in some concatenations, as for example, in the folowing construction:

A = BandedMatrix(0=>rand(10))
Ab = [A zeros(10,4); zeros(4,10) Diagonal(rand(4,4))]

with

Ab = 14×14 BandedMatrix{Float64} with bandwidths (0, 0):
 0.292548   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅ 
  ⋅        0.230225   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅        0.800509   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅        0.564469   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅        0.538882   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅        0.838634   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.575544   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.322138   ⋅         ⋅         ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.610594   ⋅         ⋅         ⋅         ⋅         ⋅ 
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.998941   ⋅         ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.330766   ⋅         ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.604465   ⋅         ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.754899   ⋅
  ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅         ⋅        0.10646

However the following produces an error

Ab = [A zeros(10,4); zeros(4,10) rand(4,4)]
ERROR: BandError: attempt to access BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}} with bandwidths (0, 0) at band -1
Stacktrace:
 [1] checkbandmatch(A::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, V::Matrix{Float64}, kr::UnitRange{Int64}, jr::UnitRange{Int64})
   @ BandedMatrices C:\Users\Andreas\.julia\packages\BandedMatrices\KJZ2p\src\generic\Band.jl:175
 [2] setindex!(A::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, V::Matrix{Float64}, kr::UnitRange{Int64}, jr::UnitRange{Int64})
   @ BandedMatrices C:\Users\Andreas\.julia\packages\BandedMatrices\KJZ2p\src\banded\BandedMatrix.jl:760
 [3] typed_hvcat(::Type{Float64}, ::Tuple{Int64, Int64}, ::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, ::Vararg{AbstractVecOrMat})
   @ Base .\abstractarray.jl:2193
 [4] hvcat(::Tuple{Int64, Int64}, ::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, ::Vararg{AbstractArray{Float64}})
   @ Base .\abstractarray.jl:2160
 [5] top-level scope
   @ REPL[4]:1

It would be nice to automatically produce a banded matrix with suitable bandwith.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions