Repository navigation
Show the array type in 2-arg show of GPU arrays - #429
Merged
Merged
Conversation
maleadt
reviewed
Sep 23, 2022
mcabbott
commented
Sep 23, 2022
christiangnrd
force-pushed
the
patch-1
branch
4 times, most recently
from
July 26, 2026 15:34
49f7bb3 to
9555eb4
Compare
Member
|
I fixed up this PR and it's pretty simple is this something we still want? |
show of GPU arrays
Member
|
Rebased and reworked, this should be good to go once CI passes. |
Two-argument `show` printed GPU arrays exactly like their CPU copy, so
`(x = CuArray([1.0]),)` was indistinguishable from `(x = [1.0],)`. Show a call
to the storage type around the copy instead, e.g. `CuArray([1.0])`.
The name comes from the unwrapped storage type, and the copy is materialized,
so wrapped arrays show as an expression for an equal array: an `Adjoint` of a
`CuMatrix` shows as `CuArray(<transposed contents>)` rather than
`Adjoint(...)`, which would evaluate to the transpose. Wrappers with a printer
of their own, such as LinearAlgebra's `Diagonal` and adjoint vectors on Julia
1.12+, keep it and show their GPU parents this way. Zero-dimensional arrays,
which used to error on scalar indexing, now show as `CuArray(fill(1.0))`.
Like Base's eltype prefix, the call is left out when the context's `:typeinfo`
is exactly the array's type, e.g. for the elements of a
`Vector{CuArray{Float32, 1, DeviceMemory}}`. Base replaces `:typeinfo` before
calling the internal helpers that wrapped matrices go through, so this is
decided in an override of `show` for the storage type.
Co-authored-by: Christian Guinard <28689358+christiangnrd@users.noreply.github.com>
This was referenced Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two-argument
showprinted GPU arrays exactly like their CPU copy, so a GPU array inside a tuple,NamedTupleor struct looked like anArray:The output is a call to the storage type around the materialized CPU copy, so it evaluates to an equal array, wrapped arrays included:
Wrappers with a printer of their own keep it, e.g. on Julia 1.12+
Tridiagonal(CuArray([3.0]), CuArray([1.0, 2.0]), CuArray([4.0]))andadjoint(CuArray([1.0])). Like Base's eltype prefix, the call is left out when the context's:typeinfois exactly the array's type, as for the elements of a concretely typed container:3-arg (REPL) display is unchanged, except where Base delegates it to 2-arg
show: empty arrays in a:compactcontext, and on Julia 1.13+ empty vectors, which now display as e.g.CuArray(Int64[])rather thanInt64[].The type parameters of the storage are not shown, so a
CuArrayin unified memory shows asCuArray(...)too. Zero-dimensional arrays used to throw a scalar-indexing error and now show as above. Wrapped arrays in a container typed on the wrapper ([m']) show asAdjoint{...}[CuArray(...)], which does not convert back; Base has the same limitation for CPU wrappers.Implementation:
show(::IO, ::AbstractGPUArray)handles unwrapped arrays and decides the:typeinfoelision, because Base replaces:typeinfobefore calling its internal helpers. Wrapped arrays still go through Base'sshowand the existing_show_nonempty,_show_emptyandshow_vectoroverrides, so wrappers with their ownshowmethod keep it.Supersedes JuliaGPU/CUDA.jl#1197.