# HG changeset patch # User James Bergstra # Date 1296853522 18000 # Node ID cff305ad9f6016ed9d8b1233480fbf96d31c4cad # Parent 383d4c061546e5690ea7336ec43a6e2a637ebcf9 TensorFnDataset - added x_ attribute that caches the dataset function return value, but does not get pickled. diff -r 383d4c061546 -r cff305ad9f60 pylearn/dataset_ops/protocol.py --- a/pylearn/dataset_ops/protocol.py Fri Feb 04 16:03:25 2011 -0500 +++ b/pylearn/dataset_ops/protocol.py Fri Feb 04 16:05:22 2011 -0500 @@ -92,13 +92,20 @@ self.fn, self.fn_args = fn except: self.fn, self.fn_args = fn, () + def __getstate__(self): + rval = dict(self.__dict__) + if 'x_' in rval: + del rval['x_'] + return rval def __eq__(self, other): return super(TensorFnDataset, self).__eq__(other) and self.fn == other.fn \ and self.fn_args == other.fn_args def __hash__(self): - return super(TensorFnDataset, self).__hash__() ^ hash(self.fn) ^ hash(self.fn_args) + return (super(TensorFnDataset, self).__hash__() + ^ hash(self.fn) + ^ hash(self.fn_args)) def __str__(self): try: @@ -107,7 +114,10 @@ return "%s{%s}" % (self.__class__.__name__, self.fn, self.fn_args) def perform(self, node, (idx,), (z,)): - x = self.fn(*self.fn_args) + try: + x = self.x_ + except: + x = self.x_ = self.fn(*self.fn_args) if idx.ndim == 0: z[0] = x[int(idx)] else: