Skip to content

Commit

Permalink
Update create_and_fill_tensor to work with InputGenerateData (openvin…
Browse files Browse the repository at this point in the history
…otoolkit#20008)

* Update create_and_fill_tensor to work with InputGenerateData
  • Loading branch information
olpipi authored Dec 13, 2023
1 parent 20ad8b4 commit d18d8a4
Show file tree
Hide file tree
Showing 98 changed files with 862 additions and 545 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ class AdaPoolLayerCPUTest : public testing::WithParamInterface<AdaPoolLayerCPUTe
dataPtr[i] = pooledVector[i];
}
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
2560,
0,
256);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 2560;
in_data.resolution = 256;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
}
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ class BatchToSpaceCPULayerTest : public testing::WithParamInterface<BatchToSpace
const auto& static_shape = targetInputStaticShapes[i];
switch (i) {
case 0: {
tensor = ov::test::utils::create_and_fill_tensor(param_type, static_shape, 2560, 0, 256);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 2560;
in_data.resolution = 256;
tensor = ov::test::utils::create_and_fill_tensor(param_type, static_shape, in_data);
break;
}
case 1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ class BroadcastLayerCPUTest : public testing::WithParamInterface<BroadcastLayerC
}
} else {
if (funcInput.get_element_type().is_real()) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
10,
0,
1000);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 10;
in_data.resolution = 1000;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ class BucketizeLayerCPUTest : public testing::WithParamInterface<BucketizeCPUPar
const auto& funcInputs = function->inputs();

auto data_size = shape_size(targetInputStaticShapes[0]);
ov::Tensor tensorData = ov::test::utils::create_and_fill_tensor(funcInputs[0].get_element_type(),
targetInputStaticShapes[0],
data_size * 5,
0,
10,
7235346);

ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = data_size * 5;
in_data.resolution = 10;
in_data.seed = 7235346;
ov::Tensor tensorData = ov::test::utils::create_and_fill_tensor(funcInputs[0].get_element_type(), targetInputStaticShapes[0], in_data);
ov::Tensor tensorBucket =
ov::test::utils::create_and_fill_tensor_unique_sequence(funcInputs[1].get_element_type(),
targetInputStaticShapes[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ void ActivationLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targe
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;
if (funcInput.get_element_type().is_real()) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i],
range, startFrom, resolution);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = startFrom;
in_data.range = range;
in_data.resolution = resolution;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ void ConvertCPULayerTest::generate_inputs(const std::vector<ov::Shape>& targetIn

auto shape = targetInputStaticShapes.front();
size_t size = shape_size(shape);
ov::Tensor tensor = ov::test::utils::create_and_fill_tensor(funcInputs[0].get_element_type(), shape, 2 * size);

ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 2 * size;
ov::Tensor tensor = ov::test::utils::create_and_fill_tensor(funcInputs[0].get_element_type(), shape, in_data);

if (inPrc == ov::element::f32) {
auto* rawBlobDataPtr = static_cast<float*>(tensor.data());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ ov::Tensor EltwiseLayerCPUTest::generate_eltwise_input(const ov::element::Type&
break;
}
}
return ov::test::utils::create_and_fill_tensor(type, shape, params.range, params.start_from, params.resolution);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = params.start_from;
in_data.range = params.range;
in_data.resolution = params.resolution;
return ov::test::utils::create_and_fill_tensor(type, shape, in_data);
}

void EltwiseLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ void ReduceCPULayerTest::generate_inputs(const std::vector<ov::Shape>& targetInp
for (size_t i = 0; i < funcInputs.size(); ++i) {
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;
if (reductionType == utils::ReductionType::Prod) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
10,
5);
if (reductionType == ngraph::helpers::ReductionType::Prod) {
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 5;
in_data.range = 10;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
if (netPrecision == ElementType::f32) {
auto* rawBlobDataPtr = static_cast<float*>(tensor.data());
for (size_t i = 0; i < tensor.get_size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ class DeconvolutionLayerCPUTest : public testing::WithParamInterface<DeconvLayer
targetInputStaticShapes[i],
outShapeData[inferRequestNum].data());
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
2560,
0,
256);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 2560;
in_data.resolution = 256;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
}

inputs.insert({funcInput.get_node_shared_ptr(), tensor});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ class CTCGreedyDecoderLayerCPUTest : public testing::WithParamInterface<CTCGreed
ov::Tensor tensor;
if (i == 0) {
if (funcInput.get_element_type().is_real()) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
10,
0,
1000);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 10;
in_data.resolution = 1000;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i]);
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i]);
}
} else {
auto T = targetInputStaticShapes[i][0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ class CTCGreedyDecoderSeqLenLayerCPUTest : public testing::WithParamInterface<CT
ov::Tensor tensor;
if (i == 0) {
if (funcInput.get_element_type().is_real()) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
10,
0,
1000);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 10;
in_data.resolution = 1000;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i]);
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i]);
}
} else if (i == 1) {
const auto seqLen = dataShape[1];
Expand All @@ -147,10 +146,10 @@ class CTCGreedyDecoderSeqLenLayerCPUTest : public testing::WithParamInterface<CT

} else if (i == 2) {
// blank should be valid class type
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
dataShape[2],
0);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = dataShape[2];
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
}
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ class CTCLossLayerCPUTest : public testing::WithParamInterface<CTCLossLayerCPUTe
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;
if (i == 0) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), dataShape, 10, 0, 10);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = 0;
in_data.range = 10;
in_data.resolution = 10;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), dataShape, in_data);
} else if (i == 1) {
tensor = ov::Tensor{funcInput.get_element_type(), {shapeN}};
if (funcInput.get_element_type() == ElementType::i32) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,48 @@ class DefConvLayerCPUTest : public testing::WithParamInterface<DefConvLayerCPUTe
for (size_t i = 0; i < funcInputs.size(); ++i) {
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;
ov::test::utils::InputGenerateData in_data;
if (i == 0) { // "a_data"
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), inShape, 2, -1, 100);
in_data.start_from = -1;
in_data.range = 2;
in_data.resolution = 100;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), inShape, in_data);
} else if (i == 1) { // "b_offset_vals"
if (offsetType == OffsetType::NATURAL) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, 10, 0, 1);
in_data.start_from = 0;
in_data.range = 10;
in_data.resolution = 1;
} else if (offsetType == OffsetType::ZERO) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, 1, 0, 1);
in_data.start_from = 0;
in_data.range = 1;
in_data.resolution = 1;
} else if (offsetType == OffsetType::REAL_POSITIVE) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, 2, 0, 100);
in_data.start_from = 0;
in_data.range = 2;
in_data.resolution = 100;
} else if (offsetType == OffsetType::REAL_NEGATIVE) {
tensor =
ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, 2, -2, 100);
in_data.start_from = -2;
in_data.range = 2;
in_data.resolution = 100;
} else if (offsetType == OffsetType::REAL_MISC) {
tensor =
ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, 4, -2, 100);
in_data.start_from = -2;
in_data.range = 4;
in_data.resolution = 100;
} else {
OPENVINO_THROW("Unexpected offset type");
}
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), offShape, in_data);
} else if (i == 2) { // "c_filter_vals"
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), filtShape, 2, -1, 100);
in_data.start_from = -1;
in_data.range = 2;
in_data.resolution = 100;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), filtShape, in_data);
} else if (i == 3) { // "c_modulation_scalars"
auto modShape = targetInputStaticShapes[3];
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), modShape, 1, 0, 100);
in_data.start_from = -1;
in_data.range = 2;
in_data.resolution = 100;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), modShape, in_data);
} else {
OPENVINO_THROW("Unknown input of DeformableConvolution");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ class EyeLayerCPUTest : public testing::WithParamInterface<EyeLayerCPUTestParams
batchShapePtr[j] = outBatchShape[j];
}
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
1,
(i == 0 ? rowNum : (i == 1 ? colNum : shift)));
ov::test::utils::InputGenerateData in_data;
in_data.start_from = i == 0 ? rowNum : (i == 1 ? colNum : 6);
in_data.range = 1;

tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);
}
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ class FakeQuantizeLayerCPUTest : public testing::WithParamInterface<fqLayerTestP
ASSERT_EQ(funcInputs.size(), 1);
const auto& funcInput = funcInputs[0];
ov::Tensor tensor;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[0],
inDataHighBounds - inDataLowBounds,
inDataLowBounds);
ov::test::utils::InputGenerateData in_data;
in_data.start_from = inDataLowBounds;
in_data.range = inDataHighBounds - inDataLowBounds;
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[0], in_data);
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}

Expand Down
Loading

0 comments on commit d18d8a4

Please sign in to comment.