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

Add a BroadcastStyle for AbstractFill #385

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Aug 26, 2024

Fixes #40
Fixes #58
Fixes #143
Fixes #145
Fixes #188

After this,

julia> Broadcast.BroadcastStyle(typeof(Fill(2,3)))
FillArrays.FillStyle{1}()

julia> Broadcast.BroadcastStyle(typeof(Zeros(2,3)))
FillArrays.ZerosStyle{2}()

A special ZerosStyle is necessary to properly handle broadcasting with structured matrix types from LinearAlgebra.

Often, we will have AbstractFill return types returned now in broadcasting operations, and --- where possible --- ones whose values are statically known:

julia> exp.(Zeros(4))
4-element Ones{Float64}

julia> (x -> x^2).(Zeros(4))
4-element Zeros{Float64}

julia> .!(Trues(4))
4-element Zeros{Bool}

This does not change the fact that broadcasting over a Fill is evaluated before others in a fused broadcast:

julia> ones(1,5) .+ (ones(1) .+ (_ -> rand()).(Fill("vec", 2)))
2×5 Matrix{Float64}:
 2.76296  2.76296  2.76296  2.76296  2.76296
 2.76296  2.76296  2.76296  2.76296  2.76296

This is achieved by recursively walking through a Broadcasted object, and evaluating the components that produce AbstractFills eagerly.

@jishnub jishnub marked this pull request as draft August 26, 2024 10:19
Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 97.11538% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.29%. Comparing base (9868632) to head (712a201).
Report is 1 commits behind head on master.

Files Patch % Lines
src/fillbroadcast.jl 97.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #385      +/-   ##
==========================================
- Coverage   99.90%   97.29%   -2.62%     
==========================================
  Files           8        8              
  Lines        1110     1148      +38     
==========================================
+ Hits         1109     1117       +8     
- Misses          1       31      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant