Skip to content

Commit

Permalink
prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
akuporos committed Nov 7, 2024
1 parent d494128 commit 982b460
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
33 changes: 1 addition & 32 deletions src/bindings/python/src/pyopenvino/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<ov::Core, std::shared_ptr<ov::Core>> cls(m, "Core");
cls.doc() =
Expand Down Expand Up @@ -549,7 +518,7 @@ void regclass_Core(py::module m) {
info = py::buffer(model_stream).request();
}

stringbuf mb(reinterpret_cast<char*>(info.ptr), info.size);
Common::utils::MemoryBuffer mb(reinterpret_cast<char*>(info.ptr), info.size);
std::istream stream(&mb);

py::gil_scoped_release release;
Expand Down
9 changes: 1 addition & 8 deletions src/bindings/python/src/pyopenvino/frontend/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<FrontEnd, std::shared_ptr<FrontEnd>> fem(m, "FrontEnd", py::dynamic_attr(), py::module_local());
fem.doc() = "openvino.frontend.FrontEnd wraps ov::frontend::FrontEnd";
Expand Down Expand Up @@ -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<char*>(info.ptr), info.size);
Common::utils::MemoryBuffer mb(reinterpret_cast<char*>(info.ptr), info.size);
std::istream _istream(&mb);
return self.load(&_istream, enable_mmap);
} else {
Expand Down
31 changes: 31 additions & 0 deletions src/bindings/python/src/pyopenvino/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down

0 comments on commit 982b460

Please sign in to comment.