Skip to content

Commit 7f0bde3

Browse files
authored
Merge pull request #1207 from Wanglongzhi2001/concat_v2_test
test: add the concat_v2 test
2 parents 44bdddc + f721bae commit 7f0bde3

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
15+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
16+
<PackageReference Include="coverlet.collector" Version="3.2.0" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\src\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
21+
<ProjectReference Include="..\tools\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Tensorflow;
3+
using Tensorflow.NumPy;
4+
using TensorFlow;
5+
using static Tensorflow.Binding;
6+
using static Tensorflow.KerasApi;
7+
8+
namespace TensorFlow.Kernel.UnitTest
9+
{
10+
[TestClass]
11+
public class concat_op_test
12+
{
13+
[TestMethod]
14+
public void testConcatEmpty()
15+
{
16+
var t1 = tf.constant(new int[] { });
17+
var t2 = tf.constant(new int[] { });
18+
var c = array_ops.concat(new[] { t1, t2 }, 0);
19+
var expected = np.array(new int[] { });
20+
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>()));
21+
}
22+
23+
[TestMethod]
24+
public void testConcatNegativeAxis()
25+
{
26+
var t1 = tf.constant(new int[,] {{ 1, 2, 3 }, { 4, 5, 6 } });
27+
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } });
28+
var c = array_ops.concat(new[] { t1, t2 }, -2);
29+
var expected = np.array(new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } });
30+
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>()));
31+
32+
c = array_ops.concat(new[] { t1, t2 }, -1);
33+
expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } });
34+
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>()));
35+
}
36+
37+
[TestMethod]
38+
[DataRow(TF_DataType.TF_INT32)]
39+
[DataRow(TF_DataType.TF_INT64)]
40+
[DataRow(TF_DataType.TF_UINT32)]
41+
[DataRow(TF_DataType.TF_UINT64)]
42+
public void testConcatDtype(TF_DataType dtype)
43+
{
44+
var t1 = tf.constant(new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }, dtype: dtype);
45+
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }, dtype: dtype);
46+
var c = array_ops.concat(new[] { t1, t2 }, 1);
47+
var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } });
48+
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>()));
49+
50+
}
51+
52+
[TestMethod]
53+
[DataRow(TF_DataType.TF_INT32)]
54+
[DataRow(TF_DataType.TF_INT64)]
55+
public void testConcatAxisType(TF_DataType dtype)
56+
{
57+
var t1 = tf.constant(new int[,] { { 1, 2, 3 }, {4, 5, 6 } });
58+
var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } });
59+
var c = array_ops.concat(new[] { t1, t2 }, tf.constant(1, dtype: dtype));
60+
var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } });
61+
Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>()));
62+
}
63+
64+
}
65+
}

TensorFlow.NET.sln

+21
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Benchmark", "too
3939
EndProject
4040
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Console", "tools\TensorFlowNET.Console\Tensorflow.Console.csproj", "{1DC32255-BA1F-4D6D-A9C9-5BD5ED71CAA0}"
4141
EndProject
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlow.Kernel.UnitTest", "TensorFlow.Kernel.UnitTest\TensorFlow.Kernel.UnitTest.csproj", "{C08C6692-4818-46C1-8462-2F0CC40C9152}"
43+
EndProject
4244
Global
4345
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4446
Debug|Any CPU = Debug|Any CPU
@@ -322,6 +324,24 @@ Global
322324
{1DC32255-BA1F-4D6D-A9C9-5BD5ED71CAA0}.Release|x64.Build.0 = Release|x64
323325
{1DC32255-BA1F-4D6D-A9C9-5BD5ED71CAA0}.Release|x86.ActiveCfg = Release|Any CPU
324326
{1DC32255-BA1F-4D6D-A9C9-5BD5ED71CAA0}.Release|x86.Build.0 = Release|Any CPU
327+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
328+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|Any CPU.Build.0 = Debug|Any CPU
329+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|x64.ActiveCfg = Debug|Any CPU
330+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|x64.Build.0 = Debug|Any CPU
331+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|x86.ActiveCfg = Debug|Any CPU
332+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Debug|x86.Build.0 = Debug|Any CPU
333+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|Any CPU.ActiveCfg = Debug|Any CPU
334+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|Any CPU.Build.0 = Debug|Any CPU
335+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|x64.ActiveCfg = Debug|Any CPU
336+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|x64.Build.0 = Debug|Any CPU
337+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|x86.ActiveCfg = Debug|Any CPU
338+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.GPU|x86.Build.0 = Debug|Any CPU
339+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|Any CPU.ActiveCfg = Release|Any CPU
340+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|Any CPU.Build.0 = Release|Any CPU
341+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|x64.ActiveCfg = Release|Any CPU
342+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|x64.Build.0 = Release|Any CPU
343+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|x86.ActiveCfg = Release|Any CPU
344+
{C08C6692-4818-46C1-8462-2F0CC40C9152}.Release|x86.Build.0 = Release|Any CPU
325345
EndGlobalSection
326346
GlobalSection(SolutionProperties) = preSolution
327347
HideSolutionNode = FALSE
@@ -342,6 +362,7 @@ Global
342362
{D24FCAA5-548C-4251-B226-A1B6535D0845} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
343363
{C23563DB-FE21-48E7-A411-87A109E4A899} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
344364
{1DC32255-BA1F-4D6D-A9C9-5BD5ED71CAA0} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
365+
{C08C6692-4818-46C1-8462-2F0CC40C9152} = {1B0918B9-65AD-4F34-A287-AF4597B27DBD}
345366
EndGlobalSection
346367
GlobalSection(ExtensibilityGlobals) = postSolution
347368
SolutionGuid = {2DEAD3CC-486B-4918-A607-50B0DE7B114A}

0 commit comments

Comments
 (0)