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

[TRANSFORMATIONS] Testing ConstantFolding transformation for SquaredDiff operation (#PR22236) #22280

Merged
merged 2 commits into from
Jan 22, 2024
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
7 changes: 2 additions & 5 deletions src/core/src/op/squared_difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ bool ov::op::v0::SquaredDifference::evaluate(TensorVector& outputs, const Tensor

bool ov::op::v0::SquaredDifference::has_evaluate() const {
OV_OP_SCOPE(v0_SquaredDifference_has_evaluate);
switch (get_input_element_type(0)) {
case element::f32:
if (get_input_element_type(0) == element::f32)
return true;
default:
return false;
}
return false;
}
18 changes: 18 additions & 0 deletions src/core/tests/pass/constant_folding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3930,3 +3930,21 @@ TEST(constant_folding, parameter_with_unspecified_type_from_host_tensor) {
auto model = std::make_shared<ov::Model>(ov::ResultVector{res}, ov::ParameterVector{param});
EXPECT_NO_THROW(run_constant_folding(model));
}

TEST(constant_folding, sq_diff) {
auto const_0 = std::make_shared<ov::op::v0::Constant>(element::f32, ov::Shape{1}, std::vector<float>{4});
auto const_1 = std::make_shared<ov::op::v0::Constant>(element::f32, ov::Shape{1}, std::vector<float>{2});
auto sq_diff = std::make_shared<ov::op::v0::SquaredDifference>(const_0, const_1);
auto res = std::make_shared<ov::op::v0::Result>(sq_diff);
auto model = std::make_shared<ov::Model>(ov::ResultVector{res}, ov::ParameterVector{});
auto ops = model->get_ops();
ASSERT_GT(ops.size(), 2);
EXPECT_NO_THROW(run_constant_folding(model));
ops = model->get_ordered_ops();
// constant + result
ASSERT_EQ(ops.size(), 2);
auto const_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(ops.front());
ASSERT_NE(const_node, nullptr);
auto res_node = std::dynamic_pointer_cast<ov::op::v0::Result>(ops.back());
ASSERT_NE(res_node, nullptr);
}
Loading