-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Compact printing for Adjoint
vectors, and Diagonal
#40722
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
Conversation
@@ -136,6 +136,11 @@ end | |||
function Base.replace_in_print_matrix(A::Diagonal,i::Integer,j::Integer,s::AbstractString) | |||
i==j ? s : Base.replace_with_centered_mark(s) | |||
end | |||
function Base.show(io::IO, A::Diagonal) |
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.
Should we add similar methods to the other banded matrix types?
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.
Could do, but maybe not this PR?
For the more complicated ones, there are choices like whether to print SymTridiagonal([1,2,3], [4,5])
or rather SymTridiagonal([1 4 0; 4 2 5; 0 5 3])
.
In this PR, only Diagonal
is the only upper-case constructor printed.
Note also that not all Adjoint or Transpose objects are affected, only the simplest ones.
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.
Xref #55347 for Bidiagonal.
There are some doctest failures, but the other test failures are unrelated. If there are no objections, it would be good to fix and merge this. |
@@ -302,6 +302,16 @@ function Base.showarg(io::IO, v::Transpose, toplevel) | |||
toplevel && print(io, " with eltype ", eltype(v)) | |||
return nothing | |||
end | |||
function Base.show(io::IO, v::Adjoint{<:Real, <:AbstractVector}) |
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.
Note that this omits vectors of complex numbers... because I thought that printing 0 + 3im
when the element is in fact 0 - 3im
here is worse than failing to note the container type:
julia> (transpose([1,2,3im]), adjoint([1,2,3im]))
(transpose(Complex{Int64}[1 + 0im, 2 + 0im, 0 + 3im]), Complex{Int64}[1 + 0im 2 + 0im 0 - 3im])
It also doesn't change how e.g. an array of matrices is printed, for the same reason -- printing [1 2; 3 4]
which isn't ==
the element seems confusing:
julia> ([[1 2; 3 4], [5 6; 7 8]]',)
(Adjoint{Int64, Matrix{Int64}}[[1 3; 2 4] [5 7; 6 8]],)
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 agree with the choices here
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.
Should we add tests for the complex case, making it explicit that this was a design choice and not an oversight?
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 think the restrictions to v::Adjoint{<:Real, <:AbstractVector}
and v::Transpose{<:Number, <:AbstractVector}
are fairly obviously deliberate.
For the complex case, it would not be crazy to print adjoint(conj([1 + 0im, 2 + 0im, 0 - 3im]))
as this also resolves to the right object (since conj
is eager). Maybe I'd rather not have explicit tests blocking that.
This changes the compact printing to preserve more information -- an adjoint vector is not quite a matrix, and Diagonal wastes a lot of space: ```julia julia> (Diagonal(1:4), [5,6,7]', transpose(8:10)) # before ([1 0 0 0; 0 2 0 0; 0 0 3 0; 0 0 0 4], [5 6 7], [8 9 10]) julia> (Diagonal(1:4), [5,6,7]', transpose(8:10)) # after (Diagonal(1:4), adjoint([5, 6, 7]), transpose(8:10)) ``` Would have been better to do at the same time as 1.6's other printing changes, I guess. --------- Co-authored-by: Jishnu Bhattacharya <[email protected]>
This changes the compact printing to preserve more information -- an adjoint vector is not quite a matrix, and Diagonal wastes a lot of space:
Would have been better to do at the same time as 1.6's other printing changes, I guess.