Mercurial > pylearn
comparison dataset.py @ 238:ae1d85aca858
optimization in ArrayDataSet::__iter__
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Thu, 29 May 2008 10:30:59 -0400 |
parents | a70f2c973ea5 |
children | ef70a665aaaf |
comparison
equal
deleted
inserted
replaced
237:584ad7c55876 | 238:ae1d85aca858 |
---|---|
1052 self.dataset=dataset | 1052 self.dataset=dataset |
1053 self.minibatch_size=minibatch_size | 1053 self.minibatch_size=minibatch_size |
1054 assert offset>=0 and offset<len(dataset.data) | 1054 assert offset>=0 and offset<len(dataset.data) |
1055 assert offset+minibatch_size<=len(dataset.data) | 1055 assert offset+minibatch_size<=len(dataset.data) |
1056 self.current=offset | 1056 self.current=offset |
1057 self.columns = [self.dataset.fields_columns[f] | |
1058 for f in self.minibatch._names] | |
1057 def __iter__(self): | 1059 def __iter__(self): |
1058 return self | 1060 return self |
1059 def next(self): | 1061 def next(self): |
1060 #@todo: we suppose that we need to stop only when minibatch_size == 1. | 1062 #@todo: we suppose that we need to stop only when minibatch_size == 1. |
1061 # Otherwise, MinibatchWrapAroundIterator do it. | 1063 # Otherwise, MinibatchWrapAroundIterator do it. |
1062 if self.current>=self.dataset.data.shape[0]: | 1064 if self.current>=self.dataset.data.shape[0]: |
1063 raise StopIteration | 1065 raise StopIteration |
1064 sub_data = self.dataset.data[self.current] | 1066 sub_data = self.dataset.data[self.current] |
1065 self.minibatch._values = [sub_data[self.dataset.fields_columns[f]] for f in self.minibatch._names] | 1067 self.minibatch._values = [sub_data[c] for c in self.columns] |
1068 | |
1066 self.current+=self.minibatch_size | 1069 self.current+=self.minibatch_size |
1067 return self.minibatch | 1070 return self.minibatch |
1068 | 1071 |
1069 return ArrayDataSetIterator2(self,self.fieldNames(),1,0,0) | 1072 return ArrayDataSetIterator2(self,self.fieldNames(),1,0,0) |
1070 | 1073 |