From fbade79b391fecc47bbf3a83419b994ce3b4b3b0 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Wed, 13 Feb 2019 17:36:41 -0800 Subject: [PATCH 01/20] Initial commit --- .../providers/cpu/cpu_execution_provider.cc | 2 + onnxruntime/core/providers/cpu/math/shrink.cc | 112 ++++++++++++++++++ onnxruntime/core/providers/cpu/math/shrink.h | 27 +++++ onnxruntime/test/onnx/main.cc | 3 - .../test/providers/cpu/math/shrink_test.cc | 50 ++++++++ .../cpu/math/{sing_test.cc => sign_test.cc} | 0 .../test/python/onnx_backend_test_series.py | 3 - 7 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 onnxruntime/core/providers/cpu/math/shrink.cc create mode 100644 onnxruntime/core/providers/cpu/math/shrink.h create mode 100644 onnxruntime/test/providers/cpu/math/shrink_test.cc rename onnxruntime/test/providers/cpu/math/{sing_test.cc => sign_test.cc} (100%) diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index d6fd83eb6497b..189f8b641cb12 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -238,6 +238,7 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Eye class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, float, IsNaN); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, MLFloat16, IsNaN); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Sign); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Shrink); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Erf); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, int64_t_int64_t_int64_t, OneHot); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, float_int64_t_int64_t, OneHot); @@ -492,6 +493,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); + kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); kernel_registry.Register(BuildKernelCreateInfo()); diff --git a/onnxruntime/core/providers/cpu/math/shrink.cc b/onnxruntime/core/providers/cpu/math/shrink.cc new file mode 100644 index 0000000000000..953e4e6466b53 --- /dev/null +++ b/onnxruntime/core/providers/cpu/math/shrink.cc @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "core/providers/cpu/math/shrink.h" +//#include "core/providers/common.h" +//#include "core/common/common.h" +//#include "core/common/exceptions.h" +//#include "core/framework/tensor.h" +#include "core/util/math.h" +#include "core/util/math_cpuonly.h" + +namespace onnxruntime { +ONNX_CPU_OPERATOR_KERNEL( + Shrink, + 9, + KernelDefBuilder().TypeConstraint("T", {DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType()}), + Shrink); + +namespace shrink_internal { +template +inline T ShrinkImpl(T val, float bias, float lambd) { + if (val < -lambd) { + return T(val + bias); + } else if (val > lambd) { + return T(val - bias); + } else { + return T(0); + } +} + +void ShrinkMLFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { + auto span = gsl::make_span(input->Data(), input->Shape().Size()); + auto output_data = output->template MutableData(); + std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const MLFloat16& val) { + float fl = math::halfToFloat(val.val); + return MLFloat16(math::floatToHalf(ShrinkImpl(fl, bias, lambd))); + }); +} + +void ShrinkBFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { + auto span = gsl::make_span(input->Data(), input->Shape().Size()); + auto output_data = output->template MutableData(); + std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const BFloat16& val) { + float fl = val.ToFloat(); + return BFloat16(ShrinkImpl(fl, bias, lambd)); + }); +} + +} // namespace shrink_internal + +Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { + using namespace shrink_internal; + + auto input = p_op_kernel_context->Input(0); + auto output = p_op_kernel_context->Output(0, input->Shape()); + + auto dtype = input->DataType(); + + if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const float& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const double& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); + } + else if (dtype == DataTypeImpl::GetType()) { + ShrinkMLFloat16(input, output, bias_, lambd_); + } + else if (dtype == DataTypeImpl::GetType()) { + ShrinkBFloat16(input, output, bias_, lambd_); + } + else { + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Unsupported input datatype"); + } + + return Status::OK(); +} +} // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/math/shrink.h b/onnxruntime/core/providers/cpu/math/shrink.h new file mode 100644 index 0000000000000..44a9d0c20f590 --- /dev/null +++ b/onnxruntime/core/providers/cpu/math/shrink.h @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include "core/framework/op_kernel.h" + +namespace onnxruntime { +class Shrink final : public OpKernel { + public: + Shrink(const OpKernelInfo& op_kernel_info) : OpKernel(op_kernel_info) { + float bias_temp; + ORT_ENFORCE(op_kernel_info.GetAttr("bias", &bias_temp).IsOK()); + bias_ = gsl::narrow_cast(bias_temp); + + float lambd_temp; + ORT_ENFORCE(op_kernel_info.GetAttr("lambd", &lambd_temp).IsOK()); + lambd_ = gsl::narrow_cast(lambd_temp); + } + + Status Compute(OpKernelContext* p_op_kernel_context) const override; + + private: + float bias_; + float lambd_; +}; +} // namespace onnxruntime diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 283422ad98ef8..7c80fe48cace5 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -312,9 +312,6 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, - {"shrink", "opset 9 not supported yet"}, - {"shrink_hard", "opset 9 not supported yet"}, - {"shrink_soft", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/math/shrink_test.cc new file mode 100644 index 0000000000000..e84238e31b8ad --- /dev/null +++ b/onnxruntime/test/providers/cpu/math/shrink_test.cc @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "gtest/gtest.h" +#include "test/providers/provider_test_utils.h" +#include "core/util/math.h" + +namespace onnxruntime { +namespace test { + +template +static void RunTest(float bias, + float lambd, + const std::vector& input_vals, + const std::vector& input_dimensions, + const std::vector& expected_vals, + const std::vector& expected_dimensions, + OpTester::ExpectResult expect_result = OpTester::ExpectResult::kExpectSuccess, + const std::string& expected_err_str = "") { + OpTester test("Shrink", 9); + if (bias != 0.0f) { + test.AddAttribute("bias", bias); + } + if (lambd != 0.5f) { + test.AddAttribute("lambd", lambd); + } + + test.AddInput("X", input_dimensions, input_vals); + test.AddOutput("Values", expected_dimensions, expected_vals); + test.Run(expect_result, expected_err_str); +} + +TEST(ShrinkOperator, FloatTypeDefaultBiasDefaultLambd) { + std::vector input_vals = {-1.0f, -0.4f, 0.4f, 1.0f}; + std::vector input_dimensions = {2, 2}; + std::vector expected_vals = {-1.0f, 0.0f, 0.0f, 1.0f}; + std::vector expected_dimensions = {2, 2}; + RunTest(0.0f, 0.5f, input_vals, input_dimensions, expected_vals, expected_dimensions); +} + +TEST(ShrinkOperator, FloatTypeNonDefaultBiasNonDefaultLambd) { + std::vector input_vals = {-1.0f, -0.4f, 0.4f, 1.0f}; + std::vector input_dimensions = {2, 2}; + std::vector expected_vals = {9.0f, 0.0f, 0.0f, -9.0f}; + std::vector expected_dimensions = {2, 2}; + RunTest(10.0f, 0.4f, input_vals, input_dimensions, expected_vals, expected_dimensions); +} + +} // namespace test +} // namespace onnxruntime \ No newline at end of file diff --git a/onnxruntime/test/providers/cpu/math/sing_test.cc b/onnxruntime/test/providers/cpu/math/sign_test.cc similarity index 100% rename from onnxruntime/test/providers/cpu/math/sing_test.cc rename to onnxruntime/test/providers/cpu/math/sign_test.cc diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 4a1ab81dfed8f..4787948b637cc 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -26,8 +26,6 @@ '|^test_convtranspose_3d_cpu.*' '|^test_scatter_with_axis_cpu.*' '|^test_scatter_without_axis_cpu.*' -'|^test_shrink_hard_cpu.*' -'|^test_shrink_soft_cpu.*' '|^test_AvgPool1d_cpu.*' '|^test_AvgPool1d_stride_cpu.*' '|^test_AvgPool2d_cpu.*' @@ -62,7 +60,6 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' -'|^test_shrink_cpu.*' '|^test_sign_model_cpu.*' ')') From 71ceae003b61f1a48ccd251ba2e94278d2d30b5a Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 15 Feb 2019 16:50:00 -0800 Subject: [PATCH 02/20] Adding shrink tests --- onnxruntime/core/providers/cpu/math/shrink.cc | 9 +- .../test/providers/cpu/math/shrink_test.cc | 151 ++++++++++++++---- 2 files changed, 126 insertions(+), 34 deletions(-) diff --git a/onnxruntime/core/providers/cpu/math/shrink.cc b/onnxruntime/core/providers/cpu/math/shrink.cc index 953e4e6466b53..3d3fb7767a89f 100644 --- a/onnxruntime/core/providers/cpu/math/shrink.cc +++ b/onnxruntime/core/providers/cpu/math/shrink.cc @@ -2,10 +2,7 @@ // Licensed under the MIT License. #include "core/providers/cpu/math/shrink.h" -//#include "core/providers/common.h" -//#include "core/common/common.h" -//#include "core/common/exceptions.h" -//#include "core/framework/tensor.h" + #include "core/util/math.h" #include "core/util/math_cpuonly.h" @@ -29,7 +26,9 @@ ONNX_CPU_OPERATOR_KERNEL( namespace shrink_internal { template -inline T ShrinkImpl(T val, float bias, float lambd) { +inline T ShrinkImpl(const T& val, float bias, float lambd) { + // The ONNX spec doesn't take numeric overflow and underflow into account + // Implementing the spec as is for now if (val < -lambd) { return T(val + bias); } else if (val > lambd) { diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/math/shrink_test.cc index e84238e31b8ad..3b78d1a970e3a 100644 --- a/onnxruntime/test/providers/cpu/math/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/math/shrink_test.cc @@ -4,46 +4,139 @@ #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" #include "core/util/math.h" +#include namespace onnxruntime { namespace test { template -static void RunTest(float bias, - float lambd, - const std::vector& input_vals, - const std::vector& input_dimensions, - const std::vector& expected_vals, - const std::vector& expected_dimensions, - OpTester::ExpectResult expect_result = OpTester::ExpectResult::kExpectSuccess, - const std::string& expected_err_str = "") { - OpTester test("Shrink", 9); - if (bias != 0.0f) { - test.AddAttribute("bias", bias); - } - if (lambd != 0.5f) { - test.AddAttribute("lambd", lambd); +struct ShrinkTestData { + std::string name; + float bias; + float lambd; + std::vector input_vals; + std::vector input_dimensions; + std::vector expected_vals; + std::vector expected_dimensions; +}; + +template +std::vector> GenerateSignedTestCases() { + std::vector> test_cases; + test_cases.push_back( + {"default attributes", + 0.0f, + 0.5f, + {-1, 0, 0, 1}, + {2, 2}, + {-1, 0, 0, 1}, + {2, 2}}); + + test_cases.push_back( + {"non-default attributes", + 10.0f, + 2.0f, + {-3, -1, 1, 4}, + {2, 2}, + {7, 0, 0, -6}, + {2, 2}}); + return test_cases; +} + +template +std::vector> GenerateUnsignedTestCases() { + std::cout << "UNSIGNED CASE "; + std::vector> test_cases; + + test_cases.push_back( + {"default attributes", + 0.0f, + 0.5f, + {0, 0, 0, 1}, + {2, 2}, + {0, 0, 0, 1}, + {2, 2}}); + + test_cases.push_back( + {"non-default attributes", + 10.0f, + 2.0f, + {37, 1, 1, 11}, + {2, 2}, + {27, 0, 0, 1}, + {2, 2}}); + + return test_cases; +} + +template +void RunShrinkTest(const std::vector>& test_cases) { + std::cout << "NUMBER OF CASES IS: " << test_cases.size(); + for (const auto& test_data : test_cases) { + OpTester test("Shrink", 9); + + if (test_data.bias != 0.0f) { + test.AddAttribute("bias", test_data.bias); + } + + if (test_data.lambd != 0.5f) { + test.AddAttribute("lambd", test_data.lambd); + } + + test.AddInput("X", test_data.input_dimensions, test_data.input_vals); + test.AddOutput("Y", test_data.expected_dimensions, test_data.expected_vals); + test.Run(); } +} + +TEST(MathOpTest, ShrinkInt8Type) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkUint8Type) { + const auto& test_cases = GenerateUnsignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkInt16Type) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkUint16Type) { + const auto& test_cases = GenerateUnsignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkInt32Type) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkUint32Type) { + const auto& test_cases = GenerateUnsignedTestCases(); + RunShrinkTest(test_cases); +} + +TEST(MathOpTest, ShrinkInt64Type) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); +} - test.AddInput("X", input_dimensions, input_vals); - test.AddOutput("Values", expected_dimensions, expected_vals); - test.Run(expect_result, expected_err_str); +TEST(MathOpTest, ShrinkUint64Type) { + const auto& test_cases = GenerateUnsignedTestCases(); + RunShrinkTest(test_cases); } -TEST(ShrinkOperator, FloatTypeDefaultBiasDefaultLambd) { - std::vector input_vals = {-1.0f, -0.4f, 0.4f, 1.0f}; - std::vector input_dimensions = {2, 2}; - std::vector expected_vals = {-1.0f, 0.0f, 0.0f, 1.0f}; - std::vector expected_dimensions = {2, 2}; - RunTest(0.0f, 0.5f, input_vals, input_dimensions, expected_vals, expected_dimensions); +TEST(MathOpTest, ShrinkFloatType) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); } -TEST(ShrinkOperator, FloatTypeNonDefaultBiasNonDefaultLambd) { - std::vector input_vals = {-1.0f, -0.4f, 0.4f, 1.0f}; - std::vector input_dimensions = {2, 2}; - std::vector expected_vals = {9.0f, 0.0f, 0.0f, -9.0f}; - std::vector expected_dimensions = {2, 2}; - RunTest(10.0f, 0.4f, input_vals, input_dimensions, expected_vals, expected_dimensions); +TEST(MathOpTest, ShrinkDoubleType) { + const auto& test_cases = GenerateSignedTestCases(); + RunShrinkTest(test_cases); } } // namespace test From 2e4996fedf901cd52bd525d0273705631806cd2c Mon Sep 17 00:00:00 2001 From: Hariharan Seshadri Date: Fri, 15 Feb 2019 19:06:15 -0800 Subject: [PATCH 03/20] Fix formatting in shrink_test.cc --- onnxruntime/test/providers/cpu/math/shrink_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/math/shrink_test.cc index 3b78d1a970e3a..352b29ac70748 100644 --- a/onnxruntime/test/providers/cpu/math/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/math/shrink_test.cc @@ -73,13 +73,13 @@ template void RunShrinkTest(const std::vector>& test_cases) { std::cout << "NUMBER OF CASES IS: " << test_cases.size(); for (const auto& test_data : test_cases) { - OpTester test("Shrink", 9); + OpTester test("Shrink", 9); - if (test_data.bias != 0.0f) { + if (test_data.bias != 0.0f) { test.AddAttribute("bias", test_data.bias); } - if (test_data.lambd != 0.5f) { + if (test_data.lambd != 0.5f) { test.AddAttribute("lambd", test_data.lambd); } @@ -140,4 +140,4 @@ TEST(MathOpTest, ShrinkDoubleType) { } } // namespace test -} // namespace onnxruntime \ No newline at end of file +} // namespace onnxruntime From 9b6efdeabd9ae4716c4dc672efdc03e3a743f94a Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 15 Feb 2019 23:06:14 -0800 Subject: [PATCH 04/20] Fix broken build --- onnxruntime/core/providers/cpu/math/shrink.cc | 5 ++++- onnxruntime/test/onnx/main.cc | 1 + onnxruntime/test/providers/cpu/math/shrink_test.cc | 3 --- onnxruntime/test/python/onnx_backend_test_series.py | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/cpu/math/shrink.cc b/onnxruntime/core/providers/cpu/math/shrink.cc index 3d3fb7767a89f..1547a07e5393b 100644 --- a/onnxruntime/core/providers/cpu/math/shrink.cc +++ b/onnxruntime/core/providers/cpu/math/shrink.cc @@ -5,6 +5,7 @@ #include "core/util/math.h" #include "core/util/math_cpuonly.h" +#include namespace onnxruntime { ONNX_CPU_OPERATOR_KERNEL( @@ -62,8 +63,10 @@ Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { using namespace shrink_internal; auto input = p_op_kernel_context->Input(0); + std::cout << "Input Shape: " << (input->Shape()) << "\n"; auto output = p_op_kernel_context->Output(0, input->Shape()); - + std::cout << "Output Shape: " << (output->Shape()) << "\n"; + auto dtype = input->DataType(); if (dtype == DataTypeImpl::GetType()) { diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 7c80fe48cace5..e53bd140de495 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -312,6 +312,7 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, + {"shrink", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/math/shrink_test.cc index 352b29ac70748..5929e4de05eb1 100644 --- a/onnxruntime/test/providers/cpu/math/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/math/shrink_test.cc @@ -4,7 +4,6 @@ #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" #include "core/util/math.h" -#include namespace onnxruntime { namespace test { @@ -45,7 +44,6 @@ std::vector> GenerateSignedTestCases() { template std::vector> GenerateUnsignedTestCases() { - std::cout << "UNSIGNED CASE "; std::vector> test_cases; test_cases.push_back( @@ -71,7 +69,6 @@ std::vector> GenerateUnsignedTestCases() { template void RunShrinkTest(const std::vector>& test_cases) { - std::cout << "NUMBER OF CASES IS: " << test_cases.size(); for (const auto& test_data : test_cases) { OpTester test("Shrink", 9); diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 4787948b637cc..265607b7b56f5 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -60,6 +60,7 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' +'|^test_shrink_cpu.*' '|^test_sign_model_cpu.*' ')') From ee71c12c76ab2b273956b163d2417097af5e04c2 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 15 Feb 2019 23:32:32 -0800 Subject: [PATCH 05/20] More changes --- onnxruntime/test/onnx/main.cc | 1 - onnxruntime/test/python/onnx_backend_test_series.py | 1 - 2 files changed, 2 deletions(-) diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index e53bd140de495..7c80fe48cace5 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -312,7 +312,6 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, - {"shrink", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 265607b7b56f5..4787948b637cc 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -60,7 +60,6 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' -'|^test_shrink_cpu.*' '|^test_sign_model_cpu.*' ')') From 17db480e5ef7f277f405e3c2c0010b19b8d623a5 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Sat, 16 Feb 2019 00:09:18 -0800 Subject: [PATCH 06/20] PR feedback and formatting --- onnxruntime/core/providers/cpu/math/shrink.cc | 47 ++++-------- onnxruntime/test/onnx/main.cc | 1 + .../test/providers/cpu/math/shrink_test.cc | 76 +++++++++---------- .../test/python/onnx_backend_test_series.py | 1 + 4 files changed, 56 insertions(+), 69 deletions(-) diff --git a/onnxruntime/core/providers/cpu/math/shrink.cc b/onnxruntime/core/providers/cpu/math/shrink.cc index 1547a07e5393b..6f6e31e44e452 100644 --- a/onnxruntime/core/providers/cpu/math/shrink.cc +++ b/onnxruntime/core/providers/cpu/math/shrink.cc @@ -5,7 +5,6 @@ #include "core/util/math.h" #include "core/util/math_cpuonly.h" -#include namespace onnxruntime { ONNX_CPU_OPERATOR_KERNEL( @@ -63,52 +62,38 @@ Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { using namespace shrink_internal; auto input = p_op_kernel_context->Input(0); - std::cout << "Input Shape: " << (input->Shape()) << "\n"; auto output = p_op_kernel_context->Output(0, input->Shape()); - std::cout << "Output Shape: " << (output->Shape()) << "\n"; - + auto dtype = input->DataType(); if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const float& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const double& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } - else if (dtype == DataTypeImpl::GetType()) { - ShrinkMLFloat16(input, output, bias_, lambd_); - } - else if (dtype == DataTypeImpl::GetType()) { + } else if (dtype == DataTypeImpl::GetType()) { + ShrinkMLFloat16(input, output, bias_, lambd_); + } else if (dtype == DataTypeImpl::GetType()) { ShrinkBFloat16(input, output, bias_, lambd_); - } - else { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Unsupported input datatype"); + } else { + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only"); } return Status::OK(); -} +} } // namespace onnxruntime diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 7c80fe48cace5..e53bd140de495 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -312,6 +312,7 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, + {"shrink", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/math/shrink_test.cc index 5929e4de05eb1..0bd04d1114ca2 100644 --- a/onnxruntime/test/providers/cpu/math/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/math/shrink_test.cc @@ -23,22 +23,22 @@ template std::vector> GenerateSignedTestCases() { std::vector> test_cases; test_cases.push_back( - {"default attributes", - 0.0f, - 0.5f, - {-1, 0, 0, 1}, - {2, 2}, - {-1, 0, 0, 1}, - {2, 2}}); + {"default attributes", + 0.0f, + 0.5f, + {-1, 0, 0, 1}, + {2, 2}, + {-1, 0, 0, 1}, + {2, 2}}); test_cases.push_back( - {"non-default attributes", - 10.0f, - 2.0f, - {-3, -1, 1, 4}, - {2, 2}, - {7, 0, 0, -6}, - {2, 2}}); + {"non-default attributes", + 10.0f, + 2.0f, + {-3, -1, 1, 4}, + {2, 2}, + {7, 0, 0, -6}, + {2, 2}}); return test_cases; } @@ -47,22 +47,22 @@ std::vector> GenerateUnsignedTestCases() { std::vector> test_cases; test_cases.push_back( - {"default attributes", - 0.0f, - 0.5f, - {0, 0, 0, 1}, - {2, 2}, - {0, 0, 0, 1}, - {2, 2}}); + {"default attributes", + 0.0f, + 0.5f, + {0, 0, 0, 1}, + {2, 2}, + {0, 0, 0, 1}, + {2, 2}}); test_cases.push_back( - {"non-default attributes", - 10.0f, - 2.0f, - {37, 1, 1, 11}, - {2, 2}, - {27, 0, 0, 1}, - {2, 2}}); + {"non-default attributes", + 10.0f, + 2.0f, + {37, 1, 1, 11}, + {2, 2}, + {27, 0, 0, 1}, + {2, 2}}); return test_cases; } @@ -71,33 +71,33 @@ template void RunShrinkTest(const std::vector>& test_cases) { for (const auto& test_data : test_cases) { OpTester test("Shrink", 9); - + if (test_data.bias != 0.0f) { test.AddAttribute("bias", test_data.bias); } - + if (test_data.lambd != 0.5f) { test.AddAttribute("lambd", test_data.lambd); } test.AddInput("X", test_data.input_dimensions, test_data.input_vals); test.AddOutput("Y", test_data.expected_dimensions, test_data.expected_vals); - test.Run(); + test.Run(); } } TEST(MathOpTest, ShrinkInt8Type) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } TEST(MathOpTest, ShrinkUint8Type) { - const auto& test_cases = GenerateUnsignedTestCases(); + const auto& test_cases = GenerateUnsignedTestCases(); RunShrinkTest(test_cases); } TEST(MathOpTest, ShrinkInt16Type) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } @@ -107,7 +107,7 @@ TEST(MathOpTest, ShrinkUint16Type) { } TEST(MathOpTest, ShrinkInt32Type) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } @@ -117,7 +117,7 @@ TEST(MathOpTest, ShrinkUint32Type) { } TEST(MathOpTest, ShrinkInt64Type) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } @@ -127,12 +127,12 @@ TEST(MathOpTest, ShrinkUint64Type) { } TEST(MathOpTest, ShrinkFloatType) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } TEST(MathOpTest, ShrinkDoubleType) { - const auto& test_cases = GenerateSignedTestCases(); + const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); } diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 4787948b637cc..265607b7b56f5 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -60,6 +60,7 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' +'|^test_shrink_cpu.*' '|^test_sign_model_cpu.*' ')') From 9519a96f60cef9d886b2099bf3bccb6d4889b957 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 11:58:15 -0800 Subject: [PATCH 07/20] Place files in the right location corresponding to def file location in onnx --- onnxruntime/core/providers/cpu/{math => nn}/shrink.cc | 2 +- onnxruntime/core/providers/cpu/{math => nn}/shrink.h | 0 onnxruntime/test/providers/cpu/{math => nn}/shrink_test.cc | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename onnxruntime/core/providers/cpu/{math => nn}/shrink.cc (99%) rename onnxruntime/core/providers/cpu/{math => nn}/shrink.h (100%) rename onnxruntime/test/providers/cpu/{math => nn}/shrink_test.cc (100%) diff --git a/onnxruntime/core/providers/cpu/math/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc similarity index 99% rename from onnxruntime/core/providers/cpu/math/shrink.cc rename to onnxruntime/core/providers/cpu/nn/shrink.cc index 6f6e31e44e452..247bc613def1b 100644 --- a/onnxruntime/core/providers/cpu/math/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "core/providers/cpu/math/shrink.h" +#include "core/providers/cpu/nn/shrink.h" #include "core/util/math.h" #include "core/util/math_cpuonly.h" diff --git a/onnxruntime/core/providers/cpu/math/shrink.h b/onnxruntime/core/providers/cpu/nn/shrink.h similarity index 100% rename from onnxruntime/core/providers/cpu/math/shrink.h rename to onnxruntime/core/providers/cpu/nn/shrink.h diff --git a/onnxruntime/test/providers/cpu/math/shrink_test.cc b/onnxruntime/test/providers/cpu/nn/shrink_test.cc similarity index 100% rename from onnxruntime/test/providers/cpu/math/shrink_test.cc rename to onnxruntime/test/providers/cpu/nn/shrink_test.cc From e31c9fc263315afdc97ffddfa35d3487f2f1ae93 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 11:59:17 -0800 Subject: [PATCH 08/20] Exclude shrink model test in test_series.py --- onnxruntime/test/python/onnx_backend_test_series.py | 1 - 1 file changed, 1 deletion(-) diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 265607b7b56f5..4787948b637cc 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -60,7 +60,6 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' -'|^test_shrink_cpu.*' '|^test_sign_model_cpu.*' ')') From f55cd8b5560b5bf98775341253edaa1d48ca2ebe Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 13:12:09 -0800 Subject: [PATCH 09/20] Remove shrink from exclusion list in main.cc --- onnxruntime/test/onnx/main.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index e18205c3eae77..2ba07f288ec46 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -311,7 +311,6 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, - {"shrink", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, From 398c06385493c1dc57fce4b7281818264d4364c6 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 14:40:24 -0800 Subject: [PATCH 10/20] Adding test to exclusion list --- onnxruntime/test/onnx/main.cc | 1 + onnxruntime/test/python/onnx_backend_test_series.py | 1 + 2 files changed, 2 insertions(+) diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 2ba07f288ec46..e18205c3eae77 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -311,6 +311,7 @@ int real_main(int argc, char* argv[]) { {"scatter_with_axis", "opset 9 not supported yet"}, {"scatter_without_axis", "opset 9 not supported yet"}, {"scan_sum", "opset 9 not supported yet"}, + {"shrink", "opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT16", "Cast opset 9 not supported yet"}, {"cast_DOUBLE_to_FLOAT", "Cast opset 9 not supported yet"}, {"cast_FLOAT_to_DOUBLE", "Cast opset 9 not supported yet"}, diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 3acd40a124559..e57873e43f1da 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -60,6 +60,7 @@ '|^test_operator_non_float_params_cpu.*' '|^test_operator_params_cpu.*' '|^test_operator_pow_cpu.*' +'|^test_shrink_cpu.*' ')') # import all test cases at global scope to make From 98ccd3f055576af6c397c606bf3eaa152021043a Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 15:52:37 -0800 Subject: [PATCH 11/20] More tests --- .../test/providers/cpu/nn/shrink_test.cc | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/onnxruntime/test/providers/cpu/nn/shrink_test.cc b/onnxruntime/test/providers/cpu/nn/shrink_test.cc index 0bd04d1114ca2..b216453f50254 100644 --- a/onnxruntime/test/providers/cpu/nn/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/nn/shrink_test.cc @@ -86,6 +86,14 @@ void RunShrinkTest(const std::vector>& test_cases) { } } +const std::vector ConvertFloatToMLFloat16(const std::vector& float_data) { + std::vector new_data; + for (const auto& f : float_data) { + new_data.push_back(MLFloat16(math::floatToHalf(f))); + } + return new_data; +} + TEST(MathOpTest, ShrinkInt8Type) { const auto& test_cases = GenerateSignedTestCases(); RunShrinkTest(test_cases); @@ -136,5 +144,33 @@ TEST(MathOpTest, ShrinkDoubleType) { RunShrinkTest(test_cases); } +TEST(MathOpTest, ShrinkMLFloat16Type) { + const std::vector input_test_data_default = ConvertFloatToMLFloat16({-1, 0, 0, 1}); + const std::vector output_test_data_default = ConvertFloatToMLFloat16({-1, 0, 0, 1}); + + const std::vector input_test_data_nondefault = ConvertFloatToMLFloat16({-3, -1, 1, 4}); + const std::vector output_test_data_nondefault = ConvertFloatToMLFloat16({7, 0, 0, -6}); + std::vector> test_cases; + test_cases.push_back( + { + "default attributes", + 0.0f, + 0.5f, + input_test_data_default, + {2, 2}, + output_test_data_default, + {2, 2} + }); + test_cases.push_back( + {"non-default attributes", + 10.0f, + 2.0f, + input_test_data_nondefault, + {2, 2}, + output_test_data_nondefault, + {2, 2}}); + RunShrinkTest(test_cases); +} + } // namespace test } // namespace onnxruntime From 6edf4742844decd24d1eac00c700ba84ed9985a4 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Tue, 19 Feb 2019 16:47:55 -0800 Subject: [PATCH 12/20] Formatting --- onnxruntime/test/providers/cpu/nn/shrink_test.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/onnxruntime/test/providers/cpu/nn/shrink_test.cc b/onnxruntime/test/providers/cpu/nn/shrink_test.cc index b216453f50254..03bf0eeb159b1 100644 --- a/onnxruntime/test/providers/cpu/nn/shrink_test.cc +++ b/onnxruntime/test/providers/cpu/nn/shrink_test.cc @@ -152,15 +152,13 @@ TEST(MathOpTest, ShrinkMLFloat16Type) { const std::vector output_test_data_nondefault = ConvertFloatToMLFloat16({7, 0, 0, -6}); std::vector> test_cases; test_cases.push_back( - { - "default attributes", - 0.0f, - 0.5f, - input_test_data_default, - {2, 2}, - output_test_data_default, - {2, 2} - }); + {"default attributes", + 0.0f, + 0.5f, + input_test_data_default, + {2, 2}, + output_test_data_default, + {2, 2}}); test_cases.push_back( {"non-default attributes", 10.0f, From 9195528a4897b3f04e8bda964c6761d84c316bf3 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 22 Feb 2019 17:25:35 -0800 Subject: [PATCH 13/20] PR feedback --- .../onnxruntime/core/framework/data_types.h | 1 + onnxruntime/core/framework/data_types.cc | 18 +++++++++++ onnxruntime/core/providers/cpu/nn/shrink.cc | 30 ++++++------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/include/onnxruntime/core/framework/data_types.h b/include/onnxruntime/core/framework/data_types.h index 69c44a63edacb..3f191a82b6ac2 100644 --- a/include/onnxruntime/core/framework/data_types.h +++ b/include/onnxruntime/core/framework/data_types.h @@ -186,6 +186,7 @@ class DataTypeImpl { static const std::vector& AllTensorTypes(); static const std::vector& AllFixedSizeTensorTypes(); + static const std::vector& AllNumericTensorTypes(); }; std::ostream& operator<<(std::ostream& out, MLDataType data_type); diff --git a/onnxruntime/core/framework/data_types.cc b/onnxruntime/core/framework/data_types.cc index 73d1db82d6937..ad8dbe8154605 100644 --- a/onnxruntime/core/framework/data_types.cc +++ b/onnxruntime/core/framework/data_types.cc @@ -736,6 +736,24 @@ const std::vector& DataTypeImpl::AllTensorTypes() { return all_tensor_types; } +const std::vector& DataTypeImpl::AllNumericTensorTypes() { + static std::vector all_numeric_size_tensor_types = + {DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType()}; + + return all_numeric_size_tensor_types; +} + // helper to stream. expected to only be used for error output, so any typeid lookup // cost should be fine. alternative would be to add a static string field to DataTypeImpl // that we set in the register macro to the type name, and output that instead. diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index 247bc613def1b..5ff76124cca48 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -10,18 +10,7 @@ namespace onnxruntime { ONNX_CPU_OPERATOR_KERNEL( Shrink, 9, - KernelDefBuilder().TypeConstraint("T", {DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType(), - DataTypeImpl::GetTensorType()}), + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllNumericTensorTypes()), Shrink); namespace shrink_internal { @@ -39,8 +28,8 @@ inline T ShrinkImpl(const T& val, float bias, float lambd) { } void ShrinkMLFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { - auto span = gsl::make_span(input->Data(), input->Shape().Size()); - auto output_data = output->template MutableData(); + const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); + auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const MLFloat16& val) { float fl = math::halfToFloat(val.val); return MLFloat16(math::floatToHalf(ShrinkImpl(fl, bias, lambd))); @@ -48,8 +37,8 @@ void ShrinkMLFloat16(const Tensor* input, Tensor* output, float bias, float lamb } void ShrinkBFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { - auto span = gsl::make_span(input->Data(), input->Shape().Size()); - auto output_data = output->template MutableData(); + const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); + auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const BFloat16& val) { float fl = val.ToFloat(); return BFloat16(ShrinkImpl(fl, bias, lambd)); @@ -61,11 +50,10 @@ void ShrinkBFloat16(const Tensor* input, Tensor* output, float bias, float lambd Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { using namespace shrink_internal; - auto input = p_op_kernel_context->Input(0); - auto output = p_op_kernel_context->Output(0, input->Shape()); - - auto dtype = input->DataType(); + const auto* input = p_op_kernel_context->Input(0); + auto* output = p_op_kernel_context->Output(0, input->Shape()); + const auto& dtype = input->DataType(); if (dtype == DataTypeImpl::GetType()) { EigenMap(*output) = EigenMap(*input).unaryExpr([this](const float& val) { return ShrinkImpl(val, bias_, lambd_); }); } else if (dtype == DataTypeImpl::GetType()) { @@ -91,7 +79,7 @@ Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { } else if (dtype == DataTypeImpl::GetType()) { ShrinkBFloat16(input, output, bias_, lambd_); } else { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only"); + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only, but got : ", dtype); } return Status::OK(); From f0fdddfe04a8dbc2643fceddc086a11ffc9d8cde Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Thu, 28 Feb 2019 14:13:50 -0800 Subject: [PATCH 14/20] PR feedback --- onnxruntime/core/framework/utils.h | 51 +++++++++++++++++++ onnxruntime/core/providers/cpu/nn/shrink.cc | 54 ++++++++------------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/onnxruntime/core/framework/utils.h b/onnxruntime/core/framework/utils.h index d5a01782081af..692983470e83c 100644 --- a/onnxruntime/core/framework/utils.h +++ b/onnxruntime/core/framework/utils.h @@ -122,5 +122,56 @@ common::Status ExecuteGraph(const SessionState& session_state, else if (tensor_type == DataTypeImpl::GetType()) \ retval = function(__VA_ARGS__) +#define DispatchOnNumericTensorType(tensor_type, function, ...) \ + if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + function(__VA_ARGS__) + +#define DispatchOnNumericTensorTypeWithReturn(tensor_type, retval, function, ...) \ + if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__); \ + else if (tensor_type == DataTypeImpl::GetType()) \ + retval = function(__VA_ARGS__) } // namespace utils } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index 5ff76124cca48..794f24ff035cc 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -5,6 +5,7 @@ #include "core/util/math.h" #include "core/util/math_cpuonly.h" +#include "core/framework/utils.h" namespace onnxruntime { ONNX_CPU_OPERATOR_KERNEL( @@ -15,7 +16,7 @@ ONNX_CPU_OPERATOR_KERNEL( namespace shrink_internal { template -inline T ShrinkImpl(const T& val, float bias, float lambd) { +inline T ShrinkCore(const T& val, float bias, float lambd) { // The ONNX spec doesn't take numeric overflow and underflow into account // Implementing the spec as is for now if (val < -lambd) { @@ -27,21 +28,28 @@ inline T ShrinkImpl(const T& val, float bias, float lambd) { } } -void ShrinkMLFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { +template +void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { + EigenMap(*output) = EigenMap(*input).unaryExpr([bias, lambd](const T& val) { return ShrinkCore(val, bias, lambd); }); +} + +template <> +void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const MLFloat16& val) { float fl = math::halfToFloat(val.val); - return MLFloat16(math::floatToHalf(ShrinkImpl(fl, bias, lambd))); + return MLFloat16(math::floatToHalf(ShrinkCore(fl, bias, lambd))); }); } -void ShrinkBFloat16(const Tensor* input, Tensor* output, float bias, float lambd) { +template <> +void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const BFloat16& val) { float fl = val.ToFloat(); - return BFloat16(ShrinkImpl(fl, bias, lambd)); + return BFloat16(ShrinkCore(fl, bias, lambd)); }); } @@ -49,39 +57,15 @@ void ShrinkBFloat16(const Tensor* input, Tensor* output, float bias, float lambd Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { using namespace shrink_internal; - const auto* input = p_op_kernel_context->Input(0); auto* output = p_op_kernel_context->Output(0, input->Shape()); - const auto& dtype = input->DataType(); - if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const float& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const double& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint64_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint32_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint16_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const int8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - EigenMap(*output) = EigenMap(*input).unaryExpr([this](const uint8_t& val) { return ShrinkImpl(val, bias_, lambd_); }); - } else if (dtype == DataTypeImpl::GetType()) { - ShrinkMLFloat16(input, output, bias_, lambd_); - } else if (dtype == DataTypeImpl::GetType()) { - ShrinkBFloat16(input, output, bias_, lambd_); - } else { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only, but got : ", dtype); - } + DispatchOnNumericTensorType(dtype, ShrinkImpl, input, output, bias_, lambd_); + + /* + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only, but got : ", dtype); + */ return Status::OK(); } -} // namespace onnxruntime +} // namespace onnxruntime \ No newline at end of file From bdbe1d4ae4bb3c498eb5bf4668eb67c8528629f5 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Thu, 28 Feb 2019 14:15:31 -0800 Subject: [PATCH 15/20] More changes --- onnxruntime/core/providers/cpu/nn/shrink.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index 794f24ff035cc..4e7a0fb196193 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -57,15 +57,12 @@ void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { using namespace shrink_internal; + const auto* input = p_op_kernel_context->Input(0); auto* output = p_op_kernel_context->Output(0, input->Shape()); const auto& dtype = input->DataType(); DispatchOnNumericTensorType(dtype, ShrinkImpl, input, output, bias_, lambd_); - /* - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only, but got : ", dtype); - */ - return Status::OK(); } } // namespace onnxruntime \ No newline at end of file From 626a8c3f0da398956b0b6f4b313cd3841b2c580f Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Thu, 28 Feb 2019 19:13:59 -0800 Subject: [PATCH 16/20] PR feedback --- onnxruntime/core/framework/utils.h | 50 --------------------- onnxruntime/core/providers/cpu/nn/shrink.cc | 20 ++++++--- 2 files changed, 14 insertions(+), 56 deletions(-) diff --git a/onnxruntime/core/framework/utils.h b/onnxruntime/core/framework/utils.h index 692983470e83c..8aae8eb91d9f6 100644 --- a/onnxruntime/core/framework/utils.h +++ b/onnxruntime/core/framework/utils.h @@ -122,56 +122,6 @@ common::Status ExecuteGraph(const SessionState& session_state, else if (tensor_type == DataTypeImpl::GetType()) \ retval = function(__VA_ARGS__) -#define DispatchOnNumericTensorType(tensor_type, function, ...) \ - if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - function(__VA_ARGS__) -#define DispatchOnNumericTensorTypeWithReturn(tensor_type, retval, function, ...) \ - if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__); \ - else if (tensor_type == DataTypeImpl::GetType()) \ - retval = function(__VA_ARGS__) } // namespace utils } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index 4e7a0fb196193..1a4eaac640ab2 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -29,28 +29,36 @@ inline T ShrinkCore(const T& val, float bias, float lambd) { } template -void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { +Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { EigenMap(*output) = EigenMap(*input).unaryExpr([bias, lambd](const T& val) { return ShrinkCore(val, bias, lambd); }); + return Status::OK(); } template <> -void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { +Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const MLFloat16& val) { float fl = math::halfToFloat(val.val); return MLFloat16(math::floatToHalf(ShrinkCore(fl, bias, lambd))); }); + return Status::OK(); } template <> -void ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { +Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { const auto& span = gsl::make_span(input->Data(), input->Shape().Size()); auto* output_data = output->template MutableData(); std::transform(span.cbegin(), span.cend(), output_data, [bias, lambd](const BFloat16& val) { float fl = val.ToFloat(); return BFloat16(ShrinkCore(fl, bias, lambd)); }); + return Status::OK(); +} + +template <> +Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only. Got bool type here."); } } // namespace shrink_internal @@ -61,8 +69,8 @@ Status Shrink::Compute(OpKernelContext* p_op_kernel_context) const { const auto* input = p_op_kernel_context->Input(0); auto* output = p_op_kernel_context->Output(0, input->Shape()); const auto& dtype = input->DataType(); - DispatchOnNumericTensorType(dtype, ShrinkImpl, input, output, bias_, lambd_); - - return Status::OK(); + Status status; + DispatchOnTensorTypeWithReturn(dtype, status, ShrinkImpl, input, output, bias_, lambd_); + return status; } } // namespace onnxruntime \ No newline at end of file From c346014fedcdccf9a8ff85ced4b8cb83e15df1d4 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Thu, 28 Feb 2019 19:16:20 -0800 Subject: [PATCH 17/20] More changes --- onnxruntime/core/framework/utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/onnxruntime/core/framework/utils.h b/onnxruntime/core/framework/utils.h index 8aae8eb91d9f6..d5a01782081af 100644 --- a/onnxruntime/core/framework/utils.h +++ b/onnxruntime/core/framework/utils.h @@ -122,6 +122,5 @@ common::Status ExecuteGraph(const SessionState& session_state, else if (tensor_type == DataTypeImpl::GetType()) \ retval = function(__VA_ARGS__) - } // namespace utils } // namespace onnxruntime From a83a75e8ef530a0f4e6328c818659e5059cd21b6 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Thu, 28 Feb 2019 22:49:43 -0800 Subject: [PATCH 18/20] Fix broken build --- onnxruntime/core/providers/cpu/nn/shrink.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index 1a4eaac640ab2..a26be14fb8f30 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -57,7 +57,7 @@ Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, flo } template <> -Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, float lambd) { +Status ShrinkImpl(const Tensor* /*input*/, Tensor* /*output*/, float /*bias*/, float /*lambd*/) { return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only. Got bool type here."); } From dfe07b17ba8bac2dbebf5d9e0d650fe23109d6b9 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 1 Mar 2019 11:23:27 -0800 Subject: [PATCH 19/20] Fix nit --- onnxruntime/core/providers/cpu/nn/shrink.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index a26be14fb8f30..b9159c219f39c 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -58,7 +58,8 @@ Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, flo template <> Status ShrinkImpl(const Tensor* /*input*/, Tensor* /*output*/, float /*bias*/, float /*lambd*/) { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained to all numeric types only. Got bool type here."); + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained \ + to all numeric types only. Got bool type here."); } } // namespace shrink_internal From 25b413b7cc9401a2ca9b35de05240a2c33e57320 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Fri, 1 Mar 2019 11:41:53 -0800 Subject: [PATCH 20/20] Fix nit --- onnxruntime/core/providers/cpu/nn/shrink.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/cpu/nn/shrink.cc b/onnxruntime/core/providers/cpu/nn/shrink.cc index b9159c219f39c..e893f126475e4 100644 --- a/onnxruntime/core/providers/cpu/nn/shrink.cc +++ b/onnxruntime/core/providers/cpu/nn/shrink.cc @@ -58,8 +58,11 @@ Status ShrinkImpl(const Tensor* input, Tensor* output, float bias, flo template <> Status ShrinkImpl(const Tensor* /*input*/, Tensor* /*output*/, float /*bias*/, float /*lambd*/) { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input types for the Shrink operator are constrained \ - to all numeric types only. Got bool type here."); + return ORT_MAKE_STATUS( + ONNXRUNTIME, INVALID_ARGUMENT, + "Input types for the Shrink operator are constrained " + "to all numeric types only. Got bool type here." + ); } } // namespace shrink_internal