Skip to content

Commit df3a7f4

Browse files
BanycOceania2018
authored andcommitted
Add ones_like test case
1 parent 48d96f4 commit df3a7f4

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

test/TensorFlowNET.UnitTest/ManagedAPI/TensorOperate.cs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TensorOperate
1212
public void TransposeTest()
1313
{
1414
// https://www.tensorflow.org/api_docs/python/tf/transpose#for_example_2
15-
var x = tf.constant(new int[,]
15+
var x = tf.constant(new int[,]
1616
{
1717
{ 1, 2, 3 },
1818
{ 4, 5, 6 }
@@ -41,7 +41,7 @@ public void TransposeTest()
4141
{ 7, 77, 8, 88 }
4242
}
4343
}
44-
}));
44+
}));
4545

4646
#endregion
4747
var actual_transposed_a = tf.transpose(a, new[] { 3, 1, 2, 0 });
@@ -71,9 +71,9 @@ public void TransposeTest()
7171
{ 44, 88 }
7272
}
7373
}
74-
}));
74+
}));
7575
#endregion
76-
Assert.AreEqual((4, 2, 1, 2 ), actual_transposed_a.TensorShape);
76+
Assert.AreEqual((4, 2, 1, 2), actual_transposed_a.TensorShape);
7777
Assert.AreEqual(expected_transposed_a.numpy(), actual_transposed_a.numpy());
7878
}
7979

@@ -130,5 +130,60 @@ public void ConcatAndSplitTest()
130130
Assert.AreEqual(3, splitValue.Length);
131131
Assert.IsTrue(Enumerable.SequenceEqual(new[] { 2, 2 }, splitValue[0].shape));
132132
}
133+
134+
#region ones/zeros like
135+
[Ignore]
136+
[TestMethod]
137+
public void TestOnesLike()
138+
{
139+
#region 2-dimension
140+
var testCase2D = tf.constant(new int[,]
141+
{
142+
{ 1, 2, 3 },
143+
{ 4, 5, 6 }
144+
});
145+
var ones2D = tf.ones_like(testCase2D);
146+
147+
Assert.AreEqual(new[] { 1, 1, 1 }, ones2D[0].numpy());
148+
Assert.AreEqual(new[] { 1, 1, 1 }, ones2D[1].numpy());
149+
#endregion
150+
151+
#region 1-dimension
152+
var testCase1D = tf.constant(new int[,]
153+
{
154+
{ 1, 2, 3 }
155+
});
156+
var ones1D = tf.ones_like(testCase1D);
157+
158+
Assert.AreEqual(new[] { 1, 1, 1 }, ones1D[0].numpy());
159+
#endregion
160+
}
161+
162+
[TestMethod]
163+
public void TestZerosLike()
164+
{
165+
#region 2-dimension
166+
var testCase2D = tf.constant(new int[,]
167+
{
168+
{ 1, 2, 3 },
169+
{ 4, 5, 6 }
170+
});
171+
var zeros2D = tf.zeros_like(testCase2D);
172+
173+
Assert.AreEqual(new[] { 0, 0, 0 }, zeros2D[0].numpy());
174+
Assert.AreEqual(new[] { 0, 0, 0 }, zeros2D[1].numpy());
175+
#endregion
176+
177+
#region 1-dimension
178+
var testCase1D = tf.constant(new int[,]
179+
{
180+
{ 1, 2, 3 }
181+
});
182+
var zeros1D = tf.zeros_like(testCase1D);
183+
184+
Assert.AreEqual(new[] { 0, 0, 0 }, zeros1D[0].numpy());
185+
#endregion
186+
}
187+
#endregion
133188
}
134189
}

0 commit comments

Comments
 (0)