Skip to content

[OpenVINO Backend] support comparison ops (>, <, <=, >=, ==, !=) for OpenVINOKerasTensor #21348

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

Merged
Merged
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
50 changes: 50 additions & 0 deletions keras/src/backend/openvino/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,56 @@ def __rpow__(self, other):
)
return OpenVINOKerasTensor(ov_opset.power(other, first).output(0))

def __lt__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__lt__"
)
return OpenVINOKerasTensor(ov_opset.less(first, other).output(0))

def __gt__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__gt__"
)
return OpenVINOKerasTensor(ov_opset.greater(first, other).output(0))

def __le__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__le__"
)
return OpenVINOKerasTensor(ov_opset.less_equal(first, other).output(0))

def __ge__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__ge__"
)
return OpenVINOKerasTensor(
ov_opset.greater_equal(first, other).output(0)
)

def __eq__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__eq__"
)
return OpenVINOKerasTensor(ov_opset.equal(first, other).output(0))

def __ne__(self, other):
first = self.output
other = get_ov_output(other)
first, other = align_operand_types(
first, other, "OpenVINOKerasTensor::__ne__"
)
return OpenVINOKerasTensor(ov_opset.not_equal(first, other).output(0))

def __getitem__(self, indices):
# now it has limited functionaly
# and supports only a case with one integer index in indices
Expand Down