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

Float32 print differently in matrices and vectors #24061

Closed
KristofferC opened this issue Oct 9, 2017 · 5 comments
Closed

Float32 print differently in matrices and vectors #24061

KristofferC opened this issue Oct 9, 2017 · 5 comments
Assignees
Labels
display and printing Aesthetics and correctness of printed representations of objects.

Comments

@KristofferC
Copy link
Member

KristofferC commented Oct 9, 2017

julia> Float32[1.4013f-10 1]
1×2 Array{Float32,2}:
 1.4013e-10  1.0

julia> Float32[1.4013f-10, 1]
2-element Array{Float32,1}:
 1.4013f-10
 1.0f0  

1.4013e-10 vs 1.4013f-10.

@fredrikekre fredrikekre added the display and printing Aesthetics and correctness of printed representations of objects. label Oct 9, 2017
@KristofferC
Copy link
Member Author

Perhaps not a bug, but it looks a bit weird. Probably another consequence of #22981.

@rfourquet
Copy link
Member

Yes this a direct consequence of it, and I already started to work on a fix. Note this is not at all limited to Float32, e.g.

julia> ModInt[ModInt{2}(0), ModInt{3}(0)]
2-element Array{Main.ModInts.ModInt,1}:
 0 mod 2
 0 mod 3

julia> ModInt[ModInt{2}(0) ModInt{3}(0)] 
1×2 Array{Main.ModInts.ModInt,2}:
 0  0

@rfourquet rfourquet self-assigned this Oct 9, 2017
@rfourquet
Copy link
Member

This example was also to show that currently in some cases the matrix printing looks better than vector's (Float32), but in other cases it seems wrong (ModInt). Also consider:

julia>  Number[Float16(1), Float32(1)]
2-element Array{Number,1}:
 Float16(1.0)
         1.0f0

julia> Number[Float16(1) Float32(1)]
1×2 Array{Number,2}:
 1.0  1.0

What would people think is better? The latter looses information, but maybe is sufficient?

@nalimilan
Copy link
Member

It seems that this example complexifies the description of the problem proposed by @StefanKarpinski at #22981 (comment), since it adds a third dimension to take into account: consistency in printing, i.e. comparability of entries.

Indeed what's most annoying in the above example is that Float16(1.0) and 1.0f0 are printed in totally inconsistent styles, making them hard to compare. It's certainly fine to print an Array{Any} as a list of visually incomparable objects since they are supposed to be heterogeneous. But with Array{Number} you're likely to compare values with one another.

OTOH, if we dropped type information, this would be the only case where you wouldn't know the type of an entry in the context of array printing. It could be confusing for people who have not realized they got a heterogeneous array.

We could decide we don't care making this pretty, because arrays with abstract element types different from Any are quite rare, and use the explicit but ugly printing (as for vectors above). This would be less of an issue if we had a way to print 1.0f0 as Float32(1.0) for consistency with Float16(1.0).

@quinnj
Copy link
Member

quinnj commented Aug 7, 2019

Looks like this is already solved:

julia> Float32[1.4013f-10, 1]
2-element Array{Float32,1}:
 1.4013e-10
 1.0

julia> Float32[1.4013f-10 1]
1×2 Array{Float32,2}:
 1.4013e-10  1.0

@quinnj quinnj closed this as completed Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

No branches or pull requests

5 participants