# HG changeset patch # User Thierry Bertin-Mahieux # Date 1213206819 14400 # Node ID 009ce84e9f5216a451ff063a1694ff79691daf22 # Parent 96cca78de3ed270218b301210976eda272c09f89 behaviour is now the same as a list in pylearn, so if len(ds) = 10, ds[10] raise an IndexError, same thing for ds[[1,10]], and ds[0:14:1] returns 10 elements diff -r 96cca78de3ed -r 009ce84e9f52 dataset.py --- a/dataset.py Wed Jun 11 13:22:00 2008 -0400 +++ b/dataset.py Wed Jun 11 13:53:39 2008 -0400 @@ -455,6 +455,8 @@ if type(i) is int: assert i >= 0 # TBM: see if someone complains and want negative i + if i >= len(self) : + raise IndexError i_batch = self.minibatches_nowrap(self.fieldNames(), minibatch_size=1, n_batches=1, offset=i) return DataSet.MinibatchToSingleExampleIterator(i_batch).next() @@ -463,6 +465,7 @@ 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 + upper_bound = min(len(self) , upper_bound) #return MinibatchDataSet(self.minibatches_nowrap(self.fieldNames(), # minibatch_size=upper_bound - offset, # n_batches=1, @@ -486,6 +489,8 @@ #dis-allow nested slices if not isinstance(idx, int): raise TypeError(idx) + if idx >= len(self) : + raise IndexError # call back into self.__getitem__ examples = [self.minibatches_nowrap(self.fieldNames(), minibatch_size=1, n_batches=1, offset=ii).next()