diff dataset.py @ 243:c8f19a9eb10f

Optimisation in ArrayDataSet::__getitem__
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 02 Jun 2008 11:59:41 -0400
parents ef70a665aaaf
children 7e6edee187e3 4ad6bc9b4f03
line wrap: on
line diff
--- a/dataset.py	Fri May 30 10:19:16 2008 -0400
+++ b/dataset.py	Mon Jun 02 11:59:41 2008 -0400
@@ -1016,12 +1016,13 @@
     def __getitem__(self,key):
         """More efficient implementation than the default __getitem__"""
         fieldnames=self.fields_columns.keys()
+        values=self.fields_columns.values()
         if type(key) is int:
             return Example(fieldnames,
-                           [self.data[key,self.fields_columns[f]] for f in fieldnames])
+                           [self.data[key,col] for col in values])
         if type(key) is slice:
             return MinibatchDataSet(Example(fieldnames,
-                                            [self.data[key,self.fields_columns[f]] for f in fieldnames]))
+                                            [self.data[key,col] for col in values]))
         if type(key) is list:
             for i in range(len(key)):
                 if self.hasFields(key[i]):
@@ -1030,9 +1031,10 @@
                                             #we must separate differently for list as numpy
                                             # doesn't support self.data[[i1,...],[i2,...]]
                                             # when their is more then two i1 and i2
-                                            [self.data[key,:][:,self.fields_columns[f]]
-                                             if isinstance(self.fields_columns[f],list) else
-                                             self.data[key,self.fields_columns[f]] for f in fieldnames]),
+                                            [self.data[key,:][:,col]
+                                             if isinstance(col,list) else
+                                             self.data[key,col] for col in values]),
+
 
                                     self.valuesVStack,self.valuesHStack)