[pypy-commit] pypy numpy-refactor: Some progress. Reimport _methods.py from numpy 1.8. It's simpler now
fijal
noreply at buildbot.pypy.org
Wed Sep 5 19:00:06 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57158:2810ac40701a
Date: 2012-09-05 18:59 +0200
http://bitbucket.org/pypy/pypy/changeset/2810ac40701a/
Log: Some progress. Reimport _methods.py from numpy 1.8. It's simpler now
diff --git a/lib_pypy/numpypy/core/_methods.py b/lib_pypy/numpypy/core/_methods.py
--- a/lib_pypy/numpypy/core/_methods.py
+++ b/lib_pypy/numpypy/core/_methods.py
@@ -1,62 +1,77 @@
# Array methods which are called by the both the C-code for the method
# and the Python code for the NumPy-namespace function
+#from numpy.core import multiarray as mu
+#from numpy.core import umath as um
import _numpypy as mu
um = mu
-#from numpypy.core import umath as um
-from numpypy.core.numeric import asanyarray
+from numpy.core.numeric import asanyarray
-def _amax(a, axis=None, out=None, skipna=False, keepdims=False):
+def _amax(a, axis=None, out=None, keepdims=False):
return um.maximum.reduce(a, axis=axis,
- out=out, skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
-def _amin(a, axis=None, out=None, skipna=False, keepdims=False):
+def _amin(a, axis=None, out=None, keepdims=False):
return um.minimum.reduce(a, axis=axis,
- out=out, skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
-def _sum(a, axis=None, dtype=None, out=None, skipna=False, keepdims=False):
+def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
return um.add.reduce(a, axis=axis, dtype=dtype,
- out=out, skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
-def _prod(a, axis=None, dtype=None, out=None, skipna=False, keepdims=False):
+def _prod(a, axis=None, dtype=None, out=None, keepdims=False):
return um.multiply.reduce(a, axis=axis, dtype=dtype,
- out=out, skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
-def _mean(a, axis=None, dtype=None, out=None, skipna=False, keepdims=False):
+def _any(a, axis=None, dtype=None, out=None, keepdims=False):
+ return um.logical_or.reduce(a, axis=axis, dtype=dtype, out=out,
+ keepdims=keepdims)
+
+def _all(a, axis=None, dtype=None, out=None, keepdims=False):
+ return um.logical_and.reduce(a, axis=axis, dtype=dtype, out=out,
+ keepdims=keepdims)
+
+def _count_reduce_items(arr, axis):
+ if axis is None:
+ axis = tuple(xrange(arr.ndim))
+ if not isinstance(axis, tuple):
+ axis = (axis,)
+ items = 1
+ for ax in axis:
+ items *= arr.shape[ax]
+ return items
+
+def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
arr = asanyarray(a)
# Upgrade bool, unsigned int, and int to float64
if dtype is None and arr.dtype.kind in ['b','u','i']:
ret = um.add.reduce(arr, axis=axis, dtype='f8',
- out=out, skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
else:
ret = um.add.reduce(arr, axis=axis, dtype=dtype,
- out=out, skipna=skipna, keepdims=keepdims)
- rcount = mu.count_reduce_items(arr, axis=axis,
- skipna=skipna, keepdims=keepdims)
+ out=out, keepdims=keepdims)
+ rcount = _count_reduce_items(arr, axis)
if isinstance(ret, mu.ndarray):
ret = um.true_divide(ret, rcount,
- casting='unsafe', subok=False)
+ out=ret, casting='unsafe', subok=False)
else:
ret = ret / float(rcount)
return ret
def _var(a, axis=None, dtype=None, out=None, ddof=0,
- skipna=False, keepdims=False):
+ keepdims=False):
arr = asanyarray(a)
# First compute the mean, saving 'rcount' for reuse later
if dtype is None and arr.dtype.kind in ['b','u','i']:
- arrmean = um.add.reduce(arr, axis=axis, dtype='f8',
- skipna=skipna, keepdims=True)
+ arrmean = um.add.reduce(arr, axis=axis, dtype='f8', keepdims=True)
else:
- arrmean = um.add.reduce(arr, axis=axis, dtype=dtype,
- skipna=skipna, keepdims=True)
- rcount = mu.count_reduce_items(arr, axis=axis,
- skipna=skipna, keepdims=True)
+ arrmean = um.add.reduce(arr, axis=axis, dtype=dtype, keepdims=True)
+ rcount = _count_reduce_items(arr, axis)
if isinstance(arrmean, mu.ndarray):
arrmean = um.true_divide(arrmean, rcount,
- casting='unsafe', subok=False)
+ out=arrmean, casting='unsafe', subok=False)
else:
arrmean = arrmean / float(rcount)
@@ -65,13 +80,12 @@
# (arr - arrmean) ** 2
if arr.dtype.kind == 'c':
- x = um.multiply(x, um.conjugate(x)).real
+ x = um.multiply(x, um.conjugate(x), out=x).real
else:
- x = um.multiply(x, x)
+ x = um.multiply(x, x, out=x)
# add.reduce((arr - arrmean) ** 2, axis)
- ret = um.add.reduce(x, axis=axis, dtype=dtype, out=out,
- skipna=skipna, keepdims=keepdims)
+ ret = um.add.reduce(x, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
# add.reduce((arr - arrmean) ** 2, axis) / (n - ddof)
if not keepdims and isinstance(rcount, mu.ndarray):
@@ -79,19 +93,18 @@
rcount -= ddof
if isinstance(ret, mu.ndarray):
ret = um.true_divide(ret, rcount,
- casting='unsafe', subok=False)
+ out=ret, casting='unsafe', subok=False)
else:
ret = ret / float(rcount)
return ret
-def _std(a, axis=None, dtype=None, out=None, ddof=0,
- skipna=False, keepdims=False):
+def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
- skipna=skipna, keepdims=keepdims)
+ keepdims=keepdims)
if isinstance(ret, mu.ndarray):
- ret = um.sqrt(ret)
+ ret = um.sqrt(ret, out=ret)
else:
ret = um.sqrt(ret)
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -8,7 +8,7 @@
newaxis = None
-def asanyarray(a, dtype=None, order=None, maskna=None, ownmaskna=False):
+def asanyarray(a, dtype=None, order=None):
"""
Convert the input to an ndarray, but pass ndarray subclasses through.
@@ -23,13 +23,6 @@
order : {'C', 'F'}, optional
Whether to use row-major ('C') or column-major ('F') memory
representation. Defaults to 'C'.
- maskna : bool or None, optional
- If this is set to True, it forces the array to have an NA mask.
- If this is set to False, it forces the array to not have an NA
- mask.
- ownmaskna : bool, optional
- If this is set to True, forces the array to have a mask which
- it owns.
Returns
-------
@@ -65,8 +58,7 @@
True
"""
- return array(a, dtype, copy=False, order=order, subok=True,
- maskna=maskna, ownmaskna=ownmaskna)
+ return array(a, dtype, copy=False, order=order, subok=True)
def base_repr(number, base=2, padding=0):
"""
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -297,7 +297,7 @@
'output must be an array'))
else:
out = w_out
- calc_dtype = out.find_dtype()
+ calc_dtype = out.get_dtype()
if self.comparison_func:
res_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
else:
More information about the pypy-commit
mailing list