FillArrays.jl icon indicating copy to clipboard operation
FillArrays.jl copied to clipboard

Implement broadcast styles

Open iamed2 opened this issue 6 years ago • 5 comments
trafficstars

There's been talk of a FillStyle before, and RectDiagonal could implement Base's StructuredMatrixStyle.

I've been working on broadcast styles for Nabla.jl so I might take a crack at them for this package in my spare time.

iamed2 avatar Jan 04 '19 22:01 iamed2

That would be great. It would be good to codify why FillStyle is the right solution while Base has no RangeStyle for AbstractRange. I guess the answer may be as simple that a broadcasted AbstractFill is always an AbstractFill.

dlfivefifty avatar Jan 04 '19 22:01 dlfivefifty

Hmm, it's not though. For example, (x -> x + rand()).(Zeros(3)).

I will do a review of all existing BroadcastStyles and report back.

iamed2 avatar Jan 04 '19 23:01 iamed2

Following SparseMatrixCSC broadcasting, yes it is:

julia> (x -> x + rand()).(spzeros(3,3))
3×3 SparseMatrixCSC{Float64,Int64} with 9 stored entries:
  [1, 1]  =  0.32463
  [2, 1]  =  0.32463
  [3, 1]  =  0.32463
  [1, 2]  =  0.32463
  [2, 2]  =  0.32463
  [3, 2]  =  0.32463
  [1, 3]  =  0.32463
  [2, 3]  =  0.32463
  [3, 3]  =  0.32463

dlfivefifty avatar Jan 05 '19 08:01 dlfivefifty

See also discussion https://github.com/JuliaArrays/FillArrays.jl/issues/29 where the current behaviour was decided on:

julia> (x ->  x + rand()).(Zeros(5))
5-element Fill{Float64,1,Tuple{Base.OneTo{Int64}}}:
 0.4797461797606011
 0.4797461797606011
 0.4797461797606011
 0.4797461797606011
 0.4797461797606011

dlfivefifty avatar Jan 05 '19 08:01 dlfivefifty

Well never mind then! That makes things simple and I think your reasoning is correct.

iamed2 avatar Jan 05 '19 15:01 iamed2