summaryrefslogtreecommitdiff
path: root/numpy/numarray/functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/numarray/functions.py')
-rw-r--r--numpy/numarray/functions.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/numpy/numarray/functions.py b/numpy/numarray/functions.py
index 7242f2870..2492d5f3f 100644
--- a/numpy/numarray/functions.py
+++ b/numpy/numarray/functions.py
@@ -1,4 +1,4 @@
-from __future__ import division
+from __future__ import division, absolute_import
# missing Numarray defined names (in from numarray import *)
@@ -40,7 +40,7 @@ from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\
resize, searchsorted, shape, size, sort, swapaxes, trace, transpose
import numpy as np
-from numerictypes import typefrom
+from .numerictypes import typefrom
if sys.version_info[0] >= 3:
import copyreg as copy_reg
@@ -155,7 +155,7 @@ class FileSeekWarning(Warning):
pass
-STRICT, SLOPPY, WARN = range(3)
+STRICT, SLOPPY, WARN = list(range(3))
_BLOCKSIZE=1024
@@ -204,8 +204,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:
@@ -216,7 +216,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)
@@ -247,20 +247,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:
@@ -405,7 +418,7 @@ def put(array, indices, values, axis=0, clipmode=RAISE):
work[indices] = values
work = work.swapaxes(0, axis)
else:
- def_axes = range(work.ndim)
+ def_axes = list(range(work.ndim))
for x in axis:
def_axes.remove(x)
axis = list(axis)+def_axes
@@ -441,7 +454,7 @@ def take(array, indices, axis=0, outarr=None, clipmode=RAISE):
return res
return
else:
- def_axes = range(array.ndim)
+ def_axes = list(range(array.ndim))
for x in axis:
def_axes.remove(x)
axis = list(axis) + def_axes