Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Extend Python API with SliceScatter-15 (#27090)

Mateusz Mikolajczyk487b3910f6d6
diff --git a/src/bindings/python/src/openvino/runtime/opset15/__init__.py b/src/bindings/python/src/openvino/runtime/opset15/__init__.py
index 1349508e84b..96643a7e93d 100644
--- a/src/bindings/python/src/openvino/runtime/opset15/__init__.py
+++ b/src/bindings/python/src/openvino/runtime/opset15/__init__.py
@@ -15,3 +15,4 @@ from openvino.runtime.opset15.ops import string_tensor_pack
from openvino.runtime.opset15.ops import string_tensor_unpack
from openvino.runtime.opset15.ops import bitwise_left_shift
from openvino.runtime.opset15.ops import bitwise_right_shift
+from openvino.runtime.opset15.ops import slice_scatter
diff --git a/src/bindings/python/src/openvino/runtime/opset15/ops.py b/src/bindings/python/src/openvino/runtime/opset15/ops.py
index 777fc165443..116f63726bf 100644
--- a/src/bindings/python/src/openvino/runtime/opset15/ops.py
+++ b/src/bindings/python/src/openvino/runtime/opset15/ops.py
@@ -274,3 +274,32 @@ def bitwise_right_shift(
"auto_broadcast": auto_broadcast.upper(),
},
)
+
+
+@nameable_op
+def slice_scatter(
+ data: NodeInput,
+ updates: NodeInput,
+ start: NodeInput,
+ stop: NodeInput,
+ step: NodeInput,
+ axes: Optional[NodeInput] = None,
+ name: Optional[str] = None,
+) -> Node:
+ """Return a node which generates SliceScatter operation.
+
+ :param data: The node providing input data.
+ :param updates: The node providing updates data.
+ :param start: The node providing start indices (inclusively).
+ :param stop: The node providing stop indices (exclusively).
+ :param step: The node providing step values.
+ :param axes: The optional node providing axes to slice, default [0, 1, ..., len(start)-1].
+ :param name: The optional name for the created output node.
+ :return: The new node performing SliceScatter operation.
+ """
+ if axes is None:
+ inputs = as_nodes(data, updates, start, stop, step, name=name)
+ else:
+ inputs = as_nodes(data, updates, start, stop, step, axes, name=name)
+
+ return _get_node_factory_opset15().create("SliceScatter", inputs)
diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.py
index dcdb8592390..c5023588f5d 100644
--- a/src/bindings/python/tests/test_graph/test_create_op.py
+++ b/src/bindings/python/tests/test_graph/test_create_op.py
@@ -2458,6 +2458,34 @@ def test_topk_opset11(op_name):
assert list(node.get_output_shape(1)) == [1, 3, 3]
+def test_slice_scatter():
+ data_shape = [10, 7, 2, 13]
+ data = ov.parameter(data_shape, name="input", dtype=np.float32)
+ updates = ov.parameter([4, 7, 2, 13], name="updates", dtype=np.float32)
+ start = ov.constant(np.array([2, 0, 0], dtype=np.int32))
+ stop = ov.constant(np.array([9, 7, 2], dtype=np.int32))
+ step = ov.constant(np.array([2, 1, 1], dtype=np.int32))
+
+ node_default_axes = ov_opset15.slice_scatter(data, updates, start, stop, step)
+
+ assert node_default_axes.get_type_name() == "SliceScatter"
+ assert node_default_axes.get_output_size() == 1
+ assert node_default_axes.get_output_element_type(0) == Type.f32
+ assert node_default_axes.get_output_shape(0) == data_shape
+
+ start = ov.constant(np.array([0, 2], dtype=np.int32))
+ stop = ov.constant(np.array([2, 9], dtype=np.int32))
+ step = ov.constant(np.array([1, 2], dtype=np.int32))
+ axes = ov.constant(np.array([-2, 0], dtype=np.int32))
+
+ node = ov_opset15.slice_scatter(data, updates, start, stop, step, axes)
+
+ assert node.get_type_name() == "SliceScatter"
+ assert node.get_output_size() == 1
+ assert node.get_output_element_type(0) == Type.f32
+ assert node_default_axes.get_output_shape(0) == data_shape
+
+
def test_parameter_get_attributes():
parameter = ov.parameter([2, 2], dtype=np.float32, name="InputData")
parameter_attributes = parameter.get_attributes()