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.

AssignTests.cs 1.0 kB

123456789101112131415161718192021222324252627282930313233343536
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using static Tensorflow.Python;
  4. namespace TensorFlowNET.UnitTest.Basics
  5. {
  6. [TestClass]
  7. public sealed class AssignTests
  8. {
  9. [Ignore("Not implemented")]
  10. [TestMethod]
  11. public void ShouldAssignVariable()
  12. {
  13. var raw_data = new[] { 1.0, 2.0, 8.0, -1.0, 0.0, 5.5, 6.0, 16.0 };
  14. var expected = new[] { false, true, false, false, true, false, true };
  15. var spike = tf.Variable(false);
  16. spike.initializer.run();
  17. foreach (var i in range(1, 2))
  18. {
  19. if (raw_data[i] - raw_data[i - 1] > 5d)
  20. {
  21. var updater = tf.assign(spike, tf.constant(true));
  22. updater.eval();
  23. }
  24. else
  25. {
  26. tf.assign(spike, tf.constant(true)).eval();
  27. }
  28. Assert.AreEqual((bool)spike.eval(), expected[i - 1]);
  29. }
  30. }
  31. }
  32. }