[pypy-commit] pypy numpy-refactor: merge default
bdkearns
noreply at buildbot.pypy.org
Thu Feb 27 13:17:40 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: numpy-refactor
Changeset: r69511:fa46e3fc1775
Date: 2014-02-27 06:59 -0500
http://bitbucket.org/pypy/pypy/changeset/fa46e3fc1775/
Log: merge default
diff --git a/lib-python/2.7/test/test_os.py b/lib-python/2.7/test/test_os.py
--- a/lib-python/2.7/test/test_os.py
+++ b/lib-python/2.7/test/test_os.py
@@ -129,9 +129,13 @@
fp = os.tmpfile()
except OSError, second:
self.assertEqual(first.args, second.args)
+ return
else:
- self.fail("expected os.tmpfile() to raise OSError")
- return
+ if test_support.check_impl_detail(pypy=False):
+ self.fail("expected os.tmpfile() to raise OSError")
+ # on PyPy, os.tmpfile() uses the tempfile module
+ # anyway, so works even if we cannot write in root.
+ fp.close()
else:
# open() worked, therefore, tmpfile() should work. Close our
# dummy file and proceed with the test as normal.
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -122,11 +122,13 @@
@entrypoint('main', [rffi.CCHARP], c_name='pypy_execute_source')
def pypy_execute_source(ll_source):
- rffi.aroundstate.after()
+ after = rffi.aroundstate.after
+ if after: after()
llop.gc_stack_bottom(lltype.Void)
source = rffi.charp2str(ll_source)
res = _pypy_execute_source(source)
- rffi.aroundstate.before()
+ before = rffi.aroundstate.before
+ if before: before()
return rffi.cast(rffi.INT, res)
@entrypoint('main', [], c_name='pypy_init_threads')
@@ -134,7 +136,8 @@
if not space.config.objspace.usemodules.thread:
return
os_thread.setup_threads(space)
- rffi.aroundstate.before()
+ before = rffi.aroundstate.before
+ if before: before()
@entrypoint('main', [], c_name='pypy_thread_attach')
def pypy_thread_attach():
@@ -145,7 +148,8 @@
rthread.gc_thread_start()
os_thread.bootstrapper.nbthreads += 1
os_thread.bootstrapper.release()
- rffi.aroundstate.before()
+ before = rffi.aroundstate.before
+ if before: before()
w_globals = space.newdict()
space.setitem(w_globals, space.wrap('__builtins__'),
diff --git a/pypy/module/micronumpy/arrayops.py b/pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -1,12 +1,12 @@
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.gateway import unwrap_spec
+from pypy.module.micronumpy import loop, descriptor, ufuncs, support, \
+ constants as NPY
from pypy.module.micronumpy.base import convert_to_array, W_NDimArray
-from pypy.module.micronumpy import loop, descriptor, ufuncs
+from pypy.module.micronumpy.converters import clipmode_converter
from pypy.module.micronumpy.strides import Chunk, Chunks, shape_agreement, \
shape_agreement_multiple
-from pypy.interpreter.error import OperationError, oefmt
-from pypy.interpreter.gateway import unwrap_spec
-from pypy.module.micronumpy.converters import clipmode_converter
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy import constants as NPY
+
def where(space, w_arr, w_x=None, w_y=None):
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -1,7 +1,6 @@
+from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError
-from pypy.interpreter.baseobjspace import W_Root
from rpython.tool.pairtype import extendabletype
-from pypy.module.micronumpy.support import calc_strides
def wrap_impl(space, w_cls, w_instance, impl):
@@ -31,9 +30,10 @@
@staticmethod
def from_shape(space, shape, dtype, order='C', w_instance=None):
from pypy.module.micronumpy import concrete
+ from pypy.module.micronumpy.strides import calc_strides
strides, backstrides = calc_strides(shape, dtype.base, order)
impl = concrete.ConcreteArray(shape, dtype.base, order, strides,
- backstrides)
+ backstrides)
if w_instance:
return wrap_impl(space, space.type(w_instance), w_instance, impl)
return W_NDimArray(impl)
@@ -42,6 +42,7 @@
def from_shape_and_storage(space, shape, storage, dtype, order='C', owning=False,
w_subtype=None, w_base=None, writable=True):
from pypy.module.micronumpy import concrete
+ from pypy.module.micronumpy.strides import calc_strides
strides, backstrides = calc_strides(shape, dtype, order)
if w_base is not None:
if owning:
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
@@ -1,23 +1,22 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.objspace.std.bytesobject import W_BytesObject
+from pypy.objspace.std.complextype import complex_typedef
from pypy.objspace.std.floattype import float_typedef
+from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
-from pypy.objspace.std.intobject import W_IntObject
-from pypy.objspace.std.complextype import complex_typedef
from rpython.rlib.rarithmetic import LONG_BIT
-from rpython.rtyper.lltypesystem import rffi
-from rpython.tool.sourcetools import func_with_new_name
-from pypy.module.micronumpy.concrete import VoidBoxStorage
-from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy.flagsobj import W_FlagsObject
-from pypy.interpreter.mixedmodule import MixedModule
-from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.objectmodel import specialize
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.tool.sourcetools import func_with_new_name
from pypy.module.micronumpy import constants as NPY
+from pypy.module.micronumpy.base import W_NDimArray
+from pypy.module.micronumpy.concrete import VoidBoxStorage
+from pypy.module.micronumpy.flagsobj import W_FlagsObject
MIXIN_32 = (W_IntObject.typedef,) if LONG_BIT == 32 else ()
diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -1,20 +1,17 @@
""" This is a set of tools for standalone compiling of numpy expressions.
It should not be imported by the module itself
"""
-
import re
-
from pypy.interpreter import special
from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
from pypy.interpreter.error import OperationError
-from pypy.module.micronumpy import boxes
-from pypy.module.micronumpy.descriptor import get_dtype_cache
+from rpython.rlib.objectmodel import specialize, instantiate
+from rpython.rlib.nonconst import NonConstant
+from pypy.module.micronumpy import boxes, ufuncs
+from pypy.module.micronumpy.arrayops import where
from pypy.module.micronumpy.base import W_NDimArray
from pypy.module.micronumpy.ctors import array
-from pypy.module.micronumpy.arrayops import where
-from pypy.module.micronumpy import ufuncs
-from rpython.rlib.objectmodel import specialize, instantiate
-from rpython.rlib.nonconst import NonConstant
+from pypy.module.micronumpy.descriptor import get_dtype_cache
class BogusBytecode(Exception):
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
@@ -1,16 +1,16 @@
-from pypy.module.micronumpy import support, loop, iter
-from pypy.module.micronumpy.base import convert_to_array, W_NDimArray,\
- ArrayArgumentException
-from pypy.module.micronumpy.strides import (Chunk, Chunks, NewAxisChunk,
- RecordChunk, calc_new_strides, shape_agreement, calculate_broadcast_strides,
- calculate_dot_strides)
+from pypy.interpreter.buffer import RWBuffer
from pypy.interpreter.error import OperationError, oefmt
-from pypy.interpreter.buffer import RWBuffer
from rpython.rlib import jit
-from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib.rawstorage import alloc_raw_storage, free_raw_storage, \
raw_storage_getitem, raw_storage_setitem, RAW_STORAGE
-from rpython.rlib.debug import make_sure_not_resized
+from rpython.rtyper.lltypesystem import rffi, lltype
+from pypy.module.micronumpy import support, loop, iter
+from pypy.module.micronumpy.base import convert_to_array, W_NDimArray, \
+ ArrayArgumentException
+from pypy.module.micronumpy.strides import (Chunk, Chunks, NewAxisChunk,
+ RecordChunk, calc_strides, calc_new_strides, shape_agreement,
+ calculate_broadcast_strides, calculate_dot_strides)
class BaseConcreteArray(object):
@@ -61,10 +61,12 @@
def get_storage_size(self):
return self.size
- def reshape(self, space, orig_array, new_shape):
+ def reshape(self, orig_array, new_shape):
# Since we got to here, prod(new_shape) == self.size
new_strides = None
- if self.size > 0:
+ if self.size == 0:
+ new_strides, _ = calc_strides(new_shape, self.dtype, self.order)
+ else:
if len(self.get_shape()) == 0:
new_strides = [self.dtype.elsize] * len(new_shape)
else:
@@ -81,7 +83,7 @@
new_shape, self, orig_array)
def get_view(self, space, orig_array, dtype, new_shape):
- strides, backstrides = support.calc_strides(new_shape, dtype,
+ strides, backstrides = calc_strides(new_shape, dtype,
self.order)
return SliceArray(self.start, strides, backstrides, new_shape,
self, orig_array, dtype=dtype)
@@ -268,7 +270,7 @@
backstrides, shape, self, orig_array)
def copy(self, space):
- strides, backstrides = support.calc_strides(self.get_shape(), self.dtype,
+ strides, backstrides = calc_strides(self.get_shape(), self.dtype,
self.order)
impl = ConcreteArray(self.get_shape(), self.dtype, self.order, strides,
backstrides)
@@ -323,7 +325,7 @@
return ArrayBuffer(self)
def astype(self, space, dtype):
- strides, backstrides = support.calc_strides(self.get_shape(), dtype,
+ strides, backstrides = calc_strides(self.get_shape(), dtype,
self.order)
impl = ConcreteArray(self.get_shape(), dtype, self.order,
strides, backstrides)
@@ -349,7 +351,7 @@
box, 0, self.size, 0)
def set_shape(self, space, orig_array, new_shape):
- strides, backstrides = support.calc_strides(new_shape, self.dtype,
+ strides, backstrides = calc_strides(new_shape, self.dtype,
self.order)
return SliceArray(0, strides, backstrides, new_shape, self,
orig_array)
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
@@ -1,16 +1,14 @@
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
+from rpython.rlib.rstring import strip_spaces
from rpython.rtyper.lltypesystem import lltype, rffi
-from pypy.module.micronumpy import descriptor, loop
-from rpython.rlib.rstring import strip_spaces
-from pypy.module.micronumpy import ufuncs
+from pypy.module.micronumpy import descriptor, loop, ufuncs
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
from pypy.module.micronumpy.converters import shape_converter
from pypy.module.micronumpy.strides import find_shape_and_elems
def build_scalar(space, w_dtype, w_state):
- from rpython.rtyper.lltypesystem import rffi, lltype
if not isinstance(w_dtype, descriptor.W_Dtype):
raise oefmt(space.w_TypeError,
"argument 1 must be numpy.dtype, not %T", w_dtype)
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -4,14 +4,12 @@
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
interp_attrproperty, interp_attrproperty_w)
-from pypy.module.micronumpy import types, boxes, base
+from rpython.rlib import jit
from rpython.rlib.objectmodel import specialize
from rpython.rlib.rarithmetic import r_longlong, r_ulonglong
-from rpython.rlib import jit
+from pypy.module.micronumpy import types, boxes, base, support, constants as NPY
from pypy.module.micronumpy.appbridge import get_appbridge_cache
from pypy.module.micronumpy.converters import byteorder_converter
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy import constants as NPY
def decode_w_dtype(space, w_dtype):
diff --git a/pypy/module/micronumpy/flagsobj.py b/pypy/module/micronumpy/flagsobj.py
--- a/pypy/module/micronumpy/flagsobj.py
+++ b/pypy/module/micronumpy/flagsobj.py
@@ -1,7 +1,7 @@
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.error import OperationError
class W_FlagsObject(W_Root):
diff --git a/pypy/module/micronumpy/flatiter.py b/pypy/module/micronumpy/flatiter.py
--- a/pypy/module/micronumpy/flatiter.py
+++ b/pypy/module/micronumpy/flatiter.py
@@ -1,7 +1,7 @@
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.module.micronumpy import loop
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
-from pypy.module.micronumpy import loop
from pypy.module.micronumpy.concrete import BaseConcreteArray
-from pypy.interpreter.error import OperationError, oefmt
class FakeArrayImplementation(BaseConcreteArray):
diff --git a/pypy/module/micronumpy/iter.py b/pypy/module/micronumpy/iter.py
--- a/pypy/module/micronumpy/iter.py
+++ b/pypy/module/micronumpy/iter.py
@@ -40,9 +40,9 @@
but then we cannot guarantee that we only overflow one single shape
dimension, perhaps we could overflow times in one big step.
"""
+from rpython.rlib import jit
+from pypy.module.micronumpy import support
from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy import support
-from rpython.rlib import jit
class PureShapeIterator(object):
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -2,15 +2,14 @@
operations. This is the place to look for all the computations that iterate
over all the array elements.
"""
-
-from rpython.rlib.rstring import StringBuilder
from pypy.interpreter.error import OperationError
from rpython.rlib import jit
+from rpython.rlib.rstring import StringBuilder
from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.module.micronumpy import support, constants as NPY
from pypy.module.micronumpy.base import W_NDimArray
from pypy.module.micronumpy.iter import PureShapeIterator
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy import constants as NPY
+
call2_driver = jit.JitDriver(name='numpy_call2',
greens = ['shapelen', 'func', 'calc_dtype',
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -1,27 +1,25 @@
-from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.rawstorage import RAW_STORAGE_PTR
from pypy.interpreter.error import OperationError, oefmt
-from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
from pypy.interpreter.gateway import interp2app, unwrap_spec, applevel, \
WrappedDefault
-from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
- ArrayArgumentException, wrap_impl
-from pypy.module.micronumpy import descriptor, ufuncs, boxes, arrayops
-from pypy.module.micronumpy.strides import get_shape_from_iterable, to_coords, \
- shape_agreement, shape_agreement_multiple
-from pypy.module.micronumpy.flagsobj import W_FlagsObject
-from pypy.module.micronumpy.flatiter import W_FlatIterator
-from pypy.module.micronumpy.appbridge import get_appbridge_cache
-from pypy.module.micronumpy import loop
-from pypy.module.micronumpy.arrayops import repeat, choose, put
-from rpython.tool.sourcetools import func_with_new_name
+from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
from rpython.rlib import jit
from rpython.rlib.rstring import StringBuilder
+from rpython.rlib.rawstorage import RAW_STORAGE_PTR
+from rpython.rtyper.lltypesystem import rffi
+from rpython.tool.sourcetools import func_with_new_name
+from pypy.module.micronumpy import descriptor, ufuncs, boxes, arrayops, loop, \
+ support, constants as NPY
+from pypy.module.micronumpy.appbridge import get_appbridge_cache
+from pypy.module.micronumpy.arrayops import repeat, choose, put
+from pypy.module.micronumpy.base import W_NDimArray, convert_to_array, \
+ ArrayArgumentException, wrap_impl
from pypy.module.micronumpy.concrete import BaseConcreteArray
from pypy.module.micronumpy.converters import order_converter, shape_converter, \
multi_axis_converter
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy import constants as NPY
+from pypy.module.micronumpy.flagsobj import W_FlagsObject
+from pypy.module.micronumpy.flatiter import W_FlatIterator
+from pypy.module.micronumpy.strides import get_shape_from_iterable, to_coords, \
+ shape_agreement, shape_agreement_multiple
def _match_dot_shapes(space, left, right):
@@ -224,7 +222,10 @@
self.implementation.setitem_index(space, index_list, w_value)
def descr_setitem(self, space, w_idx, w_value):
- if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool() \
+ if space.is_w(w_idx, space.w_Ellipsis):
+ self.implementation.setslice(space, convert_to_array(space, w_value))
+ return
+ elif isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool() \
and len(w_idx.get_shape()) > 0:
self.setitem_filter(space, w_idx, convert_to_array(space, w_value))
return
@@ -340,14 +341,13 @@
def reshape(self, space, w_shape):
new_shape = get_shape_from_iterable(space, self.get_size(), w_shape)
- new_impl = self.implementation.reshape(space, self, new_shape)
+ new_impl = self.implementation.reshape(self, new_shape)
if new_impl is not None:
return wrap_impl(space, space.type(self), self, new_impl)
# Create copy with contiguous data
arr = self.descr_copy(space)
if arr.get_size() > 0:
- arr.implementation = arr.implementation.reshape(space, self,
- new_shape)
+ arr.implementation = arr.implementation.reshape(self, new_shape)
assert arr.implementation
else:
arr.implementation.shape = new_shape
@@ -381,6 +381,8 @@
raise OperationError(space.w_NotImplementedError, space.wrap(
"unsupported value for order"))
if len(args_w) == 1:
+ if space.is_none(args_w[0]):
+ return self.descr_view(space)
w_shape = args_w[0]
else:
w_shape = space.newtuple(args_w)
@@ -1129,7 +1131,7 @@
def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
offset=0, w_strides=None, w_order=None):
from pypy.module.micronumpy.concrete import ConcreteArray
- from pypy.module.micronumpy.support import calc_strides
+ from pypy.module.micronumpy.strides import calc_strides
dtype = space.interp_w(descriptor.W_Dtype,
space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
shape = shape_converter(space, w_shape, dtype)
diff --git a/pypy/module/micronumpy/sort.py b/pypy/module/micronumpy/sort.py
--- a/pypy/module/micronumpy/sort.py
+++ b/pypy/module/micronumpy/sort.py
@@ -1,18 +1,16 @@
-
""" This is the implementation of various sorting routines in numpy. It's here
because it only makes sense on a concrete array
"""
-
-from rpython.rtyper.lltypesystem import rffi, lltype
+from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib.listsort import make_timsort_class
+from rpython.rlib.objectmodel import specialize
+from rpython.rlib.rarithmetic import widen
from rpython.rlib.rawstorage import raw_storage_getitem, raw_storage_setitem, \
free_raw_storage, alloc_raw_storage
from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.rarithmetic import widen
-from rpython.rlib.objectmodel import specialize
-from pypy.interpreter.error import OperationError, oefmt
+from rpython.rtyper.lltypesystem import rffi, lltype
+from pypy.module.micronumpy import descriptor, types, constants as NPY
from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy import descriptor, types, constants as NPY
from pypy.module.micronumpy.iter import AxisIterator
INT_SIZE = rffi.sizeof(lltype.Signed)
@@ -125,7 +123,7 @@
# note that it's fine ot pass None here as we're not going
# to pass the result around (None is the link to base in slices)
if arr.get_size() > 0:
- arr = arr.reshape(space, None, [arr.get_size()])
+ arr = arr.reshape(None, [arr.get_size()])
axis = 0
elif w_axis is None:
axis = -1
@@ -276,7 +274,7 @@
if w_axis is space.w_None:
# note that it's fine to pass None here as we're not going
# to pass the result around (None is the link to base in slices)
- arr = arr.reshape(space, None, [arr.get_size()])
+ arr = arr.reshape(None, [arr.get_size()])
axis = 0
elif w_axis is None:
axis = -1
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -1,8 +1,7 @@
+from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib import jit
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.module.micronumpy import support, constants as NPY
from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy import constants as NPY
# structures to describe slicing
@@ -21,7 +20,6 @@
# ofs only changes start
# create a view of the original array by extending
# the shape, strides, backstrides of the array
- from pypy.module.micronumpy.support import calc_strides
strides, backstrides = calc_strides(subdtype.shape,
subdtype.subdtype, arr.order)
final_shape = arr.shape + subdtype.shape
@@ -345,6 +343,25 @@
return new_shape
+ at jit.unroll_safe
+def calc_strides(shape, dtype, order):
+ strides = []
+ backstrides = []
+ s = 1
+ shape_rev = shape[:]
+ if order == 'C':
+ shape_rev.reverse()
+ for sh in shape_rev:
+ slimit = max(sh, 1)
+ strides.append(s * dtype.elsize)
+ backstrides.append(s * (slimit - 1) * dtype.elsize)
+ s *= slimit
+ if order == 'C':
+ strides.reverse()
+ backstrides.reverse()
+ return strides, backstrides
+
+
# Recalculating strides. Find the steps that the iteration does for each
# dimension, given the stride and shape. Then try to create a new stride that
# fits the new shape, using those steps. If there is a shape/step mismatch
diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -1,5 +1,5 @@
+from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib import jit
-from pypy.interpreter.error import OperationError, oefmt
def issequence_w(space, w_obj):
@@ -25,22 +25,3 @@
for x in s:
i *= x
return i
-
-
- at jit.unroll_safe
-def calc_strides(shape, dtype, order):
- strides = []
- backstrides = []
- s = 1
- shape_rev = shape[:]
- if order == 'C':
- shape_rev.reverse()
- for sh in shape_rev:
- slimit = max(sh, 1)
- strides.append(s * dtype.elsize)
- backstrides.append(s * (slimit - 1) * dtype.elsize)
- s *= slimit
- if order == 'C':
- strides.reverse()
- backstrides.reverse()
- return strides, backstrides
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -844,6 +844,23 @@
b = a.reshape(s)
assert b.shape == s
assert (b == [1]).all()
+ a = array(1.5)
+ b = a.reshape(None)
+ assert b is not a
+ assert b == a
+ b[...] = 2.5
+ assert a == 2.5
+ a = array([]).reshape((0, 2))
+ assert a.shape == (0, 2)
+ assert a.strides == (16, 8)
+ a = array([])
+ a.shape = (4, 0, 3, 0, 0, 2)
+ assert a.strides == (48, 48, 16, 16, 16, 8)
+ a = array(1.5)
+ assert a.reshape(()).shape == ()
+ a = array(1.5)
+ a.shape = ()
+ assert a.strides == ()
a = array(range(12))
exc = raises(ValueError, "b = a.reshape(())")
assert str(exc.value) == "total size of new array must be unchanged"
@@ -2303,12 +2320,12 @@
import numpy as np
a = np.array(1.5)
assert a[...] is a
- #a[...] = 2.5
- #assert a == 2.5
+ a[...] = 2.5
+ assert a == 2.5
a = np.array([1, 2, 3])
assert a[...] is a
- #a[...] = 4
- #assert (a == [4, 4, 4]).all()
+ a[...] = 4
+ assert (a == [4, 4, 4]).all()
class AppTestNumArrayFromBuffer(BaseNumpyAppTest):
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1,32 +1,31 @@
import functools
import math
-
from pypy.interpreter.error import OperationError, oefmt
-from pypy.module.micronumpy import boxes
-from pypy.module.micronumpy import support
-from pypy.module.micronumpy.concrete import SliceArray, VoidBoxStorage
from pypy.objspace.std.floatobject import float2string
from pypy.objspace.std.complexobject import str_format
-from rpython.rlib import rfloat, clibffi, rcomplex
-from rpython.rlib.rawstorage import (alloc_raw_storage,
- raw_storage_getitem_unaligned, raw_storage_setitem_unaligned)
+from rpython.rlib import clibffi, jit, rfloat, rcomplex
from rpython.rlib.objectmodel import specialize
from rpython.rlib.rarithmetic import widen, byteswap, r_ulonglong, \
most_neg_value_of, LONG_BIT
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.rstruct.runpack import runpack
-from rpython.rlib.rstruct.nativefmttable import native_is_bigendian
+from rpython.rlib.rawstorage import (alloc_raw_storage,
+ raw_storage_getitem_unaligned, raw_storage_setitem_unaligned)
+from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rstruct.ieee import (float_pack, float_unpack, unpack_float,
pack_float80, unpack_float80)
+from rpython.rlib.rstruct.nativefmttable import native_is_bigendian
+from rpython.rlib.rstruct.runpack import runpack
+from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.tool.sourcetools import func_with_new_name
-from rpython.rlib import jit
-from rpython.rlib.rstring import StringBuilder
+from pypy.module.micronumpy import boxes
+from pypy.module.micronumpy.concrete import SliceArray, VoidBoxStorage
+from pypy.module.micronumpy.strides import calc_strides
degToRad = math.pi / 180.0
log2 = math.log(2)
log2e = 1. / log2
log10 = math.log(10)
+
def simple_unary_op(func):
specialize.argtype(1)(func)
@functools.wraps(func)
@@ -1792,8 +1791,8 @@
from pypy.module.micronumpy.base import W_NDimArray
if dtype is None:
dtype = arr.dtype
- strides, backstrides = support.calc_strides(dtype.shape,
- dtype.subdtype, arr.order)
+ strides, backstrides = calc_strides(dtype.shape, dtype.subdtype,
+ arr.order)
implementation = SliceArray(i + offset, strides, backstrides,
dtype.shape, arr, W_NDimArray(arr),
dtype.subdtype)
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -2,13 +2,12 @@
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
-from pypy.module.micronumpy import boxes, descriptor, loop
from rpython.rlib import jit
from rpython.rlib.rarithmetic import LONG_BIT, maxint
from rpython.tool.sourcetools import func_with_new_name
+from pypy.module.micronumpy import boxes, descriptor, loop, constants as NPY
+from pypy.module.micronumpy.base import convert_to_array, W_NDimArray
from pypy.module.micronumpy.strides import shape_agreement
-from pypy.module.micronumpy.base import convert_to_array, W_NDimArray
-from pypy.module.micronumpy import constants as NPY
def done_if_true(dtype, val):
diff --git a/rpython/rtyper/test/test_generator.py b/rpython/rtyper/test/test_generator.py
--- a/rpython/rtyper/test/test_generator.py
+++ b/rpython/rtyper/test/test_generator.py
@@ -88,16 +88,3 @@
return s
res = self.interpret(g, [])
assert res == 6
-
- def test_send(self):
- def f():
- yield (yield 1) + 1
- def g():
- gen = f()
- res = f.send(2)
- assert res == 1
- res = f.next()
- assert res == 3
-
- res = self.interpret(g, [])
-
More information about the pypy-commit
mailing list