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

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