comparison dataset.py @ 211:bd728c83faff

in __get__, problem if the i.stop was None, i being the slice, added one line replacing None by the len(self)
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Wed, 21 May 2008 17:39:30 -0400
parents 80731832c62b
children 4b7e89b75e2b
comparison
equal deleted inserted replaced
210:ffd50efefb70 211:bd728c83faff
440 return DataSet.MinibatchToSingleExampleIterator( 440 return DataSet.MinibatchToSingleExampleIterator(
441 self.minibatches(minibatch_size=1,n_batches=1,offset=i)).next() 441 self.minibatches(minibatch_size=1,n_batches=1,offset=i)).next()
442 rows=None 442 rows=None
443 # or a slice 443 # or a slice
444 if type(i) is slice: 444 if type(i) is slice:
445 #print 'i=',i
445 if not i.start: i=slice(0,i.stop,i.step) 446 if not i.start: i=slice(0,i.stop,i.step)
447 if not i.stop: i=slice(i.start,len(self),i.step)
446 if not i.step: i=slice(i.start,i.stop,1) 448 if not i.step: i=slice(i.start,i.stop,1)
447 if i.step is 1: 449 if i.step is 1:
448 return self.minibatches(minibatch_size=i.stop-i.start,n_batches=1,offset=i.start).next().examples() 450 return self.minibatches(minibatch_size=i.stop-i.start,n_batches=1,offset=i.start).next().examples()
449 rows = range(i.start,i.stop,i.step) 451 rows = range(i.start,i.stop,i.step)
450 # or a list of indices 452 # or a list of indices
660 """ 662 """
661 The user can (and generally should) also provide values_vstack(fieldname,fieldvalues) 663 The user can (and generally should) also provide values_vstack(fieldname,fieldvalues)
662 and a values_hstack(fieldnames,fieldvalues) functions behaving with the same 664 and a values_hstack(fieldnames,fieldvalues) functions behaving with the same
663 semantics as the DataSet methods of the same name (but without the self argument). 665 semantics as the DataSet methods of the same name (but without the self argument).
664 """ 666 """
667
665 self._fields=fields_lookuplist 668 self._fields=fields_lookuplist
666 assert len(fields_lookuplist)>0 669 assert len(fields_lookuplist)>0
667 self.length=len(fields_lookuplist[0]) 670 self.length=len(fields_lookuplist[0])
668 for field in fields_lookuplist[1:]: 671 for field in fields_lookuplist[1:]:
669 assert self.length==len(field) 672 assert self.length==len(field)
1138 (provided in a list). 1141 (provided in a list).
1139 1142
1140 Note that the expected semantics of the function differs in minibatch mode 1143 Note that the expected semantics of the function differs in minibatch mode
1141 (it takes minibatches of inputs and produces minibatches of outputs, as 1144 (it takes minibatches of inputs and produces minibatches of outputs, as
1142 documented in the class comment). 1145 documented in the class comment).
1146
1147 TBM: are filedtypes the old field types (from input_dataset) or the new ones
1148 (for the new dataset created)?
1143 """ 1149 """
1144 self.input_dataset=input_dataset 1150 self.input_dataset=input_dataset
1145 self.function=function 1151 self.function=function
1146 self.output_names=output_names 1152 self.output_names=output_names
1147 self.minibatch_mode=minibatch_mode 1153 self.minibatch_mode=minibatch_mode
1179 zip(*output_examples))] 1185 zip(*output_examples))]
1180 all_outputs = Example(all_output_names,function_outputs) 1186 all_outputs = Example(all_output_names,function_outputs)
1181 if fieldnames==all_output_names: 1187 if fieldnames==all_output_names:
1182 return all_outputs 1188 return all_outputs
1183 return Example(fieldnames,[all_outputs[name] for name in fieldnames]) 1189 return Example(fieldnames,[all_outputs[name] for name in fieldnames])
1190
1184 1191
1185 return ApplyFunctionIterator(self) 1192 return ApplyFunctionIterator(self)
1186 1193
1187 def __iter__(self): # only implemented for increased efficiency 1194 def __iter__(self): # only implemented for increased efficiency
1188 class ApplyFunctionSingleExampleIterator(object): 1195 class ApplyFunctionSingleExampleIterator(object):