-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add broadcastable method for Enum #30670
Conversation
@@ -606,6 +606,7 @@ Base.RefValue{String}("hello") | |||
``` | |||
""" | |||
broadcastable(x::Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing,Val}) = Ref(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consolidate these definitions
broadcastable(x::Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing,Val}) = Ref(x)
broadcastable(x::Enum) = Ref(x)
broadcastable(x::Ptr) = Ref(x)
broadcastable(r::Regex) = Ref(r)
as one into
broadcastable(x::Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing,Val,Ptr,Regex,Enum}) = Ref(x)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Enum
definition can't go here, since Enums.jl
is loaded after this file. So you need to put Base.broadcastable(x::Enum) = Ref(x)
into Enums.jl
instead.
We could additionally consolidate this code somewhat as you say, but for simplicity you could leave it as-is in this PR.
@@ -163,3 +163,6 @@ end | |||
haggis = 4 | |||
end | |||
@test Int(haggis) == 4 | |||
|
|||
# test scalar behavior in broadcast | |||
@test (@enum Fruit apple; v = Vector{Fruit}(undef, 3); v .= apple; v) == [apple, apple, apple] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Fruit
enum is already defined in this test file. So you can just do
@test (Vector{Fruit}(undef, 3) .= apple) == [apple, apple, apple]
(Note that there is no need to define the v
variable, and the return value of .=
is the lhs.)
Thanks for the explanations! This is one of my first PRs :) |
In the future you should update an existing PR rather than creating a new one, so as not to break up the discussion. |
Thanks for letting me know. I would've done so but was not able to add commits here anymore. I suppose it is because I've made this PR without forking... Maybe it is possible, but I'm not sufficiently good at git to achieve this. I did the new PR properly forking the master. |
Fixes #30669.