Skip to content

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

@tpapp

Description

@tpapp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions