From 3527c75ad2cff62e259553559ac6aff5ebc29e69 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 15 Oct 2024 11:47:11 -0700 Subject: [PATCH 1/5] Make the zero class simpler using the empty constructor. --- src/math/zero.hpp | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/math/zero.hpp b/src/math/zero.hpp index 8fbfa1cde..80ecee26b 100644 --- a/src/math/zero.hpp +++ b/src/math/zero.hpp @@ -21,37 +21,7 @@ namespace inq { template GPU_FUNCTION auto zero(){ - return Type{0.0}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{0.0, 0.0, 0.0}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{0.0, 0.0, 0.0}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{0.0, 0.0, 0.0}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}; -} - -template <> -GPU_FUNCTION auto zero>(){ - return vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}; + return Type{}; } } From 282da432dd23a395ab27509f3f5cf93fd69adc49 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 15 Oct 2024 11:48:07 -0700 Subject: [PATCH 2/5] Check that zero works. --- src/math/zero.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/math/zero.hpp b/src/math/zero.hpp index 80ecee26b..8795cbb7a 100644 --- a/src/math/zero.hpp +++ b/src/math/zero.hpp @@ -33,6 +33,11 @@ GPU_FUNCTION auto zero(){ #include TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) { - + using namespace inq; + + CHECK(zero() == 0.0); + CHECK(zero() == complex{0.0, 0.0}); + CHECK(zero>() == vector3{0.0, 0.0, 0.0}); + CHECK(zero>() == vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}); } #endif From a0a305f0e31d535b2e6fcdd8e341f1c0c287cc5d Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 15 Oct 2024 12:18:18 -0700 Subject: [PATCH 3/5] Declare zero constrexpr. --- src/math/zero.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/zero.hpp b/src/math/zero.hpp index 8795cbb7a..01acf4d54 100644 --- a/src/math/zero.hpp +++ b/src/math/zero.hpp @@ -20,7 +20,7 @@ namespace inq { template -GPU_FUNCTION auto zero(){ +GPU_FUNCTION constexpr auto zero(){ return Type{}; } From c69402f9b1ca1c5cd1f70b876a1e9e167316d4a1 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 15 Oct 2024 12:21:51 -0700 Subject: [PATCH 4/5] Make a non-template zero() function that works for comparison. --- src/math/zero.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/math/zero.hpp b/src/math/zero.hpp index 01acf4d54..b5630e123 100644 --- a/src/math/zero.hpp +++ b/src/math/zero.hpp @@ -24,6 +24,23 @@ GPU_FUNCTION constexpr auto zero(){ return Type{}; } +struct zero_t { +}; + +auto zero() { + return zero_t{}; +} + +template +auto operator==(Type const & aa, zero_t) { + return aa == zero(); +} + +template +auto operator==(zero_t z, Type const & aa) { + return aa == z; +} + } #endif @@ -39,5 +56,15 @@ TEST_CASE(INQ_TEST_FILE, INQ_TEST_TAG) { CHECK(zero() == complex{0.0, 0.0}); CHECK(zero>() == vector3{0.0, 0.0, 0.0}); CHECK(zero>() == vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}); + + CHECK(zero() == 0.0); + CHECK(zero() == complex{0.0, 0.0}); + CHECK(zero() == vector3{0.0, 0.0, 0.0}); + CHECK(zero() == vector3{complex{0.0, 0.0}, complex{0.0, 0.0}, complex{0.0, 0.0}}); + + // double aa = zero(); + // CHECK(aa == 0.0); + } + #endif From 788e5d47057ab9aa6ffe5c838ab371fc36220c19 Mon Sep 17 00:00:00 2001 From: Xavier Andrade Date: Tue, 15 Oct 2024 14:03:57 -0700 Subject: [PATCH 5/5] Avoid ambiguity for thrust::complex values. --- src/math/zero.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/math/zero.hpp b/src/math/zero.hpp index b5630e123..6bda4ea8e 100644 --- a/src/math/zero.hpp +++ b/src/math/zero.hpp @@ -31,11 +31,19 @@ auto zero() { return zero_t{}; } +auto operator==(complex const & aa, zero_t) { + return aa == zero(); +} + template auto operator==(Type const & aa, zero_t) { return aa == zero(); } +auto operator==(zero_t z, complex const & aa) { + return aa == z; +} + template auto operator==(zero_t z, Type const & aa) { return aa == z;