-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
It would be nice if these all worked:
julia> reduce(vcat, [OffsetArray([i; 10i;;], 3,4) for i in 1:2])
4×1 Matrix{Int64}:
1
10
2
20
julia> ans == vcat([OffsetArray([i; 10i;;], 3,4) for i in 1:2]...)
true
julia> reduce(vcat, [OffsetArray([i,10i],3) for i in 1:2])
ERROR: ArgumentError: offset arrays are not supported but got an array with index other than 1
Stacktrace:
[1] require_one_based_indexing
@ ./abstractarray.jl:127 [inlined]
[2] setindex!
@ ./array.jl:977 [inlined]
[3] _typed_vcat!(a::Vector{Int64}, V::Vector{OffsetVector{Int64, Vector{Int64}}})
@ Base ~/.julia/dev/julia/base/abstractarray.jl:1625
julia> vcat([OffsetArray([i,10i],3) for i in 1:2]...)
ERROR: ArgumentError: offset arrays are not supported but got an array with index other than 1
Relatedly, writing an offset vector into a Matrix is fine, but into a Vector (as above) does not work. However, writing into a SubArray does work again:
julia> let ov = OffsetArray([1,2],3)
x = rand(4,1)
x[2:3, :] = ov
x
end
4×1 Matrix{Float64}:
0.6150462970413711
1.0
2.0
0.019942484431290763
julia> let ov = OffsetArray([1,2],3)
x = rand(4)
x[2:3] = ov # writing into a vector it fails.
x
end
ERROR: ArgumentError: offset arrays are not supported but got an array with index other than 1
Stacktrace:
[1] require_one_based_indexing
@ ./abstractarray.jl:127 [inlined]
[2] setindex!(A::Vector{Float64}, X::OffsetVector{Int64, Vector{Int64}}, I::UnitRange{Int64})
@ Base ./array.jl:977
julia> let ov = OffsetArray([1,2],3)
x = rand(4)
xv = view(x, :) # not a Vector, a different path
xv[2:3] = ov
x
end
4-element Vector{Float64}:
0.009140994466162344
1.0
2.0
0.5207867417714482
Metadata
Metadata
Assignees
Labels
No labels