# HG changeset patch # User Frederic Bastien # Date 1210616116 14400 # Node ID ad144fa72bf555dc3aa5942077dc77900e4ab00b # Parent 3f4e5c9bdc5e4b116b6c3e2399e81a8d79b12ad9# Parent f5f235bebee44b4b08a3428a076d95fd6c8dd866 Automated merge with ssh://p-omega1@lgcm.iro.umontreal.ca/tlearn diff -r 3f4e5c9bdc5e -r ad144fa72bf5 dataset.py --- a/dataset.py Fri May 09 17:38:57 2008 -0400 +++ b/dataset.py Mon May 12 14:15:16 2008 -0400 @@ -770,16 +770,19 @@ return self def next(self): # concatenate all the fields of the minibatches - return reduce(LookupList.__add__,[iterator.next() for iterator in self.iterators]) + l=LookupList() + for iter in self.iterators: + l.append_lookuplist(iter.next()) + return l assert self.hasFields(*fieldnames) # find out which underlying datasets are necessary to service the required fields # and construct corresponding minibatch iterators - if fieldnames: + if fieldnames and fieldnames!=self.fieldNames(): datasets=set([]) fields_in_dataset=dict([(dataset,[]) for dataset in datasets]) for fieldname in fieldnames: - dataset=self.datasets[self.fieldnames2dataset[fieldname]] + dataset=self.datasets[self.fieldname2dataset[fieldname]] datasets.add(dataset) fields_in_dataset[dataset].append(fieldname) datasets=list(datasets) diff -r 3f4e5c9bdc5e -r ad144fa72bf5 lookup_list.py --- a/lookup_list.py Fri May 09 17:38:57 2008 -0400 +++ b/lookup_list.py Mon May 12 14:15:16 2008 -0400 @@ -71,6 +71,12 @@ self._values.append(value) self._names.append(key) + def append_lookuplist(self, *list): + for l in list: + for key in l.keys(): + self.append_keyval(key,l[key]) + del l + def __len__(self): return len(self._values) @@ -103,3 +109,15 @@ Return a list of values associated with the given names (which must all be keys of the lookup list). """ return [self[name] for name in names] + + +if __name__ == '__main__': + + a=LookupList(['a'],[1]) + print a + b=LookupList(['b'],[2]) + print b + a.append_lookuplist(b) + print a + a.append_lookuplist(b) + print a diff -r 3f4e5c9bdc5e -r ad144fa72bf5 test_dataset.py --- a/test_dataset.py Fri May 09 17:38:57 2008 -0400 +++ b/test_dataset.py Mon May 12 14:15:16 2008 -0400 @@ -320,11 +320,17 @@ # - 'fieldtypes': a list of types (one per field) #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? - i=0 - for example in hstack([ds('x'),ds('y'),ds('z')]): - example==ds[i] - i+=1 - del i,example + #hstack([ds('x','y'),ds('z')] + #hstack([ds('z','y'),ds('x')] + #assert have_thrown("hstack([ds('x'),ds('x')]") + #assert not have_thrown("hstack([ds('x'),ds('x')]") + #accept_nonunique_names + #assert have_thrown("hstack([ds('y','x'),ds('x')]") +# i=0 +# for example in hstack([ds('x'),ds('y'),ds('z')]): +# example==ds[i] +# i+=1 +# del i,example #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????