Skip to content

Commit

Permalink
Fuse complex conversion with function application for symmetric (Juli…
Browse files Browse the repository at this point in the history
…aLang#55391)

This avoids allocating an intermediate array, which reduces allocation
slightly.
```julia
julia> S = Symmetric(diagm(0=>-rand(100)));

julia> @Btime $S^0.2;
  479.196 μs (25 allocations: 560.20 KiB) # nightly v"1.12.0-DEV.994"
  478.213 μs (23 allocations: 558.58 KiB) # This PR
```
  • Loading branch information
jishnub authored Aug 6, 2024
1 parent 0717a94 commit 7377760
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ function ^(A::Symmetric{<:Real}, p::Real)
if all-> λ 0, F.values)
return Symmetric((F.vectors * Diagonal((F.values).^p)) * F.vectors')
else
return Symmetric((F.vectors * Diagonal((complex(F.values)).^p)) * F.vectors')
return Symmetric((F.vectors * Diagonal(complex.(F.values).^p)) * F.vectors')
end
end
function ^(A::Symmetric{<:Complex}, p::Real)
Expand Down Expand Up @@ -853,7 +853,7 @@ function ^(A::Hermitian{T}, p::Real) where T
return Hermitian(retmat)
end
else
return (F.vectors * Diagonal((complex(F.values).^p))) * F.vectors'
return (F.vectors * Diagonal((complex.(F.values).^p))) * F.vectors'
end
end

Expand Down Expand Up @@ -983,7 +983,7 @@ for func in (:log, :sqrt)
end
return Hermitian(retmat)
else
retmat = (F.vectors * Diagonal(($func).(complex(F.values)))) * F.vectors'
retmat = (F.vectors * Diagonal(($func).(complex.(F.values)))) * F.vectors'
return retmat
end
end
Expand Down

0 comments on commit 7377760

Please sign in to comment.