heal-research / pyoperon

Python bindings and scikit-learn interface for the Operon library for symbolic regression.
MIT License
42 stars 12 forks source link

Fixed usage of double precision #25

Closed Smantii closed 1 week ago

Smantii commented 1 week ago

Fixes compilation error in the double-precision Operon backend.

foolnotion commented 1 week ago

As it stands, there are unneeded changes. We only need to keep these:

diff --git a/source/evaluator.cpp b/source/evaluator.cpp
index c50f8f5..d815db4 100644
--- a/source/evaluator.cpp
+++ b/source/evaluator.cpp
@@ -122,11 +122,11 @@ void InitEval(py::module_ &m)

     }, py::arg("tree"), py::arg("dataset"), py::arg("range"), py::arg("target"), py::arg("metric") = "rsquared");

-    m.def("PoissonLikelihood", [](py::array_t<float> x, py::array_t<float> y){
+    m.def("PoissonLikelihood", [](py::array_t<Operon::Scalar> x, py::array_t<Operon::Scalar> y){
         return detail::PoissonLikelihood(std::move(x), std::move(y));
     });

-    m.def("PoissonLikelihood", [](py::array_t<float> x, py::array_t<float> y, py::array_t<float> w){
+    m.def("PoissonLikelihood", [](py::array_t<Operon::Scalar> x, py::array_t<Operon::Scalar> y, py::array_t<Operon::Scalar> w){
         return detail::PoissonLikelihood(std::move(x), std::move(y), std::move(w));
     });

@@ -142,12 +142,12 @@ void InitEval(py::module_ &m)

         TDispatch dtable;

-        auto result = py::array_t<double>(static_cast<pybind11::ssize_t>(trees.size()));
+        auto result = py::array_t<Operon::Scalar>(static_cast<pybind11::ssize_t>(trees.size()));
         auto buf = result.request();
         auto values = d.GetValues(target).subspan(r.Start(), r.Size());

         // TODO: make this run in parallel with taskflow
-        std::transform(trees.begin(), trees.end(), static_cast<double*>(buf.ptr), [&](auto const& t) -> double {
+        std::transform(trees.begin(), trees.end(), static_cast<Operon::Scalar*>(buf.ptr), [&](auto const& t) -> double {
             auto estimated = TInterpreter{dtable, d, t}.Evaluate({}, r);
             return (*error)(estimated, values);
         });
Smantii commented 1 week ago

Done!

foolnotion commented 1 week ago

Done!

Hi, sorry for being pedantic but we don't want to have all these commits in the history (the last one basically reverts the previous changes). Instead, please soft-reset to HEAD~3, then commit only the required changes and force-push.

Smantii commented 1 week ago

Done, now the changes are made in a single commit.

foolnotion commented 1 week ago

Done, now the changes are made in a single commit.

Looks good, thanks!