[pypy-commit] pypy numpypy-problems: creating string array works, add more failing tests
mattip
noreply at buildbot.pypy.org
Mon Oct 15 00:18:06 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: numpypy-problems
Changeset: r58114:194672a6657e
Date: 2012-10-15 00:17 +0200
http://bitbucket.org/pypy/pypy/changeset/194672a6657e/
Log: creating string array works, add more failing tests
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -684,6 +684,7 @@
arr = W_NDimArray.from_shape(shape, dtype, order=order)
arr_iter = arr.create_iter(arr.get_shape())
for w_elem in elems_w:
+ print 'setting',arr_iter.offset,'to',w_elem
arr_iter.setitem(dtype.coerce(space, w_elem))
arr_iter.next()
return arr
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -446,6 +446,7 @@
int64_dtype = interp_dtype.get_dtype_cache(space).w_int64dtype
complex_type = interp_dtype.get_dtype_cache(space).w_complex128dtype
float_type = interp_dtype.get_dtype_cache(space).w_float64dtype
+ str_dtype = interp_dtype.get_dtype_cache(space).w_stringdtype
if isinstance(w_obj, interp_boxes.W_GenericBox):
dtype = w_obj.get_dtype(space)
if current_guess is None:
@@ -472,6 +473,15 @@
current_guess is complex_type or current_guess is float_type):
return complex_type
return current_guess
+ elif space.isinstance_w(w_obj, space.w_str):
+ if (current_guess is None):
+ return interp_dtype.variable_dtype(space,
+ 'S%d' % space.len_w(w_obj))
+ elif current_guess.num ==18:
+ if current_guess.itemtype.size < space.len_w(w_obj):
+ return interp_dtype.variable_dtype(space,
+ 'S%d' % space.len_w(w_obj))
+ return current_guess
if current_guess is complex_type:
return complex_type
return interp_dtype.get_dtype_cache(space).w_float64dtype
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2254,6 +2254,12 @@
a = array(['abc'])
assert repr(a) == "array(['abc'])"
assert str(a.dtype) == '|S3'
+ a = array(['abc','defg','ab'])
+ assert str(a.dtype) == '|S4'
+ assert a[0] == 'abc'
+ assert a[1] == 'defg'
+ assert a[2] == 'ab'
+ assert repr(a) == "array(['abc', 'defg', ab'])"
class AppTestPyPy(BaseNumpyAppTest):
More information about the pypy-commit
mailing list