Made the test more practical
@@ -149,9 +149,11 @@ class TestNpzDeserializerNonStrict(unittest.TestCase):
fd, path = tempfile.mkstemp()
os.close(fd)
self.temp_file_path = path
- with open(path, 'wb') as f:
- numpy.savez(
- f, **{'x': numpy.asarray(10)})
+
+ child = link.Chain(linear=links.Linear(2, 3))
+ parent = link.Chain(linear=links.Linear(3, 2), child=child)
+ npz.save_npz(self.temp_file_path, parent)
+ self.source = parent
self.npzfile = numpy.load(path)
self.deserializer = npz.NpzDeserializer(self.npzfile, strict=False)
@@ -163,9 +165,20 @@ class TestNpzDeserializerNonStrict(unittest.TestCase):
os.remove(self.temp_file_path)
def test_deserialize_partial(self):
- y = numpy.empty((2, 3), dtype=numpy.float32)
- ret = self.deserializer('y', y)
- self.assertIs(ret, y)
+ child = link.Chain(linear2=links.Linear(2, 3))
+ target = link.Chain(linear=links.Linear(3, 2), child=child)
+ target_child_W = numpy.copy(child.linear2.W.data)
+ target_child_b = numpy.copy(child.linear2.b.data)
+ self.deserializer.load(target)
+
+ self.assertTrue(numpy.array_equal(
+ self.source.linear.W.data, target.linear.W.data))
+ self.assertTrue(numpy.array_equal(
+ self.source.linear.b.data, target.linear.b.data))
+ self.assertTrue(numpy.array_equal(
+ target.child.linear2.W.data, target_child_W))
+ self.assertTrue(numpy.array_equal(
+ target.child.linear2.b.data, target_child_b))
@testing.parameterize(*testing.product({'compress': [False, True]}))
