Revise Clamp reference implementation (#4813)
* Operation class review * Remove clamp from FusedOp * Add node validation checks * Add type_prop unit tests * Move backend unit tests into a separate file * Remove unnecessary includes * Add support for i8, i16, u8, u16 and bf16 precisions * Refactor backend unit tests * Remove instance with f64 precision * Move dynamic shape tests to op_eval * Group failing tests into manifest * Add single layer tests and serialization tests * Skip tests with conversion due to plugin misbehavior * Add unit tests fails to manifest with documented issues * Fix centos7 test to skip slt cpu instances of integer precision * Enable dynamic test for float element type * Address review comments
This commit is contained in:
parent
8ad8b6b9b3
commit
902a89b582
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "shared_test_classes/single_layer/clamp.hpp"
|
||||
|
||||
using namespace LayerTestsDefinitions;
|
||||
|
||||
namespace {
|
||||
TEST_P(ClampLayerTest, Serialize) {
|
||||
Serialize();
|
||||
}
|
||||
|
||||
const std::vector<std::vector<size_t>> inShapes = {
|
||||
{50}, {10, 10}, {1, 20, 20}, {2, 3, 50, 50}};
|
||||
|
||||
const std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP32, InferenceEngine::Precision::I32};
|
||||
|
||||
const std::vector<std::pair<float, float>> intervals = {
|
||||
{-20.1, -10.5}, {-10.0, 10.0}, {10.3, 20.4}};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
smoke_Clamp_Serialization, ClampLayerTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(inShapes),
|
||||
::testing::ValuesIn(intervals),
|
||||
::testing::ValuesIn(netPrecisions),
|
||||
::testing::Values(CommonTestUtils::DEVICE_CPU)),
|
||||
ClampLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "single_layer_tests/clamp.hpp"
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
|
||||
using namespace LayerTestsDefinitions;
|
||||
|
||||
const std::vector<std::vector<size_t>> inShapes = {
|
||||
{50},
|
||||
{10, 10},
|
||||
{1, 20, 20}
|
||||
};
|
||||
|
||||
const std::vector<std::pair<float, float>> intervals = {
|
||||
{-20.1, -10.5},
|
||||
{-10.0, 10.0},
|
||||
{10.3, 20.4}
|
||||
};
|
||||
|
||||
const std::vector<std::pair<float, float>> intervals_unsigned = {
|
||||
{0.1, 10.1},
|
||||
{10.0, 100.0},
|
||||
{10.6, 20.6}
|
||||
};
|
||||
|
||||
const std::vector<InferenceEngine::Precision> netPrc = {
|
||||
InferenceEngine::Precision::FP32,
|
||||
InferenceEngine::Precision::FP16,
|
||||
InferenceEngine::Precision::I64,
|
||||
InferenceEngine::Precision::I32
|
||||
};
|
||||
|
||||
const auto test_Clamp_signed = ::testing::Combine(
|
||||
::testing::ValuesIn(inShapes),
|
||||
::testing::ValuesIn(intervals),
|
||||
::testing::ValuesIn(netPrc),
|
||||
::testing::Values(CommonTestUtils::DEVICE_CPU)
|
||||
);
|
||||
|
||||
const auto test_Clamp_unsigned = ::testing::Combine(
|
||||
::testing::ValuesIn(inShapes),
|
||||
::testing::ValuesIn(intervals_unsigned),
|
||||
::testing::Values(InferenceEngine::Precision::U64),
|
||||
::testing::Values(CommonTestUtils::DEVICE_CPU)
|
||||
);
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(smoke_TestsClamp_signed, ClampLayerTest, test_Clamp_signed, ClampLayerTest::getTestCaseName);
|
||||
INSTANTIATE_TEST_CASE_P(smoke_TestsClamp_unsigned, ClampLayerTest, test_Clamp_unsigned, ClampLayerTest::getTestCaseName);
|
@ -58,7 +58,10 @@ std::vector<std::string> disabledTestPatterns() {
|
||||
// Skip platforms that do not support BF16 (i.e. sse, avx, avx2)
|
||||
R"(.*BF16.*(jit_avx(?!5)|jit_sse).*)",
|
||||
// TODO: Incorrect blob sizes for node BinaryConvolution_X
|
||||
R"(.*BinaryConvolutionLayerTest.*)"
|
||||
R"(.*BinaryConvolutionLayerTest.*)",
|
||||
// TODO: 51676. Incorrect conversion of min and max limits from double to integral
|
||||
R"(.*ClampLayerTest.*netPrc=(I64|I32).*)",
|
||||
R"(.*ClampLayerTest.*netPrc=U64.*)"
|
||||
};
|
||||
|
||||
if (!InferenceEngine::with_cpu_x86_avx512_core()) {
|
||||
|
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared_test_classes/single_layer/clamp.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
TEST_P(ClampLayerTest, CompareWithRefs) {
|
||||
Run();
|
||||
}
|
||||
} // namespace LayerTestsDefinitions
|
@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
|
||||
#include "shared_test_classes/base/layer_test_utils.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
using clampParamsTuple = std::tuple<
|
||||
InferenceEngine::SizeVector, // Input shape
|
||||
std::pair<float, float>, // Interval [min, max]
|
||||
InferenceEngine::Precision, // Net precision
|
||||
std::string>; // Device name
|
||||
|
||||
class ClampLayerTest : public testing::WithParamInterface<clampParamsTuple>,
|
||||
virtual public LayerTestsUtils::LayerTestsCommon {
|
||||
public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<clampParamsTuple> obj);
|
||||
protected:
|
||||
void SetUp() override;
|
||||
};
|
||||
|
||||
} // namespace LayerTestsDefinitions
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "shared_test_classes/single_layer/clamp.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
std::string ClampLayerTest::getTestCaseName(testing::TestParamInfo<clampParamsTuple> obj) {
|
||||
InferenceEngine::SizeVector inShape;
|
||||
std::pair<float, float> interval;
|
||||
InferenceEngine::Precision netPrc;
|
||||
std::string targetDevice;
|
||||
|
||||
std::tie(inShape, interval, netPrc, targetDevice) = obj.param;
|
||||
|
||||
std::ostringstream result;
|
||||
result << "inShape=" << CommonTestUtils::vec2str(inShape) << "_";
|
||||
result << "min=" << interval.first << "_";
|
||||
result << "max=" << interval.second << "_";
|
||||
result << "netPrc=" << netPrc.name() << "_";
|
||||
result << "trgDev=" << targetDevice;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
void ClampLayerTest::SetUp() {
|
||||
InferenceEngine::SizeVector inShape;
|
||||
std::pair<float, float> interval;
|
||||
InferenceEngine::Precision netPrc;
|
||||
|
||||
std::tie(inShape, interval, netPrc, targetDevice) = this->GetParam();
|
||||
|
||||
auto ngNetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrc);
|
||||
auto input = std::make_shared<ngraph::op::Parameter>(ngNetPrc, ngraph::Shape(inShape));
|
||||
auto clamp = std::make_shared<ngraph::op::Clamp>(input, interval.first, interval.second);
|
||||
function = std::make_shared<ngraph::Function>(std::make_shared<ngraph::opset1::Result>(clamp), ngraph::ParameterVector{input});
|
||||
}
|
||||
|
||||
} // namespace LayerTestsDefinitions
|
@ -31,6 +31,20 @@ namespace clamp
|
||||
bool rc = true;
|
||||
switch (arg->get_element_type())
|
||||
{
|
||||
TYPE_CASE(i8)
|
||||
(arg,
|
||||
out,
|
||||
double_to_int<int8_t>(min, ceil_func),
|
||||
double_to_int<int8_t>(max, floor_func),
|
||||
count);
|
||||
break;
|
||||
TYPE_CASE(i16)
|
||||
(arg,
|
||||
out,
|
||||
double_to_int<int16_t>(min, ceil_func),
|
||||
double_to_int<int16_t>(max, floor_func),
|
||||
count);
|
||||
break;
|
||||
TYPE_CASE(i32)
|
||||
(arg,
|
||||
out,
|
||||
@ -45,6 +59,20 @@ namespace clamp
|
||||
double_to_int<int64_t>(max, floor_func),
|
||||
count);
|
||||
break;
|
||||
TYPE_CASE(u8)
|
||||
(arg,
|
||||
out,
|
||||
double_to_int<uint8_t>(min, ceil_func),
|
||||
double_to_int<uint8_t>(max, floor_func),
|
||||
count);
|
||||
break;
|
||||
TYPE_CASE(u16)
|
||||
(arg,
|
||||
out,
|
||||
double_to_int<uint16_t>(min, ceil_func),
|
||||
double_to_int<uint16_t>(max, floor_func),
|
||||
count);
|
||||
break;
|
||||
TYPE_CASE(u32)
|
||||
(arg,
|
||||
out,
|
||||
@ -61,6 +89,9 @@ namespace clamp
|
||||
break;
|
||||
TYPE_CASE(f16)(arg, out, static_cast<float16>(min), static_cast<float16>(max), count);
|
||||
break;
|
||||
TYPE_CASE(bf16)
|
||||
(arg, out, static_cast<bfloat16>(min), static_cast<bfloat16>(max), count);
|
||||
break;
|
||||
TYPE_CASE(f32)(arg, out, static_cast<float>(min), static_cast<float>(max), count);
|
||||
break;
|
||||
default: rc = false; break;
|
||||
@ -96,9 +127,19 @@ op::Clamp::Clamp(const Output<Node>& data, const double min, const double max)
|
||||
|
||||
void op::Clamp::validate_and_infer_types()
|
||||
{
|
||||
NODE_VALIDATION_CHECK(
|
||||
this, m_min < m_max, "The 'min' parameter needs to be less than 'max' for Clamp");
|
||||
set_output_type(0, get_input_element_type(0), get_input_partial_shape(0));
|
||||
NGRAPH_OP_SCOPE(v0_Clamp_validate_and_infer_types);
|
||||
const element::Type& input_et = get_input_element_type(0);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
input_et.is_integral_number() || input_et.is_real(),
|
||||
"Input element type must be numeric. Got: ",
|
||||
input_et);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
m_min < m_max,
|
||||
"Attribute 'min' must be less than 'max'. Got: ",
|
||||
m_min,
|
||||
" and ",
|
||||
m_max);
|
||||
set_output_type(0, input_et, get_input_partial_shape(0));
|
||||
}
|
||||
|
||||
shared_ptr<Node> op::Clamp::clone_with_new_inputs(const OutputVector& new_args) const
|
||||
|
@ -60,6 +60,7 @@ set(SRC
|
||||
op.cpp
|
||||
op_eval/binary_convolution.cpp
|
||||
op_eval/bucketize.cpp
|
||||
op_eval/clamp.cpp
|
||||
op_eval/floor_mod.cpp
|
||||
op_eval/gelu.cpp
|
||||
op_eval/hsigmoid.cpp
|
||||
@ -313,6 +314,7 @@ set(MULTI_TEST_SRC
|
||||
backend/convert_like.in.cpp
|
||||
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
|
||||
|
418
ngraph/test/backend/clamp.in.cpp
Normal file
418
ngraph/test/backend/clamp.in.cpp
Normal file
@ -0,0 +1,418 @@
|
||||
//*****************************************************************************
|
||||
// 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 "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});
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, test::TestCaseType tct = test::TestCaseType::STATIC>
|
||||
void clamp_test(const element::Type& type,
|
||||
const PartialShape& dynamic_shape,
|
||||
const Shape& static_shape,
|
||||
const std::vector<T>& input,
|
||||
double min,
|
||||
double max,
|
||||
const std::vector<T>& output)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(type, dynamic_shape);
|
||||
auto clamp = make_shared<op::Clamp>(data, min, max);
|
||||
auto function = make_shared<Function>(clamp, ParameterVector{data});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine, tct>(function);
|
||||
test_case.template add_input<T>(static_shape, input);
|
||||
test_case.template add_expected_output<T>(static_shape, output);
|
||||
return test_case.run();
|
||||
}
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_integral)
|
||||
{
|
||||
Shape in_shape{6};
|
||||
element::Type et = element::i32;
|
||||
|
||||
float min = 0.4; // ceiled to 1
|
||||
float max = 5.6; // floored to 5
|
||||
|
||||
auto input = make_shared<op::Parameter>(et, in_shape);
|
||||
auto clamp = make_shared<op::Clamp>(input, min, max);
|
||||
auto f = make_shared<Function>(clamp, ParameterVector{input});
|
||||
|
||||
vector<int32_t> in_vec{-1, 3, -10, 20, 6, 2};
|
||||
vector<int32_t> out_vec{1, 3, 1, 5, 5, 2};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input(in_shape, in_vec);
|
||||
test_case.add_expected_output(in_shape, out_vec);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_integral_negative)
|
||||
{
|
||||
Shape in_shape{6};
|
||||
element::Type et = element::i32;
|
||||
|
||||
float min = -5.6; // ceiled to -5
|
||||
float max = -0.4; // floored to -1
|
||||
|
||||
auto input = make_shared<op::Parameter>(et, in_shape);
|
||||
auto clamp = make_shared<op::Clamp>(input, min, max);
|
||||
auto f = make_shared<Function>(clamp, ParameterVector{input});
|
||||
|
||||
vector<int32_t> in_vec{-6, 1, -2, 0, -1, 2};
|
||||
vector<int32_t> out_vec{-5, -1, -2, -1, -1, -1};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input(in_shape, in_vec);
|
||||
test_case.add_expected_output(in_shape, out_vec);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_float)
|
||||
{
|
||||
auto type = element::f32;
|
||||
typedef float ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_int8)
|
||||
{
|
||||
auto type = element::i8;
|
||||
typedef int8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_int16)
|
||||
{
|
||||
auto type = element::i16;
|
||||
typedef int16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_int32)
|
||||
{
|
||||
auto type = element::i32;
|
||||
typedef int32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_int64)
|
||||
{
|
||||
auto type = element::i64;
|
||||
typedef int64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_uint8)
|
||||
{
|
||||
auto type = element::u8;
|
||||
typedef uint8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_uint16)
|
||||
{
|
||||
auto type = element::u16;
|
||||
typedef uint16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_uint32)
|
||||
{
|
||||
auto type = element::u32;
|
||||
typedef uint32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_uint64)
|
||||
{
|
||||
auto type = element::u64;
|
||||
typedef uint64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (32 - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_float16)
|
||||
{
|
||||
auto type = element::f16;
|
||||
typedef float16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, clamp_bfloat16)
|
||||
{
|
||||
auto type = element::bf16;
|
||||
typedef bfloat16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
@ -446,616 +446,6 @@ NGRAPH_TEST(${BACKEND_NAME}, DISABLED_normalize_across_chw_4d_max_bias)
|
||||
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, test::TestCaseType tct = test::TestCaseType::STATIC>
|
||||
void clamp_test(const element::Type& type,
|
||||
const PartialShape& dynamic_shape,
|
||||
const Shape& static_shape,
|
||||
const std::vector<T>& input,
|
||||
double min,
|
||||
double max,
|
||||
const std::vector<T>& output)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(type, dynamic_shape);
|
||||
auto clamp = make_shared<op::Clamp>(data, min, max);
|
||||
auto function = make_shared<Function>(clamp, ParameterVector{data});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine, tct>(function);
|
||||
test_case.template add_input<T>(static_shape, input);
|
||||
test_case.template add_expected_output<T>(static_shape, output);
|
||||
return test_case.run();
|
||||
}
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_double)
|
||||
{
|
||||
auto type = element::f64;
|
||||
typedef double ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_float)
|
||||
{
|
||||
auto type = element::f32;
|
||||
typedef float ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_int8)
|
||||
{
|
||||
auto type = element::i8;
|
||||
typedef int8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_int16)
|
||||
{
|
||||
auto type = element::i16;
|
||||
typedef int16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_int32)
|
||||
{
|
||||
auto type = element::i32;
|
||||
typedef int32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_int64)
|
||||
{
|
||||
auto type = element::i64;
|
||||
typedef int64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_uint8)
|
||||
{
|
||||
auto type = element::u8;
|
||||
typedef uint8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_uint16)
|
||||
{
|
||||
auto type = element::u16;
|
||||
typedef uint16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_uint32)
|
||||
{
|
||||
auto type = element::u32;
|
||||
typedef uint32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_uint64)
|
||||
{
|
||||
auto type = element::u64;
|
||||
typedef uint64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (32 - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype>(type, sshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_float16)
|
||||
{
|
||||
auto type = element::f16;
|
||||
typedef float16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, fused_clamp_bfloat16)
|
||||
{
|
||||
auto type = element::bf16;
|
||||
typedef bfloat16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
// static shape
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype>(type,
|
||||
sshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, mvn_mean_normalization)
|
||||
{
|
||||
Shape data_shape{1, 2, 5};
|
||||
|
402
ngraph/test/op_eval/clamp.cpp
Normal file
402
ngraph/test/op_eval/clamp.cpp
Normal file
@ -0,0 +1,402 @@
|
||||
//*****************************************************************************
|
||||
// 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 "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/engine/interpreter_engine.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}";
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, test::TestCaseType tct = test::TestCaseType::STATIC>
|
||||
void clamp_test(const element::Type& type,
|
||||
const PartialShape& dynamic_shape,
|
||||
const Shape& static_shape,
|
||||
const std::vector<T>& input,
|
||||
double min,
|
||||
double max,
|
||||
const std::vector<T>& output)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(type, dynamic_shape);
|
||||
auto clamp = make_shared<op::Clamp>(data, min, max);
|
||||
auto function = make_shared<Function>(clamp, ParameterVector{data});
|
||||
|
||||
auto test_case = test::TestCase<test::INTERPRETER_Engine, tct>(function);
|
||||
test_case.template add_input<T>(static_shape, input);
|
||||
test_case.template add_expected_output<T>(static_shape, output);
|
||||
return test_case.run();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_float_dynamic)
|
||||
{
|
||||
auto type = element::f32;
|
||||
typedef float ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_int8_dynamic)
|
||||
{
|
||||
auto type = element::i8;
|
||||
typedef int8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_int16_dynamic)
|
||||
{
|
||||
auto type = element::i16;
|
||||
typedef int16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_int32_dynamic)
|
||||
{
|
||||
auto type = element::i32;
|
||||
typedef int32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_int64_dynamic)
|
||||
{
|
||||
auto type = element::i64;
|
||||
typedef int64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<double>::infinity();
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_uint8_dynamic)
|
||||
{
|
||||
auto type = element::u8;
|
||||
typedef uint8_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_uint16_dynamic)
|
||||
{
|
||||
auto type = element::u16;
|
||||
typedef uint16_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
// dynamic shape
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_uint32_dynamic)
|
||||
{
|
||||
auto type = element::u32;
|
||||
typedef uint32_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (numeric_limits<ctype>::digits - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_uint64_dynamic)
|
||||
{
|
||||
auto type = element::u64;
|
||||
typedef uint64_t ctype;
|
||||
|
||||
auto sshape = Shape{4, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
// TODO: Fix CPU DEX / MLIR correctness bug: using signed comparison for unsigned ints
|
||||
// auto max = numeric_limits<ctype>::max();
|
||||
// auto pinf = numeric_limits<double>::infinity();
|
||||
ctype max = (static_cast<ctype>(1) << (32 - 1)) - 1;
|
||||
auto pinf = static_cast<double>(max);
|
||||
auto ninf = -numeric_limits<double>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, 9, 10, 11, 19, 20, 21};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, 20.0, {10, 20, 10, 10, 11, 19, 20, 20});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, 10.0, pinf, {10, max, 10, 10, 11, 19, 20, 21});
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type, dshape, sshape, input, ninf, 20.0, {min, 20, 9, 10, 11, 19, 20, 20});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_float16_dynamic)
|
||||
{
|
||||
auto type = element::f16;
|
||||
typedef float16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
||||
|
||||
TEST(op_eval, clamp_bfloat16_dynamic)
|
||||
{
|
||||
auto type = element::bf16;
|
||||
typedef bfloat16 ctype;
|
||||
|
||||
auto sshape = Shape{5, 2};
|
||||
auto dshape = PartialShape::dynamic();
|
||||
|
||||
auto min = numeric_limits<ctype>::min();
|
||||
auto max = numeric_limits<ctype>::max();
|
||||
auto pinf = numeric_limits<float>::infinity();
|
||||
auto ninf = -numeric_limits<float>::infinity();
|
||||
|
||||
vector<ctype> input{min, max, ninf, pinf, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.000001};
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
{-0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8},
|
||||
0.2,
|
||||
0.6,
|
||||
{0.2, 0.2, 0.2, 0.2, 0.3, 0.4, 0.5, 0.6, 0.6, 0.6});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
20.0,
|
||||
{10.0, 20.0, 10.0, 20.0, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
10.0,
|
||||
pinf,
|
||||
{10.0, max, 10.0, pinf, 10.0, 10.0, 10.000001, 19.999999, 20.0, 20.000001});
|
||||
|
||||
clamp_test<ctype, test::TestCaseType::DYNAMIC>(
|
||||
type,
|
||||
dshape,
|
||||
sshape,
|
||||
input,
|
||||
ninf,
|
||||
20.0,
|
||||
{min, 20.0, ninf, 20.0, 9.99999, 10.0, 10.000001, 19.999999, 20.0, 20.0});
|
||||
}
|
@ -106,7 +106,6 @@ ceiling_int64
|
||||
matmul_2x2x3_2x3x1_int64
|
||||
matmul_2x2x3_2x1x3_transpose_int64
|
||||
onnx_dyn_shapes_slice_10_3d_input_12_axes
|
||||
IE_CPU.fused_clamp_int64
|
||||
IE_CPU.onnx_dyn_shapes_slice_10_default_axes
|
||||
onnx_dyn_shapes_ab_plus_c_inference
|
||||
onnx_dyn_shapes_dynamic_rank_input_inference
|
||||
@ -135,9 +134,6 @@ onnx_dyn_shapes_slice_10_3d_input_12_axes
|
||||
onnx_top_k_opset_10
|
||||
onnx_model_scatterND_param_i64_indices
|
||||
|
||||
# [NOT_IMPLEMENTED] Input image format U64 is not supported yet...
|
||||
IE_CPU.fused_clamp_uint64
|
||||
|
||||
# TopK Incorrect input data/index values precision
|
||||
onnx_model_argmax_int32
|
||||
onnx_model_argmin_int32
|
||||
@ -172,12 +168,6 @@ onnx_model_one_hot_without_axis
|
||||
onnx_model_one_hot_with_axis
|
||||
|
||||
# Dynamic function 'get_shape was called on a descriptor::Tensor with dynamic shape'
|
||||
fused_clamp_uint16
|
||||
fused_clamp_uint8
|
||||
fused_clamp_int32
|
||||
fused_clamp_int8
|
||||
fused_clamp_float
|
||||
fused_clamp_int16
|
||||
onnx_dyn_shapes_model_acosh_1_3
|
||||
onnx_dyn_shapes_model_acosh_3_2
|
||||
onnx_dyn_shapes_model_asinh_1_3
|
||||
@ -573,7 +563,6 @@ select_double
|
||||
quantize_clamp_int32
|
||||
max_3d_to_scalar_double
|
||||
argmin_trivial_in_double
|
||||
IE_CPU.fused_clamp_double
|
||||
|
||||
# Incorrect precision bf16!
|
||||
convert_float32_bf16
|
||||
@ -1076,10 +1065,22 @@ gru_cell_hardsigmoid_activation_function
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Cannot cast ngraph node ReplaceSlice to CNNLayer!
|
||||
# Incorrect precision u32!
|
||||
# Parameter has zero dimension that is not allowable
|
||||
IE_CPU.fused_clamp_uint32
|
||||
# Clamp op:
|
||||
# Issue 51676: Output mismatch due to wrong conversion of bounds
|
||||
IE_CPU.clamp_integral
|
||||
IE_CPU.clamp_integral_negative
|
||||
# Issue 51679: CI failure on Ubuntu 20. Overflow handling -inf lower bound
|
||||
IE_CPU.clamp_int32
|
||||
# Precision mismatch
|
||||
IE_CPU.clamp_uint32
|
||||
IE_CPU.clamp_uint16
|
||||
IE_CPU.clamp_int16
|
||||
IE_CPU.clamp_int64
|
||||
IE_CPU.clamp_float16
|
||||
# [NOT_IMPLEMENTED] Input image format U64 is not supported yet...
|
||||
IE_CPU.clamp_uint64
|
||||
# [NOT_IMPLEMENTED] Input image format BF16 is not supported yet...
|
||||
IE_CPU.clamp_bfloat16
|
||||
|
||||
# Cannot cast ngraph node Reshape to CNNLayer!
|
||||
# Parameter has zero dimension that is not allowable
|
||||
@ -1105,12 +1106,6 @@ IE_CPU.convert_like_float32_bfloat16
|
||||
IE_CPU.convert_like_bfloat16_float32
|
||||
IE_CPU.convert_like_dyn_float16_to_int64
|
||||
|
||||
# Can't convert type f16 to IE Precision!
|
||||
IE_CPU.fused_clamp_float16
|
||||
|
||||
# [NOT_IMPLEMENTED] Input image format BF16 is not supported yet...
|
||||
IE_CPU.fused_clamp_bfloat16
|
||||
|
||||
# Operations were removed from opset
|
||||
IE_CPU.atanh
|
||||
IE_CPU.asinh
|
||||
@ -1376,7 +1371,7 @@ IE_GPU.normalize_across_chw_4d
|
||||
IE_GPU.normalize_across_h_4d
|
||||
IE_GPU.normalize_across_c_2x2_shape
|
||||
IE_GPU.normalize_across_c_2x4_shape
|
||||
IE_GPU.fused_clamp
|
||||
IE_GPU.clamp
|
||||
IE_GPU.grn_4d
|
||||
IE_GPU.squeeze
|
||||
IE_GPU.squared_difference
|
||||
|
@ -65,12 +65,6 @@ INTERPRETER.gather_axis_0_int8
|
||||
INTERPRETER.gather_axis_0_int16
|
||||
INTERPRETER.gather_axis_0_uint8
|
||||
INTERPRETER.gather_axis_0_uint16
|
||||
INTERPRETER.fused_clamp_double
|
||||
INTERPRETER.fused_clamp_int8
|
||||
INTERPRETER.fused_clamp_int16
|
||||
INTERPRETER.fused_clamp_uint8
|
||||
INTERPRETER.fused_clamp_uint16
|
||||
INTERPRETER.fused_clamp_bfloat16
|
||||
INTERPRETER.auto_bcast_binary_elementwise
|
||||
INTERPRETER.auto_bcast_binary_elementwise_pdpd
|
||||
|
||||
|
@ -9,23 +9,88 @@
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
TEST(type_prop, fused_clamp)
|
||||
TEST(type_prop, clamp_basic_f32)
|
||||
{
|
||||
const auto data = make_shared<op::Parameter>(element::f64, Shape{2, 2});
|
||||
auto data = make_shared<op::Parameter>(element::f32, Shape{1, 32, 32});
|
||||
auto clamp = make_shared<op::Clamp>(data, 0.0, 2.1);
|
||||
|
||||
ASSERT_EQ(clamp->get_element_type(), element::f32);
|
||||
ASSERT_EQ(clamp->get_min(), 0.0);
|
||||
ASSERT_EQ(clamp->get_max(), 2.1);
|
||||
ASSERT_EQ(clamp->get_output_shape(0), (Shape{1, 32, 32}));
|
||||
}
|
||||
|
||||
TEST(type_prop, clamp_basic_i32)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(element::i32, Shape{1, 32, 32});
|
||||
auto clamp = make_shared<op::Clamp>(data, 0.0, 2.1);
|
||||
|
||||
ASSERT_EQ(clamp->get_element_type(), element::i32);
|
||||
ASSERT_EQ(clamp->get_min(), 0.0);
|
||||
ASSERT_EQ(clamp->get_max(), 2.1);
|
||||
ASSERT_EQ(clamp->get_output_shape(0), (Shape{1, 32, 32}));
|
||||
}
|
||||
|
||||
TEST(type_prop, clamp_shape_static_rank)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(
|
||||
element::f16, PartialShape{Dimension::dynamic(), Dimension::dynamic(), 32});
|
||||
auto clamp = make_shared<op::Clamp>(data, -2.1, 2.1);
|
||||
|
||||
ASSERT_EQ(clamp->get_element_type(), element::f16);
|
||||
ASSERT_EQ(clamp->get_min(), -2.1);
|
||||
ASSERT_EQ(clamp->get_max(), 2.1);
|
||||
ASSERT_EQ(clamp->get_output_partial_shape(0),
|
||||
(PartialShape{Dimension::dynamic(), Dimension::dynamic(), 32}));
|
||||
}
|
||||
|
||||
TEST(type_prop, clamp_shape_dynamic)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(element::u16, PartialShape::dynamic());
|
||||
auto clamp = make_shared<op::Clamp>(data, 1.5, 15.0);
|
||||
|
||||
ASSERT_EQ(clamp->get_element_type(), element::u16);
|
||||
ASSERT_EQ(clamp->get_min(), 1.5);
|
||||
ASSERT_EQ(clamp->get_max(), 15.0);
|
||||
ASSERT_EQ(clamp->get_output_partial_shape(0), (PartialShape::dynamic()));
|
||||
}
|
||||
|
||||
TEST(type_prop, clamp_invalid_element_type)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(element::boolean, Shape{2, 2});
|
||||
|
||||
try
|
||||
{
|
||||
const auto clamp = make_shared<op::Clamp>(data, 2.0, 1.0);
|
||||
EXPECT_FALSE(clamp.get())
|
||||
<< "Clamp validation did not work. Op node was created with incorrect params.";
|
||||
auto clamp = make_shared<op::Clamp>(data, 0.5, 5.5);
|
||||
// Input element type is boolean
|
||||
FAIL() << "Invalid boolean element type for input not detected";
|
||||
}
|
||||
catch (const NodeValidationFailure& error)
|
||||
{
|
||||
EXPECT_HAS_SUBSTRING(
|
||||
error.what(), std::string("The 'min' parameter needs to be less than 'max' for Clamp"));
|
||||
EXPECT_HAS_SUBSTRING(error.what(), "Input element type must be numeric");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
FAIL() << "Numeric element type node validation check failed for unexpected reason";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(type_prop, clamp_invalid_attributes)
|
||||
{
|
||||
auto data = make_shared<op::Parameter>(element::f64, Shape{2, 2});
|
||||
|
||||
try
|
||||
{
|
||||
auto clamp = make_shared<op::Clamp>(data, 1.0, 1.0);
|
||||
// Attribute 'max' not greater than 'min'
|
||||
FAIL() << "Attribute 'min' equal to 'max' not detected";
|
||||
}
|
||||
catch (const NodeValidationFailure& error)
|
||||
{
|
||||
EXPECT_HAS_SUBSTRING(error.what(), "Attribute 'min' must be less than 'max'");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
FAIL() << "'min' and 'max' attributes node validation check failed for unexpected reason";
|
||||
}
|
||||
|
||||
const auto clamp = make_shared<op::Clamp>(data, 1.0, 2.0);
|
||||
EXPECT_EQ(clamp->get_element_type(), element::f64);
|
||||
EXPECT_EQ(clamp->get_shape(), (Shape{2, 2}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user