Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r69286:b744291da355 Date: 2014-02-23 02:39 -0500 http://bitbucket.org/pypy/pypy/changeset/b744291da355/
Log: support dtype from commastring diff --git a/pypy/module/micronumpy/appbridge.py b/pypy/module/micronumpy/appbridge.py --- a/pypy/module/micronumpy/appbridge.py +++ b/pypy/module/micronumpy/appbridge.py @@ -4,6 +4,7 @@ w__mean = None w__var = None w__std = None + w__commastring = None w_array_repr = None w_array_str = None 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 @@ -1,3 +1,4 @@ +from pypy.interpreter.argument import Arguments from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import interp2app, unwrap_spec @@ -8,6 +9,7 @@ from rpython.rlib.rarithmetic import LONG_BIT, r_longlong, r_ulonglong from rpython.rtyper.lltypesystem import rffi from rpython.rlib import jit +from pypy.module.micronumpy.appbridge import get_appbridge_cache from pypy.module.micronumpy.conversion_utils import byteorder_converter from pypy.module.micronumpy.constants import * @@ -391,9 +393,17 @@ "dtype from dict")) -def dtype_from_spec(space, name): - raise OperationError(space.w_NotImplementedError, space.wrap( - "dtype from spec")) +def dtype_from_spec(space, w_spec): + w_lst = get_appbridge_cache(space).call_method(space, + 'numpy.core._internal', '_commastring', Arguments(space, [w_spec])) + if not space.isinstance_w(w_lst, space.w_list) or space.len_w(w_lst) < 1: + raise oefmt(space.w_RuntimeError, + "_commastring is not returning a list with len >= 1") + if space.len_w(w_lst) == 1: + return descr__new__(space, space.gettypefor(W_Dtype), + space.getitem(w_lst, space.wrap(0))) + else: + return dtype_from_list(space, w_lst) def descr__new__(space, w_subtype, w_dtype, w_align=None, w_copy=None, w_shape=None): @@ -427,7 +437,7 @@ elif space.isinstance_w(w_dtype, space.w_str): name = space.str_w(w_dtype) if ',' in name: - return dtype_from_spec(space, name) + return dtype_from_spec(space, w_dtype) try: return cache.dtypes_by_name[name] except KeyError: diff --git a/pypy/module/micronumpy/test/test_appbridge.py b/pypy/module/micronumpy/test/test_appbridge.py --- a/pypy/module/micronumpy/test/test_appbridge.py +++ b/pypy/module/micronumpy/test/test_appbridge.py @@ -9,3 +9,10 @@ op() except ImportError as e: assert str(e) == 'No module named numpy.core' + + def test_dtype_commastring(self): + import numpy as np + try: + d = np.dtype('u4,u4,u4') + except ImportError as e: + assert str(e) == 'No module named numpy.core' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit