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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(long[] l1, long[] l2)
  21. {
  22. if (l1.Length != l2.Length)
  23. return false;
  24. for (var i = 0; i < l1.Length; i++)
  25. {
  26. if (l1[i] != l2[i])
  27. return false;
  28. }
  29. return true;
  30. }
  31. public bool Equal(float[] f1, float[] f2)
  32. {
  33. bool ret = false;
  34. var tolerance = .000001f;
  35. for (var i = 0; i < f1.Length; i++)
  36. {
  37. ret = Math.Abs(f1[i] - f2[i]) <= tolerance;
  38. if (!ret)
  39. break;
  40. }
  41. return ret;
  42. }
  43. public bool Equal(double[] d1, double[] d2)
  44. {
  45. bool ret = false;
  46. var tolerance = .000000000000001f;
  47. for (var i = 0; i < d1.Length; i++)
  48. {
  49. ret = Math.Abs(d1[i] - d2[i]) <= tolerance;
  50. if (!ret)
  51. break;
  52. }
  53. return ret;
  54. }
  55. }
  56. }