|
| 1 | +// Copyright (C) 2018-2025 Intel Corporation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +// |
| 4 | + |
| 5 | +#include "shared_test_classes/subgraph/stridedslice_eltwise.hpp" |
| 6 | + |
| 7 | +#include "common_test_utils/node_builders/constant.hpp" |
| 8 | +#include "common_test_utils/node_builders/eltwise.hpp" |
| 9 | +#include "common_test_utils/test_enums.hpp" |
| 10 | +#include "common_test_utils/ov_tensor_utils.hpp" |
| 11 | + |
| 12 | +#include "openvino/op/parameter.hpp" |
| 13 | +#include "openvino/op/constant.hpp" |
| 14 | +#include "openvino/op/result.hpp" |
| 15 | +#include "openvino/op/reduce_sum.hpp" |
| 16 | + |
| 17 | +namespace ov { |
| 18 | +namespace test { |
| 19 | +std::string StridedSliceEltwiseTest::getTestCaseName(const testing::TestParamInfo<StridedSliceEltwiseParamsTuple> &obj) { |
| 20 | + StridedSliceEltwiseSpecificParams params; |
| 21 | + ov::element::Type model_type; |
| 22 | + std::string target_device; |
| 23 | + std::tie(params, model_type, target_device) = obj.param; |
| 24 | + std::ostringstream result; |
| 25 | + result << "IS=("; |
| 26 | + for (size_t i = 0lu; i < params.input_shape.size(); i++) { |
| 27 | + result << ov::test::utils::partialShape2str({params.input_shape[i].first}) |
| 28 | + << (i < params.input_shape.size() - 1lu ? "_" : ""); |
| 29 | + } |
| 30 | + result << ")_TS="; |
| 31 | + for (size_t i = 0lu; i < params.input_shape.front().second.size(); i++) { |
| 32 | + result << "{"; |
| 33 | + for (size_t j = 0lu; j < params.input_shape.size(); j++) { |
| 34 | + result << ov::test::utils::vec2str(params.input_shape[j].second[i]) << (j < params.input_shape.size() - 1lu ? "_" : ""); |
| 35 | + } |
| 36 | + result << "}_"; |
| 37 | + } |
| 38 | + result << "modelType=" << model_type.to_string() << "_"; |
| 39 | + result << "begin=" << ov::test::utils::vec2str(params.begin) << "_"; |
| 40 | + result << "end=" << ov::test::utils::vec2str(params.end) << "_"; |
| 41 | + result << "stride=" << ov::test::utils::vec2str(params.strides) << "_"; |
| 42 | + result << "begin_m=" << ov::test::utils::vec2str(params.begin_mask) << "_"; |
| 43 | + result << "end_m=" << ov::test::utils::vec2str(params.end_mask) << "_"; |
| 44 | + result << "new_axis_m=" << (params.new_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.new_axis_mask)) << "_"; |
| 45 | + result << "shrink_m=" << (params.shrink_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.shrink_axis_mask)) << "_"; |
| 46 | + result << "ellipsis_m=" << (params.ellipsis_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.ellipsis_axis_mask)) << "_"; |
| 47 | + result << "trgDev=" << target_device; |
| 48 | + return result.str(); |
| 49 | +} |
| 50 | + |
| 51 | +void StridedSliceEltwiseTest::SetUp() { |
| 52 | + StridedSliceEltwiseSpecificParams ssParams; |
| 53 | + ov::element::Type type; |
| 54 | + std::tie(ssParams, type, targetDevice) = this->GetParam(); |
| 55 | + |
| 56 | + init_input_shapes(ssParams.input_shape); |
| 57 | + |
| 58 | + ASSERT_EQ(ssParams.begin.size(), ssParams.end.size()); |
| 59 | + ASSERT_EQ(ssParams.begin.size(), ssParams.strides.size()); |
| 60 | + |
| 61 | + auto param = std::make_shared<ov::op::v0::Parameter>(type, inputDynamicShapes.front()); |
| 62 | + ov::Shape const_shape = {ssParams.begin.size()}; |
| 63 | + auto begin_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.begin.data()); |
| 64 | + auto end_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.end.data()); |
| 65 | + auto stride_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.strides.data()); |
| 66 | + auto stridedSlice = std::make_shared<ov::op::v1::StridedSlice>(param, |
| 67 | + begin_node, |
| 68 | + end_node, |
| 69 | + stride_node, |
| 70 | + ssParams.begin_mask, |
| 71 | + ssParams.end_mask, |
| 72 | + ssParams.new_axis_mask, |
| 73 | + ssParams.shrink_axis_mask, |
| 74 | + ssParams.ellipsis_axis_mask); |
| 75 | + |
| 76 | + auto constant_input1_tensor = ov::test::utils::create_and_fill_tensor(type, targetStaticShapes.front()[1]); |
| 77 | + auto constant_input1 = std::make_shared<ov::op::v0::Constant>(constant_input1_tensor); |
| 78 | + auto eltw = ov::test::utils::make_eltwise(stridedSlice, constant_input1, ov::test::utils::EltwiseTypes::ADD); |
| 79 | + ov::ResultVector results{std::make_shared<ov::op::v0::Result>(eltw)}; |
| 80 | + function = std::make_shared<ov::Model>(results, ov::ParameterVector{param}, "StridedSliceEltwise"); |
| 81 | +} |
| 82 | +} // namespace test |
| 83 | +} // namespace ov |
0 commit comments