-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1207 from Wanglongzhi2001/concat_v2_test
test: add the concat_v2 test
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
TensorFlow.Kernel.UnitTest/TensorFlow.Kernel.UnitTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\TensorFlowNET.Keras\Tensorflow.Keras.csproj" /> | ||
<ProjectReference Include="..\tools\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Tensorflow; | ||
using Tensorflow.NumPy; | ||
using TensorFlow; | ||
using static Tensorflow.Binding; | ||
using static Tensorflow.KerasApi; | ||
|
||
namespace TensorFlow.Kernel.UnitTest | ||
{ | ||
[TestClass] | ||
public class concat_op_test | ||
{ | ||
[TestMethod] | ||
public void testConcatEmpty() | ||
{ | ||
var t1 = tf.constant(new int[] { }); | ||
var t2 = tf.constant(new int[] { }); | ||
var c = array_ops.concat(new[] { t1, t2 }, 0); | ||
var expected = np.array(new int[] { }); | ||
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); | ||
} | ||
|
||
[TestMethod] | ||
public void testConcatNegativeAxis() | ||
{ | ||
var t1 = tf.constant(new int[,] {{ 1, 2, 3 }, { 4, 5, 6 } }); | ||
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }); | ||
var c = array_ops.concat(new[] { t1, t2 }, -2); | ||
var expected = np.array(new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }); | ||
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); | ||
|
||
c = array_ops.concat(new[] { t1, t2 }, -1); | ||
expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); | ||
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(TF_DataType.TF_INT32)] | ||
[DataRow(TF_DataType.TF_INT64)] | ||
[DataRow(TF_DataType.TF_UINT32)] | ||
[DataRow(TF_DataType.TF_UINT64)] | ||
public void testConcatDtype(TF_DataType dtype) | ||
{ | ||
var t1 = tf.constant(new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }, dtype: dtype); | ||
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }, dtype: dtype); | ||
var c = array_ops.concat(new[] { t1, t2 }, 1); | ||
var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); | ||
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>())); | ||
|
||
} | ||
|
||
[TestMethod] | ||
[DataRow(TF_DataType.TF_INT32)] | ||
[DataRow(TF_DataType.TF_INT64)] | ||
public void testConcatAxisType(TF_DataType dtype) | ||
{ | ||
var t1 = tf.constant(new int[,] { { 1, 2, 3 }, {4, 5, 6 } }); | ||
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }); | ||
var c = array_ops.concat(new[] { t1, t2 }, tf.constant(1, dtype: dtype)); | ||
var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); | ||
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>())); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters