Skip to content

Commit

Permalink
Fix ReadValueMatrix ReadBytes issue in .NET 6.0. #880
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceania2018 committed Nov 10, 2022
1 parent a7b0a7e commit 19363cd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/TensorFlowNET.Console/Tensorflow.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Tensorflow</RootNamespace>
<AssemblyName>Tensorflow</AssemblyName>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ Array ReadValueMatrix(BinaryReader reader, Array matrix, int bytes, Type type, i
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;
Expand Down
2 changes: 1 addition & 1 deletion src/TensorFlowNET.Core/Tensorflow.Binding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Tensorflow.Binding</AssemblyName>
<RootNamespace>Tensorflow</RootNamespace>
<TargetTensorFlow>2.2.0</TargetTensorFlow>
<Version>0.70.1</Version>
<Version>0.70.2</Version>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Authors>Haiping Chen, Meinrad Recheis, Eli Belash</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
<AssemblyName>TensorFlowNET.UnitTest</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down
11 changes: 11 additions & 0 deletions test/TensorFlowNET.UnitTest/ManagedAPI/LinalgTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,16 @@ public void Tensordot()
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<int>(), new[] { 58, 64, 139, 154 });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down

0 comments on commit 19363cd

Please sign in to comment.