Skip to content

Instantly share code, notes, and snippets.

@mschauer
Last active September 18, 2018 15:46
Show Gist options
  • Select an option

  • Save mschauer/83762b81b2eaed9f1e587c4241e94658 to your computer and use it in GitHub Desktop.

Select an option

Save mschauer/83762b81b2eaed9f1e587c4241e94658 to your computer and use it in GitHub Desktop.
Minimal broadcast example
struct MyType
x
end
Base.broadcastable(x::MyType) = x
Broadcast.BroadcastStyle(::Type{<:MyType}) = Broadcast.Style{MyType}()
x = rand(5)
Base.size(x::MyType) = size(x.x)
Base.copyto!(x::MyType, y) = copyto!(x.x, y)
Base.getindex(x::MyType, i::CartesianIndex) = x.x[i]
MyType(x) .= x
MyType(x) .= 1 .* MyType(x)
x .= 1 .* MyType(x)
MyType(x) .= 1 .* MyType(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment