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
[PyAPI][Op] Extend pythonAPI with ErfInv op (#35804)
Katarzyna Mitrus26082094a473
diff --git a/src/bindings/python/src/openvino/opset17/__init__.py b/src/bindings/python/src/openvino/opset17/__init__.pyindex 6b928a6d1cb..c799ef21c18 100644--- a/src/bindings/python/src/openvino/opset17/__init__.py+++ b/src/bindings/python/src/openvino/opset17/__init__.py@@ -3,6 +3,7 @@# SPDX-License-Identifier: Apache-2.0# New operations added in Opset17+from openvino.opset17.ops import erfinv# Operators from previous opsets# TODO (ticket: 179247): Add previous opset operators at the end of opset17 developmentdiff --git a/src/bindings/python/src/openvino/opset17/ops.py b/src/bindings/python/src/openvino/opset17/ops.pyindex 82212234c1e..3d4a4e0dd2e 100644--- a/src/bindings/python/src/openvino/opset17/ops.py+++ b/src/bindings/python/src/openvino/opset17/ops.py@@ -4,9 +4,24 @@"""Factory functions for ops added to openvino opset17."""from functools import partial+from typing import Optional+from openvino import Node+from openvino.utils.decorators import unary_opfrom openvino.utils.node_factory import _get_node_factory+from openvino.utils.types import NodeInput_get_node_factory_opset17 = partial(_get_node_factory, "opset17")# -------------------------------------------- ops ------------------------------------------------+++@unary_op+def erfinv(node: NodeInput, name: Optional[str] = None) -> Node:+ """Return node which calculates the inverse error function element-wise on the input tensor.++ :param node: The node providing data for the operation. Must be of floating-point type.+ :param name: The optional name for the new output node.+ :return: The new node performing the element-wise ErfInv operation.+ """+ return _get_node_factory_opset17().create("ErfInv", [node])diff --git a/src/bindings/python/tests/test_graph/test_ops_unary.py b/src/bindings/python/tests/test_graph/test_ops_unary.pyindex e953a87c2f3..ff37ba0d747 100644--- a/src/bindings/python/tests/test_graph/test_ops_unary.py+++ b/src/bindings/python/tests/test_graph/test_ops_unary.py@@ -6,6 +6,7 @@ import numpy as npimport pytestimport openvino.opset13 as ops+import openvino.opset17 as ops_opset17from openvino import Shape, TypeR_TOLERANCE = 1e-6 # global relative tolerance@@ -121,6 +122,26 @@ def test_erf():assert list(node.get_output_shape(0)) == [6]+def test_erfinv():+ input_tensor = np.array([-0.9, -0.5, 0.0, 0.5, 0.9], dtype=np.float32)++ node = ops_opset17.erfinv(input_tensor)+ assert node.get_output_size() == 1+ assert node.get_type_name() == "ErfInv"+ assert node.get_output_element_type(0) == Type.f32+ assert list(node.get_output_shape(0)) == [5]+++def test_erfinv_parameter():+ data = ops.parameter(Shape([2, 3, 4]), dtype=np.float32, name="data")++ node = ops_opset17.erfinv(data)+ assert node.get_output_size() == 1+ assert node.get_type_name() == "ErfInv"+ assert node.get_output_element_type(0) == Type.f32+ assert list(node.get_output_shape(0)) == [2, 3, 4]++def test_hswish():float_dtype = np.float32data = ops.parameter(Shape([3, 10]), dtype=float_dtype, name="data")