Skip to content

Commit

Permalink
Bool is usually faster, even taking into account type promotion overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Jul 1, 2024
1 parent 20b2e6b commit 41beb9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function ket(::Type{T}, i::Integer, d::Integer = 2) where {T<:Number}
psi[i] = 1
return psi
end
ket(i::Integer, d::Integer = 2) = ket(ComplexF64, i, d)
ket(i::Integer, d::Integer = 2) = ket(Bool, i, d)
export ket

"""
Expand All @@ -31,7 +31,7 @@ function proj(::Type{T}, i::Integer, d::Integer = 2) where {T<:Number}
p[i, i] = 1
return p
end
proj(i::Integer, d::Integer = 2) = proj(ComplexF64, i, d)
proj(i::Integer, d::Integer = 2) = proj(Bool, i, d)
export proj

const Measurement{T} = Vector{LA.Hermitian{T,Matrix{T}}}
Expand Down
4 changes: 2 additions & 2 deletions test/basic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "Basic " begin
@testset "Kets" begin
@test isa(ket(1, 3), Vector{ComplexF64})
@test isa(proj(1, 3), Hermitian{ComplexF64})
@test isa(ket(1, 3), Vector{Bool})
@test isa(proj(1, 3), Hermitian{Bool})
for R in [Int64, Float64, Double64, Float128, BigFloat]
ψ = ket(R, 2, 3)
P = proj(R, 2, 3)
Expand Down

0 comments on commit 41beb9c

Please sign in to comment.