# HG changeset patch # User Frederic Bastien # Date 1294418558 18000 # Node ID 48e8292e22e7bcebb46ecc8c621b2ce0b0ec6892 # Parent 8ecc6da873509f00c92cd6351959ea2e6eb3d8cf new version _read_header for filetensor that allow to work gzip file. diff -r 8ecc6da87350 -r 48e8292e22e7 pylearn/io/filetensor.py --- a/pylearn/io/filetensor.py Thu Jan 06 13:33:47 2011 -0500 +++ b/pylearn/io/filetensor.py Fri Jan 07 11:42:38 2011 -0500 @@ -52,17 +52,14 @@ s_array = numpy.fromstring(s, dtype='int32') return s_array.item() -def _read_header(f, debug=False, fromstring=False): +def _read_header(f, debug=False, fromgzip=False): """ :returns: data type, element size, rank, shape, size """ #what is the data type of this matrix? #magic_s = f.read(4) #magic = numpy.fromstring(magic_s, dtype='int32') - if fromstring: - magic = numpy.fromstring(f[0:4], dtype='int32').item() - else: - magic = _read_int32(f) + magic = _read_int32(f) magic_t, elsize = _magic_dtype[magic] if debug: print 'header magic', magic, magic_t, elsize @@ -70,15 +67,13 @@ raise NotImplementedError('packed matrix not supported') #what is the rank of the tensor? - if fromstring: - ndim = numpy.fromstring(f[4:8], dtype='int32').item() - else: - ndim = _read_int32(f) + ndim = _read_int32(f) if debug: print 'header ndim', ndim #what are the dimensions of the tensor? - if fromstring: - dim = numpy.fromstring(f[8:8+max(ndim,3)*4], dtype='int32')[:ndim] + if fromgzip: + d = f.read(max(ndim,3)*4) + dim = numpy.fromstring(d, dtype='int32')[:ndim] else: dim = numpy.fromfile(f, dtype='int32', count=max(ndim,3))[:ndim] dim_size = _prod(dim)