Skip to content

Commit

Permalink
fix #22168, im*I+I should be shown as (1+1im)*I (#22169)
Browse files Browse the repository at this point in the history
* fix #22168, `im*I+I` should be shown as `(1+1im)*I`

* add test for `show(UniformScaling)`

* check the number of terms in `show(::UniformScaling)`

* fix the misuse of `|`
  • Loading branch information
sunoru authored and KristofferC committed Jun 6, 2017
1 parent 54bca01 commit e9b73ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ 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) = print(io, "$(typeof(J))\n$(J.λ)*I")
function show(io::IO, J::UniformScaling)
s = "$(J.λ)"
if ismatch(r"\w+\s*[\+\-]\s*\w+", s)
s = "($s)"
end
print(io, "$(typeof(J))\n$s*I")
end
copy(J::UniformScaling) = UniformScaling(J.λ)

transpose(J::UniformScaling) = J
Expand Down
1 change: 1 addition & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ end
end

@test copy(UniformScaling(one(Float64))) == UniformScaling(one(Float64))
@test sprint(show,UniformScaling(one(Complex128))) == "UniformScaling{Complex{Float64}}\n(1.0 + 0.0im)*I"
@test sprint(show,UniformScaling(one(Float32))) == "UniformScaling{Float32}\n1.0*I"

λ = complex(randn(),randn())
Expand Down

0 comments on commit e9b73ec

Please sign in to comment.