changeset 142:ad144fa72bf5

Automated merge with ssh://p-omega1@lgcm.iro.umontreal.ca/tlearn
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 12 May 2008 14:15:16 -0400
parents 3f4e5c9bdc5e (current diff) f5f235bebee4 (diff)
children b7ca3545186b
files dataset.py lookup_list.py
diffstat 3 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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
--- 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])#????