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

LinearAlgebra: 2-arg show for adjoint/transpose #54249

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ julia> vcat(range(1, 2, length=3)) # collects lazy ranges
2.0

julia> two = ([10, 20, 30]', Float64[4 5 6; 7 8 9]) # row vector and a matrix
([10 20 30], [4.0 5.0 6.0; 7.0 8.0 9.0])
(adjoint([10, 20, 30]), [4.0 5.0 6.0; 7.0 8.0 9.0])

julia> vcat(two...)
3×3 Matrix{Float64}:
Expand Down
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,23 @@ function Base.showarg(io::IO, v::Adjoint, toplevel)
toplevel && print(io, " with eltype ", eltype(v))
return nothing
end
function Base.show(io::IO, v::Adjoint{<:Any, <:AbstractVector})
print(io, "adjoint(")
show(io, parent(v))
print(io, ')')
end
function Base.showarg(io::IO, v::Transpose, toplevel)
print(io, "transpose(")
Base.showarg(io, parent(v), false)
print(io, ')')
toplevel && print(io, " with eltype ", eltype(v))
return nothing
end
function Base.show(io::IO, v::Transpose{<:Any, <:AbstractVector})
print(io, "transpose(")
show(io, parent(v))
print(io, ')')
end

# some aliases for internal convenience use
const AdjOrTrans{T,S} = Union{Adjoint{T,S},Transpose{T,S}} where {T,S}
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ end
@test B == A .* A'
end

@testset "show" begin
t = [1,2]
@test repr(transpose(t)) == "transpose($(repr(t)))"
@test repr(adjoint(t)) == "adjoint($(repr(t)))"
end

@testset "test show methods for $t of Factorizations" for t in (adjoint, transpose)
A = randn(ComplexF64, 4, 4)
F = lu(A)
Expand Down