Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

fix 'get_partial_shape().same_scheme(value.get_shape())' failed at src/core/src/descriptor/tensor.cpp:165 (#31156)

Evgeny Kotovd623b785df41
diff --git a/src/core/src/op/broadcast.cpp b/src/core/src/op/broadcast.cpp
index 9ff73e0688a..f376f732b5b 100644
--- a/src/core/src/op/broadcast.cpp
+++ b/src/core/src/op/broadcast.cpp
@@ -62,6 +62,11 @@ namespace {
ov::PartialShape get_result_shape_bidirectional(const ov::Node* this_ptr,
ov::PartialShape arg_shape,
ov::PartialShape target_shape) {
+ // NumPy-style bidirectional broadcasting rules:
+ // 1) Right-align shapes.
+ // 2) For each aligned axis the extents must be equal OR one of them is 1.
+ // Axis length 0 is *not* a special case: a pair (1, 0) or (0, 1)
+ // is broadcast-compatible and the resulting extent on that axis is 0.
if (arg_shape.rank().is_dynamic() || target_shape.rank().is_dynamic()) {
return ov::PartialShape::dynamic();
}
@@ -95,12 +100,12 @@ ov::PartialShape get_result_shape_bidirectional(const ov::Node* this_ptr,
const auto& arg_shape_dim = arg_shape[i].get_length();
const auto& target_shape_dim = target_shape[i].get_length();
NODE_VALIDATION_CHECK(this_ptr,
- arg_shape_dim == 1 || target_shape[i] == 1 || arg_shape_dim == target_shape_dim,
+ arg_shape_dim == 1 || target_shape_dim == 1 || arg_shape_dim == target_shape_dim,
"Broadcast incorrect target shape. Expecting either 1 or ",
arg_shape_dim,
". Got ",
target_shape[i]);
- result_shape[i] = std::max(arg_shape_dim, target_shape_dim);
+ result_shape[i] = arg_shape_dim == 1 ? target_shape_dim : arg_shape_dim;
}
return result_shape;
}
diff --git a/src/core/tests/type_prop/broadcast.cpp b/src/core/tests/type_prop/broadcast.cpp
index 14df71b380b..b2c78af1a0a 100644
--- a/src/core/tests/type_prop/broadcast.cpp
+++ b/src/core/tests/type_prop/broadcast.cpp
@@ -1349,3 +1349,13 @@ TEST(type_prop, broadcast_v3_bidirectional_tricky_partial_value_case_and_equal_p
EXPECT_EQ(calculated, expected);
}
}
+
+TEST(type_prop, broadcast_v3_bidirectional_zero_dim) {
+ auto param = make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1});
+ auto target_shape = ov::op::v0::Constant::create<int64_t>(ov::element::i64, ov::Shape{1}, {0});
+
+ auto bc = make_shared<ov::op::v3::Broadcast>(param, target_shape, "BIDIRECTIONAL");
+
+ ASSERT_EQ(bc->get_shape(), (ov::Shape{0}));
+ ASSERT_EQ(bc->get_broadcast_axes(), (make_pair<bool, ov::AxisSet>(true, ov::AxisSet{0})));
+}