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

Move up the diagonal check in matrix power #23158

Merged
merged 2 commits into from
Aug 7, 2017
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
Next Next commit
move up diagonal check in matrix power
  • Loading branch information
fredrikekre committed Aug 6, 2017
commit 04b941e7aa5a72970f44c93c9d2243f0e220e1f2
18 changes: 9 additions & 9 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ end
function (^)(A::AbstractMatrix{T}, p::Real) where T
n = checksquare(A)

# Quicker return if A is diagonal
if isdiag(A)
retmat = copy(A)
for i in 1:n
retmat[i, i] = retmat[i, i] ^ p
end
return retmat
end

# For integer powers, use power_by_squaring
isinteger(p) && return integerpow(A, p)

Expand All @@ -408,15 +417,6 @@ function (^)(A::AbstractMatrix{T}, p::Real) where T
return (Hermitian(A)^p)
end

# Quicker return if A is diagonal
if isdiag(A)
retmat = copy(A)
for i in 1:n
retmat[i, i] = retmat[i, i] ^ p
end
return retmat
end

# Otherwise, use Schur decomposition
return schurpow(A, p)
end
Expand Down