Skip to content
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

Simplify and extend broadcast eltype promotion mechanism #19723

Merged
merged 1 commit into from
Jan 1, 2017

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Dec 25, 2016

(Requires #19667.) This pull request restores the simplification of broadcast's eltype promotion mechanism in #19421. With benefit of #19667 (thanks @yuyichao!), that simplification handles more cases (e.g. closures accepting more than two arguments) than the present mechanism (_default_eltype-first-Generator-zip). This pull request also gives broadcast's eltype promotion mechanism a more precise name (_broadcast_type -> _broadcast_eltype). Best!

@Sacha0 Sacha0 added the domain:broadcast Applying a function over a collection label Dec 26, 2016
@Sacha0 Sacha0 added this to the 0.6.0 milestone Dec 26, 2016

_broadcast_type(f, T::Type, As...) = Base._return_type(f, typestuple(T, As...))
_broadcast_type(f, A, Bs...) = Base._default_eltype(Base.Generator{ziptype(A, Bs...), ftype(f, A, Bs...)})
eltypestuple(a) = (Base.@_pure_meta; Tuple{eltype(a)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of moving these either to abstractarray.jl or promotion.jl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving eltypestuple to abstractarray.jl or promotion.jl? _broadcast_eltype being the only consumer of eltypestuple, wherever _broadcast_eltype lives seems like the appropriate location? Or do you have other (broader) uses in mind for eltypesuple? Or did you mean something else altogether? Thanks for reviewing! :)

Copy link
Contributor

@pabloferz pabloferz Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting above without providing a context. I was thinking that we could change the promote_op methods to take a function and the tuple of the eltypes and remove the promote_op(Any...) = Any, so it would make sense having eltypestuple somewhere in Base. But that might fit better in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good plan! Agreed another PR might be better. Perhaps we can chat about cleaning up these mechanisms after feature freeze? Thanks again!

@Sacha0
Copy link
Member Author

Sacha0 commented Dec 30, 2016

Rewritten with the changes to _broadcast_(el)type in #16961 factored in. Unfortunately the additional parameter to _broadcast_(el)type/eltypestuple introduced by #16961 seems to kill this simplified mechanism's ability to handle the test case from #19421 without special casing (and generalizations of that case probably fail now as well). (Foisting that additional complication on the general _broadcast_(el)type mechanism to handle the idiosyncrasies of a particular type seems dubious.) Best!

@Sacha0
Copy link
Member Author

Sacha0 commented Dec 30, 2016

(Pinging @pabloferz for review. Thanks in advance!)

# other times, so there are two variants of typestuple.
# _broadcast_eltype is broadcast's primary result-eltype promotion mechanism.
# _broadcast_eltype uses eltypestuple to construct a tuple type of the eltypes
# of the input-array arguments passed to _broadcast_eltype (from an upstream broacast).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broacast typo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That word. Fixed. Thanks!

@Sacha0 Sacha0 force-pushed the bceltype branch 3 times, most recently from c113bea to 150c651 Compare December 31, 2016 05:40
@Sacha0
Copy link
Member Author

Sacha0 commented Dec 31, 2016

Rebased and fixed. Collides with #19787, not certain which should take precedence. Best!

@pabloferz
Copy link
Contributor

If no one objects I'd prefer to merge that one first.

@Sacha0
Copy link
Member Author

Sacha0 commented Dec 31, 2016

If no one objects I'd prefer to merge that one first.

If we can merge #19787 within the next few hours, then #19787 should take precedence. Otherwise I advocate for merging this pull request first, as #19724 depends on this pull request. Best!

@pabloferz
Copy link
Contributor

I had forgotten about #19724. I agree with @Sacha0's proposal above.

…re cases.

Re-simplify broadcast's eltype promotion mechanism as in JuliaLang#19421. With benefit of JuliaLang#19667, this simplified mechanism should handle additional cases (e.g. closures accepting more than two arguments). Also rename the mechanism more precisely (_broadcast_type -> _broadcast_eltype, typestuple -> eltypestuple).
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 1, 2017

Revised with #19787 in. Handles the test case from #19421 without special casing again. Best!

@tkelman
Copy link
Contributor

tkelman commented Jan 1, 2017

i686 travis failure looks related to #19792, most likely pre existing.

@tkelman tkelman merged commit 9cc7815 into JuliaLang:master Jan 1, 2017
tkelman added a commit that referenced this pull request Jan 1, 2017
@Sacha0 Sacha0 deleted the bceltype branch January 7, 2017 04:46
Sacha0 added a commit to Sacha0/julia that referenced this pull request Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:broadcast Applying a function over a collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants