type_prop template for arithmetic ops (#4941)

* create type_prop template for arithmetic ops

* make arithemtic_ops a header file

* remove power, multiply, divide, subtract and minimum from binary_elementwise

* create type_prop tests for divide

* create type_prop tests for multiply

* create type_prop tests for subtract

* update minimum type_prop tests

* update power type_prop tests

* fix style

* remove arithmetic_ops from CMakeList

* fix test
This commit is contained in:
Piotr Szmelczynski 2021-03-26 04:42:41 +01:00 committed by GitHub
parent d0ebfe06d2
commit 42bbe979b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 292 additions and 528 deletions

View File

@ -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 <vector>
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
using namespace ngraph;
template <class T>
class ArithmeticOperator : public testing::Test
{
};
TYPED_TEST_CASE_P(ArithmeticOperator);
TYPED_TEST_P(ArithmeticOperator, shape_inference_2D)
{
auto A = std::make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 2});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 2});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 2});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{1});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{5});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{4, 5});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{1, 4, 5});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{2, 3, 1, 1});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{8, 1, 6, 1});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{7, 1, 5});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = std::make_shared<op::Parameter>(element::i32, Shape{2, 2, 3, 3});
ASSERT_THROW(std::make_shared<TypeParam>(A, B), ngraph::NodeValidationFailure);
}
TYPED_TEST_P(ArithmeticOperator, incompatible_boolean_type)
{
auto A = std::make_shared<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
auto B = std::make_shared<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
ASSERT_THROW(std::make_shared<TypeParam>(A, B), ngraph::NodeValidationFailure);
}
TYPED_TEST_P(ArithmeticOperator, shape_inference_1D_x_1D_incompatible)
{
auto A = std::make_shared<op::Parameter>(element::f32, Shape{3});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{4});
ASSERT_THROW(std::make_shared<TypeParam>(A, B), ngraph::NodeValidationFailure);
}
TYPED_TEST_P(ArithmeticOperator, shape_inference_3D_x_3D_incompatible)
{
auto A = std::make_shared<op::Parameter>(element::f32, Shape{3, 5, 6});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{4, 10, 12});
ASSERT_THROW(std::make_shared<TypeParam>(A, B), ngraph::NodeValidationFailure);
}
TYPED_TEST_P(ArithmeticOperator, shape_inference_5D_x_5D_incompatible)
{
auto A = std::make_shared<op::Parameter>(element::f32, Shape{389, 112, 12});
auto B = std::make_shared<op::Parameter>(element::f32, Shape{389, 112, 19});
ASSERT_THROW(std::make_shared<TypeParam>(A, B), ngraph::NodeValidationFailure);
}
TYPED_TEST_P(ArithmeticOperator, dynamic_shape_3D)
{
Dimension dynamic = Dimension::dynamic();
auto A = std::make_shared<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
auto B = std::make_shared<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
auto B =
std::make_shared<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
const auto op = std::make_shared<TypeParam>(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<op::Parameter>(element::f64, PartialShape::dynamic());
const auto op = std::make_shared<TypeParam>(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);

View File

@ -76,30 +76,6 @@ TEST(type_prop, add_bad_arguments)
});
}
TEST(type_prop, divide_bad_arguments)
{
test_binary("Divide",
[](const shared_ptr<Node>& x, const shared_ptr<Node>& y) -> shared_ptr<Node> {
return make_shared<op::v1::Divide>(x, y);
});
}
TEST(type_prop, multiply_bad_arguments)
{
test_binary("Multiply",
[](const shared_ptr<Node>& x, const shared_ptr<Node>& y) -> shared_ptr<Node> {
return make_shared<op::v1::Multiply>(x, y);
});
}
TEST(type_prop, subtract_bad_arguments)
{
test_binary("Subtract",
[](const shared_ptr<Node>& x, const shared_ptr<Node>& y) -> shared_ptr<Node> {
return make_shared<op::v1::Subtract>(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<op::v1::Add>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Divide>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Equal>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Greater>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::GreaterEqual>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Less>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::LessEqual>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Maximum>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Minimum>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Multiply>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::NotEqual>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::LogicalOr>(element::boolean, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Power>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::v1::Subtract>(element::f32, op::AutoBroadcastType::NUMPY);
test_binary_eltwise_numpy<op::Xor>(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<op::v1::Add>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Divide>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Equal>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Greater>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::GreaterEqual>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Less>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::LessEqual>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Maximum>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Minimum>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Multiply>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::NotEqual>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::LogicalOr>(element::boolean);
test_binary_eltwise_bad_argument_shape<op::v1::Power>(element::f32);
test_binary_eltwise_bad_argument_shape<op::v1::Subtract>(element::f32);
test_binary_eltwise_bad_argument_shape<op::Xor>(element::boolean);
}

View File

@ -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<ngraph::op::v1::Divide>;
INSTANTIATE_TYPED_TEST_CASE_P(type_prop_divide, ArithmeticOperator, Type);

View File

@ -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<ngraph::op::v1::Minimum>;
TEST(type_prop, minimum_2D_same)
{
auto A = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{1});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{5});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{1, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 3, 1, 1});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{8, 1, 6, 1});
auto B = make_shared<op::Parameter>(element::f32, Shape{7, 1, 5});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::i32, Shape{2, 2, 3, 3});
try
{
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
try
{
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{3});
auto B = make_shared<op::Parameter>(element::f32, Shape{4});
try
{
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{3, 5, 6});
auto B = make_shared<op::Parameter>(element::f32, Shape{4, 10, 12});
try
{
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, Shape{389, 112, 12});
auto B = make_shared<op::Parameter>(element::f32, Shape{389, 112, 19});
try
{
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
auto B = make_shared<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
auto B =
make_shared<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
auto minimum = make_shared<op::v1::Minimum>(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<op::Parameter>(element::f64, PartialShape::dynamic());
const auto op = std::make_shared<op::v1::Minimum>(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);

View File

@ -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<ngraph::op::v1::Multiply>;
INSTANTIATE_TYPED_TEST_CASE_P(type_prop_multiply, ArithmeticOperator, Type);

View File

@ -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<ngraph::op::v1::Power>;
TEST(type_prop, power_2D_same)
{
auto A = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 2});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{1});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{5});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 3, 4, 5});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{1, 4, 5});
auto B = make_shared<op::Parameter>(element::f32, Shape{2, 3, 1, 1});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{8, 1, 6, 1});
auto B = make_shared<op::Parameter>(element::f32, Shape{7, 1, 5});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::i32, Shape{2, 2, 3, 3});
try
{
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
auto B = make_shared<op::Parameter>(element::boolean, Shape{2, 2, 3, 3});
try
{
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{3});
auto B = make_shared<op::Parameter>(element::f32, Shape{4});
try
{
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{3, 5, 6});
auto B = make_shared<op::Parameter>(element::f32, Shape{4, 10, 12});
try
{
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, Shape{389, 112, 12});
auto B = make_shared<op::Parameter>(element::f32, Shape{389, 112, 19});
try
{
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
auto B = make_shared<op::Parameter>(element::f32, PartialShape{dynamic, dynamic, 6});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
auto B =
make_shared<op::Parameter>(element::f32, PartialShape{dynamic, 4, dynamic, dynamic, 6});
auto power = make_shared<op::v1::Power>(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<op::Parameter>(element::f64, PartialShape::dynamic());
const auto op = std::make_shared<op::v1::Power>(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_power, ArithmeticOperator, Type);

View File

@ -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<ngraph::op::v1::Subtract>;
INSTANTIATE_TYPED_TEST_CASE_P(type_prop_subtract, ArithmeticOperator, Type);