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

what to do about one and zero ? #47

Open
jlapeyre opened this issue Dec 1, 2018 · 5 comments
Open

what to do about one and zero ? #47

jlapeyre opened this issue Dec 1, 2018 · 5 comments

Comments

@jlapeyre
Copy link
Contributor

jlapeyre commented Dec 1, 2018

Currently, we have this:

julia> one(Diagonal(fill(1.0, 2)))    # 1
2×2 Array{Float64,2}:
 1.0  0.0
 0.0  1.0

julia> zero(Diagonal(fill(1.0, 2)))  # 2
2×2 Diagonal{Float64,Array{Float64,1}}:
 0.0   ⋅ 
  ⋅   0.0

julia> one(Diagonal(Fill(1.0, 2)))  # 3
2×2 Array{Float64,2}:
 1.0  0.0
 0.0  1.0

julia> zero(Diagonal(Fill(1.0, 2)))  # 4
2×2 Diagonal{Float64,Array{Float64,1}}:
 0.0   ⋅ 
  ⋅   0.0

one and zero behave differently, but they probably should behave analogously.
The documentation for one says

If possible, one(x) returns a value of the same type as x,

And for zero

additive identity element for the type of x

This says to me that, of the above examples, only number 2 is correct.

@dlfivefifty
Copy link
Member

I think just return the most structured version, so one returns Eye and zero returns Zeros.

@dlfivefifty
Copy link
Member

This is partially fixed:

julia> one(Diagonal(Fill(1.0, 2)))  # 3
2×2 Diagonal{Float64,Array{Float64,1}}:
 1.0    
     1.0

julia> zero(Diagonal(Fill(1.0, 2))) 
2×2 Diagonal{Float64,Array{Float64,1}}:
 0.0    
     0.0

but still, would be better to return Eye and Zeros

@jishnub
Copy link
Member

jishnub commented Oct 16, 2022

This is largely resolved now:

julia> one(Diagonal(Fill(1.0, 2)))
2×2 Diagonal{Float64, Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}}:
 1.0    
     1.0

julia> zero(Diagonal(Fill(1.0, 2)))
2×2 Diagonal{Float64, Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}}:
 0.0    
     0.0

@dlfivefifty
Copy link
Member

Is it good that they are Fill, not Ones / Zeros ?

@jishnub
Copy link
Member

jishnub commented Oct 16, 2022

Maybe Ones or Zeros would be better, so this may be improved. This was raised here as well.

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