Migrate ngraph backend test of arithmetic2 operations (#7500)

* Remove fp16 of Convert layer test from skip_tests.config.cpp as it works now

* update repo

* add sin asin template plugin reference test

* add cos template plugin reference test and remove asin/sin/cos ngraph backend test

* update CMakeList.txt

* add template plugin reference test for asinh, cosh, sinh, tanh

* remove ngraph backend test for asinh, cosh, sinh, tanh

* update CMakeList.txt

* add ngraph type prop test for tanh

* add ngraph visitor api test for asin, sin

* add atanh type in activation SLT

* remove boolean from sin/cos/tan/asin/sinh/cosh evaluate
This commit is contained in:
Wilson Seok authored and GitHub committed 2021-09-27 05:23:52 +03:00
1 parent ef028a567e
commit 8262aed30c
31 files changed
+763 -470

No files matched your search

@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct AsinParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<AsinParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceAsinLayerTest : public testing::TestWithParam<AsinParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<AsinParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Asin = std::make_shared<op::Asin>(in);
return std::make_shared<Function>(NodeVector {Asin}, ParameterVector {in});
}
};
TEST_P(ReferenceAsinLayerTest, AsinWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Asin_With_Hardcoded_Refs, ReferenceAsinLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {-1.f, -0.75f, -0.5f, -0.25f, -0.125f, 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {-1.57079633f,
-0.84806208f,
-0.52359878f,
-0.25268026f,
-0.12532783f,
0.00000000f,
0.12532783f,
0.25268026f,
0.52359878f,
0.84806208f,
1.57079633f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {-1.f, -0.75f, -0.5f, -0.25f, -0.125f, 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f}})
.expected({{11}, element::f32, std::vector<float> {-1.57079633f,
-0.84806208f,
-0.52359878f,
-0.25268026f,
-0.12532783f,
0.00000000f,
0.12532783f,
0.25268026f,
0.52359878f,
0.84806208f,
1.57079633f}}),
Builder {}
.input({{3}, element::i32, std::vector<int32_t> {-1, 0, 1}})
.expected({{3}, element::i32, std::vector<int32_t> {-1, 0, 1}}),
Builder {}
.input({{3}, element::i64, std::vector<int64_t> {-1, 0, 1}})
.expected({{3}, element::i64, std::vector<int64_t> {-1, 0, 1}}),
Builder {}
.input({{2}, element::u32, std::vector<uint32_t> {0, 1}})
.expected({{2}, element::u32, std::vector<uint32_t> {0, 1}}),
Builder {}
.input({{2}, element::u64, std::vector<uint64_t> {0, 1}})
.expected({{2}, element::u64, std::vector<uint64_t> {0, 1}})),
ReferenceAsinLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct AsinhParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<AsinhParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceAsinhLayerTest : public testing::TestWithParam<AsinhParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<AsinhParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Asinh = std::make_shared<op::Asinh>(in);
return std::make_shared<Function>(NodeVector {Asinh}, ParameterVector {in});
}
};
TEST_P(ReferenceAsinhLayerTest, AsinhWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Asinh_With_Hardcoded_Refs, ReferenceAsinhLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {0.f, 1.f, -1.f, 2.f, -2.f, 3.f, -3.f, 4.f, 5.f, 10.f, 100.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {0.00000000f,
0.88137359f,
-0.88137359f,
1.44363548f,
-1.44363548f,
1.81844646f,
-1.81844646f,
2.09471255f,
2.31243834f,
2.99822295f,
5.29834237f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {0.f, 1.f, -1.f, 2.f, -2.f, 3.f, -3.f, 4.f, 5.f, 10.f, 100.f}})
.expected({{11}, element::f32, std::vector<float> {0.00000000f,
0.88137359f,
-0.88137359f,
1.44363548f,
-1.44363548f,
1.81844646f,
-1.81844646f,
2.09471255f,
2.31243834f,
2.99822295f,
5.29834237f}}),
Builder {}
.input({{11}, element::i32, std::vector<int32_t> {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}})
.expected({{11}, element::i32, std::vector<int32_t> {-2, -2, -2, -1, -1, 0, 1, 1, 2, 2, 2}}),
Builder {}
.input({{11}, element::i64, std::vector<int64_t> {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}})
.expected({{11}, element::i64, std::vector<int64_t> {-2, -2, -2, -1, -1, 0, 1, 1, 2, 2, 2}}),
Builder {}
.input({{6}, element::u32, std::vector<uint32_t> {0, 1, 2, 3, 4, 5}})
.expected({{6}, element::u32, std::vector<uint32_t> {0, 1, 1, 2, 2, 2}}),
Builder {}
.input({{6}, element::u64, std::vector<uint64_t> {0, 1, 2, 3, 4, 5}})
.expected({{6}, element::u64, std::vector<uint64_t> {0, 1, 1, 2, 2, 2}})),
ReferenceAsinhLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct CosParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<CosParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceCosLayerTest : public testing::TestWithParam<CosParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<CosParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Cos = std::make_shared<op::Cos>(in);
return std::make_shared<Function>(NodeVector {Cos}, ParameterVector {in});
}
};
TEST_P(ReferenceCosLayerTest, CosWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Cos_With_Hardcoded_Refs, ReferenceCosLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {1.00000000f,
0.96891242f,
0.96891242f,
0.87758256f,
0.87758256f,
0.54030231f,
0.54030231f,
-0.41614684f,
-0.41614684f,
-0.65364362f,
-0.65364362f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f}})
.expected({{11}, element::f32, std::vector<float> {1.00000000f,
0.96891242f,
0.96891242f,
0.87758256f,
0.87758256f,
0.54030231f,
0.54030231f,
-0.41614684f,
-0.41614684f,
-0.65364362f,
-0.65364362f}}),
Builder {}
.input({{5}, element::i32, std::vector<int32_t> {1, 2, 3, 4, 5}})
.expected({{5}, element::i32, std::vector<int32_t> {1, 0, -1, -1, 0}}),
Builder {}
.input({{5}, element::i64, std::vector<int64_t> {1, 2, 3, 4, 5}})
.expected({{5}, element::i64, std::vector<int64_t> {1, 0, -1, -1, 0}}),
Builder {}
.input({{3}, element::u32, std::vector<uint32_t> {1, 2, 5}})
.expected({{3}, element::u32, std::vector<uint32_t> {1, 0, 0}}),
Builder {}
.input({{3}, element::u64, std::vector<uint64_t> {1, 2, 5}})
.expected({{3}, element::u64, std::vector<uint64_t> {1, 0, 0}})),
ReferenceCosLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct CoshParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<CoshParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceCoshLayerTest : public testing::TestWithParam<CoshParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<CoshParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Cosh = std::make_shared<op::Cosh>(in);
return std::make_shared<Function>(NodeVector {Cosh}, ParameterVector {in});
}
};
TEST_P(ReferenceCoshLayerTest, CoshWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Cosh_With_Hardcoded_Refs, ReferenceCoshLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {27.30823284f,
3.76219569f,
1.54308063f,
1.12762597f,
1.03141310f,
1.00000000f,
1.03141310f,
1.12762597f,
1.54308063f,
3.76219569f,
27.30823284f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f32, std::vector<float> {27.30823284f,
3.76219569f,
1.54308063f,
1.12762597f,
1.03141310f,
1.00000000f,
1.03141310f,
1.12762597f,
1.54308063f,
3.76219569f,
27.30823284f}}),
Builder {}
.input({{7}, element::i32, std::vector<int32_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i32, std::vector<int32_t> {27, 4, 2, 1, 2, 4, 27}}),
Builder {}
.input({{7}, element::i64, std::vector<int64_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i64, std::vector<int64_t> {27, 4, 2, 1, 2, 4, 27}}),
Builder {}
.input({{4}, element::u32, std::vector<uint32_t> {0, 1, 2, 4}})
.expected({{4}, element::u32, std::vector<uint32_t> {1, 2, 4, 27}}),
Builder {}
.input({{4}, element::u64, std::vector<uint64_t> {0, 1, 2, 4}})
.expected({{4}, element::u64, std::vector<uint64_t> {1, 2, 4, 27}})),
ReferenceCoshLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct SinParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<SinParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceSinLayerTest : public testing::TestWithParam<SinParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<SinParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Sin = std::make_shared<op::Sin>(in);
return std::make_shared<Function>(NodeVector {Sin}, ParameterVector {in});
}
};
TEST_P(ReferenceSinLayerTest, SinWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Sin_With_Hardcoded_Refs, ReferenceSinLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {0.00000000f,
0.24740396f,
-0.24740396f,
0.47942554f,
-0.47942554f,
0.84147098f,
-0.84147098f,
0.90929743f,
-0.90929743f,
-0.75680250f,
0.75680250f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f}})
.expected({{11}, element::f32, std::vector<float> {0.00000000f,
0.24740396f,
-0.24740396f,
0.47942554f,
-0.47942554f,
0.84147098f,
-0.84147098f,
0.90929743f,
-0.90929743f,
-0.75680250f,
0.75680250f}}),
Builder {}
.input({{7}, element::i32, std::vector<int32_t> {0, 1, -1, 2, -2, 4, -4}})
.expected({{7}, element::i32, std::vector<int32_t> {0, 0, 0, 0, 0, 0, 0}}),
Builder {}
.input({{7}, element::i64, std::vector<int64_t> {0, 1, -1, 2, -2, 4, -4}})
.expected({{7}, element::i64, std::vector<int64_t> {0, 0, 0, 0, 0, 0, 0}}),
Builder {}
.input({{4}, element::u32, std::vector<uint32_t> {0, 1, 2, 4}})
.expected({{4}, element::u32, std::vector<uint32_t> {0, 0, 0, 0}}),
Builder {}
.input({{4}, element::u64, std::vector<uint64_t> {0, 1, 2, 4}})
.expected({{4}, element::u64, std::vector<uint64_t> {0, 0, 0, 0}})),
ReferenceSinLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct SinhParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<SinhParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceSinhLayerTest : public testing::TestWithParam<SinhParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<SinhParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Sinh = std::make_shared<op::Sinh>(in);
return std::make_shared<Function>(NodeVector {Sinh}, ParameterVector {in});
}
};
TEST_P(ReferenceSinhLayerTest, SinhWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Sinh_With_Hardcoded_Refs, ReferenceSinhLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {-27.28991720f,
-3.62686041f,
-1.17520120f,
-0.52109531f,
-0.25261232f,
0.00000000f,
0.25261232f,
0.52109531f,
1.17520120f,
3.62686041f,
27.28991720f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f32, std::vector<float> {-27.28991720f,
-3.62686041f,
-1.17520120f,
-0.52109531f,
-0.25261232f,
0.00000000f,
0.25261232f,
0.52109531f,
1.17520120f,
3.62686041f,
27.28991720f}}),
Builder {}
.input({{7}, element::i32, std::vector<int32_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i32, std::vector<int32_t> {-27, -4, -1, 0, 1, 4, 27}}),
Builder {}
.input({{7}, element::i64, std::vector<int64_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i64, std::vector<int64_t> {-27, -4, -1, 0, 1, 4, 27}}),
Builder {}
.input({{4}, element::u32, std::vector<uint32_t> {0, 1, 2, 4}})
.expected({{4}, element::u32, std::vector<uint32_t> {0, 1, 4, 27}}),
Builder {}
.input({{4}, element::u64, std::vector<uint64_t> {0, 1, 2, 4}})
.expected({{4}, element::u64, std::vector<uint64_t> {0, 1, 4, 27}})),
ReferenceSinhLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -0,0 +1,103 @@
// 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 <vector>
#include "base_reference_test.hpp"
using namespace ngraph;
namespace reference_tests {
namespace {
struct TanhParams {
Tensor input;
Tensor expected;
};
struct Builder : ParamsBuilder<TanhParams> {
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
};
class ReferenceTanhLayerTest : public testing::TestWithParam<TanhParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.input.shape, params.input.type);
inputData = {params.input.data};
refOutData = {params.expected.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<TanhParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "shape=" << param.input.shape << "_";
result << "type=" << param.input.type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Tanh = std::make_shared<op::Tanh>(in);
return std::make_shared<Function>(NodeVector {Tanh}, ParameterVector {in});
}
};
TEST_P(ReferenceTanhLayerTest, TanhWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Tanh_With_Hardcoded_Refs, ReferenceTanhLayerTest,
::testing::Values(
Builder {}
.input({{11}, element::f16, std::vector<ngraph::float16> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f16, std::vector<ngraph::float16> {-0.99932930f,
-0.96402758f,
-0.76159416f,
-0.46211716f,
-0.24491866f,
0.00000000f,
0.24491866f,
0.46211716f,
0.76159416f,
0.96402758f,
0.99932930f}}),
Builder {}
.input({{11}, element::f32, std::vector<float> {-4.f, -2.f, -1.f, -0.5f, -0.25f, 0.f, 0.25f, 0.5f, 1.f, 2.f, 4.f}})
.expected({{11}, element::f32, std::vector<float> {-0.99932930f,
-0.96402758f,
-0.76159416f,
-0.46211716f,
-0.24491866f,
0.00000000f,
0.24491866f,
0.46211716f,
0.76159416f,
0.96402758f,
0.99932930f}}),
Builder {}
.input({{7}, element::i32, std::vector<int32_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i32, std::vector<int32_t> {-1, -1, -1, 0, 1, 1, 1}}),
Builder {}
.input({{7}, element::i64, std::vector<int64_t> {-4, -2, -1, 0, 1, 2, 4}})
.expected({{7}, element::i64, std::vector<int64_t> {-1, -1, -1, 0, 1, 1, 1}}),
Builder {}
.input({{4}, element::u32, std::vector<uint32_t> {0, 1, 2, 4}})
.expected({{4}, element::u32, std::vector<uint32_t> {0, 1, 1, 1}}),
Builder {}
.input({{4}, element::u64, std::vector<uint64_t> {0, 1, 2, 4}})
.expected({{4}, element::u64, std::vector<uint64_t> {0, 1, 1, 1}})),
ReferenceTanhLayerTest::getTestCaseName);
} // namespace reference_tests
@@ -40,6 +40,7 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes
{Asin, {}},
{Asinh, {}},
{Atan, {}},
{Atanh, {}},
{Cos, {}},
{Cosh, {}},
{Floor, {}},
@@ -42,13 +42,13 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes
{Asin, {}},
{Asinh, {}},
{Atan, {}},
{Atanh, {}},
{Cos, {}},
{Cosh, {}},
{Floor, {}},
{Sin, {}},
{Sinh, {}},
{Sqrt, {}},
{Tan, {}},
{Elu, {{0.1f}}},
{Erf, {}},
{HardSigmoid, {{0.2f, 0.5f}}},
@@ -38,6 +38,7 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes
{Asin, {}},
{Asinh, {}},
{Atan, {}},
{Atanh, {}},
{Cos, {}},
{Cosh, {}},
{Floor, {}},
@@ -43,6 +43,7 @@ static std::map<ngraph::helpers::ActivationTypes, std::string> activationNames =
{ngraph::helpers::ActivationTypes::Asin, "Asin"},
{ngraph::helpers::ActivationTypes::Asinh, "Asinh"},
{ngraph::helpers::ActivationTypes::Atan, "Atan"},
{ngraph::helpers::ActivationTypes::Atanh, "Atanh"},
{ngraph::helpers::ActivationTypes::Cos, "Cos"},
{ngraph::helpers::ActivationTypes::Cosh, "Cosh"},
{ngraph::helpers::ActivationTypes::Floor, "Floor"},
@@ -90,6 +90,12 @@ InferenceEngine::Blob::Ptr ActivationLayerTest::GenerateInput(const InferenceEng
resolution = 32768;
break;
}
case ngraph::helpers::ActivationTypes::Atanh: {
data_start_from = -1;
data_range = 2;
resolution = 32768;
break;
}
case ngraph::helpers::ActivationTypes::Ceiling: {
data_start_from = -1000;
data_range = 2000;
@@ -103,6 +103,7 @@ enum ActivationTypes {
Asin,
Asinh,
Atan,
Atanh,
Cos,
Cosh,
Floor,
@@ -54,6 +54,8 @@ std::shared_ptr<ngraph::Node> makeActivation(const ngraph::Output<Node> &in,
return std::make_shared<ngraph::op::Asinh>(in);
case ngraph::helpers::ActivationTypes::Atan:
return std::make_shared<ngraph::op::Atan>(in);
case ngraph::helpers::ActivationTypes::Atanh:
return std::make_shared<ngraph::op::Atanh>(in);
case ngraph::helpers::ActivationTypes::Cos:
return std::make_shared<ngraph::op::Cos>(in);
case ngraph::helpers::ActivationTypes::Cosh:
-2
View File
@@ -47,7 +47,6 @@ bool evaluate_asin(const HostTensorPtr& arg0, const HostTensorPtr& out, const si
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_asin, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_asin, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_asin, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_asin, u32, arg0, out, count);
@@ -70,7 +69,6 @@ bool op::Asin::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Asin::has_evaluate() const {
NGRAPH_OP_SCOPE(v1_Asin_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
-2
View File
@@ -42,7 +42,6 @@ bool evaluate_cos(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_cos, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cos, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cos, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cos, u32, arg0, out, count);
@@ -66,7 +65,6 @@ bool op::Cos::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Cos::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_Cos_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
-2
View File
@@ -42,7 +42,6 @@ bool evaluate_cosh(const HostTensorPtr& arg0, const HostTensorPtr& out, const si
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_cosh, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cosh, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cosh, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_cosh, u32, arg0, out, count);
@@ -66,7 +65,6 @@ bool op::Cosh::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Cosh::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_Cosh_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
-2
View File
@@ -43,7 +43,6 @@ bool evaluate_sin(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_sin, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sin, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sin, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sin, u32, arg0, out, count);
@@ -66,7 +65,6 @@ bool op::Sin::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Sin::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_Sin_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
-2
View File
@@ -42,7 +42,6 @@ bool evaluate_sinh(const HostTensorPtr& arg0, const HostTensorPtr& out, const si
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_sinh, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sinh, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sinh, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_sinh, u32, arg0, out, count);
@@ -66,7 +65,6 @@ bool op::Sinh::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Sinh::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_Sinh_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
-2
View File
@@ -44,7 +44,6 @@ bool evaluate_tan(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz
out->set_unary(arg0);
switch (arg0->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_tan, boolean, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_tan, i32, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_tan, i64, arg0, out, count);
NGRAPH_TYPE_CASE(evaluate_tan, u32, arg0, out, count);
@@ -67,7 +66,6 @@ bool op::Tan::evaluate(const HostTensorVector& outputs, const HostTensorVector&
bool op::Tan::has_evaluate() const {
NGRAPH_OP_SCOPE(v0_Tan_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::boolean:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u32:
+3 -7
View File
@@ -234,6 +234,7 @@ set(SRC
type_prop/squeeze.cpp
type_prop/swish.cpp
type_prop/tan.cpp
type_prop/tanh.cpp
type_prop/ti.cpp
type_prop/tile.cpp
type_prop/top_k.cpp
@@ -250,6 +251,7 @@ set(SRC
visitors/op/adaptive_avg_pool.cpp
visitors/op/adaptive_max_pool.cpp
visitors/op/add.cpp
visitors/op/asin.cpp
visitors/op/asinh.cpp
visitors/op/atan.cpp
visitors/op/atanh.cpp
@@ -345,6 +347,7 @@ set(SRC
visitors/op/selu.cpp
visitors/op/shuffle_channels.cpp
visitors/op/sign.cpp
visitors/op/sin.cpp
visitors/op/sinh.cpp
visitors/op/slice.cpp
visitors/op/softmax.cpp
@@ -418,8 +421,6 @@ set(MULTI_TEST_SRC
backend/add.in.cpp
backend/aliased_output.in.cpp
backend/api.in.cpp
backend/asin.in.cpp
backend/asinh.in.cpp
backend/auto_broadcast.in.cpp
backend/avg_pool.in.cpp
backend/batch_norm.in.cpp
@@ -434,8 +435,6 @@ set(MULTI_TEST_SRC
backend/convolution.in.cpp
backend/binary_convolution.in.cpp
backend/clamp.in.cpp
backend/cos.in.cpp
backend/cosh.in.cpp
backend/ctc_greedy_decoder.in.cpp
backend/ctc_greedy_decoder_seq_len.in.cpp
backend/deformable_psroi_pooling.in.cpp
@@ -510,8 +509,6 @@ set(MULTI_TEST_SRC
backend/shape_of.in.cpp
backend/shuffle_channels.in.cpp
backend/sigmoid.in.cpp
backend/sin.in.cpp
backend/sinh.in.cpp
backend/softmax.in.cpp
backend/softplus.in.cpp
backend/space_to_batch.in.cpp
@@ -521,7 +518,6 @@ set(MULTI_TEST_SRC
backend/squeeze.in.cpp
backend/subtract.in.cpp
backend/swish.in.cpp
backend/tanh.in.cpp
backend/tile.in.cpp
backend/topk.in.cpp
backend/transpose.in.cpp
-54
View File
@@ -1,54 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, asin) {
Shape shape{11};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Asin>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({-1.f, -0.75f, -0.5f, -0.25f, -0.125f, 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f});
test_case.add_expected_output<float>(shape,
{-1.57079633f,
-0.84806208f,
-0.52359878f,
-0.25268026f,
-0.12532783f,
0.00000000f,
0.12532783f,
0.25268026f,
0.52359878f,
0.84806208f,
1.57079633f});
test_case.run();
}
-63
View File
@@ -1,63 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, asinh) {
Shape shape{11};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Asinh>(A), ParameterVector{A});
vector<float> input{0.f, 1.f, -1.f, 2.f, -2.f, 3.f, -3.f, 4.f, 5.f, 10.f, 100.f};
vector<float> expected;
for (float f : input) {
expected.push_back(std::asinh(f));
}
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(input);
test_case.add_expected_output<float>(shape, expected);
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, asinh_i32) {
Shape shape{11};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Asinh>(A), ParameterVector{A});
vector<int> input{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
vector<int> expected{-2, -2, -2, -1, -1, 0, 1, 1, 2, 2, 2};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int>(input);
test_case.add_expected_output<int>(shape, expected);
test_case.run();
}
-48
View File
@@ -1,48 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, cos_float) {
Shape shape{11};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Cos>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f});
test_case.add_expected_output<float>(shape,
{1.00000000f,
0.96891242f,
0.96891242f,
0.87758256f,
0.87758256f,
0.54030231f,
0.54030231f,
-0.41614684f,
-0.41614684f,
-0.65364362f,
-0.65364362f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, cos_int) {
Shape shape{5};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Cos>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>({1, 2, 3, 4, 5});
test_case.add_expected_output<int32_t>(shape, {1, 0, -1, -1, 0});
test_case.run();
}
-43
View File
@@ -1,43 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, cosh_float) {
Shape shape{6};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Cosh>(A), ParameterVector{A});
vector<float> input{1.0f, 0.0f, -0.0f, -1.0f, 5.0f, -5.0f};
vector<float> expected;
for (float f : input) {
expected.push_back(coshf(f));
}
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(input);
test_case.add_expected_output<float>(shape, expected);
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, cosh_int) {
Shape shape{5};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Cosh>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>({1, 5, 2, 3, 3});
test_case.add_expected_output<int32_t>(shape, {2, 74, 4, 10, 10});
test_case.run();
}
-63
View File
@@ -1,63 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, sin) {
Shape shape{11};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Sin>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
vector<float> input{0.f, 0.25f, -0.25f, 0.5f, -0.5f, 1.f, -1.f, 2.f, -2.f, 4.f, -4.f};
copy_data(a, input);
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f(vector<float>{0.00000000f,
0.24740396f,
-0.24740396f,
0.47942554f,
-0.47942554f,
0.84147098f,
-0.84147098f,
0.90929743f,
-0.90929743f,
-0.75680250f,
0.75680250f},
read_vector<float>(result)));
}
-100
View File
@@ -1,100 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, sinh) {
Shape shape{8};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Sinh>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({-4, -3, -2, -1, 0, 1, 2, 3});
test_case.add_expected_output<float>(
shape,
{sinhf(-4), sinhf(-3), sinhf(-2), sinhf(-1), sinhf(0), sinhf(1), sinhf(2), sinhf(3)});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, sinh_negative) {
Shape shape{5};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Sinh>(A), ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({-4, -3, -2, -1, -5});
test_case.add_expected_output<float>(shape, {sinhf(-4), sinhf(-3), sinhf(-2), sinhf(-1), sinhf(-5)});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, sinh_scalar) {
Shape shape{};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Sinh>(A), ParameterVector{A});
const vector<float> a{13};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({a});
test_case.add_expected_output<float>(shape, {sinhf(13)});
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 2);
}
NGRAPH_TEST(${BACKEND_NAME}, sinh_in_place) {
Shape shape{2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto T = make_shared<op::Sinh>(A);
auto T2 = make_shared<op::Sinh>(T);
auto f = make_shared<Function>(T2, ParameterVector{A});
const vector<float> a{1, 3};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>({a});
test_case.add_expected_output<float>(shape, {sinhf(sinhf(1)), sinhf(sinhf(3))});
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 2);
}
NGRAPH_TEST(${BACKEND_NAME}, sinh_i32) {
Shape shape{5};
auto A = make_shared<op::Parameter>(element::i32, shape);
;
auto f = make_shared<Function>(make_shared<op::Sinh>(A), ParameterVector{A});
const vector<int32_t> input{2, 1, 0, -1, -2};
const vector<int32_t> expected{4, 1, 0, -1, -4};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>({input});
test_case.add_expected_output<int32_t>(shape, {expected});
test_case.run();
}
-79
View File
@@ -1,79 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, tanh_f32) {
Shape shape{8};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Tanh>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
const vector<float> input{2.f, 1.f, 0.5f, 0.f, -0.f, -0.5f, -1.f, -2.f};
const auto expected = [&] {
vector<float> e(input.size(), 0);
std::transform(begin(input), end(input), begin(e), [](float v) {
return std::tanh(v);
});
return e;
}();
copy_data(a, input);
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, tanh_int32) {
Shape shape{5};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Tanh>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
const vector<int32_t> input{2, 1, 0, -1, -2};
const vector<int32_t> expected{1, 1, 0, -1, -1};
copy_data(a, input);
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ(expected, read_vector<int32_t>(result));
}
+9
View File
@@ -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::Tanh>;
INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_tanh, UnaryOperator, Type);
+8
View File
@@ -0,0 +1,8 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "unary_ops.hpp"
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::Asin, ngraph::element::f32>>;
INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, UnaryOperatorTypeName);
+9
View File
@@ -0,0 +1,9 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "unary_ops.hpp"
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Sin, ngraph::element::f32>>;
INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, UnaryOperatorTypeName);