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

Broadcast.result_style(x::S, y::S) does not work unless S() is a constructor #50937

Closed
tpapp opened this issue Aug 16, 2023 · 2 comments · Fixed by #50938
Closed

Broadcast.result_style(x::S, y::S) does not work unless S() is a constructor #50937

tpapp opened this issue Aug 16, 2023 · 2 comments · Fixed by #50938
Labels
broadcast Applying a function over a collection

Comments

@tpapp
Copy link
Contributor

tpapp commented Aug 16, 2023

This line does not work with broadcast styles that have fields, eg

import Broadcast: BroadcastStyle

struct MyStyle <: BroadcastStyle
    some_info
end

BroadcastStyle(x::MyStyle, y::MyStyle) = MyStyle(compute_field(x.some_info, y.some_info))

A possible fix (in user code) is defining

Broadcast.result_style(::MyStyle, ::MyStyle)

but that function does not seem to be part of the API.

A possible fix (in Julia) would be

result_join(::Any, ::Any, x::S, y::S) where S<:BroadcastStyle = x # just pick the first

I wanted to ask if this matches the intention of #20740 before making a PR.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 16, 2023

Yes, that matches the intent of #49395 also, if you could make a PR

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 16, 2023

I think it might be x === y ? x : error("custom rule needed") though?

@brenhinkeller brenhinkeller added the broadcast Applying a function over a collection label Aug 17, 2023
N5N3 pushed a commit that referenced this issue Aug 18, 2023
Fixes #50937.

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
vtjnash added a commit to vtjnash/julia that referenced this issue Aug 18, 2023
)

Fixes JuliaLang#50937.

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
vtjnash added a commit to vtjnash/julia that referenced this issue Aug 18, 2023
)

Fixes JuliaLang#50937.

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants