Skip to content

Commit

Permalink
there's no need to restrict it to Hermitian
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Jul 5, 2024
1 parent 0a0d5c2 commit 5c54864
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/states.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
"""
white_noise(rho::LA.Hermitian, v::Real)
white_noise(rho::AbstractMatrix, v::Real)
Returns `v * rho + (1 - v) * id`, where `id` is the maximally mixed state.
"""
function white_noise(rho::LA.Hermitian, v::Real)
function white_noise(rho::AbstractMatrix, v::Real)
return white_noise!(copy(rho), v)
end
export white_noise

"""
white_noise!(rho::LA.Hermitian, v::Real)
white_noise!(rho::AbstractMatrix, v::Real)
Modifies `rho` in place to tranform in into `v * rho + (1 - v) * id`
where `id` is the maximally mixed state.
"""
function white_noise!(rho::LA.Hermitian, v::Real)
if v != 1
rho.data .*= v
tmp = (1 - v) / size(rho, 1)
# https://discourse.julialang.org/t/change-the-diagonal-of-an-abstractmatrix-in-place/67294/2
for i in axes(rho, 1)
@inbounds rho[i, i] += tmp
end
function white_noise!(rho::AbstractMatrix, v::Real)
v == 1 && return rho
parent(rho) .*= v
tmp = (1 - v) / size(rho, 1)
# https://discourse.julialang.org/t/change-the-diagonal-of-an-abstractmatrix-in-place/67294/2
for i in axes(rho, 1)
@inbounds rho[i, i] += tmp
end
return rho
end
Expand Down

0 comments on commit 5c54864

Please sign in to comment.