-
-
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
fix #22168, im*I+I
should be shown as (1+1im)*I
#22169
Conversation
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.
Looks good to me. Thanks for the contribution!
base/linalg/uniformscaling.jl
Outdated
@@ -31,6 +31,7 @@ eltype(::Type{UniformScaling{T}}) where {T} = T | |||
ndims(J::UniformScaling) = 2 | |||
getindex(J::UniformScaling, i::Integer,j::Integer) = ifelse(i==j,J.λ,zero(J.λ)) | |||
|
|||
show(io::IO, J::UniformScaling{T}) where {T<:Complex} = print(io, "$(typeof(J))\n($(J.λ))*I") |
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 we do a check for the number of terms instead? Minor use case but this would still be wrong for quaternions.
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.
That's true. But if we do such a check we have to deal with strings. Don't know if it's OK to do so.
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.
Aren't we already dealing with strings? My idea was to add the parentheses if something like ismatch(r"[0-9]+ ?\+|\- ?[0-9]+", "$(J.λ)")
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.
Oh I see. How about just checking r"\w+\s*\+|\-\s*\w+"
as there must be +
or -
between terms if there are more than one term.
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.
That was also my first version but I think negative reals become false positives here
julia> ismatch(r"\w+\s*\+|\-\s*\w+", "-1")
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.
Ah I'm sorry. It's because of the misuse of |
and we should use r"\w+\s*[\+\-]\s*\w+"
.
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 you perhaps add tests for the things that wasn't completely right with the first regexp.
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 know what common things can be wrong with the first regexp, but I believe there could be situations when users define a type that doesn't contain digit-[plus/minus]-digit pattern, such as something like 1i+2j
. (The current displays of complex and quaternion numbers have something like 0+0im
so the first regexp always works with them.)
No description provided.