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

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