diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/elementwise.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/elementwise.cpp new file mode 100644 index 00000000000..120408a6ad6 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/elementwise.cpp @@ -0,0 +1,63 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "shared_test_classes/single_layer/eltwise.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +TEST_P(EltwiseLayerTest, Serialize) { Serialize(); } +const std::vector inputPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::I32, + }; + +std::vector>> inputShapes = { + {{2}}, + {{1, 5, 50}}, + {{2, 10, 1, 4}, {2, 10, 1, 1}} +}; + +std::vector secondaryInputTypes = { + ngraph::helpers::InputLayerType::CONSTANT, + ngraph::helpers::InputLayerType::PARAMETER, +}; + +std::vector opTypes = { + CommonTestUtils::OpType::SCALAR, + CommonTestUtils::OpType::VECTOR, +}; + +std::vector eltwiseOpTypes = { + ngraph::helpers::EltwiseTypes::ADD, + ngraph::helpers::EltwiseTypes::MULTIPLY, + ngraph::helpers::EltwiseTypes::SUBTRACT, + ngraph::helpers::EltwiseTypes::DIVIDE, + ngraph::helpers::EltwiseTypes::FLOOR_MOD, + ngraph::helpers::EltwiseTypes::SQUARED_DIFF, + ngraph::helpers::EltwiseTypes::POWER, + ngraph::helpers::EltwiseTypes::MOD +}; + +std::map additionalConfig = {}; + +const auto elementiwiseParams = ::testing::Combine( + ::testing::ValuesIn(inputShapes), + ::testing::ValuesIn(eltwiseOpTypes), + ::testing::ValuesIn(secondaryInputTypes), + ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(inputPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additionalConfig)); + +INSTANTIATE_TEST_CASE_P(smoke_ElementwiseSerialization, EltwiseLayerTest, + elementiwiseParams, + EltwiseLayerTest::getTestCaseName); +} // namespace diff --git a/ngraph/test/backend/add.in.cpp b/ngraph/test/backend/add.in.cpp index 5da62422747..451f814aade 100644 --- a/ngraph/test/backend/add.in.cpp +++ b/ngraph/test/backend/add.in.cpp @@ -95,3 +95,53 @@ NGRAPH_TEST(${BACKEND_NAME}, add_in_place) 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/type_prop/binary_elementwise.cpp b/ngraph/test/type_prop/binary_elementwise.cpp index b036fb73e48..94e939827e6 100644 --- a/ngraph/test/type_prop/binary_elementwise.cpp +++ b/ngraph/test/type_prop/binary_elementwise.cpp @@ -274,6 +274,26 @@ TEST(type_prop, binary_arithmetic_bad_argument_element_types) } } +TEST(type_prop, binary_arithmetic_bad_argument_shape_with_none_autobroadcast_attribute) +{ + auto input1 = make_shared(element::f32, Shape{2, 4}); + auto input2 = make_shared(element::f32, Shape{1, 2, 4}); + try + { + auto bc = make_shared(input1, input2, op::AutoBroadcastType::NONE); + // Should have thrown, so fail if it didn't + FAIL() << "Did not detect incorrect element types for arithmetic operator"; + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); + } + catch (...) + { + FAIL() << "Deduced type check failed for unexpected reason"; + } +} + TEST(type_prop, binary_elementwise_arithmetic_both_dynamic) { auto a = make_shared(element::f32, PartialShape::dynamic());