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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow.Keras;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.Keras.UnitTest
  6. {
  7. public class EagerModeTestBase
  8. {
  9. [TestInitialize]
  10. public void TestInit()
  11. {
  12. tf.UseKeras<KerasInterface>();
  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. }