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

Unify Ones and Zeros as SFill{0} and SFill{k}? #104

Open
dlfivefifty opened this issue Jul 6, 2020 · 9 comments
Open

Unify Ones and Zeros as SFill{0} and SFill{k}? #104

dlfivefifty opened this issue Jul 6, 2020 · 9 comments

Comments

@dlfivefifty
Copy link
Member

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.

@c42f
Copy link
Member

c42f commented Sep 16, 2020

Coming here from JuliaArrays/StaticArrays.jl#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.

@dlfivefifty
Copy link
Member Author

dlfivefifty commented Sep 16, 2020

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

@oschulz
Copy link

oschulz commented Apr 6, 2022

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?

@dlfivefifty
Copy link
Member Author

Where did T go?

@oschulz
Copy link

oschulz commented Apr 6, 2022

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)

@oschulz
Copy link

oschulz commented Apr 6, 2022

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)

@dlfivefifty
Copy link
Member Author

Except then you lose the propagation of static values so there's no point...

@dlfivefifty
Copy link
Member Author

I would say a better solution may be to just support Fill{StaticInt}, etc.

@oschulz
Copy link

oschulz commented Apr 6, 2022

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?

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

No branches or pull requests

3 participants