From 3a587d787b184ff94f970baf6d4b4ee1db9ba96b Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Tue, 26 Mar 2013 19:35:06 +0100 Subject: [PATCH] BUG: fix undefined function and add integer divisions in numarray --- numpy/numarray/functions.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/numpy/numarray/functions.py b/numpy/numarray/functions.py index 1c2141c98bf1..4b6397d5dbd3 100644 --- a/numpy/numarray/functions.py +++ b/numpy/numarray/functions.py @@ -216,8 +216,8 @@ def fromfile(infile, type=None, shape=None, sizing=STRICT, ##file whose size may be determined before allocation, should be ##quick -- only one allocation will be needed. - recsize = dtype.itemsize * np.product([i for i in shape if i != -1]) - blocksize = max(_BLOCKSIZE/recsize, 1)*recsize + recsize = int(dtype.itemsize * np.product([i for i in shape if i != -1])) + blocksize = max(_BLOCKSIZE//recsize, 1)*recsize ##try to estimate file size try: @@ -228,7 +228,7 @@ def fromfile(infile, type=None, shape=None, sizing=STRICT, except (AttributeError, IOError): initsize=blocksize else: - initsize=max(1,(endpos-curpos)/recsize)*recsize + initsize=max(1,(endpos-curpos)//recsize)*recsize buf = np.newbuffer(initsize) @@ -259,20 +259,33 @@ def fromfile(infile, type=None, shape=None, sizing=STRICT, except IOError: _warnings.warn("Could not rewind (IOError in seek)", FileSeekWarning) - datasize = (len(data)/recsize) * recsize + datasize = (len(data)//recsize) * recsize if len(buf) != bytesread+datasize: buf=_resizebuf(buf,bytesread+datasize) buf[bytesread:bytesread+datasize]=data[:datasize] ##deduce shape from len(buf) shape = list(shape) uidx = shape.index(-1) - shape[uidx]=len(buf) / recsize + shape[uidx]=len(buf) // recsize a = np.ndarray(shape=shape, dtype=type, buffer=buf) if a.dtype.char == '?': np.not_equal(a, 0, a) return a + +# this function is referenced in the code above but not defined. adding +# it back. - phensley +def _resizebuf(buf,newsize): + "Return a copy of BUF of size NEWSIZE." + newbuf = np.newbuffer(newsize) + if newsize > len(buf): + newbuf[:len(buf)]=buf + else: + newbuf[:]=buf[:len(newbuf)] + return newbuf + + def fromstring(datastring, type=None, shape=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, True) if shape is None: