[pypy-commit] pypy object-dtype2: small tweaks to dtype name, customtrace; add (failing) tests
mattip
noreply at buildbot.pypy.org
Fri Apr 3 08:02:46 CEST 2015
Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76694:be19ae2bdd93
Date: 2015-04-01 23:22 +0300
http://bitbucket.org/pypy/pypy/changeset/be19ae2bdd93/
Log: small tweaks to dtype name, customtrace; add (failing) tests
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
@@ -868,7 +868,7 @@
__len__ = interp2app(W_UnicodeBox.descr_len),
)
-W_ObjectBox.typedef = TypeDef("numpy.object", W_ObjectBox.typedef,
+W_ObjectBox.typedef = TypeDef("numpy.object_", W_ObjectBox.typedef,
__new__ = interp2app(W_ObjectBox.descr__new__.im_func),
__getattr__ = interp2app(W_ObjectBox.descr__getattr__),
)
diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -346,15 +346,12 @@
def customtrace(gc, obj, callback, arg):
#debug_print('in customtrace w/obj', obj)
- length = rffi.cast(rffi.SIGNEDP, obj + offset_of_length)[0]
- step = rffi.cast(rffi.SIGNEDP, obj + offset_of_step)[0]
+ length = (obj + offset_of_length).signed[0]
+ step = (obj + offset_of_step).signed[0]
storage = (obj + offset_of_storage).address[0]
- debug_print('tracing', length, 'objects in ndarray.storage')
+ #debug_print('tracing', length, 'objects in ndarray.storage')
i = 0
while i < length:
- #gcref = rffi.cast(llmemory.GCREF, storage)
- #w_obj = cast_gcref_to_instance(W_Root, gcref)
- #debug_print('tracing', w_obj)
gc._trace_callback(callback, arg, storage)
storage += step
i += 1
@@ -369,7 +366,7 @@
gcstruct = lltype.malloc(OBJECTSTORE)
# JIT does not support cast_ptr_to_adr
gcstruct.storage = llmemory.cast_ptr_to_adr(storage)
- print 'create gcstruct',gcstruct,'with storage',storage,'as',gcstruct.storage
+ #print 'create gcstruct',gcstruct,'with storage',storage,'as',gcstruct.storage
gcstruct.length = length
gcstruct.step = elsize
return gcstruct
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
@@ -1350,42 +1350,4 @@
assert a[0] == 1
assert (a + a)[1] == 4
-class AppTestObjectDtypes(BaseNumpyAppTest):
- def test_scalar_from_object(self):
- from numpy import array
- import sys
- class Polynomial(object):
- def whatami(self):
- return 'an object'
- a = array(Polynomial())
- assert a.shape == ()
- assert a.sum().whatami() == 'an object'
- def test_uninitialized_object_array_is_filled_by_None(self):
- import numpy as np
-
- a = np.ndarray([5], dtype="O")
-
- assert a[0] == None
-
- def test_object_arrays_add(self):
- import numpy as np
-
- a = np.array(["foo"], dtype=object)
- b = np.array(["bar"], dtype=object)
-
- res = a + b
- assert res[0] == "foobar"
-
- def test_keep_object_alive(self):
- # XXX how can I run this test?
- import numpy as np
- import gc
- class O(object):
- def whatami(self):
- return 'an object'
- fiveOs = [O()] * 5
- a = np.array(fiveOs, dtype=object)
- del fiveOs
- gc.collect()
- assert a[2].whatami() == 'an object'
diff --git a/pypy/module/micronumpy/test/test_object_arrays.py b/pypy/module/micronumpy/test/test_object_arrays.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -0,0 +1,53 @@
+from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
+
+
+class AppTestObjectDtypes(BaseNumpyAppTest):
+ def test_scalar_from_object(self):
+ from numpy import array
+ import sys
+ class Polynomial(object):
+ def whatami(self):
+ return 'an object'
+ a = array(Polynomial())
+ assert a.shape == ()
+ assert a.sum().whatami() == 'an object'
+
+ def test_uninitialized_object_array_is_filled_by_None(self):
+ import numpy as np
+
+ a = np.ndarray([5], dtype="O")
+
+ assert a[0] == None
+
+ def test_object_arrays_add(self):
+ import numpy as np
+
+ a = np.array(["foo"], dtype=object)
+ b = np.array(["bar"], dtype=object)
+
+ res = a + b
+ assert res[0] == "foobar"
+
+ def test_reduce(self):
+ import numpy as np
+ class O(object):
+ def whatami(self):
+ return 'an object'
+ fiveOs = [O()] * 5
+ a = np.array(fiveOs, dtype=object)
+ print np.maximum
+ b = np.maximum.reduce(a)
+ assert b is not None
+
+ def test_keep_object_alive(self):
+ # only translated does it really test the gc
+ import numpy as np
+ import gc
+ class O(object):
+ def whatami(self):
+ return 'an object'
+ fiveOs = [O()] * 5
+ a = np.array(fiveOs, dtype=object)
+ del fiveOs
+ gc.collect()
+ assert a[2].whatami() == 'an object'
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
@@ -401,7 +401,7 @@
# tests that by calling all available ufuncs on scalars, none will
# raise uncaught interp-level exceptions, (and crash the test)
# and those that are uncallable can be accounted for.
- # test on the four base-class dtypes: int, bool, float, complex
+ # test on the base-class dtypes: int, bool, float, complex, object
# We need this test since they have no common base class.
import numpy as np
def find_uncallable_ufuncs(dtype):
@@ -427,6 +427,7 @@
'fabs', 'fmod', 'invert', 'mod',
'logaddexp', 'logaddexp2', 'left_shift', 'right_shift',
'copysign', 'signbit', 'ceil', 'floor', 'trunc'])
+ assert find_uncallable_ufuncs('object') == set()
def test_int_only(self):
from numpy import bitwise_and, array
More information about the pypy-commit
mailing list