From fdffbdc7be860b099cd1fb22bf944c958b22b905 Mon Sep 17 00:00:00 2001 From: Paul Sardin Date: Fri, 16 Jan 2026 08:35:34 +0100 Subject: [PATCH 1/2] Add path serialization --- src/pyhpp/core/path/vector.cc | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/pyhpp/core/path/vector.cc b/src/pyhpp/core/path/vector.cc index 6388da39..89c83d10 100644 --- a/src/pyhpp/core/path/vector.cc +++ b/src/pyhpp/core/path/vector.cc @@ -30,9 +30,12 @@ #include #include #include +#include #include #include #include +#include +#include using namespace boost::python; @@ -41,6 +44,31 @@ namespace core { namespace path { using namespace hpp::core; +void savePathVector(PathVectorPtr_t pathVector, const std::string& filename) { + if (!pathVector) { + throw std::invalid_argument("Cannot save null PathVector"); + } + std::ofstream ofs(filename, std::ios::binary); + if (!ofs.is_open()) { + throw std::runtime_error("Failed to open file for writing: " + filename); + } + hpp::serialization::binary_oarchive ar(ofs); + ar.initialize(); + ar << hpp::serialization::make_nvp("pathVector", pathVector); +} + +PathVectorPtr_t loadPathVector(const std::string& filename) { + std::ifstream ifs(filename, std::ios::binary); + if (!ifs.is_open()) { + throw std::runtime_error("Failed to open file for reading: " + filename); + } + hpp::serialization::binary_iarchive ar(ifs); + ar.initialize(); + PathVectorPtr_t pathVector; + ar >> hpp::serialization::make_nvp("pathVector", pathVector); + return pathVector; +} + void exposeVector() { class_, boost::noncopyable>("Vector", no_init) @@ -52,7 +80,14 @@ void exposeVector() { .PYHPP_DEFINE_METHOD(PathVector, rankAtParam) .PYHPP_DEFINE_METHOD(PathVector, appendPath) .PYHPP_DEFINE_METHOD(PathVector, concatenate) - .PYHPP_DEFINE_METHOD(PathVector, flatten); + .PYHPP_DEFINE_METHOD(PathVector, flatten) + + // Serialization methods (binary format) + .def("save", &savePathVector, + "Save PathVector to file (binary format)") + .def("load", &loadPathVector, + "Load PathVector from file (binary format)") + .staticmethod("load"); class_("Vectors").def( vector_indexing_suite()); From b9be7de89d55a0950228f6e606723de4c3e66402 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 Jan 2026 08:46:52 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyhpp/core/path/vector.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pyhpp/core/path/vector.cc b/src/pyhpp/core/path/vector.cc index 6bc77f07..d64d5ea2 100644 --- a/src/pyhpp/core/path/vector.cc +++ b/src/pyhpp/core/path/vector.cc @@ -31,12 +31,10 @@ #include #include #include -#include #include #include #include #include -#include #include using namespace boost::python; @@ -85,10 +83,8 @@ void exposeVector() { .PYHPP_DEFINE_METHOD(PathVector, flatten) // Serialization methods (binary format) - .def("save", &savePathVector, - "Save PathVector to file (binary format)") - .def("load", &loadPathVector, - "Load PathVector from file (binary format)") + .def("save", &savePathVector, "Save PathVector to file (binary format)") + .def("load", &loadPathVector, "Load PathVector from file (binary format)") .staticmethod("load"); class_("Vectors").def(