Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise sign #6581

Merged
merged 21 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions docs/ops/arithmetic/Sign_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@

**Category**: Arithmetic unary operation

**Short description**: *Sign* performs element-wise sign operation with given tensor.
**Short description**: *Sign* performs element-wise sign operation on a given input tensor.

**Attributes**:
**Detailed description**: *Sign* performs element-wise sign operation on a given input tensor, based on the following mathematical formula:

No attributes available.
\f[
a_{i} = sign(a_{i})
\f]

**Attributes**: *Sign* operation has no attributes.

**Inputs**

* **1**: An tensor of type *T*. **Required.**
* **1**: A tensor of type *T* and arbitrary shape. **Required.**

**Outputs**

* **1**: The result of element-wise sign operation. A tensor of type *T* with mapped elements of the input tensor to -1 (if it is negative), 0 (if it is zero), or 1 (if it is positive).
* **1**: The result of element-wise *Sign* operation. A tensor of type *T* with mapped elements of the input tensor to -1 (if it is negative), 0 (if it is zero), or 1 (if it is positive).

**Types**

* *T*: any numeric type.

*Sign* does the following with the input tensor *a*:

\f[
a_{i} = sign(a_{i})
\f]

**Examples**

*Example 1*
**Example**

```xml
<layer ... type="Sign">
Expand Down
75 changes: 75 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/sign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <tuple>

#include "base_reference_test.hpp"

using namespace ngraph;
using namespace InferenceEngine;

struct SignParams {
template <class IT, class OT>
SignParams(const ngraph::PartialShape& shape, const ngraph::element::Type& iType, const ngraph::element::Type& oType, const std::vector<IT>& iValues,
const std::vector<OT>& oValues, size_t iSize = 0, size_t oSize = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that you need to have iSize, oSize. You always work with default types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, removed.

: pshape(shape), inType(iType), outType(oType), inputData(CreateBlob(iType, iValues, iSize)), refData(CreateBlob(oType, oValues, oSize)) {}
ngraph::PartialShape pshape;
ngraph::element::Type inType;
ngraph::element::Type outType;
InferenceEngine::Blob::Ptr inputData;
InferenceEngine::Blob::Ptr refData;
};

class ReferenceSignLayerTest : public testing::TestWithParam<SignParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.pshape, params.inType);
inputData = {params.inputData};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<SignParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.pshape << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType;
return result.str();
}

private:
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape, const element::Type& input_type) {
const auto in = std::make_shared<op::Parameter>(input_type, input_shape);
const auto sign = std::make_shared<op::Sign>(in);
return std::make_shared<Function>(NodeVector {sign}, ParameterVector {in});
}
};

TEST_P(ReferenceSignLayerTest, CompareWithHardcodedRefs) {
Exec();
}

INSTANTIATE_TEST_SUITE_P(
smoke_Sign_With_Hardcoded_Refs, ReferenceSignLayerTest,
::testing::Values(
// destination boolean
SignParams(ngraph::PartialShape {6}, ngraph::element::f32, ngraph::element::f32,
ilyachur marked this conversation as resolved.
Show resolved Hide resolved
std::vector<float> {1, -2, 0, -4.8f, 4.8f, -0.0f},
std::vector<float> {1, -1, 0, -1, 1, 0}),
SignParams(ngraph::PartialShape {6}, ngraph::element::i16, ngraph::element::i16,
std::vector<int16_t> {1, -2, 0, -4, 4, -0},
std::vector<int16_t> {1, -1, 0, -1, 1, 0}),
SignParams(ngraph::PartialShape {6}, ngraph::element::i32, ngraph::element::i32,
std::vector<int32_t> {1, -2, 0, -4, 4, -0},
std::vector<int32_t> {1, -1, 0, -1, 1, 0}),
SignParams(ngraph::PartialShape {6}, ngraph::element::i64, ngraph::element::i64,
std::vector<int64_t> {1, -2, 0, -4, 4, -0},
std::vector<int64_t> {1, -1, 0, -1, 1, 0})),
ReferenceSignLayerTest::getTestCaseName);
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> intActivationTy
{Negative, {}},
{Ceiling, {}},
{Cos, {}},
{Sign, {}},
{Sinh, {}},
{Sqrt, {}},
{Tanh, {}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
'ShapeOf-1',
'ShapeOf-3',
'Sigmoid-1',
'Sign-1',
'Sin-1',
'Sinh-1'
'SoftPlus-4',
Expand Down
4 changes: 2 additions & 2 deletions ngraph/core/include/ngraph/op/sign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace ngraph
class NGRAPH_API Sign : public util::UnaryElementwiseArithmetic
{
public:
static constexpr NodeTypeInfo type_info{"Sign", 0};
const NodeTypeInfo& get_type_info() const override { return type_info; }
NGRAPH_RTTI_DECLARATION;

Sign() = default;
/// \brief Constructs an elementwise sign operation.
///
Expand Down
5 changes: 4 additions & 1 deletion ngraph/core/src/op/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ using namespace ngraph;
#include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/runtime/reference/sign.hpp"

constexpr NodeTypeInfo op::Sign::type_info;
#include "ngraph/validation_util.hpp"

NGRAPH_RTTI_DEFINITION(op::v0::Sign, "Sign", 0, util::UnaryElementwiseArithmetic);

op::Sign::Sign(const Output<Node>& arg)
: UnaryElementwiseArithmetic(arg)
Expand Down Expand Up @@ -66,6 +68,7 @@ namespace signop
bool op::Sign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const
{
NGRAPH_OP_SCOPE(v0_Sign_evaluate);
NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1));
return signop::evaluate_sign(inputs[0], outputs[0], shape_size(get_output_shape(0)));
}

Expand Down
5 changes: 3 additions & 2 deletions ngraph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ set(SRC
type_prop/lstm_sequence.cpp
type_prop/loop.cpp
type_prop/matmul.cpp
type_prop/matrix_nms.cpp
type_prop/matrix_nms.cpp
type_prop/maximum.cpp
type_prop/max_pool.cpp
type_prop/minimum.cpp
Expand Down Expand Up @@ -206,6 +206,7 @@ set(SRC
type_prop/selu.cpp
type_prop/shape_of.cpp
type_prop/shuffle_channels.cpp
type_prop/sign.cpp
type_prop/sin.cpp
type_prop/sinh.cpp
type_prop/softmax.cpp
Expand Down Expand Up @@ -300,6 +301,7 @@ set(SRC
visitors/op/space_to_depth.cpp
visitors/op/selu.cpp
visitors/op/shuffle_channels.cpp
visitors/op/sign.cpp
visitors/op/sinh.cpp
visitors/op/softmax.cpp
visitors/op/softplus.cpp
Expand Down Expand Up @@ -485,7 +487,6 @@ set(MULTI_TEST_SRC
backend/shape_of.in.cpp
backend/shuffle_channels.in.cpp
backend/sigmoid.in.cpp
backend/sign.in.cpp
backend/sin.in.cpp
backend/sinh.in.cpp
backend/softmax.in.cpp
Expand Down
54 changes: 0 additions & 54 deletions ngraph/test/backend/sign.in.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion ngraph/test/frontend/shared/include/op_fuzzy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class FrontEndFuzzyOpTest : public ::testing::TestWithParam<FuzzyOpTestParam>

void doLoadFromFile();

void runConvertedModel(const std::shared_ptr<ngraph::Function> function, const std::string& model_file);
void runConvertedModel(const std::shared_ptr<ngraph::Function> function,
const std::string& model_file);
};
2 changes: 1 addition & 1 deletion ngraph/test/frontend/shared/src/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include <cnpy.h>

#include "op_fuzzy.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "op_fuzzy.hpp"
#include "utils.hpp"

using namespace ngraph;
Expand Down
9 changes: 9 additions & 0 deletions ngraph/test/type_prop/sign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "unary_ops.hpp"

using Type = ::testing::Types<ngraph::op::Sign>;

INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_sign, UnaryOperator, Type);
11 changes: 11 additions & 0 deletions ngraph/test/visitors/op/sign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "unary_ops.hpp"
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Sign, element::f32>>;

INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute,
UnaryOperatorVisitor,
Type,
UnaryOperatorTypeName);