-
-
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
Use containertype to determine array type for array broadcast #19745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,20 +11,9 @@ export bitbroadcast, dotview | |
export broadcast_getindex, broadcast_setindex! | ||
|
||
## Broadcasting utilities ## | ||
|
||
broadcast_array_type() = Array | ||
broadcast_array_type(A, As...) = | ||
if is_nullable_array(A) || broadcast_array_type(As...) === Array{Nullable} | ||
Array{Nullable} | ||
else | ||
Array | ||
end | ||
|
||
# fallbacks for some special cases | ||
@inline broadcast(f, x::Number...) = f(x...) | ||
@inline broadcast{N}(f, t::NTuple{N}, ts::Vararg{NTuple{N}}) = map(f, t, ts...) | ||
@inline broadcast(f, As::AbstractArray...) = | ||
broadcast_c(f, broadcast_array_type(As...), As...) | ||
|
||
# special cases for "X .= ..." (broadcast!) assignments | ||
broadcast!(::typeof(identity), X::AbstractArray, x::Number) = fill!(X, x) | ||
|
@@ -313,7 +302,7 @@ ziptype{T}(::Type{T}, A) = typestuple(T, A) | |
ziptype{T}(::Type{T}, A, B) = (Base.@_pure_meta; Iterators.Zip2{typestuple(T, A), typestuple(T, B)}) | ||
@inline ziptype{T}(::Type{T}, A, B, C, D...) = Iterators.Zip{typestuple(T, A), ziptype(T, B, C, D...)} | ||
|
||
_broadcast_type{S}(::Type{S}, f, T::Type, As...) = Base._return_type(S, typestuple(S, T, As...)) | ||
_broadcast_type{S}(::Type{S}, f, T::Type, As...) = Base._return_type(f, typestuple(S, T, As...)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TotalVerb I'm not sure what the purpose of the first type argument is but it seemed wrong to pass it as the first argument to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first argument is used to differentiate when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this was a mistake. |
||
_broadcast_type{T}(::Type{T}, f, A, Bs...) = Base._default_eltype(Base.Generator{ziptype(T, A, Bs...), ftype(f, A, Bs...)}) | ||
|
||
# broadcast methods that dispatch on the type of the final container | ||
|
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.
I think we can avoid defining these if we delete the method in line 26 and just use this method which was the origin purpose of this PR.
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.
Yes, you can remove this, it should do no harm. But I believe the
## Broadcasting utilities ##
is still useful for organizing the code.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.
Yep, this was an annoying special case I had to add. Thanks for addressing it!