Unify `Ones` and `Zeros` as `SFill{0}` and `SFill{k}`?
It might make the code cleaner to do:
struct SFill{k, T, N, Axes} <: AbstractFill{T,N}
axes::Axes
end
getindex_value(F::SFill{k,T}) where {k,T} = convert(T,k)
const Ones{T,N,Axes} = SFill{true,T,N,Axes}
const Zeros{T,N,Axes} = SFill{false,T,N,Axes}
It would then be possible to support other special cases. Though whether this machinery is worth it is not clear.
Coming here from https://github.com/JuliaArrays/StaticArrays.jl/issues/815.
I'll let others debate about whether the machinery is worth it :) A small note - I'm not sure you want the value k in the type if it can be a non bits type? Though it seems fine for the Ones and Zeros you've defined here.
We already have Fill when the value is not in the type...
A more pressing case is where the length is static. But it seems this might be better done via Axes? If only there were a SOneTo.
Edit: Errr, there is:
julia> axes(SVector(1,2))
(SOneTo(2),)
So Actually we can already support static lengthed Fill:
julia> Fill(1, (SOneTo{2}(),))
2-element Fill{Int64,1,Tuple{SOneTo{2}}} with indices SOneTo(2): entries equal to 1
Coming from #176 (compatibility with Static.jl), might
const Ones{T,N,Axes} = Fill{Static.True,N,Axes}
const Zeros{T,N,Axes} = Fill{Static.False,N,Axes}
not be an elegant alternative?
Where did T go?
If FillArrays would take on Static as a dependency, also #140 could be extended to enable Fill-to-Fill vcat for arbitrary static values, not just one and zero, we could have
vcat(Fill(static(4.2), 5), Fill(static(4.2), 5)) === Fill(static(4.2), 10)
Where did T go?
Ooops, indeed! :-) That's a problem, because there's no common static supertype across all value types in Static.jl. But we could do
~~Struct SFill ...~~
(Update: As @dlfivefifty pointed out, no we can't)
Except then you lose the propagation of static values so there's no point...
I would say a better solution may be to just support Fill{StaticInt}, etc.
Except then you lose the propagation of static values so there's no point...
Ah, silly me convert(T,static(k)) doesn't return a static number, of course, that approach won't work. Sorry, I think I misunderstood the semantics of Ones and Zeros a bit.
I would say a better solution may be to just support Fill{StaticInt}, etc.
General support for Static would be awesome (e.g. for the possibilities with vcat mentioned above).
And I guess one you just use Ones{StaticInt}(5) then, right?