Files
slopetimize/src/module.cpp
T
2026-10-06 17:20:47 +02:00

53 lines
1.8 KiB
C++

#include <nanobind/eigen/dense.h>
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/filesystem.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/pair.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/function.h>
#include <Eigen/Eigen>
#include <autoopt/optimizer.hpp>
#include <autoopt/util.hpp>
#include <format>
#include <optional>
namespace nb = nanobind;
namespace std {
template <typename T>
struct formatter<optional<T>> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
auto format(const optional<T>& opt, format_context& ctx) const {
if (opt) {
return format_to(ctx.out(), "{}", opt.value());
} else {
return format_to(ctx.out(), "None");
}
}
};
} // namespace std
NB_MODULE(slopefit, m) {
nb::class_<autoopt::optimizer>(m, "Optimizer")
.def(nb::init<>())
.def("import_file", &autoopt::optimizer::import_file)
.def("set_lower_bound", &autoopt::optimizer::set_lower_bound)
.def("set_upper_bound", &autoopt::optimizer::set_upper_bound)
.def("set_curve_type", &autoopt::optimizer::set_curve_type)
.def("set_initial", &autoopt::optimizer::set_initial)
.def("set_delta", &autoopt::optimizer::set_delta)
.def("flip_curve", &autoopt::optimizer::flip_curve)
.def("calc_fit", &autoopt::optimizer::calc_fit)
.def("set_plot_input_cb", &autoopt::optimizer::set_plot_input_cb)
.def("set_init_bounds_cb", &autoopt::optimizer::set_init_bounds_cb)
.def("set_plot_slope_cb", &autoopt::optimizer::set_plot_slope_cb)
.def("set_update_table_cb", &autoopt::optimizer::set_update_table_cb)
.def("set_plot_error_cb", &autoopt::optimizer::set_plot_error_cb);
}