OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[PyOV] Extend Python API with `SparseFillEmptyRows-16` (#30487)
Przemyslaw Wysockib6404a311be0
diff --git a/src/bindings/python/src/openvino/_pyopenvino/__init__.pyi b/src/bindings/python/src/openvino/_pyopenvino/__init__.pyiindex dcf6742cd8e..a659c06612d 100644--- a/src/bindings/python/src/openvino/_pyopenvino/__init__.pyi+++ b/src/bindings/python/src/openvino/_pyopenvino/__init__.pyi@@ -721,6 +721,20 @@ class Core::rtype: openvino.RemoteContext"""@typing.overload+ def get_property(self, device_name: str, name: str, arguments: dict[str, typing.Any]) -> typing.Any:+ """+ Gets properties dedicated to device behaviour.++ :param device_name: A name of a device to get a properties value.+ :type device_name: str+ :param name: Property or name of Property.+ :type name: str+ :param arguments: Additional arguments to get a property.+ :type arguments: dict[str, typing.Any]+ :return: Extracted information from property.+ :rtype: typing.Any+ """+ @typing.overloaddef get_property(self, device_name: str, property: str) -> typing.Any:"""Gets properties dedicated to device behaviour.diff --git a/src/bindings/python/src/openvino/opset16/__init__.py b/src/bindings/python/src/openvino/opset16/__init__.pyindex 231f2914013..5f23ed843e1 100644--- a/src/bindings/python/src/openvino/opset16/__init__.py+++ b/src/bindings/python/src/openvino/opset16/__init__.py@@ -6,6 +6,7 @@from openvino.opset16.ops import identityfrom openvino.opset16.ops import istftfrom openvino.opset16.ops import segment_max+from openvino.opset16.ops import sparse_fill_empty_rows# Operators from previous opsets# TODO (ticket: 156877): Add previous opset operators at the end of opset16 developmentdiff --git a/src/bindings/python/src/openvino/opset16/__init__.pyi b/src/bindings/python/src/openvino/opset16/__init__.pyiindex 389eccc737b..35be81c0722 100644--- a/src/bindings/python/src/openvino/opset16/__init__.pyi+++ b/src/bindings/python/src/openvino/opset16/__init__.pyi@@ -4,4 +4,5 @@ from __future__ import annotationsfrom openvino.opset16.ops import identityfrom openvino.opset16.ops import istftfrom openvino.opset16.ops import segment_max-__all__ = ['identity', 'istft', 'ops', 'segment_max']+from openvino.opset16.ops import sparse_fill_empty_rows+__all__ = ['identity', 'istft', 'ops', 'segment_max', 'sparse_fill_empty_rows']diff --git a/src/bindings/python/src/openvino/opset16/ops.py b/src/bindings/python/src/openvino/opset16/ops.pyindex de7e57deb1a..e2828dc8b30 100644--- a/src/bindings/python/src/openvino/opset16/ops.py+++ b/src/bindings/python/src/openvino/opset16/ops.py@@ -96,3 +96,29 @@ def segment_max(as_nodes(*inputs, name=name),{"fill_mode": fill_mode},)+++@nameable_op+def sparse_fill_empty_rows(+ values: NodeInput,+ dense_shape: NodeInput,+ indices: NodeInput,+ default_value: NodeInput,+ name: Optional[str] = None,+) -> Node:+ """Fills empty rows of an input sparse tensor with a default value.++ :param values: 1D tensor containing the values to be inserted at the specified indices.+ :param dense_shape: 1D tensor indicating the shape of the 2D dense tensor.+ :param indices: 2D tensor indicating the positions at which values are placed.+ :param default_value: A scalar value to be inserted into empty rows.+ :param name: Optional name for the node.++ :return: The new node performing SparseFillEmptyRows operation with three outputs:+ [output_indices, output_values, empty_row_indicator]+ """+ return _get_node_factory_opset16().create(+ "SparseFillEmptyRows",+ as_nodes(values, dense_shape, indices, default_value, name=name),+ {},+ )diff --git a/src/bindings/python/src/openvino/opset16/ops.pyi b/src/bindings/python/src/openvino/opset16/ops.pyiindex d3e4ed47753..1b213473922 100644--- a/src/bindings/python/src/openvino/opset16/ops.pyi+++ b/src/bindings/python/src/openvino/opset16/ops.pyi@@ -11,7 +11,7 @@ import typing"""Factory functions for ops added to openvino opset16."""-__all__ = ['Node', 'NodeInput', 'as_nodes', 'identity', 'istft', 'nameable_op', 'partial', 'segment_max']+__all__ = ['Node', 'NodeInput', 'as_nodes', 'identity', 'istft', 'nameable_op', 'partial', 'segment_max', 'sparse_fill_empty_rows']def identity(*args, **kwargs) -> openvino._pyopenvino.Node:"""Identity operation is used as a placeholder. It creates a copy of the input to forward to the output.@@ -48,6 +48,20 @@ def segment_max(*args, **kwargs) -> openvino._pyopenvino.Node::return: The new node performing SegmentMax operation.+ """+def sparse_fill_empty_rows(*args, **kwargs) -> openvino._pyopenvino.Node:+ """+ Fills empty rows of an input sparse tensor with a default value.++ :param values: 1D tensor containing the values to be inserted at the specified indices.+ :param dense_shape: 1D tensor indicating the shape of the 2D dense tensor.+ :param indices: 2D tensor indicating the positions at which values are placed.+ :param default_value: A scalar value to be inserted into empty rows.+ :param name: Optional name for the node.++ :return: The new node performing SparseFillEmptyRows operation with three outputs:+ [output_indices, output_values, empty_row_indicator]+"""NodeInput: typing._UnionGenericAlias # value = typing.Union[openvino._pyopenvino.Node, int, float, numpy.ndarray]_get_node_factory_opset16: functools.partial # value = functools.partial(<function _get_node_factory at memory_address>, 'opset16')diff --git a/src/bindings/python/src/openvino/runtime/opset16/__init__.py b/src/bindings/python/src/openvino/runtime/opset16/__init__.pyindex 028452c4817..f8a43ffd551 100644--- a/src/bindings/python/src/openvino/runtime/opset16/__init__.py+++ b/src/bindings/python/src/openvino/runtime/opset16/__init__.py@@ -8,6 +8,7 @@ from openvino.runtime.opset16 import opsfrom openvino.opset16.ops import identityfrom openvino.opset16.ops import istftfrom openvino.opset16.ops import segment_max+from openvino.opset16.ops import sparse_fill_empty_rows# Operators from previous opsets# TODO (ticket: 156877): Add previous opset operators at the end of opset16 developmentdiff --git a/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py b/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.pyindex 566efc11530..04e8f479dcd 100644--- a/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py+++ b/src/bindings/python/src/openvino/runtime/opset16/ops/__init__.py@@ -5,3 +5,4 @@from openvino.opset16.ops import identityfrom openvino.opset16.ops import istftfrom openvino.opset16.ops import segment_max+from openvino.opset16.ops import sparse_fill_empty_rowsdiff --git a/src/bindings/python/tests/test_graph/test_sparse_fill_empty_rows.py b/src/bindings/python/tests/test_graph/test_sparse_fill_empty_rows.pynew file mode 100644index 00000000000..c1e39eb29f4--- /dev/null+++ b/src/bindings/python/tests/test_graph/test_sparse_fill_empty_rows.py@@ -0,0 +1,42 @@+# -*- coding: utf-8 -*-+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++from openvino import Type+from openvino.opset15 import parameter+import openvino.opset16 as ov+import pytest++[email protected]("values_dtype", [+ Type.f32,+ Type.f16,+ Type.i32+])[email protected]("indices_dtype", [+ Type.i32,+ Type.i64+])[email protected](("values_shape", "indices_shape", "dense_shape_value"), [+ ((5,), (5, 2), [10, 10]), # Basic case+ ((0,), (0, 2), [5, 5]), # Empty values+])+def test_sparse_fill_empty_rows(values_dtype, indices_dtype, values_shape, indices_shape, dense_shape_value):+ values = parameter(values_shape, name="values", dtype=values_dtype)+ dense_shape = parameter((len(dense_shape_value),), name="dense_shape", dtype=indices_dtype)+ indices = parameter(indices_shape, name="indices", dtype=indices_dtype)+ default_value = parameter((), name="default_value", dtype=values_dtype)++ node = ov.sparse_fill_empty_rows(values, dense_shape, indices, default_value)++ assert node.get_type_name() == "SparseFillEmptyRows"+ assert node.get_output_size() == 3++ assert node.get_output_element_type(0) == indices_dtype+ assert node.get_output_element_type(1) == values_dtype+ assert node.get_output_element_type(2) == Type.boolean++ assert node.get_output_partial_shape(0).rank == 2+ assert node.get_output_partial_shape(0)[1] == 2+ assert node.get_output_partial_shape(1).rank == 1+ assert node.get_output_partial_shape(2).rank == 1