# HG changeset patch # User Thierry Bertin-Mahieux # Date 1213197494 14400 # Node ID 923de30457f000a3c9e1e3bc5be955e205f24f1a # Parent 9ebc960260c531767d9096853d1248ae30a49576 get item now returns LookupLists diff -r 9ebc960260c5 -r 923de30457f0 dataset.py --- a/dataset.py Tue Jun 10 20:02:25 2008 -0400 +++ b/dataset.py Wed Jun 11 11:18:14 2008 -0400 @@ -437,9 +437,9 @@ @type i: integer or slice or of integers @param i: dataset[i] returns the (i+1)-th example of the dataset. - dataset[i:j] returns the subdataset with examples i,i+1,...,j-1. - dataset[i:j:s] returns the subdataset with examples i,i+2,i+4...,j-2. - dataset[[i1,i2,..,in]] returns the subdataset with examples i1,i2,...,in. + dataset[i:j] returns a LookupList with examples i,i+1,...,j-1. + dataset[i:j:s] returns a LookupList with examples i,i+2,i+4...,j-2. + dataset[[i1,i2,..,in]] returns a LookupList with examples i1,i2,...,in. @note: Some stream datasets may be unable to implement random access, i.e. @@ -454,7 +454,7 @@ """ if type(i) is int: - #TODO: consider asserting that i >= 0 + assert i >= 0 # TBM: see if someone complains and want negative i i_batch = self.minibatches_nowrap(self.fieldNames(), minibatch_size=1, n_batches=1, offset=i) return DataSet.MinibatchToSingleExampleIterator(i_batch).next() @@ -463,10 +463,15 @@ if type(i) is slice and (i.step in (None, 1)): offset = 0 if i.start is None else i.start upper_bound = len(self) if i.stop is None else i.stop - return MinibatchDataSet(self.minibatches_nowrap(self.fieldNames(), + #return MinibatchDataSet(self.minibatches_nowrap(self.fieldNames(), + # minibatch_size=upper_bound - offset, + # n_batches=1, + # offset=offset).next()) + # now returns a LookupList + return self.minibatches_nowrap(self.fieldNames(), minibatch_size=upper_bound - offset, n_batches=1, - offset=offset).next()) + offset=offset).next() # if slice has a step param, convert it to list and handle it with the # list code @@ -494,7 +499,11 @@ zz = zip(self.fieldNames(),field_values) vst = [self.valuesVStack(fieldname,field_values) for fieldname,field_values in zz] example = Example(self.fieldNames(), vst) - return MinibatchDataSet(example, self.valuesVStack, self.valuesHStack) + #return MinibatchDataSet(example, self.valuesVStack, self.valuesHStack) + # now returns a LookupList + return example + + # what in the world is i? raise TypeError(i, type(i)) def valuesHStack(self,fieldnames,fieldvalues):