From a299d739e131b69bfed5673253eb0ee4ec4ad392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Mon, 12 Sep 2022 23:45:53 +0200 Subject: [PATCH] Fix comparison of zero NBodyMatrixElements (#19) * Fix comparison of zero NBodyMatrixElements * Bump version * Update CI config --- .github/workflows/CI.yml | 3 +-- Project.toml | 2 +- src/nbody_matrix_elements.jl | 1 + test/nbody_matrix_elements.jl | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f42222b..891a70e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,8 +13,7 @@ jobs: matrix: version: - '1.6' - - '1.7' - - 'nightly' + - '1' os: - ubuntu-latest - macOS-latest diff --git a/Project.toml b/Project.toml index c9c2e2b..29bf669 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "EnergyExpressions" uuid = "f4b57a2e-27c7-11e9-0cb0-edd185b706f6" authors = ["Stefanos Carlström "] -version = "0.1.0" +version = "0.1.1" [deps] AtomicLevels = "10933b4c-d60f-11e8-1fc6-bd9035a249a1" diff --git a/src/nbody_matrix_elements.jl b/src/nbody_matrix_elements.jl index 528ad7a..465b24d 100644 --- a/src/nbody_matrix_elements.jl +++ b/src/nbody_matrix_elements.jl @@ -387,6 +387,7 @@ an expression with a reference, generated otherwise. It may not be performant. It may also fail on edge cases. """ function compare(a::NBodyMatrixElement, op, b::NBodyMatrixElement; kwargs...) + iszero(a) && iszero(b) && return op(0, 0) ad,bd = map((a,b)) do o od = Dict{Vector{NBodyTermFactor},Number}() for term in o.terms diff --git a/test/nbody_matrix_elements.jl b/test/nbody_matrix_elements.jl index 96dce04..c8752f1 100644 --- a/test/nbody_matrix_elements.jl +++ b/test/nbody_matrix_elements.jl @@ -85,12 +85,18 @@ @testset "NBodyMatrixElement" begin o = one(NBodyMatrixElement) z = zero(NBodyMatrixElement) + az = convert(NBodyMatrixElement, 0) + bz = 0convert(NBodyMatrixElement, 1) @test o == one(z) @test isone(o) @test z == zero(o) @test iszero(z) + @test z == az + @test z == bz + @test z ≈ az + @test z ≈ bz h = FieldFreeOneBodyHamiltonian()