Skip to content

Conversion of Block to Tuple #317

@mtfishman

Description

@mtfishman

It would be nice to be able to convert a Block to a Tuple. Of course it leaves the question of whether it should convert to a tuple of Integer or Block{1}. I would vote for the latter but I could see arguments either way.

This would be analagous to:

julia> Tuple(CartesianIndex(2, 2))
(2, 2)

in Base, so either:

julia> using BlockArrays

julia> Base.Tuple(b::Block) = b.n
Tuple

julia> Tuple(Block(2, 2))
(2, 2)

or:

julia> Base.Tuple(b::Block) = Block.(b.n)
Tuple

julia> Tuple(Block(2, 2))
(Block(2), Block(2))

There are a number of places in the source code where the definition Base.Tuple(b::Block) = Block.(b.n) would be useful, for example:

k, j = b.n

to_indices(A, inds, (Block.(I[1].n)..., tail(I)...))

Block{N, T}(ntuple(i -> blocks[i].n[1], Val(N)))

range = getindex.(axes(block_arr), Block.(block.n))

It seems common to want a Tuple of Block{1} so perhaps that could guide the design choice (also that it loses less information about the input, so is closer in spirit to a conversion).

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