[pypy-commit] pypy fix-result-types: Fix inplace operations on arrays in cases where an unsafe cast is needed
rlamy
noreply at buildbot.pypy.org
Fri May 29 19:33:00 CEST 2015
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: fix-result-types
Changeset: r77697:23b0d856e8fc
Date: 2015-05-29 18:32 +0100
http://bitbucket.org/pypy/pypy/changeset/23b0d856e8fc/
Log: Fix inplace operations on arrays in cases where an unsafe cast is
needed
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -240,7 +240,7 @@
# TODO: support all kwargs in ufuncs like numpy ufunc_object.c
sig = None
- cast = None
+ cast = 'unsafe'
extobj = None
def _unaryop_impl(ufunc_name):
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -896,7 +896,7 @@
# --------------------- operations ----------------------------
# TODO: support all kwargs like numpy ufunc_object.c
sig = None
- cast = None
+ cast = 'unsafe'
extobj = None
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -997,7 +997,7 @@
r = [1, 2] + array([1, 2])
assert (r == [2, 4]).all()
- def test_inline_op_scalar(self):
+ def test_inplace_op_scalar(self):
from numpy import array
for op in [
'__iadd__',
@@ -1016,7 +1016,7 @@
getattr(a, op).__call__(2)
assert id(a) == id(b)
- def test_inline_op_array(self):
+ def test_inplace_op_array(self):
from numpy import array
for op in [
'__iadd__',
@@ -1040,6 +1040,14 @@
for i in range(5):
assert a[i] == getattr(c[i], reg_op).__call__(d[i])
+ def test_inplace_cast(self):
+ import numpy as np
+ a = np.zeros(5, dtype=np.float64)
+ b = np.zeros(5, dtype=np.complex64)
+ a += b
+ assert a.sum() == 0
+ assert a.dtype is np.dtype(np.float64)
+
def test_add_list(self):
from numpy import array, ndarray
a = array(range(5))
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -424,6 +424,7 @@
return space.getattr(w_obj, space.wrap('__' + refops[op] + '__')) is not None
def safe_casting_mode(casting):
+ assert casting is not None
if casting in ('unsafe', 'same_kind'):
return 'safe'
else:
More information about the pypy-commit
mailing list