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

Make StructArrays broadcast aware #90

Closed
wants to merge 1 commit into from

Conversation

Keno
Copy link
Contributor

@Keno Keno commented Oct 12, 2019

Fixes #89

cc @mbauman who can say whether this is right

@codecov-io
Copy link

codecov-io commented Oct 12, 2019

Codecov Report

Merging #90 into master will decrease coverage by 0.22%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #90      +/-   ##
==========================================
- Coverage   91.08%   90.86%   -0.23%     
==========================================
  Files           9        9              
  Lines         370      372       +2     
==========================================
+ Hits          337      338       +1     
- Misses         33       34       +1
Impacted Files Coverage Δ
src/structarray.jl 85.85% <50%> (-0.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d22a69e...68f3ac7. Read the comment docs.

@piever
Copy link
Collaborator

piever commented Oct 12, 2019

Thanks! I'll need @mbauman review as well as I'm not super familiar with the broadcast machinery.

The example

s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
s .+ s

is very convincing, but what should one expect from

s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
t = rand(2,2)
s .+ t

Is the rule that, in order for the result to be a StructArray, all members of the broadcasted operation have to be StructArrays and the resulting eltype a struct?


@testset "broadcast" begin
s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
@test isa(s .+ s, StructArray)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably this also needs to test that things like broadcast(t -> 1, s) don't give an error (I'm not sure what exactly should happen when the result of broadcasting StructArrays has a eltype that is not a struct).

@vchuravy
Copy link

This won't work for the case where your StructArray contains a different array than Base.Array. Normally you have to unwrap the wrapper and do the broadcast on the underlying array to reach the right implementation.

@cossio
Copy link

cossio commented Apr 21, 2020

Could this help with #124?

@piever
Copy link
Collaborator

piever commented Jul 14, 2020

Superseded by #136.

@piever piever closed this Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broadcasting a StructArray yields a regular array
5 participants