From 982b46042b74ea0e283c7d72113300b7a49ff7a0 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Thu, 7 Nov 2024 23:43:09 +0000 Subject: [PATCH] prettify --- .../python/src/pyopenvino/core/core.cpp | 33 +------------------ .../src/pyopenvino/frontend/frontend.cpp | 9 +---- .../python/src/pyopenvino/utils/utils.hpp | 31 +++++++++++++++++ 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/bindings/python/src/pyopenvino/core/core.cpp b/src/bindings/python/src/pyopenvino/core/core.cpp index 81c3107c6e5063..68e3e5cc4841ed 100644 --- a/src/bindings/python/src/pyopenvino/core/core.cpp +++ b/src/bindings/python/src/pyopenvino/core/core.cpp @@ -18,37 +18,6 @@ namespace py = pybind11; -class stringbuf : public std::streambuf { -public: - stringbuf(char* data, std::size_t size) { - setg(data, data, data + size); - } - -protected: - pos_type seekoff(off_type off, - std::ios_base::seekdir dir, - std::ios_base::openmode which = std::ios_base::in) override { - switch (dir) { - case std::ios_base::beg: - setg(eback(), eback() + off, egptr()); - break; - case std::ios_base::end: - setg(eback(), egptr() + off, egptr()); - break; - case std::ios_base::cur: - setg(eback(), gptr() + off, egptr()); - break; - default: - return pos_type(off_type(-1)); - } - return (gptr() < eback() || gptr() > egptr()) ? pos_type(off_type(-1)) : pos_type(gptr() - eback()); - } - - pos_type seekpos(pos_type pos, std::ios_base::openmode which) override { - return seekoff(pos, std::ios_base::beg, which); - } -}; - void regclass_Core(py::module m) { py::class_> cls(m, "Core"); cls.doc() = @@ -549,7 +518,7 @@ void regclass_Core(py::module m) { info = py::buffer(model_stream).request(); } - stringbuf mb(reinterpret_cast(info.ptr), info.size); + Common::utils::MemoryBuffer mb(reinterpret_cast(info.ptr), info.size); std::istream stream(&mb); py::gil_scoped_release release; diff --git a/src/bindings/python/src/pyopenvino/frontend/frontend.cpp b/src/bindings/python/src/pyopenvino/frontend/frontend.cpp index afc9e0af361c52..758fb505f5f885 100644 --- a/src/bindings/python/src/pyopenvino/frontend/frontend.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/frontend.cpp @@ -20,13 +20,6 @@ namespace py = pybind11; using namespace ov::frontend; -class MemoryBuffer : public std::streambuf { -public: - MemoryBuffer(char* data, std::size_t size) { - setg(data, data, data + size); - } -}; - void regclass_frontend_FrontEnd(py::module m) { py::class_> fem(m, "FrontEnd", py::dynamic_attr(), py::module_local()); fem.doc() = "openvino.frontend.FrontEnd wraps ov::frontend::FrontEnd"; @@ -57,7 +50,7 @@ void regclass_frontend_FrontEnd(py::module m) { } else if (py::isinstance(py_obj, pybind11::module::import("io").attr("BytesIO"))) { // support of BytesIO py::buffer_info info = py::buffer(py_obj.attr("getbuffer")()).request(); - MemoryBuffer mb(reinterpret_cast(info.ptr), info.size); + Common::utils::MemoryBuffer mb(reinterpret_cast(info.ptr), info.size); std::istream _istream(&mb); return self.load(&_istream, enable_mmap); } else { diff --git a/src/bindings/python/src/pyopenvino/utils/utils.hpp b/src/bindings/python/src/pyopenvino/utils/utils.hpp index b59ffe530f6045..2a7b6505269535 100644 --- a/src/bindings/python/src/pyopenvino/utils/utils.hpp +++ b/src/bindings/python/src/pyopenvino/utils/utils.hpp @@ -32,6 +32,37 @@ namespace py = pybind11; namespace Common { namespace utils { +class MemoryBuffer : public std::streambuf { +public: + MemoryBuffer(char* data, std::size_t size) { + setg(data, data, data + size); + } + +protected: + pos_type seekoff(off_type off, + std::ios_base::seekdir dir, + std::ios_base::openmode which = std::ios_base::in) override { + switch (dir) { + case std::ios_base::beg: + setg(eback(), eback() + off, egptr()); + break; + case std::ios_base::end: + setg(eback(), egptr() + off, egptr()); + break; + case std::ios_base::cur: + setg(eback(), gptr() + off, egptr()); + break; + default: + return pos_type(off_type(-1)); + } + return (gptr() < eback() || gptr() > egptr()) ? pos_type(off_type(-1)) : pos_type(gptr() - eback()); + } + + pos_type seekpos(pos_type pos, std::ios_base::openmode which) override { + return seekoff(pos, std::ios_base::beg, which); + } +}; + enum class PY_TYPE : int { UNKNOWN = 0, STR, INT, FLOAT, BOOL, PARTIAL_SHAPE }; struct EmptyList {};