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

show of 0-dimensional array misleading #31481

Closed
maleadt opened this issue Mar 26, 2019 · 5 comments · Fixed by #33206
Closed

show of 0-dimensional array misleading #31481

maleadt opened this issue Mar 26, 2019 · 5 comments · Fixed by #33206
Labels
domain:arrays [a, r, r, a, y, s] domain:display and printing Aesthetics and correctness of printed representations of objects.

Comments

@maleadt
Copy link
Member

maleadt commented Mar 26, 2019

julia> using Test

julia> a = zeros(Int)
0-dimensional Array{Int64,0}:
0

julia> @test a == 0
Test Failed at REPL[12]:1
  Expression: a == 0
   Evaluated: 0 == 0
ERROR: There was an error during testing

julia> @test a[] == 0
Test Passed

Not sure what to do here since we don't have a short syntax for 0-dimensional arrays.

@maleadt maleadt added test This change adds or pertains to unit tests domain:display and printing Aesthetics and correctness of printed representations of objects. labels Mar 26, 2019
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 26, 2019

Seems to be intentional:

303 # 0-dimensional arrays
304 print_array(io::IO, X::AbstractArray{T,0} where T) =
305     isassigned(X) ? show(io, X[]) :
306                     print(io, undef_ref_str)

But I'm not sure these are really desirable formats, except for 1-d and 2-d cases:

julia> println(zeros(Float32))
0.0

julia> println(zeros(Float32, 2))
Float32[0.0, 0.0]

julia> println(zeros(Float32, 2, 2))
Float32[0.0 0.0; 0.0 0.0]

julia> println(zeros(Float32, 2, 2, 2))
Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

julia> println(zeros(Float32, 2, 2, 2, 2))
Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

julia> println(zeros(Float32, 2, 2, 2, 2, 2))
Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Float32[0.0 0.0; 0.0 0.0]

Not sure what to do here since we don't have a short syntax for 0-dimensional arrays.

Sure we do: 🙂

julia> fill(1.0)
0-dimensional Array{Float64,0}:
1.0

@vtjnash vtjnash removed the test This change adds or pertains to unit tests label Mar 26, 2019
@vtjnash vtjnash changed the title Confusing output with failed comparison to 0-dimensional array show of 0-dimensional array misleading Mar 26, 2019
@JeffBezanson JeffBezanson added the domain:arrays [a, r, r, a, y, s] label Mar 26, 2019
@eulerkochy
Copy link
Contributor

Intended display @vtjnash ?

@vtjnash vtjnash added the status:triage This should be discussed on a triage call label Apr 3, 2019
@JeffBezanson
Copy link
Sponsor Member

Ways we could display this:

fill(0)

reshape([0], ())

Any other ideas?

@JeffBezanson
Copy link
Sponsor Member

Triage says 👍 to changing this.

@JeffBezanson JeffBezanson removed the status:triage This should be discussed on a triage call label Apr 11, 2019
@mbauman
Copy link
Sponsor Member

mbauman commented Apr 11, 2019

I'm favoring fill(0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] domain:display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants