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.

DatasetTest.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow.UnitTest;
  6. using static Tensorflow.Binding;
  7. namespace TensorFlowNET.UnitTest.Dataset
  8. {
  9. [TestClass]
  10. public class DatasetTest : EagerModeTestBase
  11. {
  12. [TestMethod]
  13. public void Range()
  14. {
  15. int iStep = 0;
  16. long value = 0;
  17. var dataset = tf.data.Dataset.range(3);
  18. foreach(var (step, item) in enumerate(dataset))
  19. {
  20. Assert.AreEqual(iStep, step);
  21. iStep++;
  22. Assert.AreEqual(value, (long)item.Item1);
  23. value++;
  24. }
  25. }
  26. [TestMethod]
  27. public void Prefetch()
  28. {
  29. int iStep = 0;
  30. long value = 1;
  31. var dataset = tf.data.Dataset.range(1, 5, 2);
  32. dataset = dataset.prefetch(2);
  33. foreach (var (step, item) in enumerate(dataset))
  34. {
  35. Assert.AreEqual(iStep, step);
  36. iStep++;
  37. Assert.AreEqual(value, (long)item.Item1);
  38. value += 2;
  39. }
  40. }
  41. }
  42. }