Broadcast and .* not the same

I have an AutoVector type for which broadcast(,v,v) works but v . v doesn’t. The indexing is
more flexible than the usual type, so I don’t want it to be a subtype of AbstractVector. Here is
a drastically simplified set of code that illustrates the problem:

mutable struct AutoVector  
    dat::Vector{Float64}
end

import Base.broadcast
function broadcast(::typeof(*),x::AutoVector,y::AutoVector)
    println("got here")
end

av = AutoVector([1.0])

println("Calling broadcast")
broadcast(*,av,av)

println("Calling .*")
av .* av

================================
This is julia 0.6.2
julia AV2.jl

Calling broadcast
got here
Calling .*
ERROR: LoadError: MethodError: no method matching *(::AutoVector, ::AutoVector)
Closest candidates are:
  *(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:424
Stacktrace:
 [1] (::##1#2)(::AutoVector) at ./<missing>:0
 [2] broadcast(::Function, ::AutoVector) at ./broadcast.jl:455
 [3] include_from_node1(::String) at ./loading.jl:576
 [4] include(::String) at ./sysimg.jl:14
 [5] process_options(::Base.JLOptions) at ./client.jl:305
 [6] _start() at ./client.jl:371
while loading /Users/srw/Dropbox/julia/Modules/AV2.jl, in expression starting on line 16

Yes, dot fusion creates an anonymous function to broadcast over. Don’t define broadcast calls on specific functions.

For 0.6, see Broadcast for custom type - #3 by fengyang.wang for how to implement broadcast for a custom type. Note that a lot changes to broadcast[!] are coming in 0.7/1.0:

3 Likes