Exposes ov::Symbol and new methods of ov::Dimension (#23688)
### Details: - *Exposes ov::Symbol to py API* - *Exposes new ov::Dimension methods to py API* ### Tickets: - *CVS-136760* --------- Co-authored-by: Jan Iwaszkiewicz <jan.iwaszkiewicz@intel.com> Co-authored-by: Anastasia Kuporosova <anastasia.kuporosova@intel.com>
This commit is contained in:
parent
22d67427c2
commit
6306ee1a86
|
|
@ -32,6 +32,7 @@ from openvino.runtime import CompiledModel
|
|||
from openvino.runtime import InferRequest
|
||||
from openvino.runtime import AsyncInferQueue
|
||||
|
||||
from openvino.runtime import Symbol
|
||||
from openvino.runtime import Dimension
|
||||
from openvino.runtime import Strides
|
||||
from openvino.runtime import PartialShape
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from openvino._pyopenvino import get_version
|
|||
__version__ = get_version()
|
||||
|
||||
# Openvino pybind bindings and python extended classes
|
||||
from openvino._pyopenvino import Symbol
|
||||
from openvino._pyopenvino import Dimension
|
||||
from openvino._pyopenvino import Input
|
||||
from openvino._pyopenvino import Output
|
||||
|
|
|
|||
|
|
@ -121,6 +121,36 @@ void regclass_graph_Dimension(py::module m) {
|
|||
:return: Value of the dimension.
|
||||
:rtype: int
|
||||
)");
|
||||
|
||||
/// Symbol-related methods: START
|
||||
dim.def("has_symbol",
|
||||
&ov::Dimension::has_symbol,
|
||||
R"(
|
||||
Check if Dimension has meaningful symbol.
|
||||
|
||||
:return: True if symbol was set, else False.
|
||||
:rtype: bool
|
||||
)");
|
||||
dim.def("get_symbol",
|
||||
&ov::Dimension::get_symbol,
|
||||
R"(
|
||||
Return this dimension's symbol as Symbol object.
|
||||
|
||||
:return: Value of the dimension.
|
||||
:rtype: openvino.Symbol
|
||||
)");
|
||||
|
||||
dim.def("set_symbol",
|
||||
&ov::Dimension::set_symbol,
|
||||
py::arg("symbol"),
|
||||
R"(
|
||||
Sets provided Symbol as this dimension's symbol.
|
||||
|
||||
:param symbol: The symbol to set to this dimension.
|
||||
:type symbol: openvino.Symbol
|
||||
)");
|
||||
/// Symbol-related methods: END
|
||||
|
||||
dim.def("same_scheme",
|
||||
&ov::Dimension::same_scheme,
|
||||
py::arg("dim"),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2018-2024 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/core/symbol.hpp" // ov::Symbol
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include "pyopenvino/graph/symbol.hpp"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_graph_Symbol(py::module m) {
|
||||
py::class_<ov::Symbol, std::shared_ptr<ov::Symbol>> symbol(m, "Symbol");
|
||||
symbol.doc() = "openvino.runtime.Symbol wraps ov::Symbol";
|
||||
|
||||
symbol.def(py::init([]() {
|
||||
return std::make_shared<ov::Symbol>();
|
||||
}));
|
||||
|
||||
symbol.def(
|
||||
"__eq__",
|
||||
[](const std::shared_ptr<ov::Symbol>& a, const std::shared_ptr<ov::Symbol>& b) {
|
||||
return ov::symbol::are_equal(a, b);
|
||||
},
|
||||
py::is_operator());
|
||||
|
||||
symbol.def(
|
||||
"__bool__",
|
||||
[](const std::shared_ptr<ov::Symbol>& a) -> bool {
|
||||
return a != nullptr;
|
||||
},
|
||||
"Check whether the symbol is meaningful");
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2018-2024 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
void regclass_graph_Symbol(py::module m);
|
||||
|
|
@ -62,6 +62,7 @@
|
|||
#include "pyopenvino/graph/rt_map.hpp"
|
||||
#include "pyopenvino/graph/shape.hpp"
|
||||
#include "pyopenvino/graph/strides.hpp"
|
||||
#include "pyopenvino/graph/symbol.hpp"
|
||||
#include "pyopenvino/graph/types/regmodule_graph_types.hpp"
|
||||
#include "pyopenvino/graph/util.hpp"
|
||||
#include "pyopenvino/utils/utils.hpp"
|
||||
|
|
@ -215,6 +216,7 @@ PYBIND11_MODULE(_pyopenvino, m) {
|
|||
|
||||
regclass_graph_PyRTMap(m);
|
||||
regmodule_graph_types(m);
|
||||
regclass_graph_Symbol(m); // Symbol must be registered before Dimension
|
||||
regclass_graph_Dimension(m); // Dimension must be registered before PartialShape
|
||||
regclass_graph_Layout(m);
|
||||
regclass_graph_Shape(m);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright (C) 2018-2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from openvino import Dimension
|
||||
from openvino import Dimension, Symbol
|
||||
|
||||
|
||||
def test_dynamic_dimension():
|
||||
|
|
@ -61,3 +61,20 @@ def test_dim_refine():
|
|||
assert Dimension(3).refines(Dimension(3)) is True
|
||||
assert Dimension(3).refines(Dimension(4)) is False
|
||||
assert Dimension().refines(Dimension(4)) is False
|
||||
|
||||
|
||||
def test_symbol():
|
||||
dimension = Dimension()
|
||||
assert not dimension.has_symbol(), "Check: Default created Dimension has no symbol: Dimension.has_symbol()"
|
||||
assert not dimension.get_symbol(), "Check: Default created Dimension symbol is null: Symbol.__bool__"
|
||||
|
||||
symbol = Symbol()
|
||||
dimension.set_symbol(symbol)
|
||||
assert dimension.has_symbol(), "Check: After setting the symbol, Dimension has symbol: Dimension.has_symbol()"
|
||||
assert dimension.get_symbol(), "Check: After setting the symbol, Dimension symbol isn't null: Symbol.__bool__"
|
||||
|
||||
new_dimension = Dimension()
|
||||
assert dimension.get_symbol() != new_dimension.get_symbol(), "Check: Two symbols are not equal: Symbol.__eq__"
|
||||
|
||||
new_dimension.set_symbol(dimension.get_symbol())
|
||||
assert dimension.get_symbol() == new_dimension.get_symbol(), "Check: Two symbols are equal: Symbol.__eq__"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ from openvino.runtime import CompiledModel
|
|||
from openvino.runtime import InferRequest
|
||||
from openvino.runtime import AsyncInferQueue
|
||||
|
||||
from openvino.runtime import Symbol
|
||||
from openvino.runtime import Dimension
|
||||
from openvino.runtime import Strides
|
||||
from openvino.runtime import PartialShape
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ try:
|
|||
from openvino.runtime import InferRequest
|
||||
from openvino.runtime import AsyncInferQueue
|
||||
|
||||
from openvino.runtime import Symbol
|
||||
from openvino.runtime import Dimension
|
||||
from openvino.runtime import Strides
|
||||
from openvino.runtime import PartialShape
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ try:
|
|||
from openvino.runtime import InferRequest
|
||||
from openvino.runtime import AsyncInferQueue
|
||||
|
||||
from openvino.runtime import Symbol
|
||||
from openvino.runtime import Dimension
|
||||
from openvino.runtime import Strides
|
||||
from openvino.runtime import PartialShape
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ from openvino.runtime import CompiledModel
|
|||
from openvino.runtime import InferRequest
|
||||
from openvino.runtime import AsyncInferQueue
|
||||
|
||||
from openvino.runtime import Symbol
|
||||
from openvino.runtime import Dimension
|
||||
from openvino.runtime import Strides
|
||||
from openvino.runtime import PartialShape
|
||||
|
|
|
|||
Loading…
Reference in New Issue