From 50c00a7e04193b1adf34a3234af12b9ff6054933 Mon Sep 17 00:00:00 2001 From: Dominik Grewe Date: Thu, 21 Jan 2016 19:29:24 +0000 Subject: [PATCH] read and write methods for nn.Module. Allows modules that want to implement custom `read` and `write` methods to call `parent.read/write`. --- Module.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Module.lua b/Module.lua index 5bf771a3e..a7310d894 100644 --- a/Module.lua +++ b/Module.lua @@ -141,6 +141,22 @@ end function Module:reset() end +function Module:write(file) + -- Write all values in the object as a table. + local object = {} + for k, v in pairs(self) do + object[k] = v + end + file:writeObject(object) +end + +function Module:read(file) + local object = file:readObject() + for k, v in pairs(object) do + self[k] = v + end +end + -- This function is not easy to understand. It works as follows: -- -- - gather all parameter tensors for this module (and children);