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

Broadcasting style for FillArrays? #188

Open
jishnub opened this issue Sep 8, 2022 · 3 comments · May be fixed by #385
Open

Broadcasting style for FillArrays? #188

jishnub opened this issue Sep 8, 2022 · 3 comments · May be fixed by #385

Comments

@jishnub
Copy link
Member

jishnub commented Sep 8, 2022

Perhaps we need a broadcasting rule for FillArrays that takes precedence over Broadcast.DefaultArrayStyle{0}. Currently, we obtain the somewhat unsatisfactory

julia> x = Fill(2, 10)
10-element Fill{Int64}, with entries equal to 2

julia> 2 * x * 3
10-element Fill{Int64}, with entries equal to 12

julia> 2 .* x .* 3
10-element Fill{Int64}, with entries equal to 12

julia> @. 2 * x * 3
10-element Vector{Int64}:
 12
 12
 12
 12
 12
 12
 12
 12
 12
 12

This may be resolved by defining a custom broadcast style.

@dlfivefifty
Copy link
Member

Note the current approach overloads broadcasted:

broadcasted(::DefaultArrayStyle{N}, op, r::AbstractFill{T,N}, x::Number) where {T,N} = Fill(op(getindex_value(r),x), axes(r))

So your second case case works because it's equivalent to broadcasted(*, 2, broadcasted(*, x, 3)) where each one is captured. Probably your third case fails since it is equivalent to broadcasted(*, 2, x, 3) which is not overloaded.

I agree this might be better accomplished with a BroadcastStyle. In particular, many of the other special cases could probably be removed.

@rcalxrc08
Copy link

Due to the missing broadcast style it is quite hard to manage interaction with other array packages.

@dlfivefifty
Copy link
Member

I agree, but I think someone (other than me, I don't have time) just needs to take the lead on this and make a PR...

@jishnub jishnub linked a pull request Aug 26, 2024 that will close this issue
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 a pull request may close this issue.

3 participants