Skip to content

broadcast fails - bad error message #348

@lmiq

Description

@lmiq

This is both a feature request and the report that the error message is not good:

julia> using OffsetArrays

julia> x = OffsetArray([1,2,3], 0:2)
3-element OffsetArray(::Vector{Int64}, 0:2) with eltype Int64 with indices 0:2:
 1
 2
 3

julia> x .+ [1,2,3]
ERROR: DimensionMismatch: arrays could not be broadcast to a common size; got a dimension with lengths 3 and 3
Stacktrace:
 [1] _bcs1
   @ ./broadcast.jl:555 [inlined]
 [2] _bcs
   @ ./broadcast.jl:549 [inlined]
 [3] broadcast_shape
   @ ./broadcast.jl:543 [inlined]
 [4] combine_axes
   @ ./broadcast.jl:524 [inlined]
 [5] instantiate
   @ ./broadcast.jl:306 [inlined]
 [6] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{…}, Nothing, typeof(+), Tuple{…}})
   @ Base.Broadcast ./broadcast.jl:903
 [7] top-level scope
   @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

First, it would be nice if broadcasting worked in such a case. Second, in any case, the error message is not good and does not point to any possible solution, if supporting broadcasting in these cases is not possible for more fundamental reasons.

I guess there is the question on the nature of the indices of the returned array.

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