Xp/fix jira 6671 atanh fail mac wins (#8058)
* tmp * Fix atanh correctness test issue and veriyf pass. Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Only keep available input value for correctness test. Signed-off-by: Yan, Xiping <xiping.yan@intel.com>
This commit is contained in:
parent
4964ec890c
commit
b7ccdf4490
@ -8,8 +8,19 @@
|
||||
|
||||
**Detailed description**: *Atanh* performs element-wise hyperbolic inverse tangent (arctangenth) operation on a given input tensor, based on the following mathematical formula:
|
||||
|
||||
Float type input:
|
||||
|
||||
\f[ a_{i} = atanh(a_{i}) \f]
|
||||
|
||||
Signed Intragral type put:
|
||||
|
||||
\f[ a_{i} = (i <= -1) ? std::numeric_limits<T>::min() : (i >= 1) ? std::numeric_limits<T>::max() : atanh(a_{i}) \f]
|
||||
|
||||
Unsigned Intragral type put:
|
||||
|
||||
\f[ a_{i} = (i > 0) ? std::numeric_limits<T>::max() : atanh(a_{i}) \f]
|
||||
|
||||
|
||||
**Attributes**: Atanh operation has no attributes.
|
||||
|
||||
**Inputs**
|
||||
|
@ -2,88 +2,94 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/atanh.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "openvino/op/atanh.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
#include "openvino/runtime/allocator.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace reference_tests {
|
||||
namespace {
|
||||
|
||||
struct AtanhParams {
|
||||
template <class IT>
|
||||
AtanhParams(const ov::PartialShape& shape, const ov::element::Type& iType, const std::vector<IT>& iValues)
|
||||
: pshape(shape), inType(iType), outType(iType), inputData(CreateTensor(iType, iValues)) {
|
||||
std::vector<IT> oValues;
|
||||
std::vector<double> output;
|
||||
for (auto element : iValues)
|
||||
output.push_back(static_cast<double>(element));
|
||||
Tensor input;
|
||||
Tensor expected;
|
||||
};
|
||||
|
||||
std::transform(output.begin(), output.end(), output.begin(), [](double input) -> double {
|
||||
return std::atanh(input);
|
||||
});
|
||||
|
||||
if (std::is_integral<IT>()) {
|
||||
std::transform(output.begin(), output.end(), output.begin(), [](double input) -> double {
|
||||
return std::round(input);
|
||||
});
|
||||
}
|
||||
|
||||
for (auto element : output)
|
||||
oValues.push_back(static_cast<IT>(element));
|
||||
refData = CreateTensor(outType, oValues);
|
||||
}
|
||||
ov::PartialShape pshape;
|
||||
ov::element::Type inType;
|
||||
ov::element::Type outType;
|
||||
ov::runtime::Tensor inputData;
|
||||
ov::runtime::Tensor refData;
|
||||
struct Builder : ParamsBuilder<AtanhParams> {
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input);
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
|
||||
};
|
||||
|
||||
class ReferenceAtanhLayerTest : public testing::TestWithParam<AtanhParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.pshape, params.inType, params.outType);
|
||||
inputData = {params.inputData};
|
||||
refOutData = {params.refData};
|
||||
function = CreateFunction(params.input.shape, params.input.type);
|
||||
inputData = {params.input.data};
|
||||
refOutData = {params.expected.data};
|
||||
}
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<AtanhParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "shape=" << param.pshape << "_";
|
||||
result << "iType=" << param.inType << "_";
|
||||
result << "oType=" << param.outType;
|
||||
result << "shape=" << param.input.shape << "_";
|
||||
result << "type=" << param.input.type;
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape, const element::Type& input_type,
|
||||
const element::Type& expected_output_type) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto atanh = std::make_shared<op::v3::Atanh>(in);
|
||||
return std::make_shared<ov::Function>(NodeVector {atanh}, ParameterVector {in});
|
||||
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
|
||||
const auto out = std::make_shared<op::v3::Atanh>(in);
|
||||
return std::make_shared<ov::Function>(NodeVector{out}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceAtanhLayerTest, CompareWithRefs) {
|
||||
TEST_P(ReferenceAtanhLayerTest, AtanhWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Atanh_With_Hardcoded_Refs, ReferenceAtanhLayerTest,
|
||||
::testing::Values(AtanhParams(ov::PartialShape {2, 4}, ov::element::f32,
|
||||
std::vector<float> {-INFINITY, -2.0f, -1.0f, -0.5f, 0.0f, 0.8f, 1.0f, INFINITY}),
|
||||
AtanhParams(ov::PartialShape {2, 4}, ov::element::f16,
|
||||
std::vector<float16> {-INFINITY, -2.0f, -1.0f, -0.5f, -0.0f, 0.8f, 1.0f, INFINITY}),
|
||||
AtanhParams(ov::PartialShape {2, 3}, ov::element::i32,
|
||||
std::vector<int32_t> {std::numeric_limits<int32_t>::min(), -2, -1, 1, 2, std::numeric_limits<int32_t>::max()}),
|
||||
AtanhParams(ov::PartialShape {2, 3}, ov::element::u32,
|
||||
std::vector<uint32_t> {std::numeric_limits<uint32_t>::min(), 0, 1, 2, 3, std::numeric_limits<uint32_t>::max()}),
|
||||
AtanhParams(ov::PartialShape {2, 3}, ov::element::i64,
|
||||
std::vector<int64_t> {std::numeric_limits<int64_t>::min(), -2, -1, 1, 2, std::numeric_limits<int64_t>::max()}),
|
||||
AtanhParams(ov::PartialShape {2, 3}, ov::element::u64,
|
||||
std::vector<uint64_t> {std::numeric_limits<uint64_t>::min(), 0, 1, 2, 3, std::numeric_limits<uint64_t>::max()})),
|
||||
smoke_Atanh_With_Hardcoded_Refs,
|
||||
ReferenceAtanhLayerTest,
|
||||
::testing::Values(
|
||||
Builder{}
|
||||
.input({{5}, element::f16, std::vector<ngraph::float16>{-1.0f, -0.5f, 0.0f, 0.8f, 1.0f}})
|
||||
.expected({{5},
|
||||
element::f16,
|
||||
std::vector<ngraph::float16>{-INFINITY, -0.54930614f, 0.00000000f, 1.0986123f, INFINITY}}),
|
||||
Builder{}
|
||||
.input({{5}, element::f32, std::vector<float>{-1.0f, -0.5f, 0.0f, 0.8f, 1.0f}})
|
||||
.expected(
|
||||
{{5}, element::f32, std::vector<float>{-INFINITY, -0.54930614f, 0.00000000f, 1.0986123f, INFINITY}}),
|
||||
Builder{}
|
||||
.input({{3}, element::i32, std::vector<int32_t>{-1, 0, 1}})
|
||||
.expected(
|
||||
{{3},
|
||||
element::i32,
|
||||
std::vector<int32_t>{std::numeric_limits<int32_t>::min(), 0, std::numeric_limits<int32_t>::max()}}),
|
||||
Builder{}
|
||||
.input({{2}, element::u32, std::vector<uint32_t>{0, 1}})
|
||||
.expected({{2}, element::u32, std::vector<uint32_t>{0, std::numeric_limits<uint32_t>::max()}}),
|
||||
Builder{}
|
||||
.input({{3}, element::i64, std::vector<int64_t>{-1, 0, 1}})
|
||||
.expected({{3},
|
||||
element::i64,
|
||||
std::vector<int64_t>{
|
||||
std::numeric_limits<int64_t>::min(),
|
||||
0,
|
||||
std::numeric_limits<int64_t>::max(),
|
||||
}}),
|
||||
Builder{}
|
||||
.input({{2}, element::u64, std::vector<uint64_t>{0, 1}})
|
||||
.expected({{2}, element::u64, std::vector<uint64_t>{0, std::numeric_limits<uint64_t>::max()}})),
|
||||
ReferenceAtanhLayerTest::getTestCaseName);
|
||||
} // namespace reference_tests
|
||||
|
@ -21,8 +21,26 @@ void atanh(const T* arg, T* out, size_t count) {
|
||||
template <typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = true>
|
||||
void atanh(const T* arg, T* out, size_t count) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
/**
|
||||
* Intgral type don't support: NAN and INFINITY.
|
||||
* So we clip input value, and make sure return avaiable value.
|
||||
*/
|
||||
if (std::is_same<T, uint8_t>::value || std::is_same<T, uint32_t>::value || std::is_same<T, uint64_t>::value) {
|
||||
if (arg[i] > 0) {
|
||||
out[i] = std::numeric_limits<T>::max();
|
||||
} else {
|
||||
out[i] = std::roundl(std::atanh(arg[i]));
|
||||
}
|
||||
} else {
|
||||
if (arg[i] <= -1) {
|
||||
out[i] = std::numeric_limits<T>::min();
|
||||
} else if (arg[i] >= 1) {
|
||||
out[i] = std::numeric_limits<T>::max();
|
||||
} else {
|
||||
out[i] = std::roundl(std::atanh(arg[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace runtime
|
||||
|
Loading…
Reference in New Issue
Block a user