Skip to content

Commit

Permalink
replace qr with qr!, speedup randstate_haar
Browse files Browse the repository at this point in the history
  • Loading branch information
apkille committed Nov 24, 2024
1 parent f1cdea3 commit 81c1105
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/state_definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ Returns a Haar random pure state of dimension `length(b)` by applying a Haar ran
function randstate_haar(b::Basis)
dim = length(b)
mat = rand(ComplexF64, dim, dim)
q, r = qr(mat)
d = Diagonal([r[i, i] / abs(r[i, i]) for i in 1:dim])
data = q * d
return Ket(b, data[:,1])
q, r = qr!(mat)
return Ket(b, q[:,1])
end

"""
Expand All @@ -42,7 +40,7 @@ Returns a Haar random unitary matrix of dimension `length(b)`.
function randunitary_haar(b::Basis)
dim = length(b)
mat = rand(ComplexF64, dim, dim)
q, r = qr(mat)
q, r = qr!(mat)
d = Diagonal([r[i, i] / abs(r[i, i]) for i in 1:dim])
data = q * d
DenseOperator(b, b, data)
Expand Down

0 comments on commit 81c1105

Please sign in to comment.