Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyOV] Extend Python API with SearchSorted-15 #27230

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from openvino.runtime.opset15.ops import bitwise_right_shift
from openvino.runtime.opset15.ops import slice_scatter
from openvino.runtime.opset15.ops import stft
from openvino.runtime.opset15.ops import search_sorted
21 changes: 21 additions & 0 deletions src/bindings/python/src/openvino/runtime/opset15/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,24 @@ def stft(
"""
inputs = as_nodes(data, window, frame_size, frame_step, name=name)
return _get_node_factory_opset15().create("STFT", inputs)


@nameable_op
def search_sorted(
sorted_sequence: NodeInput,
values: NodeInput,
right_mode: bool = False,
name: Optional[str] = None,
) -> Node:
"""Return a node which generates SearchSorted operation.

:param sorted_sequence: The node providing sorted sequence to search in.
:param values: The node providing searched values.
:param right_mode: If set to False, return the first suitable index that is found for given value.
If set to True, return the last such index. Defaults to False.
:param name: The optional name for the created output node.
:return: The new node performing SearchSorted operation.
"""
inputs = as_nodes(sorted_sequence, values, name=name)
attributes = {"right_mode": right_mode}
return _get_node_factory_opset15().create("SearchSorted", inputs, attributes)
28 changes: 28 additions & 0 deletions src/bindings/python/tests/test_graph/test_create_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,34 @@ def test_stft():
assert op.get_output_shape(0) == [4, 13, 6, 2]


def test_search_sorted():
sorted_sequence = ov.parameter([7, 256, 200, 200], name="sorted", dtype=np.float32)
values = ov.parameter([7, 256, 200, 10], name="values", dtype=np.float32)
op = ov_opset15.search_sorted(sorted_sequence=sorted_sequence, values=values, name="default")
assert op.get_type_name() == "SearchSorted"
assert op.get_output_size() == 1
assert op.get_output_element_type(0) == Type.i64
assert op.get_output_shape(0) == [7, 256, 200, 10]
assert op.get_attributes()["right_mode"] is False
assert op.get_friendly_name() == "default"

op = ov_opset15.search_sorted(sorted_sequence, values, right_mode=True, name="right")
assert op.get_type_name() == "SearchSorted"
assert op.get_output_size() == 1
assert op.get_output_element_type(0) == Type.i64
assert op.get_output_shape(0) == [7, 256, 200, 10]
assert op.get_attributes()["right_mode"] is True
assert op.get_friendly_name() == "right"

op = ov_opset15.search_sorted(sorted_sequence, values, False, name="left")
assert op.get_type_name() == "SearchSorted"
assert op.get_output_size() == 1
assert op.get_output_element_type(0) == Type.i64
assert op.get_output_shape(0) == [7, 256, 200, 10]
assert op.get_attributes()["right_mode"] is False
assert op.get_friendly_name() == "left"


def test_parameter_get_attributes():
parameter = ov.parameter([2, 2], dtype=np.float32, name="InputData")
parameter_attributes = parameter.get_attributes()
Expand Down
Loading