changeset 309:923de30457f0

get item now returns LookupLists
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Wed, 11 Jun 2008 11:18:14 -0400
parents 9ebc960260c5
children ebccfd05ccd5
files dataset.py
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 <iterable> 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):