changeset 310:ebccfd05ccd5

dataset.subset implemented
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Wed, 11 Jun 2008 11:43:54 -0400
parents 923de30457f0
children 0690de82c338
files dataset.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dataset.py	Wed Jun 11 11:18:14 2008 -0400
+++ b/dataset.py	Wed Jun 11 11:43:54 2008 -0400
@@ -506,6 +506,32 @@
         # what in the world is i?
         raise TypeError(i, type(i))
 
+
+    """
+    Enables the call dataset.subset[a:b:c] that will return a DataSet
+    around the examples returned by __getitem__(slice(a,b,c))
+       
+    @SEE DataSet.__getsubset(self)
+    """
+    subset = property(lambda s : s.__getsubset(),doc="returns a subset as a DataSet")
+
+
+    def __getsubset(self) :
+        """
+        Enables the call data.subset[a:b:c], returns a DataSet.
+        Default implementation is a simple wrap around __getitem__() using MinibatchDataSet.
+
+        @RETURN DataSet
+        @SEE DataSet.subset = property(lambda s : s.__getsubset())
+        """
+        _self = self
+        class GetSliceReturnsDataSet(object) :
+            def __getitem__(self,slice) :
+                return MinibatchDataSet(_self.__getitem__(slice))
+        return GetSliceReturnsDataSet()
+
+
+
     def valuesHStack(self,fieldnames,fieldvalues):
         """
         Return a value that corresponds to concatenating (horizontally) several field values.