From d034b432ece3233b53798c8d34e654c610a3d3a3 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 23 Feb 2023 17:05:28 -0800 Subject: [PATCH] Add support for handling sbyte (Int8) data in C# inference tests (#14807) ### Description Add sbyte specific test case support. ### Motivation and Context C# Test Data loading code and comparators are missing sbyte (Int8) specializations. This fails a test --- .../Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs | 6 +++++- .../InferenceTest.netcore.cs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs index 1e44cfdf36..2086fa0ec3 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs @@ -177,6 +177,10 @@ namespace Microsoft.ML.OnnxRuntime.Tests { return CreateNamedOnnxValueFromRawData(nodeName, tensor.RawData.ToArray(), sizeof(byte), intDims); } + else if (nodeMeta.ElementType == typeof(sbyte)) + { + return CreateNamedOnnxValueFromRawData(nodeName, tensor.RawData.ToArray(), sizeof(sbyte), intDims); + } else if (nodeMeta.ElementType == typeof(bool)) { return CreateNamedOnnxValueFromRawData(nodeName, tensor.RawData.ToArray(), sizeof(bool), intDims); @@ -192,7 +196,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests else { //TODO: Add support for remaining types - throw new Exception($"Tensors of type {nameof(nodeMeta.ElementType)} not currently supporte in the LoadTensorFromEmbeddedResource"); + throw new Exception($"Tensors of type {nameof(nodeMeta.ElementType)} not currently supported in the LoadTensorFromEmbeddedResource"); } } diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/InferenceTest.netcore.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/InferenceTest.netcore.cs index 8599db8492..61ff2a43ff 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/InferenceTest.netcore.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/InferenceTest.netcore.cs @@ -352,7 +352,6 @@ namespace Microsoft.ML.OnnxRuntime.Tests // unnecessary and fails as ORT support for Exp started at opset 6 (as ORT didn't exist until opset 7). { "test_softplus_example_expanded", "Not applicable"}, { "test_softplus_expanded", "Not applicable"}, - { "test_bitwise_or_i16_4d", "8bit test data is not support by C#"}, { "test_col2im_pads", "due to a typo in test data"}, { "test_optional_has_element_empty_optional_input", "C# API doesn't support optional input"}, { "test_optional_get_element_optional_tensor", "C# API doesn't support optional input"}, @@ -577,6 +576,10 @@ namespace Microsoft.ML.OnnxRuntime.Tests { Assert.Equal(result.AsTensor(), outputValue.AsTensor(), new ExactComparer()); } + else if (outputMeta.ElementType == typeof(sbyte)) + { + Assert.Equal(result.AsTensor(), outputValue.AsTensor(), new ExactComparer()); + } else if (outputMeta.ElementType == typeof(bool)) { Assert.Equal(result.AsTensor(), outputValue.AsTensor(), new ExactComparer());