-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add showarg(io, ::Slices)
printing for eachslice
#45355
base: master
Are you sure you want to change the base?
Conversation
Is there a copy/paste bug here? I don't understand where the "0-element view(::Matrix{Int64}, :, 1) with eltype Int64" part comes from, and it doesn't appear in the examples in the diff. |
base/slicearray.jl
Outdated
return nothing | ||
end | ||
|
||
# This hides the SubArray type in compact printing, e.g. (0, eachcol(Float32[1 2; 3 4]), 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this comment. Maybe develop a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear what this is doing, this is the effect:
julia> (0, eachcol(Float32[1 2; 3 4]), 5) # master
(0, SubArray{Float32, 1, Matrix{Float32}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}[[1.0, 3.0], [2.0, 4.0]], 5)
julia> (0, eachcol(Float32[1 2; 3 4]), 5) # this PR
(0, [Float32[1.0, 3.0], Float32[2.0, 4.0]], 5)
The default 2-arg show for an array of arrays prints the whole type of the inner arrays as the eltype of the outer. This line removes that. But also notifies show
that the eltype of the inner arrays has not been printed anywhere, hence they become Float32[...]
.
Will expand the comment a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanded in f37584d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. The new printing is certainly clearer, but I wonder it's consistent with what we do elsewhere. Are there any equivalent constructs that could benefit from the same simplification? My concern is that if it's the only case where we omit the actual eltype then people could be misled into thinking they really have a Vector{Vector{Float32}}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not sure. Compact printing is sometimes lossy, e.g. Transpose is not marked here (but matters):
julia> ([1 2], transpose([3,4]), [[5,6], [6,7]]')
([1 2], [3 4], Adjoint{Int64, Vector{Int64}}[[5 6] [6 7]])
julia> Adjoint{Int64, Vector{Int64}}[[5 6] [6 7]]
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Adjoint{Int64, Vector{Int64}}
Also, the Adjoint printing is not copy-pastable, it does not re-create such elements. That's also true of the SubArray types which will be shown for eachcol. Perhaps both should be abbreviated somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f3869c9 reverts this for now.
I don't think so. But it's a confusing example now, sorry. Initially I treated empty cases differently, to use |
Last commit removes the changes to 2-arg show, keeping only |
63ac0c1
to
353d759
Compare
julia> a = [1 2; 3 4] | ||
2×2 Matrix{Int64}: | ||
1 2 | ||
3 4 | ||
julia> a = [1 2 3; 40 50 60] | ||
2×3 Matrix{Int64}: | ||
1 2 3 | ||
40 50 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing these examples from 2x2 to 2x3 will, I hope, make it more obvious which dimension is which.
julia> s isa RowSlices, s[1] isa SubArray | ||
(true, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added because the type alias RowSlices is no longer printed.
This proposes to print the
Slices
objects from #32310 in a similar way toSubArray
,ReshapedArray
, etc. These compose nicely:Most
showarg
methods have the outermost one print theeltype
of the object. Here this is a long and not especially illuminating SubArray type, so instead it prints the size of the elements, andeltype(eltype(s))
. Examples (edit: focusing on the empty case, as initially this needed special treatment):Finally, it also hides this(removed for now)SubArray
type in compact show. Not completely sure that's a good idea: