fix(eos-bindings): minor bug fixes to bring eos bindings up to main

specifically, renamed EosIO -> EOSio, and updated read_helm_table signature
This commit is contained in:
2025-06-12 14:21:28 -04:00
parent e5d796f177
commit dd28e555c8
5 changed files with 33 additions and 29 deletions

View File

@@ -8,34 +8,38 @@
// #include "resourceManager.h"
#include "bindings.h"
#include "EOSio.h"
#include "../../eos/public/helm.h"
#include "helm.h"
namespace serif::eos {
class EOSio;
}
namespace py = pybind11;
void register_eos_bindings(pybind11::module &eos_submodule) {
py::class_<EOSio>(eos_submodule, "EOSio")
py::class_<serif::eos::EOSio>(eos_submodule, "EOSio")
.def(py::init<std::string>(), py::arg("filename"))
// .def("load", &EOSio::load)
.def("getFormat", &EOSio::getFormat, "Get the format of the EOS table.")
.def("getFormat", &serif::eos::EOSio::getFormat, "Get the format of the EOS table.")
.def("__repr__", [](const EOSio &eos) {
.def("__repr__", [](const serif::eos::EOSio &eos) {
return "<EOSio(filename='" + eos.getFilename() + "', format='" + eos.getFormat() + "')>";
});
py::class_<EOSTable>(eos_submodule, "EOSTable");
py::class_<serif::eos::EOSTable>(eos_submodule, "EOSTable");
py::class_<helmholtz::HELMTable>(eos_submodule, "HELMTable")
.def_readonly("loaded", &helmholtz::HELMTable::loaded)
.def_readonly("imax", &helmholtz::HELMTable::imax)
.def_readonly("jmax", &helmholtz::HELMTable::jmax)
.def_readonly("t", &helmholtz::HELMTable::t)
.def_readonly("d", &helmholtz::HELMTable::d)
.def("__repr__", [](const helmholtz::HELMTable &table) {
py::class_<serif::eos::helmholtz::HELMTable>(eos_submodule, "HELMTable")
.def_readonly("loaded", &serif::eos::helmholtz::HELMTable::loaded)
.def_readonly("imax", &serif::eos::helmholtz::HELMTable::imax)
.def_readonly("jmax", &serif::eos::helmholtz::HELMTable::jmax)
.def_readonly("t", &serif::eos::helmholtz::HELMTable::t)
.def_readonly("d", &serif::eos::helmholtz::HELMTable::d)
.def("__repr__", [](const serif::eos::helmholtz::HELMTable &table) {
return "<HELMTable(loaded=" + std::to_string(table.loaded) + ", imax=" + std::to_string(table.imax) +
", jmax=" + std::to_string(table.jmax) + ")>";
})
.def_property_readonly("f", [](helmholtz::HELMTable &table) -> py::array_t<double> {
.def_property_readonly("f", [](serif::eos::helmholtz::HELMTable &table) -> py::array_t<double> {
// --- Check Preconditions ---
// 1. Check if dimensions are valid
if (table.imax <= 0 || table.jmax <= 0) {
@@ -57,8 +61,10 @@ void register_eos_bindings(pybind11::module &eos_submodule) {
// --- Define NumPy array shape and strides ---
std::vector<py::ssize_t> shape = {rows, cols};
std::vector<py::ssize_t> strides = {cols * sizeof(double), // Stride to next row
sizeof(double)}; // Stride to next element in row
std::vector<py::ssize_t> strides = {
static_cast<py::ssize_t>(cols * sizeof(double)), // Stride to next row
static_cast<py::ssize_t>( sizeof(double)) // Stride to next element in row
};
// --- Create and return the py::array_t ---
// py::cast(table) creates a py::object that acts as the 'base'.