Skip to content

Add support for multiple layers of block arrays #49

@dlfivefifty

Description

@dlfivefifty

It's sometimes useful to have multiple layers of blocks, see conversation in

SciML/MultiScaleArrays.jl#25

I think one way to do this would be to support some sort of BlockView that converts an AbstractBlockVector{T} into an AbstractVector{Vector{T}}:

struct BlockView{AT, p, BA <: AbstractBlockArray} <: AbstractArray{AT, p}
   data::BA
end

_BlockView(data::BA) where BA<:AbstractBlockArray{T,p} where T = BlockView{Array{T,p},p,BA}(data)

getindex(A::BlockView, i...) = A[Block(i...)]
size(A::BlockView) = nblocks(A)

Then one create a hierarchical block array view (here we have sub-blocks of length 10 and super-blocks of length 5):

A_sub = PseudoBlockArray(randn(10*5*n), fill(10,5n))
A = PseudoBlockArray(BlockView(A_sub), fill(5,n))
A[Block(2)][3]  # returns the 3rd sub-block of the 2nd super-block

I'm still working out how to get it to work with A[Block(2)][Block(3)]...

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