From 8f467b952cfa0d48b72f8b7fff54854d34a0cb02 Mon Sep 17 00:00:00 2001 From: Brian Doolittle Date: Wed, 1 Sep 2021 09:51:28 -0500 Subject: [PATCH] fixing bug in is_hermitian() --- CITATION.bib | 2 +- Project.toml | 2 +- src/math/matrices.jl | 2 +- test/unit/math/matrices.jl | 6 +++++- test/unit/types/measurements.jl | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CITATION.bib b/CITATION.bib index 3c3950d..f35905c 100644 --- a/CITATION.bib +++ b/CITATION.bib @@ -3,7 +3,7 @@ @gmail.com> title = {QBase.jl}, howpublished = {\url{https://github.com/ChitambarLab/QBase.jl}}, url = {https://github.com/chitambarlab/QBase.jl}, - version = {v0.2.0}, + version = {v0.2.1}, year = {2020}, month = {August} } diff --git a/Project.toml b/Project.toml index 3b2c042..6850031 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QBase" uuid = "e52e8ede-12bf-4731-8af7-b01f6064cb11" authors = ["Brian Doolittle and contributors"] -version = "0.2.0" +version = "0.2.1" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/math/matrices.jl b/src/math/matrices.jl index 96805cd..7d8399d 100644 --- a/src/math/matrices.jl +++ b/src/math/matrices.jl @@ -93,7 +93,7 @@ function is_hermitian(M :: AbstractMatrix{<:Number}; atol=ATOL :: Float64) :: Bo end for i = indsn, j = i:last(indsn) - if M[i,j] != adjoint(M[j,i]) && !isapprox(M[i,j],M[j,i],atol=atol) + if M[i,j] != M[j,i]' && !isapprox(M[i,j], M[j,i]', atol=atol) return false end end diff --git a/test/unit/math/matrices.jl b/test/unit/math/matrices.jl index e2eb277..8df4e10 100644 --- a/test/unit/math/matrices.jl +++ b/test/unit/math/matrices.jl @@ -1,4 +1,5 @@ -using Test, LinearAlgebra +using Test +using LinearAlgebra using QBase @testset "./src/math/matrices.jl" begin @@ -54,6 +55,9 @@ end @testset "using atol" begin @test !is_hermitian([1 1;1+1e-6 1]) @test is_hermitian([1 1;1+1e-6 1], atol=1e-5) + + @test !is_hermitian([1 1e-6 + 1im;-1im 1]) + @test is_hermitian([1 1e-6 + 1im;-1im 1], atol=1e-5) end end diff --git a/test/unit/types/measurements.jl b/test/unit/types/measurements.jl index 57e6ac1..3b1d171 100644 --- a/test/unit/types/measurements.jl +++ b/test/unit/types/measurements.jl @@ -54,9 +54,9 @@ end @test M isa POVMel{Complex{Float64}} @test M == [0.5 0.5im;-0.5im 0.5] - M = POVMel([0.5 0.5im;0.5im 0.5], atol=0.51) + M = POVMel([0.5 0.45im;-0.5im 0.5], atol=0.06) @test M isa POVMel{Complex{Float64}} - @test M == [0.5 0.5im;0.5im 0.5] + @test M == [0.5 0.45im;-0.5im 0.5] end @testset "errors" begin