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

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