You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EagerModeTestBase.cs 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using static Tensorflow.Binding;
  4. namespace TensorFlowNET.UnitTest
  5. {
  6. public class EagerModeTestBase : PythonTest
  7. {
  8. [TestInitialize]
  9. public void TestInit()
  10. {
  11. if (!tf.executing_eagerly())
  12. tf.enable_eager_execution();
  13. tf.Context.ensure_initialized();
  14. }
  15. [TestCleanup]
  16. public void TestClean()
  17. {
  18. }
  19. public bool Equal(float[] f1, float[] f2)
  20. {
  21. bool ret = false;
  22. var tolerance = .000001f;
  23. for (var i = 0; i < f1.Length; i++)
  24. {
  25. ret = Math.Abs(f1[i] - f2[i]) <= tolerance;
  26. if (!ret)
  27. break;
  28. }
  29. return ret;
  30. }
  31. public bool Equal(double[] d1, double[] d2)
  32. {
  33. bool ret = false;
  34. var tolerance = .000000000000001f;
  35. for (var i = 0; i < d1.Length; i++)
  36. {
  37. ret = Math.Abs(d1[i] - d2[i]) <= tolerance;
  38. if (!ret)
  39. break;
  40. }
  41. return ret;
  42. }
  43. }
  44. }