Skip to content

Commit

Permalink
Fix corner case with empty string for EqualStr (openvinotoolkit#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Kazantsev, Roman <[email protected]>
  • Loading branch information
rkazants authored Mar 20, 2024
1 parent 38f95c0 commit 93efc09
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/equal_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ bool EqualStr::evaluate(ov::TensorVector& outputs, const ov::TensorVector& input

size_t num_elems1 = inputs[0].get_size();
size_t num_elems2 = inputs[3].get_size();
size_t num_elems = std::max(num_elems1, num_elems2);

// in case broadcasting with at least one input empty tensor
// output tensor must be also empty according to TensorFlow
size_t num_elems = (num_elems1 == 0 || num_elems2 == 0) ? 0 : std::max(num_elems1, num_elems2);
outputs[0].set_shape(ov::Shape{ num_elems });
auto result = outputs[0].data<int32_t>();

Expand All @@ -46,16 +49,14 @@ bool EqualStr::evaluate(ov::TensorVector& outputs, const ov::TensorVector& input
auto begin2 = begins2[idx2];
auto end1 = ends1[idx1];
auto end2 = ends2[idx2];
end1 = (end1 < begin1 ? begin1 : end1);
end2 = (end2 < begin2 ? begin2 : end2);

if (end1 - begin1 == 0 && end2 - begin2 != 0) {
if (end1 == begin1 && end2 != begin2) {
result[idx] = 0;
}
else if (end1 - begin1 != 0 && end2 - begin2 == 0) {
else if (end1 != begin1 && end2 == begin2) {
result[idx] = 0;
}
else if (end1 - begin1 == 0 && end2 - begin2 == 0) {
else if (end1 == begin1 && end2 == begin2) {
result[idx] = 1;
}

Expand Down

0 comments on commit 93efc09

Please sign in to comment.