# HG changeset patch # User Frederic Bastien # Date 1336578988 14400 # Node ID a6e634b83d887ff29a091ffd87b010960c68672c # Parent 57feab73c783fe15f23d128676b24302a697be1d allow to read filetensor compressed with bz2 diff -r 57feab73c783 -r a6e634b83d88 pylearn/io/filetensor.py --- a/pylearn/io/filetensor.py Mon Mar 05 17:35:15 2012 -0500 +++ b/pylearn/io/filetensor.py Wed May 09 11:56:28 2012 -0400 @@ -20,6 +20,7 @@ @todo: add complex type support """ +import bz2 import gzip import numpy @@ -64,7 +65,7 @@ :returns: data type, element size, rank, shape, size """ if fromgzip is None: - fromgzip = isinstance(f, gzip.GzipFile) + fromgzip = isinstance(f, (gzip.GzipFile, bz2.BZ2File)) #what is the data type of this matrix? #magic_s = f.read(4) @@ -183,6 +184,7 @@ """Load all or part of file 'f' into a numpy ndarray @param f: file from which to read + file can be opended with open(), gzip.open() and bz2.BZ2File() @type f: file-like object. Can be a gzip open file. If subtensor is not None, it should be like the argument to @@ -200,7 +202,7 @@ f_start = f.tell() rval = None - if isinstance(f, gzip.GzipFile): + if isinstance(f, (gzip.GzipFile, bz2.BZ2File)): assert subtensor is None, "Not implemented the subtensor case for gzip file" d = f.read(_prod(dim)*elsize) rval = numpy.fromstring(d, dtype=magic_t).reshape(dim)