Mercurial > pylearn
comparison dataset.py @ 422:32c5f87bc54e
Added __len__ to HStackedDataSet and replaced default len() by sys.maxint instead of None
author | Yoshua Bengio <bengioy@iro.umontreal.ca> |
---|---|
date | Sat, 19 Jul 2008 14:12:41 -0400 |
parents | 835830e52b42 |
children | 0231eeac11c9 |
comparison
equal
deleted
inserted
replaced
421:e01f17be270a | 422:32c5f87bc54e |
---|---|
218 len(dataset) returns the number of examples in the dataset. | 218 len(dataset) returns the number of examples in the dataset. |
219 By default, a DataSet is a 'stream', i.e. it has an unbounded length (sys.maxint). | 219 By default, a DataSet is a 'stream', i.e. it has an unbounded length (sys.maxint). |
220 Sub-classes which implement finite-length datasets should redefine this method. | 220 Sub-classes which implement finite-length datasets should redefine this method. |
221 Some methods only make sense for finite-length datasets. | 221 Some methods only make sense for finite-length datasets. |
222 """ | 222 """ |
223 return None | 223 from sys import maxint |
224 return maxint | |
224 | 225 |
225 | 226 |
226 class MinibatchToSingleExampleIterator(object): | 227 class MinibatchToSingleExampleIterator(object): |
227 """ | 228 """ |
228 Converts the result of minibatch iterator with minibatch_size==1 into | 229 Converts the result of minibatch iterator with minibatch_size==1 into |
941 self.fieldname2dataset[fieldname]=i | 942 self.fieldname2dataset[fieldname]=i |
942 for fieldname,i in names_to_change: | 943 for fieldname,i in names_to_change: |
943 del self.fieldname2dataset[fieldname] | 944 del self.fieldname2dataset[fieldname] |
944 self.fieldname2dataset[rename_field(fieldname,self.datasets[i],i)]=i | 945 self.fieldname2dataset[rename_field(fieldname,self.datasets[i],i)]=i |
945 | 946 |
947 def __len__(self): | |
948 return len(self.datasets[0]) | |
949 | |
946 def hasFields(self,*fieldnames): | 950 def hasFields(self,*fieldnames): |
947 for fieldname in fieldnames: | 951 for fieldname in fieldnames: |
948 if not fieldname in self.fieldname2dataset: | 952 if not fieldname in self.fieldname2dataset: |
949 return False | 953 return False |
950 return True | 954 return True |