JuliaArrays / FillArrays.jl

Julia package for lazily representing matrices filled with a single entry

Home Page:https://juliaarrays.github.io/FillArrays.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Static.jl to implement elements of Ones and Zeros?

oschulz opened this issue · comments

Currently, we have

Ones(5)[1] isa Float64

Using Static.jl, the elements of Ones could be static(1) or static(1.0), which would propagate the fact that the number is static deeper into calculations and could enable better compiler optimizations.

Static.jl is a comparatively lightweight dependency on top of FillArrays, load-time impact would probably be minor:

julia> @time using FillArrays
  0.398913 seconds (764.83 k allocations: 46.937 MiB, 72.11% compilation time)

julia> @time using Static
  0.062017 seconds (93.65 k allocations: 5.420 MiB)

Can't you just use Fill(static(1),n) for this?

Can't you just use Fill(static(1),n) for this?

I typically will. But Fill often get's lost e.g. by vcat (which I'll have to use a lot):

julia> vcat(Fill(static(1), 5), Fill(static(1), 5))
10-element Vector{StaticInt{1}}:

Speaking of which, explicit support for Static.jl would allow us to specialize things like vcat to return a Fill.

I just think Ones{T} is a very different thing than what you want.

Note this issue is basically the same as #104 so I'm closing this

I just think Ones{T} is a very different thing than what you want.

You were right, I want Ones{StaticInt} and Ones{StaticFloat64}, not Ones{Int} and Ones{Float64} - sorry for the misunderstanding.