# HG changeset patch # User Frederic Bastien # Date 1294341821 18000 # Node ID 212b142dcfc8c736639bee014239aa3d1ae7968b # Parent 5e481b2241173ffa9c443d3bb388bfb00cf0bcf1 reverted previous change as it did not work. diff -r 5e481b224117 -r 212b142dcfc8 datasets/ftfile.py --- a/datasets/ftfile.py Thu Jan 06 13:57:05 2011 -0500 +++ b/datasets/ftfile.py Thu Jan 06 14:23:41 2011 -0500 @@ -1,12 +1,8 @@ -from itertools import izip -import os - -import numpy from pylearn.io.filetensor import _read_header, _prod - +import numpy, theano from dataset import DataSet from dsetiter import DataIterator - +from itertools import izip, imap class FTFile(object): def __init__(self, fname, scale=1, dtype=None): @@ -14,17 +10,8 @@ Tests: >>> f = FTFile('/data/lisa/data/nist/by_class/digits/digits_test_labels.ft') """ - if os.path.exists(fname): - self.file = open(fname, 'rb') - self.magic_t, self.elsize, _, self.dim, _ = _read_header(self.file, False) - self.gz=False - else: - import gzip - self.file = gzip.open(fname+'.gz','rb') - self.magic_t, self.elsize, _, self.dim, _ = _read_header(self.file.read(100), False, True) - self.file.seek(0) - self.gz=True - + self.file = open(fname, 'rb') + self.magic_t, self.elsize, _, self.dim, _ = _read_header(self.file, False) self.size = self.dim[0] self.scale = scale self.dtype = dtype @@ -94,10 +81,7 @@ num = self.size self.dim[0] = num self.size -= num - if self.gz: - res = numpy.fromstring(self.file.read(), dtype=self.magic_t, count=_prod(self.dim)).reshape(self.dim) - else: - res = numpy.fromfile(self.file, dtype=self.magic_t, count=_prod(self.dim)).reshape(self.dim) + res = numpy.fromfile(self.file, dtype=self.magic_t, count=_prod(self.dim)).reshape(self.dim) if self.dtype is not None: res = res.astype(self.dtype) if self.scale != 1: