From 19363cdf1133e2c4478f6c7b273728e0c9dd6b2b Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Wed, 9 Nov 2022 18:41:08 -0600 Subject: [PATCH] Fix ReadValueMatrix ReadBytes issue in .NET 6.0. #880 --- src/TensorFlowNET.Console/Tensorflow.Console.csproj | 2 +- .../NumPy/Implementation/NumPyImpl.Creation.cs | 5 ++--- src/TensorFlowNET.Core/Tensorflow.Binding.csproj | 2 +- .../Tensorflow.Benchmark.csproj | 2 +- .../TensorFlowNET.Graph.UnitTest.csproj | 2 +- .../Tensorflow.Keras.UnitTest.csproj | 2 +- .../Tensorflow.Native.UnitTest.csproj | 2 +- test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs | 11 +++++++++++ .../Tensorflow.Binding.UnitTest.csproj | 2 +- 9 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/TensorFlowNET.Console/Tensorflow.Console.csproj b/src/TensorFlowNET.Console/Tensorflow.Console.csproj index e352cde5..058722eb 100644 --- a/src/TensorFlowNET.Console/Tensorflow.Console.csproj +++ b/src/TensorFlowNET.Console/Tensorflow.Console.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 Tensorflow Tensorflow AnyCPU;x64 diff --git a/src/TensorFlowNET.Core/NumPy/Implementation/NumPyImpl.Creation.cs b/src/TensorFlowNET.Core/NumPy/Implementation/NumPyImpl.Creation.cs index 84ffe75e..f29879b0 100644 --- a/src/TensorFlowNET.Core/NumPy/Implementation/NumPyImpl.Creation.cs +++ b/src/TensorFlowNET.Core/NumPy/Implementation/NumPyImpl.Creation.cs @@ -90,9 +90,8 @@ namespace Tensorflow.NumPy int total = 1; for (int i = 0; i < shape.Length; i++) total *= shape[i]; - var buffer = new byte[bytes * total]; - - reader.Read(buffer, 0, buffer.Length); + + var buffer = reader.ReadBytes(bytes * total); System.Buffer.BlockCopy(buffer, 0, matrix, 0, buffer.Length); return matrix; diff --git a/src/TensorFlowNET.Core/Tensorflow.Binding.csproj b/src/TensorFlowNET.Core/Tensorflow.Binding.csproj index bc0ee964..4bd0a490 100644 --- a/src/TensorFlowNET.Core/Tensorflow.Binding.csproj +++ b/src/TensorFlowNET.Core/Tensorflow.Binding.csproj @@ -5,7 +5,7 @@ Tensorflow.Binding Tensorflow 2.2.0 - 0.70.1 + 0.70.2 9.0 enable Haiping Chen, Meinrad Recheis, Eli Belash diff --git a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj index 6fc8c5f4..ee0c113f 100644 --- a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj +++ b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 AnyCPU;x64 diff --git a/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj b/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj index 2b1825cc..e05d48bb 100644 --- a/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj +++ b/test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 9.0 false TensorFlowNET.UnitTest diff --git a/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj b/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj index 3186bbaf..6d0b1ca3 100644 --- a/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj +++ b/test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj b/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj index 926012c7..d7af0376 100644 --- a/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj +++ b/test/TensorFlowNET.Native.UnitTest/Tensorflow.Native.UnitTest.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs b/test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs index 45448cbb..fb515af1 100644 --- a/test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs +++ b/test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs @@ -77,5 +77,16 @@ namespace TensorFlowNET.UnitTest.ManagedAPI Assert.AreEqual(c.shape.ndim, 0); Assert.AreEqual(c.numpy(), 8); } + + [TestMethod] + public void Matmul() + { + var a = tf.constant(new[] { 1, 2, 3, 4, 5, 6 }, shape: (2, 3)); + var b = tf.constant(new[] { 7, 8, 9, 10, 11, 12 }, shape: (3, 2)); + var c = tf.linalg.matmul(a, b); + + Assert.AreEqual(c.shape, (2, 2)); + AssetSequenceEqual(c.ToArray(), new[] { 58, 64, 139, 154 }); + } } } diff --git a/test/TensorFlowNET.UnitTest/Tensorflow.Binding.UnitTest.csproj b/test/TensorFlowNET.UnitTest/Tensorflow.Binding.UnitTest.csproj index 05a0df74..ffb583c9 100644 --- a/test/TensorFlowNET.UnitTest/Tensorflow.Binding.UnitTest.csproj +++ b/test/TensorFlowNET.UnitTest/Tensorflow.Binding.UnitTest.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 false