Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/torch7.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoray kavukcuoglu <koray@kavukcuoglu.org>2013-02-12 14:37:23 +0400
committerkoray kavukcuoglu <koray@kavukcuoglu.org>2013-02-12 14:37:23 +0400
commitf4098402113f4a3766e747cf0f70dd994c11a9d8 (patch)
tree877d9ca1f9762304cc225f8b837c03d9dd784d3b /File.lua
parente098ae1382c3a635a696bd66aca29a45af25cad5 (diff)
add referenced function to disable/enable indexing/referencing behaviour of the writeObject mechanism.
Diffstat (limited to 'File.lua')
-rw-r--r--File.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/File.lua b/File.lua
index a003e62..0e09b3b 100644
--- a/File.lua
+++ b/File.lua
@@ -41,12 +41,21 @@ function File:isWritableObject(object)
return typeidx
end
-function File:writeObject(object, force)
+function File:referenced(ref)
+ local env = torch.getenv(self)
+ env.force = ref
+ torch.setenv(self,env)
+ return self
+end
+
+function File:writeObject(object)
-- we use an environment to keep a record of written objects
if not torch.getenv(self).writeObjects then
torch.setenv(self, {writeObjects={}, writeObjectsRef={}, readObjects={}})
end
+ local force = torch.getenv(self).force
+
-- if nil object, only write the type and return
if type(object) ~= 'boolean' and not object then
self:writeInt(TYPE_NIL)
@@ -94,7 +103,9 @@ function File:writeObject(object, force)
index = objects.nWriteObject or 0
index = index + 1
objects[torch.pointer(object)] = index
- objectsRef[object] = index -- we make sure the object is not going to disappear
+ if not force then
+ objectsRef[object] = index -- we make sure the object is not going to disappear
+ end
self:writeInt(index)
objects.nWriteObject = index