Skip to content

Should broadcast on Adjoint should use the parent array's BroadcastStyle? #25671

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

Open
andyferris opened this issue Jan 21, 2018 · 3 comments
Open
Labels
broadcast Applying a function over a collection

Comments

@andyferris
Copy link
Member

andyferris commented Jan 21, 2018

It seems that BroadcastStyle(::Type{<:Adjoint}) uses the default style instead of that of its parent.

E.g. at an earlier stage today I was upgrading StaticArrays to work on v0.7 and came across this:

julia> using StaticArrays

julia> Broadcast.BroadcastStyle(SVector{3, Float64}))
Base.Broadcast.DefaultArrayStyle{2}()

This gives different results in vector + vector' than I originally expected, even though we've defined a StaticArrayStyle <: AbstractArrayStyle.

Would using the parent's array style work, or might there be some issues with that?

@nalimilan
Copy link
Member

Cc: @timholy

@ajkeller34
Copy link
Contributor

I noticed this when I was playing around with getting broadcasting to work with AxisArrays as well. Gory details at JuliaArrays/AxisArrays.jl#131.

@mbauman
Copy link
Member

mbauman commented Jan 22, 2018

My gut reaction here is that — unfortunately — we probably need to make you do this yourself. A fallback definition won't always be right since we don't know how you'll use the styles.

I've been working with more BroadcastStyles in the context of #25377 (but for these purposes I don't think it matters). One potential new broadcast style is for LinearAlgebra's structured matrices. I'm trying out a StructuredMatrixStyle{LowerTriangular} to replace some of the currently-existing broadcast methods. That would be one obvious case where the adjoint cannot share its parent's style.

@mbauman mbauman added broadcast Applying a function over a collection and removed broadcast labels Apr 24, 2018
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

No branches or pull requests

4 participants