Migrate the unary OP visitor to typed template test. (#6181)
* Migrate the unary OP visitor to typed template test. The unaray OP list is :Floor, Log, Result, Sqrt, Squeeze. Signed-off-by: Luwei Zhou <luwei.zhou@intel.com> * Add element precision type into GTEST typed parameter. Signed-off-by: Luwei Zhou <luwei.zhou@intel.com> * Update the license to new version. Signed-off-by: Luwei Zhou <luwei.zhou@intel.com> * Update the OP Ceiling visitor test to use unary typed template. Signed-off-by: Luwei Zhou <luwei.zhou@intel.com>
This commit is contained in:
parent
7e66411928
commit
0361e7ca73
@ -2,25 +2,10 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "unary_ops.hpp"
|
||||||
|
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Ceiling, element::f32>>;
|
||||||
|
|
||||||
#include "ngraph/ngraph.hpp"
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
#include "ngraph/op/util/attr_types.hpp"
|
UnaryOperatorVisitor,
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
Type,
|
||||||
#include "util/visitor.hpp"
|
UnaryOperatorTypeName);
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace ngraph;
|
|
||||||
using ngraph::test::NodeBuilder;
|
|
||||||
|
|
||||||
TEST(attributes, ceiling_op)
|
|
||||||
{
|
|
||||||
NodeBuilder::get_ops().register_factory<opset1::Ceiling>();
|
|
||||||
const auto A = make_shared<op::Parameter>(element::f32, Shape{5, 2});
|
|
||||||
|
|
||||||
const auto ceiling = make_shared<opset1::Ceiling>(A);
|
|
||||||
NodeBuilder builder(ceiling);
|
|
||||||
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
@ -2,25 +2,12 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "unary_ops.hpp"
|
||||||
|
|
||||||
#include "ngraph/ngraph.hpp"
|
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Floor, element::f32>,
|
||||||
#include "ngraph/op/util/attr_types.hpp"
|
UnaryOperatorType<ngraph::op::v0::Floor, element::f16>>;
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
|
||||||
#include "util/visitor.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
using namespace ngraph;
|
UnaryOperatorVisitor,
|
||||||
using ngraph::test::NodeBuilder;
|
Types,
|
||||||
|
UnaryOperatorTypeName);
|
||||||
TEST(attributes, floor_op)
|
|
||||||
{
|
|
||||||
NodeBuilder::get_ops().register_factory<opset1::Floor>();
|
|
||||||
const auto A = make_shared<op::Parameter>(element::f32, Shape{5, 2});
|
|
||||||
|
|
||||||
const auto floor = make_shared<opset1::Floor>(A);
|
|
||||||
NodeBuilder builder(floor);
|
|
||||||
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
@ -1,29 +1,11 @@
|
|||||||
// Copyright (C) 2021 Intel Corporation
|
// Copyright (C) 2021 Intel Corporation
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
#include "unary_ops.hpp"
|
||||||
|
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Log, element::f32>,
|
||||||
|
UnaryOperatorType<ngraph::op::v0::Log, element::f16>>;
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
|
UnaryOperatorVisitor,
|
||||||
#include "ngraph/ngraph.hpp"
|
Types,
|
||||||
#include "ngraph/op/util/attr_types.hpp"
|
UnaryOperatorTypeName);
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
|
||||||
|
|
||||||
#include "util/visitor.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace ngraph;
|
|
||||||
using ngraph::test::NodeBuilder;
|
|
||||||
|
|
||||||
TEST(attributes, log_op)
|
|
||||||
{
|
|
||||||
using namespace opset1;
|
|
||||||
|
|
||||||
NodeBuilder::get_ops().register_factory<Log>();
|
|
||||||
const auto data_input = make_shared<Parameter>(element::f32, Shape{1, 2, 3});
|
|
||||||
const auto op = make_shared<Sqrt>(data_input);
|
|
||||||
|
|
||||||
NodeBuilder builder(op);
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
@ -2,24 +2,12 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "unary_ops.hpp"
|
||||||
#include "ngraph/ngraph.hpp"
|
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
|
||||||
#include "util/visitor.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Result, element::f32>,
|
||||||
using namespace ngraph;
|
UnaryOperatorType<ngraph::op::v0::Result, element::f16>>;
|
||||||
using ngraph::test::NodeBuilder;
|
|
||||||
using ngraph::test::ValueMap;
|
|
||||||
|
|
||||||
TEST(attributes, result)
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
{
|
UnaryOperatorVisitor,
|
||||||
NodeBuilder::get_ops().register_factory<opset1::Squeeze>();
|
Types,
|
||||||
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1});
|
UnaryOperatorTypeName);
|
||||||
const auto result = make_shared<op::Result>(data_node);
|
|
||||||
|
|
||||||
NodeBuilder builder(result);
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
@ -2,28 +2,11 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "unary_ops.hpp"
|
||||||
|
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Sqrt, element::f32>,
|
||||||
|
UnaryOperatorType<ngraph::op::v0::Sqrt, element::f16>>;
|
||||||
|
|
||||||
#include "ngraph/ngraph.hpp"
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
#include "ngraph/op/util/attr_types.hpp"
|
UnaryOperatorVisitor,
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
Types,
|
||||||
|
UnaryOperatorTypeName);
|
||||||
#include "util/visitor.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace ngraph;
|
|
||||||
using ngraph::test::NodeBuilder;
|
|
||||||
|
|
||||||
TEST(attributes, sqrt_op)
|
|
||||||
{
|
|
||||||
using namespace opset1;
|
|
||||||
|
|
||||||
NodeBuilder::get_ops().register_factory<Sqrt>();
|
|
||||||
const auto data_input = make_shared<Parameter>(element::f32, Shape{1, 2, 3});
|
|
||||||
const auto op = make_shared<Sqrt>(data_input);
|
|
||||||
|
|
||||||
NodeBuilder builder(op);
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
@ -2,27 +2,11 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "unary_ops.hpp"
|
||||||
|
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Squeeze, element::f32>,
|
||||||
|
UnaryOperatorType<ngraph::op::v0::Squeeze, element::f16>>;
|
||||||
|
|
||||||
#include "ngraph/ngraph.hpp"
|
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||||
#include "ngraph/op/util/attr_types.hpp"
|
UnaryOperatorVisitor,
|
||||||
#include "ngraph/opsets/opset1.hpp"
|
Types,
|
||||||
|
UnaryOperatorTypeName);
|
||||||
#include "util/visitor.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace ngraph;
|
|
||||||
using ngraph::test::NodeBuilder;
|
|
||||||
using ngraph::test::ValueMap;
|
|
||||||
|
|
||||||
TEST(attributes, squeeze_op)
|
|
||||||
{
|
|
||||||
NodeBuilder::get_ops().register_factory<opset1::Squeeze>();
|
|
||||||
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1});
|
|
||||||
const auto squeeze = make_shared<op::Squeeze>(data_node);
|
|
||||||
|
|
||||||
NodeBuilder builder(squeeze);
|
|
||||||
const auto expected_attr_count = 0;
|
|
||||||
|
|
||||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
|
||||||
}
|
|
59
ngraph/test/visitors/op/unary_ops.hpp
Normal file
59
ngraph/test/visitors/op/unary_ops.hpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Copyright (C) 2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "ngraph/ngraph.hpp"
|
||||||
|
|
||||||
|
#include "ngraph/op/util/attr_types.hpp"
|
||||||
|
#include "util/visitor.hpp"
|
||||||
|
|
||||||
|
using namespace ngraph;
|
||||||
|
using ngraph::test::NodeBuilder;
|
||||||
|
template <typename T, element::Type_t ELEMENT_TYPE>
|
||||||
|
class UnaryOperatorType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using op_type = T;
|
||||||
|
static constexpr element::Type_t element_type = ELEMENT_TYPE;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class UnaryOperatorVisitor : public testing::Test
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnaryOperatorTypeName
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename T>
|
||||||
|
static std::string GetName(int)
|
||||||
|
{
|
||||||
|
using OP_Type = typename T::op_type;
|
||||||
|
constexpr element::Type precision(T::element_type);
|
||||||
|
const ngraph::Node::type_info_t typeinfo = OP_Type::get_type_info_static();
|
||||||
|
std::string op_name{typeinfo.name};
|
||||||
|
op_name.append("_");
|
||||||
|
return (op_name.append(precision.get_type_name()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TYPED_TEST_CASE_P(UnaryOperatorVisitor);
|
||||||
|
|
||||||
|
TYPED_TEST_P(UnaryOperatorVisitor, No_Attribute_4D)
|
||||||
|
{
|
||||||
|
using OP_Type = typename TypeParam::op_type;
|
||||||
|
const element::Type_t element_type = TypeParam::element_type;
|
||||||
|
|
||||||
|
NodeBuilder::get_ops().register_factory<OP_Type>();
|
||||||
|
const auto A = std::make_shared<op::Parameter>(element_type, PartialShape{2, 2, 2, 2});
|
||||||
|
|
||||||
|
const auto op_func = std::make_shared<OP_Type>(A);
|
||||||
|
NodeBuilder builder(op_func);
|
||||||
|
const auto expected_attr_count = 0;
|
||||||
|
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_TYPED_TEST_CASE_P(UnaryOperatorVisitor, No_Attribute_4D);
|
Loading…
Reference in New Issue
Block a user