Skip to content

Broadcasting over views with non-Int indices fails (or creates an OffsetArray) #32442

@jaakkor2

Description

@jaakkor2

Some variation of the view does not get broadcasted due to MethodError.

a=rand(UInt32,20); b=view(a,UInt64.(11:20)); c=rand(UInt64,5); tmp=reinterpret(UInt64,b) .- c # ok
a=rand(UInt32,20); b=view(a,(11:20)); c=rand(UInt64,5); tmp=reinterpret(UInt64,b) .- c # ok
a=rand(UInt32,20); b=view(a,(UInt64(11):UInt64(20))); c=rand(UInt64,5); tmp=reinterpret(UInt64,b) .- c # not ok
ERROR: MethodError: no method matching similar(::Type{Array{UInt64,N} where N}, ::Tuple{UnitRange{Int64}})
Closest candidates are:
  similar(::AbstractArray{T,N} where N, ::Tuple) where T at abstractarray.jl:573
  similar(::Type{T<:AbstractArray}, ::Union{Integer, AbstractUnitRange}...) where T<:AbstractArray at abstractarray.jl:616
  similar(::Type{T<:AbstractArray}, ::Tuple{Vararg{Int64,N}} where N) where T<:AbstractArray at abstractarray.jl:618
  ...
Stacktrace:
 [1] similar(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Tuple{UnitRange{Int64}},typeof(-),Tuple{Base.ReinterpretArray{UInt64,1,UInt32,SubArray{UInt32,1,Array{UInt32,1},Tuple{UnitRange{UInt64}},true}},Array{UInt64,1}}}, ::Type{UInt64}) at .\broadcast.jl:196
 [2] copy at .\broadcast.jl:773 [inlined]
 [3] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(-),Tuple{Base.ReinterpretArray{UInt64,1,UInt32,SubArray{UInt32,1,Array{UInt32,1},Tuple{UnitRange{UInt64}},true}},Array{UInt64,1}}}) at .\broadcast.jl:753
 [4] top-level scope at none:0

This works

a=rand(UInt32,20); b=view(a,(UInt64(11):UInt64(20))); c=rand(UInt64,5); tmp=copy(reinterpret(UInt64,b)) .- c # ok

and a bit surprisingly this as well

using Interpolations
a=rand(UInt32,20); b=view(a,(UInt64(11):UInt64(20))); c=rand(UInt64,5); tmp=reinterpret(UInt64,b) .- c # now ok

this failed above, now the output is an OffsetArray.

Version info as follows

julia> versioninfo()
Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]broadcastApplying a function over a collectionbugIndicates an unexpected problem or unintended behaviorregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions