Skip to content

Commit

Permalink
Add Algorithm: almost_equal (almostEqual) (#398)
Browse files Browse the repository at this point in the history
Add floating point _almost equal_ comparison from `AMReX_Algorithm`.
  • Loading branch information
ax3l authored Jan 4, 2025
1 parent d07b738 commit 81c9793
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Base/Algorithm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright 2021-2025 The AMReX Community
*
* Authors: Axel Huebl
* License: BSD-3-Clause-LBNL
*/
#include "pyAMReX.H"

#include <AMReX_Algorithm.H>

#include <type_traits>


void init_Algorithm (py::module& m)
{
using namespace amrex;

m.def(
"almost_equal",
&almostEqual<Real>,
py::arg("x"), py::arg("y"), py::arg("ulp")=2
);

if constexpr (!std::is_same_v<Real, ParticleReal>)
{
m.def(
"almost_equal",
&almostEqual<ParticleReal>,
py::arg("x"), py::arg("y"), py::arg("ulp")=2
);
}
}
1 change: 1 addition & 0 deletions src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
foreach(D IN LISTS AMReX_SPACEDIM)
target_sources(pyAMReX_${D}d
PRIVATE
Algorithm.cpp
AMReX.cpp
Arena.cpp
Array4.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/pyAMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 81c9793

Please sign in to comment.