[pypy-commit] pypy default: test, fix failures due to dtype=(('O', spec)) union, demarcate probable bug in upstream frompyfunc
mattip
noreply at buildbot.pypy.org
Sat Nov 21 15:23:14 EST 2015
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r80821:dcf9a1751e29
Date: 2015-11-21 22:23 +0200
http://bitbucket.org/pypy/pypy/changeset/dcf9a1751e29/
Log: test, fix failures due to dtype=(('O', spec)) union, demarcate
probable bug in upstream frompyfunc
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -422,6 +422,10 @@
if space.is_w(self, w_other):
return True
if isinstance(w_other, W_Dtype):
+ if self.is_object() and w_other.is_object():
+ # ignore possible 'record' unions
+ # created from dtype(('O', spec))
+ return True
return space.eq_w(self.descr_reduce(space),
w_other.descr_reduce(space))
return False
@@ -1017,7 +1021,8 @@
raise oefmt(space.w_ValueError,
'mismatch in size of old and new data-descriptor')
retval = W_Dtype(w_dtype.itemtype, w_dtype.w_box_type,
- names=w_dtype1.names[:], fields=w_dtype1.fields.copy())
+ names=w_dtype1.names[:], fields=w_dtype1.fields.copy(),
+ elsize=w_dtype1.elsize)
return retval
if space.is_none(w_dtype):
return cache.w_float64dtype
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
@@ -1002,7 +1002,7 @@
# --------------------- operations ----------------------------
# TODO: support all kwargs like numpy ufunc_object.c
sig = None
- cast = 'unsafe'
+ cast = 'safe'
extobj = None
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -345,7 +345,7 @@
def test_can_subclass(self):
import numpy as np
- import sys
+ import sys, pickle
class xyz(np.void):
pass
assert np.dtype(xyz).name == 'xyz'
@@ -356,12 +356,18 @@
data = [(1, 'a'), (2, 'bbb')]
b = np.dtype((xyz, [('a', int), ('b', object)]))
if '__pypy__' in sys.builtin_module_names:
- raises(NotImplemented, np.array, data, dtype=b)
+ raises(NotImplementedError, np.array, data, dtype=b)
else:
arr = np.array(data, dtype=b)
assert arr[0][0] == 1
assert arr[0][1] == 'a'
-
+ b = np.dtype((xyz, [("col1", "<i4"), ("col2", "<i4"), ("col3", "<i4")]))
+ data = [(1, 2,3), (4, 5, 6)]
+ a = np.array(data, dtype=b)
+ x = pickle.loads(pickle.dumps(a))
+ assert (x == a).all()
+ assert x.dtype == a.dtype
+
def test_index(self):
import numpy as np
for dtype in [np.int8, np.int16, np.int32, np.int64]:
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -86,6 +86,7 @@
def test_frompyfunc_innerloop(self):
from numpy import ufunc, frompyfunc, arange, dtype
+ import sys
def adder(a, b):
return a+b
def sumdiff(a, b):
@@ -123,7 +124,10 @@
res = int_func12(a)
assert len(res) == 2
assert isinstance(res, tuple)
- assert all([r is None for r in res[0]]) # ??? no warning or error, just a fail?
+ if '__pypy__' in sys.builtin_module_names:
+ assert (res[0] == a).all()
+ else:
+ assert all([r is None for r in res[0]]) # ??? no warning or error, just a fail?
res = sumdiff(2 * a, a)
assert (res[0] == 3 * a).all()
assert (res[1] == a).all()
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
@@ -471,7 +471,8 @@
def find_specialization(self, space, dtype, out, casting):
if dtype.is_flexible():
- raise oefmt(space.w_TypeError, 'Not implemented for this type')
+ raise oefmt(space.w_TypeError, "ufunc '%s' did not contain a loop",
+ self.name)
if (not self.allow_bool and dtype.is_bool() or
not self.allow_complex and dtype.is_complex()):
raise oefmt(space.w_TypeError,
@@ -555,7 +556,23 @@
w_ldtype = w_lhs.get_dtype(space)
w_rdtype = w_rhs.get_dtype(space)
if w_ldtype.is_object() or w_rdtype.is_object():
- pass
+ if ((w_ldtype.is_object() and w_ldtype.is_record()) and
+ (w_rdtype.is_object() and w_rdtype.is_record())):
+ pass
+ elif ((w_ldtype.is_object() and w_ldtype.is_record()) or
+ (w_rdtype.is_object() and w_rdtype.is_record())):
+ if self.name == 'not_equal':
+ return space.wrap(True)
+ elif self.name == 'equal':
+ return space.wrap(False)
+ else:
+ msg = ("ufunc '%s' not supported for the input types, "
+ "and the inputs could not be safely coerced to "
+ "any supported types according to the casting "
+ "rule '%s'")
+ raise oefmt(space.w_TypeError, msg, self.name, casting)
+ else:
+ pass
elif w_ldtype.is_str() and w_rdtype.is_str() and \
self.bool_result:
pass
More information about the pypy-commit
mailing list