Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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.λ)")

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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+".

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.)

show(io::IO, J::UniformScaling) = print(io, "$(typeof(J))\n$(J.λ)*I")
copy(J::UniformScaling) = UniformScaling(J.λ)

Expand Down