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.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public bool Equal(float f1, float f2)
  16. {
  17. var tolerance = .000001f;
  18. return Math.Abs(f1 - f2) <= tolerance;
  19. }
  20. public bool Equal(float[] f1, float[] f2)
  21. {
  22. bool ret = false;
  23. var tolerance = .000001f;
  24. for (var i = 0; i < f1.Length; i++)
  25. {
  26. ret = Math.Abs(f1[i] - f2[i]) <= tolerance;
  27. if (!ret)
  28. break;
  29. }
  30. return ret;
  31. }
  32. public bool Equal(double[] d1, double[] d2)
  33. {
  34. bool ret = false;
  35. var tolerance = .000000000000001f;
  36. for (var i = 0; i < d1.Length; i++)
  37. {
  38. ret = Math.Abs(d1[i] - d2[i]) <= tolerance;
  39. if (!ret)
  40. break;
  41. }
  42. return ret;
  43. }
  44. }
  45. }