Skip to content

Commit cacf302

Browse files
committed
show adjoint vectors not as matrices
1 parent 32a94fd commit cacf302

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/LinearAlgebra/src/adjtrans.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ function Base.showarg(io::IO, v::Transpose, toplevel)
181181
toplevel && print(io, " with eltype ", eltype(v))
182182
return nothing
183183
end
184+
function Base.show(io::IO, v::Adjoint{<:Real, <:AbstractVector})
185+
print(io, "adjoint(")
186+
show(io, parent(v))
187+
print(io, ")")
188+
end
189+
function Base.show(io::IO, v::Transpose{<:Number, <:AbstractVector})
190+
print(io, "transpose(")
191+
show(io, parent(v))
192+
print(io, ")")
193+
end
184194

185195
# some aliases for internal convenience use
186196
const AdjOrTrans{T,S} = Union{Adjoint{T,S},Transpose{T,S}} where {T,S}

stdlib/LinearAlgebra/test/adjtrans.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ end
502502
@test String(take!(io)) == "transpose(::Matrix{Float64})"
503503
end
504504

505+
@testset "show" begin
506+
@test repr(adjoint([1,2,3])) == "adjoint([1, 2, 3])"
507+
@test repr(transpose([1f0,2f0])) == "transpose(Float32[1.0, 2.0])"
508+
end
509+
505510
@testset "strided transposes" begin
506511
for t in (Adjoint, Transpose)
507512
@test strides(t(rand(3))) == (3, 1)

0 commit comments

Comments
 (0)