Skip to content

Fix indexing with Vector{Block{1}} #184

Closed
@dlfivefifty

Description

@dlfivefifty

Below gives an error. I think Vector{<:Block{1}} indexing should work like BlockRange, but this needs some thought.

julia> a = BlockArray(1:6, [1,2,2,1])
4-blocked 6-element BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{Vector{Int64}}}}:
 12
 34
 56

julia> a[Block.(2:3)]
2-blocked 4-element BlockArray{Int64,1}:
 2
 34
 5

julia> a[collect(Block.(2:3))]
ERROR: MethodError: Cannot `convert` an object of type UnitRange{Int64} to an object of type Int64
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number at number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...
Stacktrace:
  [1] setindex!(A::Vector{Int64}, x::UnitRange{Int64}, i1::Int64)
    @ Base ./array.jl:839
  [2] copyto_unaliased!(deststyle::IndexLinear, dest::Vector{Int64}, srcstyle::IndexCartesian, src::SubArray{Int64, 1, BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, Tuple{Vector{Block{1, Int64}}}, false})
    @ Base ./abstractarray.jl:976
  [3] copyto!
    @ ./abstractarray.jl:950 [inlined]
  [4] _copyto!
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:205 [inlined]
  [5] _copyto!
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:209 [inlined]
  [6] copyto!
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:218 [inlined]
  [7] copyto_axcheck!(dest::Vector{Int64}, src::SubArray{Int64, 1, BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, Tuple{Vector{Block{1, Int64}}}, false})
    @ Base ./abstractarray.jl:1056
  [8] Array
    @ ./array.jl:540 [inlined]
  [9] Array
    @ ./boot.jl:472 [inlined]
 [10] sub_materialize
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:101 [inlined]
 [11] sub_materialize
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:102 [inlined]
 [12] sub_materialize
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:103 [inlined]
 [13] layout_getindex
    @ ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:109 [inlined]
 [14] getindex(A::BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{Vector{Int64}}}}, kr::Vector{Block{1, Int64}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/3lnt1/src/ArrayLayouts.jl:160
 [15] top-level scope
    @ REPL[5]:1

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