Skip to content

what to do about one and zero ? #47

Open
@jlapeyre

Description

@jlapeyre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions