Skip to content

Commit

Permalink
Tests for squared difference op (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Zerrell <[email protected]>
  • Loading branch information
2 people authored and YangleiZouIntel committed Jan 14, 2021
1 parent 0628d3d commit 34bdf2b
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <cstddef>
#include <map>
#include <vector>

#include "common_test_utils/test_constants.hpp"
#include "single_layer_tests/squared_difference.hpp"

using LayerTestsDefinitions::SquaredDifferenceLayerTest;

namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};

const std::vector<std::vector<std::size_t>> inputShapes = {
{1, 30}, {1, 10, 30}
};

INSTANTIATE_TEST_CASE_P(CompareWithRefs, SquaredDifferenceLayerTest,
::testing::Combine(::testing::ValuesIn(netPrecisions), ::testing::Values(inputShapes),
::testing::Values(CommonTestUtils::DEVICE_PLAIDML)),
SquaredDifferenceLayerTest::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <tuple>
#include <string>
#include <vector>
#include <memory>

#include "functional_test_utils/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"

namespace LayerTestsDefinitions {

using squaredDifferenceParams = std::tuple<
InferenceEngine::Precision, // Net precision
std::vector<std::vector<size_t>>, // Input shapes
std::string // Target device name
>;

class SquaredDifferenceLayerTest : public testing::WithParamInterface<squaredDifferenceParams>,
virtual public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(const testing::TestParamInfo<squaredDifferenceParams> obj);

protected:
void SetUp() override;
};

} // namespace LayerTestsDefinitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include <functional>
#include <functional_test_utils/skip_tests_config.hpp>

#include "ie_core.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"

#include "ngraph/op/squared_difference.hpp"

#include "common_test_utils/common_utils.hpp"
#include "functional_test_utils/precision_utils.hpp"
#include "functional_test_utils/blob_utils.hpp"
#include "functional_test_utils/plugin_cache.hpp"
#include "functional_test_utils/layer_test_utils.hpp"

#include "single_layer_tests/squared_difference.hpp"

namespace LayerTestsDefinitions {

std::string SquaredDifferenceLayerTest::getTestCaseName(testing::TestParamInfo<squaredDifferenceParams> obj) {
InferenceEngine::Precision netPrecision;
std::vector<std::vector<size_t>> inputShapes;
std::string targetDevice;
std::tie(netPrecision, inputShapes, targetDevice) = obj.param;
std::ostringstream result;
result << "IS_" << CommonTestUtils::vec2str(inputShapes) << "_";
result << "netPRC_" << netPrecision.name() << "_";
result << "targetDevice_" << targetDevice;
return result.str();
}

void SquaredDifferenceLayerTest::SetUp() {
InferenceEngine::Precision netPrecision;
std::vector<InferenceEngine::SizeVector> inputShapes;
std::tie(netPrecision, inputShapes, targetDevice) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes});

auto paramOuts = ngraph::helpers::convert2OutputVector(
ngraph::helpers::castOps2Nodes<ngraph::op::Parameter>(params));
IE_ASSERT(paramOuts.size() == 2);
const auto squared_difference = std::make_shared<ngraph::opset1::SquaredDifference>(paramOuts.at(0), paramOuts.at(1));

ngraph::ResultVector results;
results.push_back(std::make_shared<ngraph::opset1::Result>(squared_difference));
function = std::make_shared<ngraph::Function>(results, params, "squared_difference");
}

TEST_P(SquaredDifferenceLayerTest, CompareWithRefs) {
Run();
};

} // namespace LayerTestsDefinitions

0 comments on commit 34bdf2b

Please sign in to comment.