From 81c979326660865f29cdaf58241af71e8439a9f1 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 3 Jan 2025 23:42:12 -0800 Subject: [PATCH] Add Algorithm: `almost_equal` (`almostEqual`) (#398) Add floating point _almost equal_ comparison from `AMReX_Algorithm`. --- src/Base/Algorithm.cpp | 31 +++++++++++++++++++++++++++++++ src/Base/CMakeLists.txt | 1 + src/pyAMReX.cpp | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 src/Base/Algorithm.cpp diff --git a/src/Base/Algorithm.cpp b/src/Base/Algorithm.cpp new file mode 100644 index 00000000..5c468302 --- /dev/null +++ b/src/Base/Algorithm.cpp @@ -0,0 +1,31 @@ +/* Copyright 2021-2025 The AMReX Community + * + * Authors: Axel Huebl + * License: BSD-3-Clause-LBNL + */ +#include "pyAMReX.H" + +#include + +#include + + +void init_Algorithm (py::module& m) +{ + using namespace amrex; + + m.def( + "almost_equal", + &almostEqual, + py::arg("x"), py::arg("y"), py::arg("ulp")=2 + ); + + if constexpr (!std::is_same_v) + { + m.def( + "almost_equal", + &almostEqual, + py::arg("x"), py::arg("y"), py::arg("ulp")=2 + ); + } +} diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index b80c820b..0db7d7cb 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -1,6 +1,7 @@ foreach(D IN LISTS AMReX_SPACEDIM) target_sources(pyAMReX_${D}d PRIVATE + Algorithm.cpp AMReX.cpp Arena.cpp Array4.cpp diff --git a/src/pyAMReX.cpp b/src/pyAMReX.cpp index aebe7403..ed52c2be 100644 --- a/src/pyAMReX.cpp +++ b/src/pyAMReX.cpp @@ -12,6 +12,7 @@ // forward declarations of exposed classes +void init_Algorithm(py::module&); void init_AMReX(py::module&); void init_Arena(py::module&); void init_Array4(py::module&); @@ -90,6 +91,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) { init_AMReX(m); init_Arena(m); init_Dim3(m); + init_Algorithm(m); init_IntVect(m); init_IndexType(m); init_RealVect(m);