-
-
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 matrix trig functions for matrices of integers #24180
Conversation
base/linalg/dense.jl
Outdated
@@ -718,14 +718,16 @@ function cos(A::AbstractMatrix{<:Real}) | |||
if issymmetric(A) | |||
return full(cos(Symmetric(A))) | |||
end | |||
return real(exp!(im*A)) | |||
T = complex(float(eltype(A))) | |||
return real(exp!(convert(AbstractArray{T}, im*A))) |
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.
If A
is an integer array, this makes an extra copy. Maybe
real(exp!(Complex.(zero(float(eltype(A))), A))) # real(exp!(im*A)))
instead?
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.
Or T.(im .* A)
should avoid the temporary as well.
base/linalg/dense.jl
Outdated
X .= (X .+ exp!(-im*A)) ./ 2 | ||
T = complex(float(eltype(A))) | ||
X = exp!(convert(AbstractArray{T}, im*A)) | ||
X .= (X .+ exp!(convert(AbstractArray{T}, -im*A))) ./ 2 |
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.
See above. T.(im .* A)
and convert.(T, .- im .* A)
, maybe? Or
X = exp!(T.(im .* A))
@. X = (X + $exp!(T(-im*A))) / 2
if you want to reduce the number of dots in the second line
base/linalg/dense.jl
Outdated
X = exp(A) | ||
X .= (X .+ exp!(-A)) ./ 2 | ||
X .= (X .+ exp!(convert(AbstractArray{T}, -A))) ./ 2 |
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.
can just use float.(.-A)
here
@stevengj Thanks a bunch for the review! So dotty. Took me a few days to get back to this, but I just pushed the changes. |
Should not error because
exp!(::Matrix{<:Integer})
is undefined anymore.