-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Description
using OffsetArrays
i = OffsetArray([1,2,3], -3)
similar(typeof(i), axes(i))
I would expect this code to construct an OffsetArray
with a similar
backing array. The current version of the package appears to be lacking such an implementation and it would be nice for it to have this.
My own use case is that I have my own array type that may itself be backed by an OffsetArray
, and calling similar
on such an array type (e.g. during broadcasting) would fail due to a lack of this very method.
Error message
ERROR: MethodError: no method matching OffsetVector{Int64, UnitRange{Int64}}(::UndefInitializer, ::Tuple{Int64})
Closest candidates are:
OffsetArray{T, N, AA}(::AA, ::Tuple{Vararg{Int64, N}}; checkoverflow) where {T, N, AA<:AbstractArray{T, N}} at ~/.julia/packages/OffsetArrays/TKbp1/src/OffsetArrays.jl:115
OffsetArray{T, N, A}(::AbstractArray{var"#s8", N} where var"#s8", ::Tuple{Vararg{Int64, N}}; checkoverflow) where {T, N, A<:AbstractArray{T, N}} at ~/.julia/packages/OffsetArrays/TKbp1/src/OffsetArrays.jl:224
OffsetArray{T, N, AA}(::AbstractArray{var"#s8", N} where var"#s8", ::Tuple{Vararg{Integer, N}}; kw...) where {T, N, AA<:AbstractArray{T, N}} at ~/.julia/packages/OffsetArrays/TKbp1/src/OffsetArrays.jl:231
...
Stacktrace:
[1] similar(#unused#::Type{OffsetVector{Int64, UnitRange{Int64}}}, dims::Tuple{Int64})
@ Base ./abstractarray.jl:785
[2] similar(#unused#::Type{OffsetVector{Int64, UnitRange{Int64}}}, shape::Tuple{Base.OneTo{Int64}})
@ Base ./abstractarray.jl:784
[3] _similar_axes_or_length(AT::Type, ax::Tuple{Base.OneTo{Int64}}, #unused#::Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}})
@ OffsetArrays ~/.julia/packages/OffsetArrays/TKbp1/src/OffsetArrays.jl:334
[4] similar(#unused#::Type{OffsetVector{Int64, UnitRange{Int64}}}, shape::Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}})
@ OffsetArrays ~/.julia/packages/OffsetArrays/TKbp1/src/OffsetArrays.jl:325
[5] top-level scope
@ REPL[7]:1
Metadata
Metadata
Assignees
Labels
No labels