[pypy-commit] pypy numpy-subarrays: Make the creation of subarrays at applevel possible
rguillebert
noreply at buildbot.pypy.org
Tue May 14 14:41:27 CEST 2013
Author: Romain Guillebert <romain.py at gmail.com>
Branch: numpy-subarrays
Changeset: r64069:e90bb7b49080
Date: 2013-05-14 14:40 +0200
http://bitbucket.org/pypy/pypy/changeset/e90bb7b49080/
Log: Make the creation of subarrays at applevel possible
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -349,10 +349,12 @@
# w_align and w_copy are necessary for pickling
cache = get_dtype_cache(space)
- if w_shape is not None and space.len_w(w_shape) > 0:
+ if w_shape is not None and (space.isinstance_w(w_shape, space.w_int) or space.len_w(w_shape) > 0):
subdtype = descr__new__(space, w_subtype, w_dtype, w_align, w_copy)
assert isinstance(subdtype, W_Dtype)
size = 1
+ if space.isinstance_w(w_shape, space.w_int):
+ w_shape = space.newtuple([w_shape])
shape = space.listview(w_shape)
for dim in shape:
size *= space.int_w(dim)
@@ -377,6 +379,8 @@
"data type %s not understood" % name))
elif space.isinstance_w(w_dtype, space.w_list):
return dtype_from_list(space, w_dtype)
+ elif space.isinstance_w(w_dtype, space.w_tuple):
+ return descr__new__(space, w_subtype, space.getitem(w_dtype, space.wrap(0)), w_align, w_copy, w_shape=space.getitem(w_dtype, space.wrap(1)))
elif space.isinstance_w(w_dtype, space.w_dict):
return dtype_from_dict(space, w_dtype)
for dtype in cache.builtin_dtypes:
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
@@ -804,6 +804,11 @@
assert e.fields.keys() == keys
assert e['x'].shape == (2,)
+ dt = dtype((float, 10))
+ assert dt.shape == (10,)
+ assert dt.kind == 'V'
+ assert dt.fields == None
+ assert dt.subdtype == (dtype("float64"), (10,))
class AppTestNotDirect(BaseNumpyAppTest):
def setup_class(cls):
More information about the pypy-commit
mailing list