Skip to content

Commit

Permalink
Merge pull request #8524 from juliantaylor/f2-mean-fix
Browse files Browse the repository at this point in the history
BUG: fix mean for float 16 non-array inputs
  • Loading branch information
charris committed Jan 24, 2017
2 parents 81d176e + 9ae8485 commit f737b35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions numpy/core/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
ret = um.true_divide(
ret, rcount, out=ret, casting='unsafe', subok=False)
if is_float16_result and out is None:
ret = a.dtype.type(ret)
ret = arr.dtype.type(ret)
elif hasattr(ret, 'dtype'):
if is_float16_result:
ret = a.dtype.type(ret / rcount)
ret = arr.dtype.type(ret / rcount)
else:
ret = ret.dtype.type(ret / rcount)
else:
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4407,6 +4407,12 @@ def setUp(self):
self.omat = np.array([Decimal(repr(r)) for r in self.rmat.flat])
self.omat = self.omat.reshape(4, 5)

def test_python_type(self):
for x in (np.float16(1.), 1, 1., 1+0j):
assert_equal(np.mean([x]), 1.)
assert_equal(np.std([x]), 0.)
assert_equal(np.var([x]), 0.)

def test_keepdims(self):
mat = np.eye(3)
for f in self.funcs:
Expand Down

0 comments on commit f737b35

Please sign in to comment.