forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersistence.Test.cs
More file actions
42 lines (35 loc) · 1.18 KB
/
Copy pathPersistence.Test.cs
File metadata and controls
42 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tensorflow.NumPy;
namespace TensorFlowNET.UnitTest.NumPy;
/// <summary>
/// https://numpy.org/doc/stable/reference/generated/numpy.save.html
/// </summary>
[TestClass]
public class PersistenceTest : EagerModeTestBase
{
[TestMethod]
public void SaveNpy()
{
var x = np.arange(10f).reshape((2, 5));
np.save("arange.npy", x);
var x2 = np.load("arange.npy");
Assert.AreEqual(x.shape, x2.shape);
}
[TestMethod]
public void SaveNpz()
{
var x = np.arange(10f).reshape((2, 5));
var y = np.arange(10f).reshape((5, 2));
np.savez("arange.npz", x, y);
var z = np.loadz("arange.npz");
np.savez("arange_named.npz", new { x, y });
z = np.loadz("arange_named.npz");
Assert.AreEqual(z["x"].shape, x.shape);
Assert.AreEqual(z["y"].shape, y.shape);
np.savez_compressed("arange_compressed.npz", x, y);
np.savez_compressed("arange_compressed_named.npz", new { x, y });
z = np.loadz("arange_compressed_named.npz");
Assert.AreEqual(z["x"].shape, x.shape);
Assert.AreEqual(z["y"].shape, y.shape);
}
}