diff --git a/ngraph/test/type_prop/arithmetic_ops.hpp b/ngraph/test/type_prop/arithmetic_ops.hpp new file mode 100644 index 00000000000..103982f9b1a --- /dev/null +++ b/ngraph/test/type_prop/arithmetic_ops.hpp @@ -0,0 +1,223 @@ +//***************************************************************************** +// Copyright 2017-2021 Intel Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" + +using namespace ngraph; + +template +class ArithmeticOperator : public testing::Test +{ +}; + +TYPED_TEST_CASE_P(ArithmeticOperator); + +TYPED_TEST_P(ArithmeticOperator, shape_inference_2D) +{ + auto A = std::make_shared(element::f32, Shape{2, 2}); + auto B = std::make_shared(element::f32, Shape{2, 2}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 2})); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_4D) +{ + auto A = std::make_shared(element::f32, Shape{2, 2, 3, 3}); + auto B = std::make_shared(element::f32, Shape{2, 2, 3, 3}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 2, 3, 3})); +} + +TYPED_TEST_P(ArithmeticOperator, default_autobroadcast) +{ + auto A = std::make_shared(element::f32, Shape{2, 2}); + auto B = std::make_shared(element::f32, Shape{2, 2}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 2})); + ASSERT_EQ(op->get_autob(), op::AutoBroadcastType::NUMPY); +} + +TYPED_TEST_P(ArithmeticOperator, no_autobroadcast) +{ + auto A = std::make_shared(element::f32, Shape{2, 2}); + auto B = std::make_shared(element::f32, Shape{2, 2}); + + const auto op = std::make_shared(A, B, op::AutoBroadcastSpec::NONE); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 2})); + ASSERT_EQ(op->get_autob(), op::AutoBroadcastType::NONE); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_4D_x_scalar_numpy_broadcast) +{ + auto A = std::make_shared(element::f32, Shape{2, 3, 4, 5}); + auto B = std::make_shared(element::f32, Shape{1}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 3, 4, 5})); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_4D_x_1D_numpy_broadcast) +{ + auto A = std::make_shared(element::f32, Shape{2, 3, 4, 5}); + auto B = std::make_shared(element::f32, Shape{5}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 3, 4, 5})); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_2D_x_4D_numpy_broadcast) +{ + auto A = std::make_shared(element::f32, Shape{4, 5}); + auto B = std::make_shared(element::f32, Shape{2, 3, 4, 5}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 3, 4, 5})); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_3D_x_4D_numpy_broadcast) +{ + auto A = std::make_shared(element::f32, Shape{1, 4, 5}); + auto B = std::make_shared(element::f32, Shape{2, 3, 1, 1}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{2, 3, 4, 5})); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_4D_x_3D_numpy_broadcast) +{ + auto A = std::make_shared(element::f32, Shape{8, 1, 6, 1}); + auto B = std::make_shared(element::f32, Shape{7, 1, 5}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_shape(), (Shape{8, 7, 6, 5})); + ASSERT_EQ(op->get_autob(), op::AutoBroadcastType::NUMPY); +} + +TYPED_TEST_P(ArithmeticOperator, incompatible_element_types) +{ + auto A = std::make_shared(element::f32, Shape{2, 2, 3, 3}); + auto B = std::make_shared(element::i32, Shape{2, 2, 3, 3}); + + ASSERT_THROW(std::make_shared(A, B), ngraph::NodeValidationFailure); +} + +TYPED_TEST_P(ArithmeticOperator, incompatible_boolean_type) +{ + auto A = std::make_shared(element::boolean, Shape{2, 2, 3, 3}); + auto B = std::make_shared(element::boolean, Shape{2, 2, 3, 3}); + + ASSERT_THROW(std::make_shared(A, B), ngraph::NodeValidationFailure); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_1D_x_1D_incompatible) +{ + auto A = std::make_shared(element::f32, Shape{3}); + auto B = std::make_shared(element::f32, Shape{4}); + + ASSERT_THROW(std::make_shared(A, B), ngraph::NodeValidationFailure); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_3D_x_3D_incompatible) +{ + auto A = std::make_shared(element::f32, Shape{3, 5, 6}); + auto B = std::make_shared(element::f32, Shape{4, 10, 12}); + + ASSERT_THROW(std::make_shared(A, B), ngraph::NodeValidationFailure); +} + +TYPED_TEST_P(ArithmeticOperator, shape_inference_5D_x_5D_incompatible) +{ + auto A = std::make_shared(element::f32, Shape{389, 112, 12}); + auto B = std::make_shared(element::f32, Shape{389, 112, 19}); + + ASSERT_THROW(std::make_shared(A, B), ngraph::NodeValidationFailure); +} + +TYPED_TEST_P(ArithmeticOperator, dynamic_shape_3D) +{ + Dimension dynamic = Dimension::dynamic(); + auto A = std::make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); + auto B = std::make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_output_partial_shape(0), (PartialShape{dynamic, dynamic, 6})); +} + +TYPED_TEST_P(ArithmeticOperator, dynamic_shape_5D) +{ + Dimension dynamic = Dimension::dynamic(); + auto A = + std::make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); + auto B = + std::make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); + + const auto op = std::make_shared(A, B); + + ASSERT_EQ(op->get_element_type(), element::f32); + ASSERT_EQ(op->get_output_partial_shape(0), + (PartialShape{dynamic, 4, dynamic, dynamic, 6})); +} + +TYPED_TEST_P(ArithmeticOperator, full_dynamic_shape) +{ + auto param = std::make_shared(element::f64, PartialShape::dynamic()); + const auto op = std::make_shared(param, param); + ASSERT_EQ(op->get_element_type(), element::f64); + ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); +} + +REGISTER_TYPED_TEST_CASE_P(ArithmeticOperator, + shape_inference_2D, + shape_inference_4D, + default_autobroadcast, + no_autobroadcast, + shape_inference_4D_x_scalar_numpy_broadcast, + shape_inference_4D_x_1D_numpy_broadcast, + shape_inference_2D_x_4D_numpy_broadcast, + shape_inference_3D_x_4D_numpy_broadcast, + shape_inference_4D_x_3D_numpy_broadcast, + incompatible_element_types, + incompatible_boolean_type, + shape_inference_1D_x_1D_incompatible, + shape_inference_3D_x_3D_incompatible, + shape_inference_5D_x_5D_incompatible, + dynamic_shape_3D, + dynamic_shape_5D, + full_dynamic_shape); diff --git a/ngraph/test/type_prop/binary_elementwise.cpp b/ngraph/test/type_prop/binary_elementwise.cpp index dcb0e6570df..6f39b7bcbae 100644 --- a/ngraph/test/type_prop/binary_elementwise.cpp +++ b/ngraph/test/type_prop/binary_elementwise.cpp @@ -76,30 +76,6 @@ TEST(type_prop, add_bad_arguments) }); } -TEST(type_prop, divide_bad_arguments) -{ - test_binary("Divide", - [](const shared_ptr& x, const shared_ptr& y) -> shared_ptr { - return make_shared(x, y); - }); -} - -TEST(type_prop, multiply_bad_arguments) -{ - test_binary("Multiply", - [](const shared_ptr& x, const shared_ptr& y) -> shared_ptr { - return make_shared(x, y); - }); -} - -TEST(type_prop, subtract_bad_arguments) -{ - test_binary("Subtract", - [](const shared_ptr& x, const shared_ptr& y) -> shared_ptr { - return make_shared(x, y); - }); -} - // // Tests for binary elementwise logical ops. // @@ -219,19 +195,14 @@ void test_binary_eltwise_numpy(const element::Type& et, const op::AutoBroadcastS TEST(type_prop, eltwise_auto_bcast) { test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); - test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); - test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); - test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::boolean, op::AutoBroadcastType::NUMPY); - test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); - test_binary_eltwise_numpy(element::f32, op::AutoBroadcastType::NUMPY); test_binary_eltwise_numpy(element::boolean, op::AutoBroadcastType::NUMPY); } @@ -292,19 +263,14 @@ namespace TEST(type_prop, binary_arithmetic_bad_argument_shape_with_none_autobroadcast_attribute) { test_binary_eltwise_bad_argument_shape(element::f32); - test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); - test_binary_eltwise_bad_argument_shape(element::f32); - test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::boolean); - test_binary_eltwise_bad_argument_shape(element::f32); - test_binary_eltwise_bad_argument_shape(element::f32); test_binary_eltwise_bad_argument_shape(element::boolean); } diff --git a/ngraph/test/type_prop/divide.cpp b/ngraph/test/type_prop/divide.cpp new file mode 100644 index 00000000000..599312f77cf --- /dev/null +++ b/ngraph/test/type_prop/divide.cpp @@ -0,0 +1,21 @@ +//***************************************************************************** +// Copyright 2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_divide, ArithmeticOperator, Type); diff --git a/ngraph/test/type_prop/minimum.cpp b/ngraph/test/type_prop/minimum.cpp index 4076e761ea9..f62373923d5 100644 --- a/ngraph/test/type_prop/minimum.cpp +++ b/ngraph/test/type_prop/minimum.cpp @@ -2,252 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/type_prop.hpp" +#include "arithmetic_ops.hpp" -using namespace std; -using namespace ngraph; +using Type = ::testing::Types; -TEST(type_prop, minimum_2D_same) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 2})); -} - -TEST(type_prop, minimum_4D_same) -{ - auto A = make_shared(element::f32, Shape{2, 2, 3, 3}); - auto B = make_shared(element::f32, Shape{2, 2, 3, 3}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 2, 3, 3})); -} - -TEST(type_prop, minimum_default_autobroadcast) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 2})); - ASSERT_EQ(minimum->get_autob(), op::AutoBroadcastType::NUMPY); -} - -TEST(type_prop, minimum_no_autobroadcast) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto minimum = make_shared(A, B, op::AutoBroadcastSpec::NONE); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 2})); - ASSERT_EQ(minimum->get_autob(), op::AutoBroadcastType::NONE); -} - -TEST(type_prop, minimum_4D_x_scalar_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{2, 3, 4, 5}); - auto B = make_shared(element::f32, Shape{1}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, minimum_4D_x_1D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{2, 3, 4, 5}); - auto B = make_shared(element::f32, Shape{5}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, minimum_2D_x_4D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{4, 5}); - auto B = make_shared(element::f32, Shape{2, 3, 4, 5}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, minimum_3D_x_4D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{1, 4, 5}); - auto B = make_shared(element::f32, Shape{2, 3, 1, 1}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, minimum_4D_x_3D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{8, 1, 6, 1}); - auto B = make_shared(element::f32, Shape{7, 1, 5}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_shape(), (Shape{8, 7, 6, 5})); - ASSERT_EQ(minimum->get_autob(), op::AutoBroadcastType::NUMPY); -} - -TEST(type_prop, minimum_incompatible_element_types) -{ - auto A = make_shared(element::f32, Shape{2, 2, 3, 3}); - auto B = make_shared(element::i32, Shape{2, 2, 3, 3}); - - try - { - auto minimum = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible element types not detected"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument element types are inconsistent")); - } - catch (...) - { - FAIL() << "Minimum element type validation failed for unexpexted reason"; - } -} - -TEST(type_prop, minimum_incompatible_boolean_type) -{ - auto A = make_shared(element::boolean, Shape{2, 2, 3, 3}); - auto B = make_shared(element::boolean, Shape{2, 2, 3, 3}); - - try - { - auto minimum = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible boolean type not detected"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Arguments cannot have boolean element type")); - } - catch (...) - { - FAIL() << "Minimum element type validation failed for unexpexted reason"; - } -} - -TEST(type_prop, minimum_1D_x_1D_incompatible) -{ - auto A = make_shared(element::f32, Shape{3}); - auto B = make_shared(element::f32, Shape{4}); - - try - { - auto minimum = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "Minimum shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, minimum_3D_x_3D_incompatible) -{ - auto A = make_shared(element::f32, Shape{3, 5, 6}); - auto B = make_shared(element::f32, Shape{4, 10, 12}); - - try - { - auto minimum = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "Minimum shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, minimum_5D_x_5D_incompatible) -{ - auto A = make_shared(element::f32, Shape{389, 112, 12}); - auto B = make_shared(element::f32, Shape{389, 112, 19}); - - try - { - auto minimum = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "Minimum shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, minimum_3D_dynamic_shape) -{ - Dimension dynamic = Dimension::dynamic(); - auto A = make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); - auto B = make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_output_partial_shape(0), (PartialShape{dynamic, dynamic, 6})); -} - -TEST(type_prop, minimum_5D_dynamic_shape) -{ - Dimension dynamic = Dimension::dynamic(); - auto A = - make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); - auto B = - make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); - - auto minimum = make_shared(A, B); - - ASSERT_EQ(minimum->get_element_type(), element::f32); - ASSERT_EQ(minimum->get_output_partial_shape(0), - (PartialShape{dynamic, 4, dynamic, dynamic, 6})); -} - -TEST(type_prop, minimum_full_dynamic_shape) -{ - auto param = std::make_shared(element::f64, PartialShape::dynamic()); - const auto op = std::make_shared(param, param); - ASSERT_EQ(op->get_element_type(), element::f64); - ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); -} +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_minimum, ArithmeticOperator, Type); diff --git a/ngraph/test/type_prop/multiply.cpp b/ngraph/test/type_prop/multiply.cpp new file mode 100644 index 00000000000..423aaa78ace --- /dev/null +++ b/ngraph/test/type_prop/multiply.cpp @@ -0,0 +1,21 @@ +//***************************************************************************** +// Copyright 2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_multiply, ArithmeticOperator, Type); diff --git a/ngraph/test/type_prop/power.cpp b/ngraph/test/type_prop/power.cpp index 73c3679dc03..c8e3580cb6a 100644 --- a/ngraph/test/type_prop/power.cpp +++ b/ngraph/test/type_prop/power.cpp @@ -2,252 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/type_prop.hpp" +#include "arithmetic_ops.hpp" -using namespace std; -using namespace ngraph; +using Type = ::testing::Types; -TEST(type_prop, power_2D_same) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 2})); -} - -TEST(type_prop, power_4D_same) -{ - auto A = make_shared(element::f32, Shape{2, 2, 3, 3}); - auto B = make_shared(element::f32, Shape{2, 2, 3, 3}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 2, 3, 3})); -} - -TEST(type_prop, power_default_autobroadcast) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 2})); - ASSERT_EQ(power->get_autob(), op::AutoBroadcastType::NUMPY); -} - -TEST(type_prop, power_no_autobroadcast) -{ - auto A = make_shared(element::f32, Shape{2, 2}); - auto B = make_shared(element::f32, Shape{2, 2}); - - auto power = make_shared(A, B, op::AutoBroadcastSpec::NONE); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 2})); - ASSERT_EQ(power->get_autob(), op::AutoBroadcastType::NONE); -} - -TEST(type_prop, power_4D_x_scalar_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{2, 3, 4, 5}); - auto B = make_shared(element::f32, Shape{1}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, power_4D_x_1D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{2, 3, 4, 5}); - auto B = make_shared(element::f32, Shape{5}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, power_2D_x_4D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{4, 5}); - auto B = make_shared(element::f32, Shape{2, 3, 4, 5}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, power_3D_x_4D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{1, 4, 5}); - auto B = make_shared(element::f32, Shape{2, 3, 1, 1}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{2, 3, 4, 5})); -} - -TEST(type_prop, power_4D_x_3D_numpy_broadcast) -{ - auto A = make_shared(element::f32, Shape{8, 1, 6, 1}); - auto B = make_shared(element::f32, Shape{7, 1, 5}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_shape(), (Shape{8, 7, 6, 5})); - ASSERT_EQ(power->get_autob(), op::AutoBroadcastType::NUMPY); -} - -TEST(type_prop, power_incompatible_element_types) -{ - auto A = make_shared(element::f32, Shape{2, 2, 3, 3}); - auto B = make_shared(element::i32, Shape{2, 2, 3, 3}); - - try - { - auto power = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible element types not detected"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument element types are inconsistent")); - } - catch (...) - { - FAIL() << "power element type validation failed for unexpexted reason"; - } -} - -TEST(type_prop, power_incompatible_boolean_type) -{ - auto A = make_shared(element::boolean, Shape{2, 2, 3, 3}); - auto B = make_shared(element::boolean, Shape{2, 2, 3, 3}); - - try - { - auto power = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible boolean type not detected"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Arguments cannot have boolean element type")); - } - catch (...) - { - FAIL() << "power element type validation failed for unexpexted reason"; - } -} - -TEST(type_prop, power_1D_x_1D_incompatible) -{ - auto A = make_shared(element::f32, Shape{3}); - auto B = make_shared(element::f32, Shape{4}); - - try - { - auto power = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "power shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, power_3D_x_3D_incompatible) -{ - auto A = make_shared(element::f32, Shape{3, 5, 6}); - auto B = make_shared(element::f32, Shape{4, 10, 12}); - - try - { - auto power = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "power shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, power_5D_x_5D_incompatible) -{ - auto A = make_shared(element::f32, Shape{389, 112, 12}); - auto B = make_shared(element::f32, Shape{389, 112, 19}); - - try - { - auto power = make_shared(A, B); - // Should have thrown, so fail if it didn't - FAIL() << "Incompatible matrix dimensions not detected. "; - } - catch (const ngraph_error& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("Argument shapes are inconsistent")); - } - catch (...) - { - FAIL() << "power shape validation failed for unexpected reason"; - } -} - -TEST(type_prop, power_3D_dynamic_shape) -{ - Dimension dynamic = Dimension::dynamic(); - auto A = make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); - auto B = make_shared(element::f32, PartialShape{dynamic, dynamic, 6}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_output_partial_shape(0), (PartialShape{dynamic, dynamic, 6})); -} - -TEST(type_prop, power_5D_dynamic_shape) -{ - Dimension dynamic = Dimension::dynamic(); - auto A = - make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); - auto B = - make_shared(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6}); - - auto power = make_shared(A, B); - - ASSERT_EQ(power->get_element_type(), element::f32); - ASSERT_EQ(power->get_output_partial_shape(0), - (PartialShape{dynamic, 4, dynamic, dynamic, 6})); -} - -TEST(type_prop, power_full_dynamic_shape) -{ - auto param = std::make_shared(element::f64, PartialShape::dynamic()); - const auto op = std::make_shared(param, param); - ASSERT_EQ(op->get_element_type(), element::f64); - ASSERT_TRUE(op->get_output_partial_shape(0).same_scheme(PartialShape::dynamic())); -} \ No newline at end of file +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_power, ArithmeticOperator, Type); diff --git a/ngraph/test/type_prop/subtract.cpp b/ngraph/test/type_prop/subtract.cpp new file mode 100644 index 00000000000..a36447311e1 --- /dev/null +++ b/ngraph/test/type_prop/subtract.cpp @@ -0,0 +1,21 @@ +//***************************************************************************** +// Copyright 2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include "arithmetic_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_subtract, ArithmeticOperator, Type);