Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Help implementing `copyto!` for broadcasting

$
0
0

I have a type DataRow. It’s goal is to act like a row of a DataFrame, but standing on its own.

  1. It’s one dimensional
  2. It’s indexable
  3. It iterates through values
  4. It stores values in a Vector{Any} internally

I’m trying to extend in-place broadcasting, via this link.

If r is a DataRow with two elements, I would like

r .= [3, 4]

to update the values of r. I’ve implemented


Base.BroadcastStyle(::Type{<:DataRow}) = Broadcast.Style{DataRow}()

function copyto!(dest::DataRow, bc::Broadcasted{Broadcast.DefaultArrayStyle{1}})
	println("success")
	nothing
end

This feels like the method to implement, but I haven’t yet been able to hit this method

julia> r .= [1, 2]
ERROR: MethodError: no method matching copyto!(::DataRow, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(identity),Tuple{Array{Int64,1}}})

Overall I’m pretty lost about how to implement broadcasting. Any help is appreciated, particularly if someone could point me to a good implementation in some package that I can copy

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images