diff --git a/docs/template_plugin/tests/functional/op_reference/add.cpp b/docs/template_plugin/tests/functional/op_reference/add.cpp new file mode 100644 index 00000000000..26bd0af5abd --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/add.cpp @@ -0,0 +1,220 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/add.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct AddParams { + template + AddParams(const PartialShape& shape1, + const PartialShape& shape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(shape1), + pshape2(shape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceAddLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape1=" << param.pshape1 << "_"; + result << "shape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto add = std::make_shared(in1, in2); + return std::make_shared(NodeVector{add}, ParameterVector{in1, in2}); + } +}; + +class ReferenceAddInPlaceLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape1=" << param.pshape1 << "_"; + result << "shape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + auto add = std::make_shared(in1, in2); + add = std::make_shared(add, add); + add = std::make_shared(add, add); + add = std::make_shared(add, add); + return std::make_shared(NodeVector{add}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceAddLayerTest, AddWithHardcodedRefs) { + Exec(); +} + +TEST_P(ReferenceAddInPlaceLayerTest, AddWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForAdd() { + using T = typename element_type_traits::value_type; + + std::vector params{ + AddParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{5, 6, 7, 8}, + std::vector{6, 8, 10, 12}), + AddParams(ov::PartialShape{1, 2}, + ov::PartialShape{3, 2, 2}, + IN_ET, + std::vector{1, 2}, + std::vector{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}, + std::vector{6, 8, 8, 10, 3, 5, 2, 7, 7, 9, 2, 5}), + AddParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{2}, + std::vector{8}, + std::vector{10}), + AddParams(ov::PartialShape{2, 2}, + ov::PartialShape{1}, + IN_ET, + std::vector{2, 4, 7, 8}, + std::vector{8}, + std::vector{10, 12, 15, 16}), + }; + return params; +} + +template +std::vector generateParamsForAddInPlace() { + using T = typename element_type_traits::value_type; + + std::vector params{ + AddParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{5, 6, 7, 8}, + std::vector{48, 64, 80, 96}) + }; + return params; +} + +std::vector generateCombinedParamsForAdd() { + const std::vector> allTypeParams{ + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd(), + generateParamsForAdd() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForAddInPlace() { + const std::vector> allTypeParams{ + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace(), + generateParamsForAddInPlace() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Add_With_Hardcoded_Refs, + ReferenceAddLayerTest, + ::testing::ValuesIn(generateCombinedParamsForAdd()), + ReferenceAddLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Add_In_Place_With_Hardcoded_Refs, + ReferenceAddInPlaceLayerTest, + ::testing::ValuesIn(generateCombinedParamsForAddInPlace()), + ReferenceAddLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/divide.cpp b/docs/template_plugin/tests/functional/op_reference/divide.cpp new file mode 100644 index 00000000000..6bba344dbd2 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/divide.cpp @@ -0,0 +1,362 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/divide.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct DivideParams { + template + DivideParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +struct DivideRoundingParams : public DivideParams { + template + DivideRoundingParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues, + const bool pythondiv) + : DivideParams(iShape1, iShape2, iType, iValues1, iValues2, oValues), pythonDivision(pythondiv) {} + + bool pythonDivision; +}; + +class ReferenceDivideLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto divide = std::make_shared(in1, in2); + return std::make_shared(NodeVector{divide}, ParameterVector{in1, in2}); + } +}; + +class ReferenceDivideRoundingLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType, params.pythonDivision); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type, + const bool pythondiv) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto divide = std::make_shared(in1, in2, pythondiv); + return std::make_shared(NodeVector{divide}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceDivideLayerTest, DivideWithHardcodedRefs) { + Exec(); +} + +TEST_P(ReferenceDivideRoundingLayerTest, DivideWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForDivide() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{2, 4, 8, 16}, + std::vector{1, 2, 4, 8}, + std::vector{2, 2, 2, 2}) + }; + return params; +} + +template +std::vector generateParamsForDivideFloat32() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{18}, + std::vector{8}, + std::vector{2.25}), + DivideParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{2, 4, 8, 16}, + std::vector{0, 0, 0, 0}, + std::vector{std::numeric_limits::infinity(), + std::numeric_limits::infinity(), + std::numeric_limits::infinity(), + std::numeric_limits::infinity()}) + }; + return params; +} + +template +std::vector generateParamsForDivideInt32() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{0x40000140, 0x40000001, 8, 16}, + std::vector{2, 5, 4, 8}, + std::vector{536871072, 214748365, 2, 2}), + DivideParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{18}, + std::vector{8}, + std::vector{2}) + }; + return params; +} + +template +std::vector generateParamsForDivideBroadcast() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideParams(ov::PartialShape{3, 2, 1}, + ov::PartialShape{1, 6}, + IN_ET, + std::vector{12, 24, 36, 48, 60, 72}, + std::vector{1, 2, 3, 4, 6, 1}, + std::vector{12, 6, 4, 3, 2, 12, + 24, 12, 8, 6, 4, 24, + 36, 18, 12, 9, 6, 36, + 48, 24, 16, 12, 8, 48, + 60, 30, 20, 15, 10, 60, + 72, 36, 24, 18, 12, 72}) + }; + return params; +} + +template +std::vector generateParamsForDividePythonRoundingInt32() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{-10, -10, 10, 10}, + std::vector{-3, 3, -3, 3}, + std::vector{3, -4, -4, 3}) + }; + return params; +} + +template +std::vector generateParamsForDivideCppRoundingInt32() { + using T = typename element_type_traits::value_type; + + std::vector params{ + DivideRoundingParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{-10, -10, 10, 10}, + std::vector{-3, 3, -3, 3}, + std::vector{3, -3, -3, 3}, + false) + }; + return params; +} + +std::vector generateCombinedParamsForDivide() { + const std::vector> allTypeParams{ + generateParamsForDivide(), + generateParamsForDivide(), + generateParamsForDivide(), + generateParamsForDivide(), + generateParamsForDivide(), + generateParamsForDivide(), + generateParamsForDivide() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForDivideFloat32() { + const std::vector> allTypeParams{ + generateParamsForDivideFloat32() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForDivideInt32() { + const std::vector> allTypeParams{ + generateParamsForDivideInt32() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForDivideBroadcast() { + const std::vector> allTypeParams{ + generateParamsForDivideBroadcast(), + generateParamsForDivideBroadcast() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForDividePythonRoundingInt32() { + const std::vector> allTypeParams{ + generateParamsForDividePythonRoundingInt32() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForDivideCppRoundingInt32() { + const std::vector> allTypeParams{ + generateParamsForDivideCppRoundingInt32() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_With_Hardcoded_Refs, + ReferenceDivideLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDivide()), + ReferenceDivideLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_Float32_With_Hardcoded_Refs, + ReferenceDivideLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDivideFloat32()), + ReferenceDivideLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_Int32_With_Hardcoded_Refs, + ReferenceDivideLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDivideInt32()), + ReferenceDivideLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_Broadcast_With_Hardcoded_Refs, + ReferenceDivideLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDivideBroadcast()), + ReferenceDivideLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_Python_Rounding_Int32_With_Hardcoded_Refs, + ReferenceDivideLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDividePythonRoundingInt32()), + ReferenceDivideLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Divide_Cpp_Rounding_Int32_With_Hardcoded_Refs, + ReferenceDivideRoundingLayerTest, + ::testing::ValuesIn(generateCombinedParamsForDivideCppRoundingInt32()), + ReferenceDivideRoundingLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/floor_mod.cpp b/docs/template_plugin/tests/functional/op_reference/floor_mod.cpp new file mode 100644 index 00000000000..ffb26b86a8c --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/floor_mod.cpp @@ -0,0 +1,194 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/floor_mod.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct FloorModParams { + template + FloorModParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceFloorModLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto floormod = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{floormod}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceFloorModLayerTest, DivideWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForFloorMod() { + using T = typename element_type_traits::value_type; + + std::vector params{ + FloorModParams(ov::PartialShape{4}, + ov::PartialShape{4}, + IN_ET, + std::vector{7, -7, 7, -7}, + std::vector{3, 3, -3, -3}, + std::vector{1, 2, -2, -1}) + }; + return params; +} + +template +std::vector generateParamsForFloorModBroadcast() { + using T = typename element_type_traits::value_type; + + std::vector params{ + FloorModParams(ov::PartialShape{2, 1, 2}, + ov::PartialShape{2, 1}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{2, 3}, + std::vector{1.0f, 0.0f, 1.0f, 2.0f, 1.0f, 0.0f, 0.0f, 1.0f}), + }; + return params; +} + +template +std::vector generateParamsForFloorModScalar() { + using T = typename element_type_traits::value_type; + + std::vector params{ + FloorModParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{2}, + std::vector{4}, + std::vector{2}), + }; + return params; +} + +std::vector generateCombinedParamsForFloorMod() { + const std::vector> allTypeParams{ + generateParamsForFloorMod(), + generateParamsForFloorMod(), + generateParamsForFloorMod(), + generateParamsForFloorMod(), + generateParamsForFloorMod(), + generateParamsForFloorMod() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForFloorModBroadcast() { + const std::vector> allTypeParams{ + generateParamsForFloorModBroadcast(), + generateParamsForFloorModBroadcast() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForFloorModScalar() { + const std::vector> allTypeParams{ + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar(), + generateParamsForFloorModScalar() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_FloorMod_With_Hardcoded_Refs, + ReferenceFloorModLayerTest, + ::testing::ValuesIn(generateCombinedParamsForFloorMod()), + ReferenceFloorModLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_FloorMod_Broadcast_With_Hardcoded_Refs, + ReferenceFloorModLayerTest, + ::testing::ValuesIn(generateCombinedParamsForFloorModBroadcast()), + ReferenceFloorModLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_FloorMode_Scalar_With_Hardcoded_Refs, + ReferenceFloorModLayerTest, + ::testing::ValuesIn(generateCombinedParamsForFloorModScalar()), + ReferenceFloorModLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/maximum.cpp b/docs/template_plugin/tests/functional/op_reference/maximum.cpp new file mode 100644 index 00000000000..b585af5e673 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/maximum.cpp @@ -0,0 +1,217 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/maximum.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct MaximumParams { + template + MaximumParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceMaximumLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto maximum = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{maximum}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceMaximumLayerTest, MaximumWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForMaximumFloat() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MaximumParams(ov::PartialShape{2, 2, 2}, + ov::PartialShape{2, 2, 2}, + IN_ET, + std::vector{1, 8, -8, 17, -0.5, 0.5, 2, 1}, + std::vector{1, 2, 4, 8, 0, 0, 1, 1.5}, + std::vector{1, 8, 4, 17, 0, 0.5, 2, 1.5}) + }; + return params; +} + +template +std::vector generateParamsForMaximumInt32() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MaximumParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{0x40000140, 0x40000001, -8, 17}, + std::vector{0x40000170, 0x40000000, 4, 8}, + std::vector{0x40000170, 0x40000001, 4, 17}) + }; + return params; +} + +template +std::vector generateParamsForMaximumInt64() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MaximumParams(ov::PartialShape{2, 2, 2}, + ov::PartialShape{2, 2, 2}, + IN_ET, + std::vector{1, 8, -8, 17, -5, 67635216, 2, 17179887632}, + std::vector{1, 2, 4, 8, 0, 18448, 1, 28059}, + std::vector{1, 8, 4, 17, 0, 67635216, 2, 17179887632}) + }; + return params; +} + +template +std::vector generateParamsForMaximumUnsignedInt() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MaximumParams(ov::PartialShape{2, 2, 2}, + ov::PartialShape{2, 2, 2}, + IN_ET, + std::vector{1, 8, 7, 17, 5, 67635216, 2, 17179887}, + std::vector{1, 2, 4, 8, 0, 18448, 1, 28059}, + std::vector{1, 8, 7, 17, 5, 67635216, 2, 17179887}) + }; + return params; +} + +std::vector generateCombinedParamsForMaximumFloat() { + const std::vector> allTypeParams{ + generateParamsForMaximumFloat(), + generateParamsForMaximumFloat() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForMaximumInt32() { + const std::vector> allTypeParams{ + generateParamsForMaximumInt32() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForMaximumInt64() { + const std::vector> allTypeParams{ + generateParamsForMaximumInt64() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForMaximumUnsignedInt() { + const std::vector> allTypeParams{ + generateParamsForMaximumUnsignedInt(), + generateParamsForMaximumUnsignedInt() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Maximum_Float_With_Hardcoded_Refs, + ReferenceMaximumLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMaximumFloat()), + ReferenceMaximumLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Maximum_Int32_With_Hardcoded_Refs, + ReferenceMaximumLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMaximumInt32()), + ReferenceMaximumLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Maximume_Int64_With_Hardcoded_Refs, + ReferenceMaximumLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMaximumInt64()), + ReferenceMaximumLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Maximume_UnsignedInt_With_Hardcoded_Refs, + ReferenceMaximumLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMaximumUnsignedInt()), + ReferenceMaximumLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/mod.cpp b/docs/template_plugin/tests/functional/op_reference/mod.cpp new file mode 100644 index 00000000000..25dedfd9454 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/mod.cpp @@ -0,0 +1,251 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/mod.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct ModParams { + template + ModParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceModLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto mod = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{mod}, ParameterVector{in1, in2}); + } +}; + +class ReferenceModInPlaceLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + auto mod = std::make_shared(in1, in2); + mod = std::make_shared(mod, mod); + + return std::make_shared(NodeVector{mod}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceModLayerTest, ModWithHardcodedRefs) { + Exec(); +} + +TEST_P(ReferenceModInPlaceLayerTest, ModWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForMod() { + using T = typename element_type_traits::value_type; + + std::vector params{ + ModParams(ov::PartialShape{1, 2}, + ov::PartialShape{1, 2}, + IN_ET, + std::vector{256, 56}, + std::vector{256, 56}, + std::vector{0, 0}), + ModParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{256, 56, 21, 14}, + std::vector{112, 56, 6, 8}, + std::vector{32, 0, 3, 6}), + ModParams(ov::PartialShape{1, 2}, + ov::PartialShape{3, 2, 2}, + IN_ET, + std::vector{1, 2}, + std::vector{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}, + std::vector{1, 2, 1, 2, 1, 2, 0, 2, 1, 2, 0, 2}), + ModParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{57}, + std::vector{13}, + std::vector{5}), + ModParams(ov::PartialShape{2, 2}, + ov::PartialShape{1}, + IN_ET, + std::vector{2, 4, 7, 8}, + std::vector{8}, + std::vector{2, 4, 7, 0}) + }; + return params; +} + +template +std::vector generateParamsForModNegative() { + using T = typename element_type_traits::value_type; + + std::vector params{ + ModParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{-57, -14, -12, -6}, + std::vector{13, -7, 5, -5}, + std::vector{-5, 0, -2, -1}) + }; + return params; +} + +template +std::vector generateParamsForModInPlace() { + using T = typename element_type_traits::value_type; + + std::vector params{ + ModParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{5, 6, 7, 8}, + std::vector{0, 0, 0, 0}) + }; + return params; +} + +std::vector generateCombinedParamsForMod() { + const std::vector> allTypeParams{ + generateParamsForMod(), + generateParamsForMod(), + generateParamsForMod(), + generateParamsForMod() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForModNegative() { + const std::vector> allTypeParams{ + generateParamsForModNegative(), + generateParamsForModNegative(), + generateParamsForModNegative(), + generateParamsForModNegative() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + + +std::vector generateCombinedParamsForModInPlace() { + const std::vector> allTypeParams{ + generateParamsForModInPlace(), + generateParamsForModInPlace(), + generateParamsForModInPlace(), + generateParamsForModInPlace() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Mod_With_Hardcoded_Refs, + ReferenceModLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMod()), + ReferenceModLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Mod_Negative_With_Hardcoded_Refs, + ReferenceModLayerTest, + ::testing::ValuesIn(generateCombinedParamsForModNegative()), + ReferenceModLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Mod_InPlace_With_Hardcoded_Refs, + ReferenceModInPlaceLayerTest, + ::testing::ValuesIn(generateCombinedParamsForModInPlace()), + ReferenceModInPlaceLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/multiply.cpp b/docs/template_plugin/tests/functional/op_reference/multiply.cpp new file mode 100644 index 00000000000..db7d09f01de --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/multiply.cpp @@ -0,0 +1,166 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/multiply.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct MultiplyParams { + template + MultiplyParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceMultiplyLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto multiply = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{multiply}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceMultiplyLayerTest, MultiplyWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForMultiply() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MultiplyParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{5, 6, 7, 8}, + std::vector{5, 12, 21, 32}), + MultiplyParams(ov::PartialShape{3, 2, 1}, + ov::PartialShape{1, 6}, + IN_ET, + std::vector{12, 24, 36, 48, 60, 72}, + std::vector{1, 2, 3, 4, 6, 1}, + std::vector{12, 24, 36, 48, 72, 12, 24, 48, 72, 96, 144, 24, + 36, 72, 108, 144, 216, 36, 48, 96, 144, 192, 288, 48, + 60, 120, 180, 240, 360, 60, 72, 144, 216, 288, 432, 72}), + MultiplyParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{2}, + std::vector{8}, + std::vector{16}) + }; + return params; +} + +template +std::vector generateParamsForMultiplyFloat() { + using T = typename element_type_traits::value_type; + + std::vector params{ + MultiplyParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{3.1}, + std::vector{8}, + std::vector{24.8}) + }; + return params; +} + +std::vector generateCombinedParamsForMultiply() { + const std::vector> allTypeParams{ + generateParamsForMultiply(), + generateParamsForMultiply(), + generateParamsForMultiply(), + generateParamsForMultiply(), + generateParamsForMultiply(), + generateParamsForMultiply(), + generateParamsForMultiply() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForMultiplyFloat() { + const std::vector> allTypeParams{ + generateParamsForMultiplyFloat(), + generateParamsForMultiplyFloat() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Multiply_With_Hardcoded_Refs, + ReferenceMultiplyLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMultiply()), + ReferenceMultiplyLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Multiply_Float_With_Hardcoded_Refs, + ReferenceMultiplyLayerTest, + ::testing::ValuesIn(generateCombinedParamsForMultiplyFloat()), + ReferenceMultiplyLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/power.cpp b/docs/template_plugin/tests/functional/op_reference/power.cpp new file mode 100644 index 00000000000..aeb88180947 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/power.cpp @@ -0,0 +1,134 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/power.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct PowerParams { + template + PowerParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferencePowerLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto power = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{power}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferencePowerLayerTest, PowerWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForPower() { + using T = typename element_type_traits::value_type; + + std::vector params{ + PowerParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 5}, + std::vector{2, 0, 6, 3}, + std::vector{1, 1, 729, 125}), + PowerParams(ov::PartialShape{2, 1, 5}, + ov::PartialShape{2, 1}, + IN_ET, + std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + std::vector{1, 2}, + std::vector{1, 2, 3, 4, 5, 1, 4, 9, 16, 25, 6, 7, 8, 9, 10, 36, 49, 64, 81, 100}), + PowerParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{2}, + std::vector{3}, + std::vector{8}), + PowerParams(ov::PartialShape{2, 2}, + ov::PartialShape{1}, + IN_ET, + std::vector{2, 3, 4, 5}, + std::vector{2}, + std::vector{4, 9, 16, 25}) + }; + return params; +} + +std::vector generateCombinedParamsForPower() { + const std::vector> allTypeParams{ + generateParamsForPower(), + generateParamsForPower(), + generateParamsForPower(), + generateParamsForPower(), + generateParamsForPower(), + generateParamsForPower(), + generateParamsForPower() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Power_With_Hardcoded_Refs, + ReferencePowerLayerTest, + ::testing::ValuesIn(generateCombinedParamsForPower()), + ReferencePowerLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/squared_difference.cpp b/docs/template_plugin/tests/functional/op_reference/squared_difference.cpp new file mode 100644 index 00000000000..80f9c921f24 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/squared_difference.cpp @@ -0,0 +1,212 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/squared_difference.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct SquaredDifferenceParams { + template + SquaredDifferenceParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceSquaredDifferenceLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto squared_difference = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{squared_difference}, ParameterVector{in1, in2}); + } +}; + +class ReferenceSquaredDifferenceInPlaceLayerTest : public testing::TestWithParam, + public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + auto squared_difference = std::make_shared(in1, in2); + squared_difference = std::make_shared(squared_difference, squared_difference); + + return std::make_shared(NodeVector{squared_difference}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceSquaredDifferenceLayerTest, SquaredDifferenceWithHardcodedRefs) { + Exec(); +} + +TEST_P(ReferenceSquaredDifferenceInPlaceLayerTest, SquaredDifferenceWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForSquaredDifference() { + using T = typename element_type_traits::value_type; + + std::vector params{ + SquaredDifferenceParams(ov::PartialShape{1, 2}, + ov::PartialShape{1, 2}, + IN_ET, + std::vector{256, 56}, + std::vector{256, 56}, + std::vector{0, 0}), + SquaredDifferenceParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{256, 56, -21, -14}, + std::vector{-112, 56, 6, -8}, + std::vector{135424, 0, 729, 36}), + SquaredDifferenceParams(ov::PartialShape{1, 2}, + ov::PartialShape{3, 2, 2}, + IN_ET, + std::vector{1, 2}, + std::vector{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}, + std::vector{16, 16, 36, 36, 1, 1, 0, 9, 25, 25, 0, 1}), + SquaredDifferenceParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{57}, + std::vector{13}, + std::vector{1936}), + SquaredDifferenceParams(ov::PartialShape{2, 2}, + ov::PartialShape{1}, + IN_ET, + std::vector{2, 4, 7, 8}, + std::vector{8}, + std::vector{36, 16, 1, 0}) + }; + return params; +} + +template +std::vector generateParamsForSquaredDifferenceInPlace() { + using T = typename element_type_traits::value_type; + + std::vector params{ + SquaredDifferenceParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{1, 2, 3, 4}, + std::vector{5, 6, 7, 8}, + std::vector{0, 0, 0, 0}) + }; + return params; +} + +std::vector generateCombinedParamsForSquaredDifference() { + const std::vector> allTypeParams{ + generateParamsForSquaredDifference(), + generateParamsForSquaredDifference(), + generateParamsForSquaredDifference(), + generateParamsForSquaredDifference() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForSquaredDifferenceInPlace() { + const std::vector> allTypeParams{ + generateParamsForSquaredDifferenceInPlace(), + generateParamsForSquaredDifferenceInPlace(), + generateParamsForSquaredDifferenceInPlace(), + generateParamsForSquaredDifferenceInPlace()}; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_SquaredDifference_With_Hardcoded_Refs, + ReferenceSquaredDifferenceLayerTest, + ::testing::ValuesIn(generateCombinedParamsForSquaredDifference()), + ReferenceSquaredDifferenceLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_SquaredDifferenceInPlace_With_Hardcoded_Refs, + ReferenceSquaredDifferenceInPlaceLayerTest, + ::testing::ValuesIn(generateCombinedParamsForSquaredDifferenceInPlace()), + ReferenceSquaredDifferenceInPlaceLayerTest::getTestCaseName); + +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/subtract.cpp b/docs/template_plugin/tests/functional/op_reference/subtract.cpp new file mode 100644 index 00000000000..6bf4b9e4857 --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/subtract.cpp @@ -0,0 +1,169 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/subtract.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct SubtractParams { + template + SubtractParams(const PartialShape& iShape1, + const PartialShape& iShape2, + const element::Type& iType, + const std::vector& iValues1, + const std::vector& iValues2, + const std::vector& oValues) + : pshape1(iShape1), + pshape2(iShape2), + inType(iType), + outType(iType), + inputData1(CreateTensor(iType, iValues1)), + inputData2(CreateTensor(iType, iValues2)), + refData(CreateTensor(iType, oValues)) {} + + PartialShape pshape1; + PartialShape pshape2; + element::Type inType; + element::Type outType; + runtime::Tensor inputData1; + runtime::Tensor inputData2; + runtime::Tensor refData; +}; + +class ReferenceSubtractLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType); + inputData = {params.inputData1, params.inputData2}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "iShape1=" << param.pshape1 << "_"; + result << "iShape2=" << param.pshape2 << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in1 = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto subtract = std::make_shared(in1, in2); + + return std::make_shared(NodeVector{subtract}, ParameterVector{in1, in2}); + } +}; + +TEST_P(ReferenceSubtractLayerTest, SubtractWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForSubtract() { + using T = typename element_type_traits::value_type; + + std::vector params{ + SubtractParams(ov::PartialShape{2, 2}, + ov::PartialShape{2, 2}, + IN_ET, + std::vector{2, 4, 8, 16}, + std::vector{1, 2, 4, 8}, + std::vector{1, 2, 4, 8}), + SubtractParams(ov::PartialShape{3, 2, 1}, + ov::PartialShape{1, 6}, + IN_ET, + std::vector{12, 24, 36, 48, 60, 72}, + std::vector{1, 2, 3, 4, 6, 1}, + std::vector{11, 10, 9, 8, 6, 11, + 23, 22, 21, 20, 18, 23, + 35, 34, 33, 32, 30, 35, + 47, 46, 45, 44, 42, 47, + 59, 58, 57, 56, 54, 59, + 71, 70, 69, 68, 66, 71}), + SubtractParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{8}, + std::vector{2}, + std::vector{6}) + }; + return params; +} + +template +std::vector generateParamsForSubtractFloat() { + using T = typename element_type_traits::value_type; + + std::vector params{ + SubtractParams(ov::PartialShape{1}, + ov::PartialShape{1}, + IN_ET, + std::vector{3.1}, + std::vector{8}, + std::vector{-4.9}) + }; + return params; +} + +std::vector generateCombinedParamsForSubtract() { + const std::vector> allTypeParams{ + generateParamsForSubtract(), + generateParamsForSubtract(), + generateParamsForSubtract(), + generateParamsForSubtract(), + generateParamsForSubtract(), + generateParamsForSubtract(), + generateParamsForSubtract() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +std::vector generateCombinedParamsForSubtractFloat() { + const std::vector> allTypeParams{ + generateParamsForSubtractFloat(), + generateParamsForSubtractFloat() + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_Subtract_With_Hardcoded_Refs, + ReferenceSubtractLayerTest, + ::testing::ValuesIn(generateCombinedParamsForSubtract()), + ReferenceSubtractLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P( + smoke_Subtract_Float_With_Hardcoded_Refs, + ReferenceSubtractLayerTest, + ::testing::ValuesIn(generateCombinedParamsForSubtractFloat()), + ReferenceSubtractLayerTest::getTestCaseName); + +} // namespace diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 4e60dfe918d..4d28fe209e9 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -101,6 +101,7 @@ set(SRC type_prop/acos.cpp type_prop/adaptive_avg_pool.cpp type_prop/adaptive_max_pool.cpp + type_prop/add.cpp type_prop/asin.cpp type_prop/asinh.cpp type_prop/assign.cpp @@ -285,6 +286,7 @@ set(SRC visitors/op/deformable_psroi_pooling.cpp visitors/op/depth_to_space.cpp visitors/op/detection_output.cpp + visitors/op/divide.cpp visitors/op/einsum.cpp visitors/op/elu.cpp visitors/op/equal.cpp @@ -451,7 +453,6 @@ set(MULTI_TEST_SRC backend/abs.in.cpp backend/adaptive_avg_pool.in.cpp backend/adaptive_max_pool.in.cpp - backend/add.in.cpp backend/aliased_output.in.cpp backend/api.in.cpp backend/auto_broadcast.in.cpp @@ -468,7 +469,6 @@ set(MULTI_TEST_SRC backend/deformable_psroi_pooling.in.cpp backend/detection_output.in.cpp backend/dft.in.cpp - backend/divide.in.cpp backend/depth_to_space.in.cpp backend/dyn_reshape.in.cpp backend/experimental_detectron_generate_proposals.in.cpp @@ -479,7 +479,6 @@ set(MULTI_TEST_SRC backend/experimental_detectron_prior_grid.in.cpp backend/fake_quantize.in.cpp backend/floor.in.cpp - backend/floor_mod.in.cpp backend/function_name.in.cpp backend/gather.in.cpp backend/gather_elements.in.cpp @@ -490,13 +489,10 @@ set(MULTI_TEST_SRC backend/lrn.in.cpp backend/matmul.in.cpp backend/matrix_nms.in.cpp - backend/maximum.in.cpp backend/max_pool.in.cpp - backend/mod.in.cpp backend/multiclass_nms.in.cpp backend/multiple_backends.in.cpp backend/multiple_result.in.cpp - backend/multiply.in.cpp backend/negative.in.cpp backend/node_name.in.cpp backend/normalize_l2.in.cpp @@ -504,7 +500,6 @@ set(MULTI_TEST_SRC backend/one_hot.in.cpp backend/pad.in.cpp backend/parameter_as_output.in.cpp - backend/power.in.cpp backend/prior_box_clustered.in.cpp backend/prior_box.in.cpp backend/proposal.in.cpp @@ -525,9 +520,7 @@ set(MULTI_TEST_SRC backend/space_to_batch.in.cpp backend/split.in.cpp backend/sqrt.in.cpp - backend/squared_difference.in.cpp backend/squeeze.in.cpp - backend/subtract.in.cpp backend/tile.in.cpp backend/topk.in.cpp backend/transpose.in.cpp diff --git a/ngraph/test/backend/add.in.cpp b/ngraph/test/backend/add.in.cpp deleted file mode 100644 index 0916d09583f..00000000000 --- a/ngraph/test/backend/add.in.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, add) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{1, 2, 3, 4}; - vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {6, 8, 10, 12}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, add_overload) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{1, 2, 3, 4}; - vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {6, 8, 10, 12}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, add_in_place) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto T = make_shared(A, B); - auto T2 = make_shared(T, T); - auto T3 = make_shared(T2, T2); - auto T4 = make_shared(T3, T3); - - auto f = make_shared(T4, ParameterVector{A, B}); - - vector a{1, 2, 3, 4}; - vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {48, 64, 80, 96}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, add_broadcast) { - Shape shape_a{1, 2}; - Shape shape_b{3, 2, 2}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{1, 2}; - vector b{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_b, {6, 8, 8, 10, 3, 5, 2, 7, 7, 9, 2, 5}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, add_scalars) { - Shape shape{}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{2}; - vector b{8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {10}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, add_vector_and_scalar) { - Shape shape_a{2, 2}; - Shape shape_b{}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{2, 4, 7, 8}; - vector b{8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_a, {10, 12, 15, 16}); - test_case.run(); -} diff --git a/ngraph/test/backend/divide.in.cpp b/ngraph/test/backend/divide.in.cpp deleted file mode 100644 index 3bf533e8203..00000000000 --- a/ngraph/test/backend/divide.in.cpp +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "util/type_prop.hpp" -#include "runtime/backend.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "ngraph/ngraph.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/test_control.hpp" -#include "engines_util/execute_tools.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, divide) { - Shape shape{2, 2}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{2, 4, 8, 16}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{2, 2, 2, 2}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_int32) { - Shape shape{2, 2}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{0x40000140, 0x40000001, 8, 16}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{2, 5, 4, 8}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{536871072, 214748365, 2, 2}), read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_cpp_rounding_int32) { - Shape shape{2, 2}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B, false), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{-10, -10, 10, 10}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{-3, 3, -3, 3}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{3, -3, -3, 3}), read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_python_rounding_int32) { - Shape shape{2, 2}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{-10, -10, 10, 10}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{-3, 3, -3, 3}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{3, -4, -4, 3}), read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_overload) { - Shape shape{2, 2}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{2, 4, 8, 16}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{2, 2, 2, 2}), read_vector(result))); -} - -namespace { -template -void divide_broadcast() { - const auto element_type = ngraph::element::from(); - const Shape shape_a{3, 2, 1}; - const Shape shape_b{1, 6}; - const Shape shape_o{3, 2, 6}; - std::vector in_a{12, 24, 36, 48, 60, 72}; - std::vector in_b{1, 2, 3, 4, 6, 1}; - // clang-format off - std::vector out{12, 6, 4, 3, 2, 12, - 24, 12, 8, 6, 4, 24, - - 36, 18, 12, 9, 6, 36, - 48, 24, 16, 12, 8, 48, - - 60, 30, 20, 15, 10, 60, - 72, 36, 24, 18, 12, 72}; - // clang-format on - - auto A = make_shared(element_type, shape_a); - auto B = make_shared(element_type, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element_type, shape_a, in_a.data()); - auto b = backend->create_tensor(element_type, shape_b, in_b.data()); - auto result = backend->create_tensor(element_type, shape_o); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(out, read_vector(result)); -} -} // namespace - -NGRAPH_TEST(${BACKEND_NAME}, divide_int32_broadcast) { - divide_broadcast(); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_f32_broadcast) { - divide_broadcast(); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_int32_scalar) { - Shape shape{}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{18}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(vector{2}, read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_f32_scalar) { - Shape shape{}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{18}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{2.25}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, divide_by_zero_float32) { - Shape shape{2, 2}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{2, 4, 8, 16}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{0, 0, 0, 0}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{std::numeric_limits::infinity(), - std::numeric_limits::infinity(), - std::numeric_limits::infinity(), - std::numeric_limits::infinity()}), - read_vector(result)); -} diff --git a/ngraph/test/backend/floor_mod.in.cpp b/ngraph/test/backend/floor_mod.in.cpp deleted file mode 100644 index 4d61cc8fb38..00000000000 --- a/ngraph/test/backend/floor_mod.in.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, floor_mod_int32) { - Shape shape{4}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{7, -7, 7, -7}; - std::vector b{3, 3, -3, -3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 2, -2, -1}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, floor_mod_int64) { - Shape shape{4}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{7, -7, 7, -7}; - std::vector b{3, 3, -3, -3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 2, -2, -1}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, floor_mod_float) { - Shape shape{4}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{7, -7, 7, -7}; - std::vector b{3, 3, -3, -3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 2, -2, -1}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, floor_mod_broadcasted) { - Shape shape_a{2, 1, 2}; - Shape shape_b{2, 1}; - Shape shape_r{2, 2, 2}; - - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 2, 3, 4}; - std::vector b{2, 3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_r, {1.0f, 0.0f, 1.0f, 2.0f, 1.0f, 0.0f, 0.0f, 1.0f}); - test_case.run(); -} -NGRAPH_TEST(${BACKEND_NAME}, floor_mod_scalars) { - Shape shape{}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{2}; - std::vector b{4}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {2.0f}); - test_case.run(); -} diff --git a/ngraph/test/backend/maximum.in.cpp b/ngraph/test/backend/maximum.in.cpp deleted file mode 100644 index b7e6e664552..00000000000 --- a/ngraph/test/backend/maximum.in.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, maximum) { - Shape shape{2, 2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 8, -8, 17, -0.5, 0.5, 2, 1}; - std::vector b{1, 2, 4, 8, 0, 0, 1, 1.5}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 8, 4, 17, 0, 0.5, 2, 1.5}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, maximum_int32) { - Shape shape{2, 2}; - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{0x40000140, 0x40000001, -8, 17}; - std::vector b{0x40000170, 0x40000000, 4, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {0x40000170, 0x40000001, 4, 17}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, maximum_int64) { - Shape shape{2, 2, 2}; - auto A = make_shared(element::i64, shape); - auto B = make_shared(element::i64, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 8, -8, 17, -5, 67635216, 2, 17179887632}; - std::vector b{1, 2, 4, 8, 0, 18448, 1, 280592}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 8, 4, 17, 0, 67635216, 2, 17179887632}); - test_case.run(); -} diff --git a/ngraph/test/backend/mod.in.cpp b/ngraph/test/backend/mod.in.cpp deleted file mode 100644 index 860ffd817b2..00000000000 --- a/ngraph/test/backend/mod.in.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, mod_no_broadcast) { - Shape shape{1, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{256, 56}; - vector b{256, 56}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {0, 0}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_no_broadcast_remainder) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{256, 56, 21, 14}; - vector b{112, 56, 6, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {32, 0, 3, 6}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_broadcast) { - Shape shape_a{1, 2}; - Shape shape_b{3, 2, 2}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{1, 2}; - vector b{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_b, {1, 2, 1, 2, 1, 2, 0, 2, 1, 2, 0, 2}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_scalars) { - Shape shape{}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{57}; - vector b{13}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {5}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_negative_numbers) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{-57, -14, -12, -6}; - vector b{13, -7, 5, -5}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {-5, 0, -2, -1}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_vector_and_scalar) { - Shape shape_a{2, 2}; - Shape shape_b{}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{2, 4, 7, 8}; - vector b{8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_a, {2, 4, 7, 0}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, mod_in_place) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto T = make_shared(A, B); - auto T2 = make_shared(T, T); - - auto f = make_shared(T2, ParameterVector{A, B}); - - vector a{1, 2, 3, 4}; - vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {0, 0, 0, 0}); - test_case.run(); -} diff --git a/ngraph/test/backend/multiply.in.cpp b/ngraph/test/backend/multiply.in.cpp deleted file mode 100644 index f8ce5adc788..00000000000 --- a/ngraph/test/backend/multiply.in.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, multiply) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 2, 3, 4}; - std::vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {5, 12, 21, 32}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, multiply_overload) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 2, 3, 4}; - std::vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {5, 12, 21, 32}); - test_case.run(); -} - -namespace { -template -void multiply_broadcst() { - const auto element_type = ngraph::element::from(); - const Shape shape_a{3, 2, 1}; - const Shape shape_b{1, 6}; - const Shape shape_o{3, 2, 6}; - std::vector in_a{12, 24, 36, 48, 60, 72}; - std::vector in_b{1, 2, 3, 4, 6, 1}; - // clang-format off - std::vector out{12, 24, 36, 48, 72, 12, - 24, 48, 72, 96, 144, 24, - - 36, 72, 108, 144, 216, 36, - 48, 96, 144, 192, 288, 48, - - 60, 120, 180, 240, 360, 60, - 72, 144, 216, 288, 432, 72}; - // clang-format on - - auto A = make_shared(element_type, shape_a); - auto B = make_shared(element_type, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element_type, shape_a, in_a.data()); - auto b = backend->create_tensor(element_type, shape_b, in_b.data()); - auto result = backend->create_tensor(element_type, shape_o); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(out, read_vector(result)); -} -} // namespace - -NGRAPH_TEST(${BACKEND_NAME}, multiply_int32_broadcast) { - multiply_broadcst(); -} - -NGRAPH_TEST(${BACKEND_NAME}, multiply_f32_broadcast) { - multiply_broadcst(); -} - -NGRAPH_TEST(${BACKEND_NAME}, multiply_int32_scalar) { - Shape shape{}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{2}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(vector{16}, read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, multiply_f32_scalar) { - Shape shape{}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{3.1}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{24.8}), read_vector(result))); -} diff --git a/ngraph/test/backend/power.in.cpp b/ngraph/test/backend/power.in.cpp deleted file mode 100644 index 23fc582a301..00000000000 --- a/ngraph/test/backend/power.in.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -NGRAPH_SUPPRESS_DEPRECATED_START - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, power) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 2, 3, 5}; - std::vector b{2, 0, 6, 3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1, 1, 729, 125}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, power_broadcasted) { - Shape shape_a{2, 1, 5}; - Shape shape_b{2, 1}; - Shape shape_r{2, 2, 5}; - - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - std::vector b{1, 2}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_r, - {1, 2, 3, 4, 5, 1, 4, 9, 16, 25, 6, 7, 8, 9, 10, 36, 49, 64, 81, 100}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, power_scalars) { - Shape shape{}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{2}; - std::vector b{3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {8}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, power_vector_and_scalar) { - Shape shape_a{2, 2}; - Shape shape_b{}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - std::vector a{2, 3, 4, 5}; - std::vector b{2}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_a, {4, 9, 16, 25}); - test_case.run(); -} diff --git a/ngraph/test/backend/squared_difference.in.cpp b/ngraph/test/backend/squared_difference.in.cpp deleted file mode 100644 index 7c5e89faa14..00000000000 --- a/ngraph/test/backend/squared_difference.in.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "engines_util/test_engines.hpp" -#include "engines_util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_no_broadcast) { - Shape shape{1, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{256, 56}; - vector b{256, 56}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {0, 0}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_negative_numbers) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{256, 56, -21, -14}; - vector b{-112, 56, 6, -8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {135424, 0, 729, 36}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_broadcast) { - Shape shape_a{1, 2}; - Shape shape_b{3, 2, 2}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{1, 2}; - vector b{5, 6, 7, 8, 2, 3, 1, 5, 6, 7, 1, 3}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_b, {16, 16, 36, 36, 1, 1, 0, 9, 25, 25, 0, 1}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_scalars) { - Shape shape{}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{57}; - vector b{13}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {1936}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_vector_and_scalar) { - Shape shape_a{2, 2}; - Shape shape_b{}; - auto A = make_shared(element::f32, shape_a); - auto B = make_shared(element::f32, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - vector a{2, 4, 7, 8}; - vector b{8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape_a, {36, 16, 1, 0}); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, squared_difference_in_place) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto T = make_shared(A, B); - auto T2 = make_shared(T, T); - - auto f = make_shared(T2, ParameterVector{A, B}); - - vector a{1, 2, 3, 4}; - vector b{5, 6, 7, 8}; - - auto test_case = test::TestCase(f); - test_case.add_multiple_inputs({a, b}); - test_case.add_expected_output(shape, {0, 0, 0, 0}); - test_case.run(); -} diff --git a/ngraph/test/backend/subtract.in.cpp b/ngraph/test/backend/subtract.in.cpp deleted file mode 100644 index 473d6468859..00000000000 --- a/ngraph/test/backend/subtract.in.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "runtime/backend.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "ngraph/ngraph.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/test_control.hpp" -#include "engines_util/execute_tools.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, subtract) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{2, 4, 8, 16}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{1, 2, 4, 8}), read_vector(result))); -} - -NGRAPH_TEST(${BACKEND_NAME}, subtract_overload) { - Shape shape{2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(std::make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{2, 4, 8, 16}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{1, 2, 4, 8}), read_vector(result))); -} - -namespace { -template -void subtract_broadcst() { - const auto element_type = ngraph::element::from(); - const Shape shape_a{3, 2, 1}; - const Shape shape_b{1, 6}; - const Shape shape_o{3, 2, 6}; - std::vector in_a{12, 24, 36, 48, 60, 72}; - std::vector in_b{1, 2, 3, 4, 6, 1}; - // clang-format off - std::vector out{11, 10, 9, 8, 6, 11, - 23, 22, 21, 20, 18, 23, - - 35, 34, 33, 32, 30, 35, - 47, 46, 45, 44, 42, 47, - - 59, 58, 57, 56, 54, 59, - 71, 70, 69, 68, 66, 71}; - // clang-format on - - auto A = make_shared(element_type, shape_a); - auto B = make_shared(element_type, shape_b); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element_type, shape_a, in_a.data()); - auto b = backend->create_tensor(element_type, shape_b, in_b.data()); - auto result = backend->create_tensor(element_type, shape_o); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(out, read_vector(result)); -} -} // namespace - -NGRAPH_TEST(${BACKEND_NAME}, subtract_int32_broadcast) { - subtract_broadcst(); -} - -NGRAPH_TEST(${BACKEND_NAME}, subtract_f32_broadcast) { - subtract_broadcst(); -} - -NGRAPH_TEST(${BACKEND_NAME}, subtract_int32_scalar) { - Shape shape{}; - - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{2}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ(vector{-6}, read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, subtract_f32_scalar) { - Shape shape{}; - - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{3.1}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{8}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE(test::all_close_f((vector{-4.9}), read_vector(result))); -} diff --git a/ngraph/test/type_prop/add.cpp b/ngraph/test/type_prop/add.cpp new file mode 100644 index 00000000000..94430ce0a17 --- /dev/null +++ b/ngraph/test/type_prop/add.cpp @@ -0,0 +1,9 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_add, ArithmeticOperator, Type); diff --git a/ngraph/test/visitors/op/divide.cpp b/ngraph/test/visitors/op/divide.cpp new file mode 100644 index 00000000000..41417bc8bf3 --- /dev/null +++ b/ngraph/test/visitors/op/divide.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +/* +#include "binary_ops.hpp" +#include "ngraph/opsets/opset1.hpp" + +using Type = ::testing::Types>; + +INSTANTIATE_TYPED_TEST_SUITE_P(visitor_with_auto_broadcast, BinaryOperatorVisitor, Type, BinaryOperatorTypeName); + +*/ +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "ngraph/op/util/attr_types.hpp" +#include "ngraph/opsets/opset1.hpp" +#include "util/visitor.hpp" + +using namespace std; +using namespace ngraph; +using ngraph::test::NodeBuilder; +using ngraph::test::ValueMap; + +TEST(attributes, divide) { + NodeBuilder::get_ops().register_factory(); + + const auto in1 = make_shared(element::f32, Shape{2, 4}); + const auto in2 = make_shared(element::f32, Shape{2, 4}); + const bool pythondiv = true; + const op::AutoBroadcastSpec& auto_broadcast = op::AutoBroadcastSpec(op::AutoBroadcastType::NUMPY); + const auto divide = make_shared(in1, in2, pythondiv, auto_broadcast); + + NodeBuilder builder(divide); + auto g_divide = ov::as_type_ptr(builder.create()); + + const auto expected_attr_count = 2; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); + + EXPECT_EQ(g_divide->is_pythondiv(), divide->is_pythondiv()); + EXPECT_EQ(g_divide->get_autob(), divide->get_autob()); +}