Skip to content

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.22222% with 3 lines in your changes missing coverage. Please review.

Project coverage is 98.83%. Comparing base (6f61dc3) to head (7296e78).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/fillbroadcast.jl 97.11% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #385      +/-   ##
==========================================
- Coverage   99.91%   98.83%   -1.09%     
==========================================
  Files           8        8              
  Lines        1147     1197      +50     
==========================================
+ Hits         1146     1183      +37     
- Misses          1       14      +13     

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

@putianyi889
Copy link
Contributor

This could also fix #394

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