changeset 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 c702abb7f875 0fb75fdd727d
files dataset.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
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)