Permalink
Browse files

add referenced function to disable/enable indexing/referencing behavi…

…our of the writeObject mechanism.
  • Loading branch information...
koraykv committed Feb 12, 2013
1 parent 3d7ecd2 commit 60ba9ea5b0634c6c9bf024d8b2cfa3f9713152e0
Showing with 13 additions and 2 deletions.
  1. +13 −2 pkg/torch/File.lua
View
@@ -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

0 comments on commit 60ba9ea

Please sign in to comment.