Author: Ronan Lamy <ronan.l...@gmail.com> Branch: issue-2148 Changeset: r79983:8ead82751615 Date: 2015-10-04 23:30 +0100 http://bitbucket.org/pypy/pypy/changeset/8ead82751615/
Log: Begin creating fast path for scalars in numpify() diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py --- a/pypy/module/micronumpy/ctors.py +++ b/pypy/module/micronumpy/ctors.py @@ -9,6 +9,7 @@ W_NDimArray, convert_to_array, W_NumpyObject) from pypy.module.micronumpy.converters import shape_converter from . import constants as NPY +from .casting import scalar2dtype def build_scalar(space, w_dtype, w_state): @@ -173,8 +174,12 @@ if w_array is not None: return w_array - shape, elems_w = find_shape_and_elems(space, w_object, None) - dtype = find_dtype_for_seq(space, elems_w, None) + if is_scalar_like(space, w_object, dtype=None): + shape, elems_w = [], [w_object] + dtype = scalar2dtype(space, w_object) + else: + shape, elems_w = _find_shape_and_elems(space, w_object) + dtype = find_dtype_for_seq(space, elems_w, None) if dtype is None: dtype = descriptor.get_dtype_cache(space).w_float64dtype elif dtype.is_str_or_unicode() and dtype.elsize < 1: @@ -206,7 +211,7 @@ return True return False -def _find_shape_and_elems(space, w_iterable, is_rec_type): +def _find_shape_and_elems(space, w_iterable, is_rec_type=False): from pypy.objspace.std.bufferobject import W_Buffer shape = [space.len_w(w_iterable)] if space.isinstance_w(w_iterable, space.w_buffer): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit