Skip to content

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

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

Closed
dlfivefifty opened this issue Aug 6, 2021 · 1 comment
Closed

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

dlfivefifty opened this issue Aug 6, 2021 · 1 comment

Comments

@dlfivefifty
Copy link
Member

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
@mtfishman
Copy link
Collaborator

This would be great to have! I have a use case for that (in my application I am permuting blocks of a block sparse array in order to merge them into bigger blocks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants