Skip to content
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

broadcast fails - bad error message #348

Closed
lmiq opened this issue Mar 14, 2024 · 2 comments
Closed

broadcast fails - bad error message #348

lmiq opened this issue Mar 14, 2024 · 2 comments

Comments

@lmiq
Copy link

lmiq commented Mar 14, 2024

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.

@jishnub
Copy link
Member

jishnub commented Mar 14, 2024

Re. the error message, this needs to be fixed in Base (something similar to JuliaLang/julia#41311). There is certainly scope for a much better error message here, and it's just that someone needs to do the work and submit a PR.

it would be nice if broadcasting worked in such a case

This is also prohibited by Base at present. I doubt that there's anything inherent in OffsetArrays that prevents this.

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

Exactly, what would be the axes of the result? In particular, if we have two offset arrays (instead of only one), what axes does the result have? I think this is the main unresolved point.

@lmiq lmiq closed this as completed Mar 14, 2024
@jishnub
Copy link
Member

jishnub commented Mar 14, 2024

The error message seems to have improved on Julia v1.11.0-alpha1:

julia> x .+ [1,2,3]
ERROR: DimensionMismatch: arrays could not be broadcast to a common size: a has axes OffsetArrays.IdOffsetRange(values=0:2, indices=0:2) and b has axes Base.OneTo(3)
[...]

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