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.

Persistence.Test.cs 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow.NumPy;
  3. namespace TensorFlowNET.UnitTest.NumPy;
  4. /// <summary>
  5. /// https://numpy.org/doc/stable/reference/generated/numpy.save.html
  6. /// </summary>
  7. [TestClass]
  8. public class PersistenceTest : EagerModeTestBase
  9. {
  10. [TestMethod]
  11. public void SaveNpy()
  12. {
  13. var x = np.arange(10f).reshape((2, 5));
  14. np.save("arange.npy", x);
  15. var x2 = np.load("arange.npy");
  16. Assert.AreEqual(x.shape, x2.shape);
  17. }
  18. [TestMethod]
  19. public void SaveNpz()
  20. {
  21. var x = np.arange(10f).reshape((2, 5));
  22. var y = np.arange(10f).reshape((5, 2));
  23. np.savez("arange.npz", x, y);
  24. var z = np.loadz("arange.npz");
  25. np.savez("arange_named.npz", new { x, y });
  26. z = np.loadz("arange_named.npz");
  27. Assert.AreEqual(z["x"].shape, x.shape);
  28. Assert.AreEqual(z["y"].shape, y.shape);
  29. np.savez_compressed("arange_compressed.npz", x, y);
  30. np.savez_compressed("arange_compressed_named.npz", new { x, y });
  31. z = np.loadz("arange_compressed_named.npz");
  32. Assert.AreEqual(z["x"].shape, x.shape);
  33. Assert.AreEqual(z["y"].shape, y.shape);
  34. }
  35. }