Skip to content
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

Merged
merged 3 commits into from
Oct 23, 2017

Conversation

dalum
Copy link
Contributor

@dalum dalum commented Oct 17, 2017

Should not error because exp!(::Matrix{<:Integer}) is undefined anymore.

@dalum dalum closed this Oct 17, 2017
@dalum dalum reopened this Oct 17, 2017
@@ -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)))
Copy link
Member

@stevengj stevengj Oct 17, 2017

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?

Copy link
Member

@stevengj stevengj Oct 17, 2017

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.

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
Copy link
Member

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

X = exp(A)
X .= (X .+ exp!(-A)) ./ 2
X .= (X .+ exp!(convert(AbstractArray{T}, -A))) ./ 2
Copy link
Member

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

@kshyatt kshyatt added linear algebra Linear algebra maths Mathematical functions labels Oct 17, 2017
@dalum
Copy link
Contributor Author

dalum commented Oct 23, 2017

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

@andreasnoack andreasnoack merged commit 8798936 into JuliaLang:master Oct 23, 2017
@dalum dalum deleted the evey/matrigfix branch October 24, 2017 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants