summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorMark Harfouche <mark.harfouche@gmail.com>2019-05-09 16:56:16 -0400
committerMark Harfouche <mark.harfouche@gmail.com>2019-05-09 16:56:16 -0400
commite6b68e55ab1cfa66ae046ccc949b557a94a7c366 (patch)
treec4fdb373d381e4406c13ba16ffa41b7d44806cf3 /numpy/testing/_private/utils.py
parent634d66d5c5461c6c1480e97c1d3fbc4c4ea96a00 (diff)
downloadnumpy-e6b68e55ab1cfa66ae046ccc949b557a94a7c366.tar.gz
MNT: implement assert_array_compare without converting array to python list.
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index c22348103..3953439f0 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -20,7 +20,8 @@ from warnings import WarningMessage
import pprint
from numpy.core import(
- float32, empty, arange, array_repr, ndarray, isnat, array)
+ intp, float32, empty, arange, array_repr, ndarray, isnat, array,
+ logical_not)
from numpy.lib.utils import deprecate
if sys.version_info[0] >= 3:
@@ -784,18 +785,18 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
if isinstance(val, bool):
cond = val
- reduced = [0]
+ reduced = array([0])
else:
reduced = val.ravel()
cond = reduced.all()
- reduced = reduced.tolist()
# The below comparison is a hack to ensure that fully masked
# results, for which val.ravel().all() returns np.ma.masked,
# do not trigger a failure (np.ma.masked != True evaluates as
# np.ma.masked, which is falsy).
if cond != True:
- mismatch = 100.0 * reduced.count(0) / ox.size
+ logical_not(reduced, out=reduced)
+ mismatch = 100.0 * reduced.sum(dtype=intp) / ox.size
remarks = ['Mismatch: {:.3g}%'.format(mismatch)]
with errstate(invalid='ignore', divide='ignore'):