Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov-alexander committed Nov 11, 2023
1 parent b6db941 commit 7968dc3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/Tensorflow.UnitTest/PythonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,23 @@ public void assertTrue(bool cond)

public void assertAllClose(NDArray array1, NDArray array2, double eps = 1e-5)
{
Assert.IsTrue(np.allclose(array1, array2, rtol: eps));
CollectionAssert.AreEqual(array1.ToArray(), array2.ToArray(), new CollectionComparer(eps));

//TODO: Assert.IsTrue(np.allclose(array1, array2, rtol: eps));
}

public void assertAllClose(double value, NDArray array2, double eps = 1e-5)
{
if (array2.shape.IsScalar)
{
double value2 = array2;
Assert.AreEqual(value, value2, eps);
return;
}
var array1 = np.ones_like(array2) * value;
Assert.IsTrue(np.allclose(array1, array2, rtol: eps));
CollectionAssert.AreEqual(array1.ToArray(), array2.ToArray(), new CollectionComparer(eps));

//TODO: Assert.IsTrue(np.allclose(array1, array2, rtol: eps));
}

private class CollectionComparer : IComparer
Expand All @@ -158,7 +168,7 @@ public int Compare(object? x, object? y)
}
else if (x == null)
{
return -1;
return -1;
}
else if (y == null)
{
Expand Down

0 comments on commit 7968dc3

Please sign in to comment.