e3c6
1
The following code used to work in Julia v0.6.4, but it is not working in Julia v1.0.
struct Q
x::Int
end
f(q::Q, x::Int) = q.x + x
f.(Q(2), [1,2,3])
# ERROR: MethodError: no method matching length(::Q)
What should I do to broadcast on Q
as a scalar?
Base.Broadcast.broadcastable(q::Q) = Ref(q)
5 Likes
e3c6
3
What’s the reasoning for not having something like this as the default for new types?
Also, wrapping as a Ref
does not incur any performance costs?
Sukera
5
Also:
Although it wouldn’t have helped in this special case, the advice is generally sound if you’re porting old code (older than 0.7) to 0.7/1.0.
1 Like
e3c6
6