[pypy-commit] pypy default: merge heads
arigo
noreply at buildbot.pypy.org
Tue Dec 9 16:32:07 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r74862:b32441833d66
Date: 2014-12-09 16:31 +0100
http://bitbucket.org/pypy/pypy/changeset/b32441833d66/
Log: merge heads
diff too long, truncating to 2000 out of 6151 lines
diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -6,6 +6,10 @@
C. It was developed in collaboration with Roberto De Ioris from the `uwsgi`_
project. The `PyPy uwsgi plugin`_ is a good example of using the embedding API.
+**NOTE**: As of 1st of December, PyPy comes with ``--shared`` by default
+on linux, linux64 and windows. We will make it the default on all platforms
+by the time of the next release.
+
The first thing that you need is to compile PyPy yourself with the option
``--shared``. We plan to make ``--shared`` the default in the future. Consult
the `how to compile PyPy`_ doc for details. This will result in ``libpypy.so``
diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst
--- a/pypy/doc/project-ideas.rst
+++ b/pypy/doc/project-ideas.rst
@@ -35,6 +35,13 @@
PyPy's bytearray type is very inefficient. It would be an interesting
task to look into possible optimizations on this.
+Implement AF_XXX packet types for PyPy
+--------------------------------------
+
+PyPy is missing AF_XXX types of sockets. Implementing it is easy-to-medium
+task. `bug report`_
+
+.. _`bug report`: https://bitbucket.org/pypy/pypy/issue/1942/support-for-af_xxx-sockets#more
Implement copy-on-write list slicing
------------------------------------
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -52,7 +52,8 @@
if not OPENSSL_NO_SSL2:
constants["PROTOCOL_SSLv2"] = PY_SSL_VERSION_SSL2
-constants["PROTOCOL_SSLv3"] = PY_SSL_VERSION_SSL3
+if not OPENSSL_NO_SSL3:
+ constants["PROTOCOL_SSLv3"] = PY_SSL_VERSION_SSL3
constants["PROTOCOL_SSLv23"] = PY_SSL_VERSION_SSL23
constants["PROTOCOL_TLSv1"] = PY_SSL_VERSION_TLS1
@@ -656,7 +657,7 @@
# set up context
if protocol == PY_SSL_VERSION_TLS1:
method = libssl_TLSv1_method()
- elif protocol == PY_SSL_VERSION_SSL3:
+ elif protocol == PY_SSL_VERSION_SSL3 and not OPENSSL_NO_SSL3:
method = libssl_SSLv3_method()
elif protocol == PY_SSL_VERSION_SSL2 and not OPENSSL_NO_SSL2:
method = libssl_SSLv2_method()
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
@@ -59,9 +59,9 @@
_mixin_ = True
def reduce(self, space):
- numpypy = space.getbuiltinmodule("_numpypy")
- assert isinstance(numpypy, MixedModule)
- multiarray = numpypy.get("multiarray")
+ _numpypy = space.getbuiltinmodule("_numpypy")
+ assert isinstance(_numpypy, MixedModule)
+ multiarray = _numpypy.get("multiarray")
assert isinstance(multiarray, MixedModule)
scalar = multiarray.get("scalar")
@@ -167,7 +167,7 @@
if len(args_w) >= 1:
for w_arg in args_w:
try:
- idx = support.index_w(space, w_arg)
+ support.index_w(space, w_arg)
except OperationError:
raise oefmt(space.w_TypeError, "an integer is required")
raise oefmt(space.w_ValueError, "axes don't match array")
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
@@ -34,8 +34,8 @@
SINGLE_ARG_FUNCTIONS = ["sum", "prod", "max", "min", "all", "any",
- "unegative", "flat", "tostring","count_nonzero",
- "argsort"]
+ "unegative", "flat", "tostring", "count_nonzero",
+ "argsort", "cumsum", "logical_xor_reduce"]
TWO_ARG_FUNCTIONS = ["dot", 'take', 'searchsorted']
TWO_ARG_FUNCTIONS_OR_NONE = ['view', 'astype']
THREE_ARG_FUNCTIONS = ['where']
@@ -559,6 +559,11 @@
w_res = arr.descr_any(interp.space)
elif self.name == "all":
w_res = arr.descr_all(interp.space)
+ elif self.name == "cumsum":
+ w_res = arr.descr_cumsum(interp.space)
+ elif self.name == "logical_xor_reduce":
+ logical_xor = ufuncs.get(interp.space).logical_xor
+ w_res = logical_xor.reduce(interp.space, arr, None)
elif self.name == "unegative":
neg = ufuncs.get(interp.space).negative
w_res = neg.call(interp.space, [arr])
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
@@ -286,7 +286,6 @@
def descr_hash(self, space):
return space.wrap(self._compute_hash(space, 0x345678))
-
def descr_str(self, space):
if self.fields:
return space.str(self.descr_get_descr(space))
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
@@ -22,6 +22,9 @@
def get_shape(self):
return self.shape
+ def get_size(self):
+ return self.base().get_size()
+
def create_iter(self, shape=None, backward_broadcast=False):
assert isinstance(self.base(), W_NDimArray)
return self.base().create_iter()
@@ -41,8 +44,8 @@
return space.wrap(self.state.index)
def descr_coords(self, space):
- self.state = self.iter.update(self.state)
- return space.newtuple([space.wrap(c) for c in self.state.indices])
+ coords = self.iter.indices(self.state)
+ return space.newtuple([space.wrap(c) for c in coords])
def descr_iter(self):
return self
@@ -54,7 +57,7 @@
if self.iter.done(self.state):
raise OperationError(space.w_StopIteration, space.w_None)
w_res = self.iter.getitem(self.state)
- self.state = self.iter.next(self.state)
+ self.iter.next(self.state, mutate=True)
return w_res
def descr_getitem(self, space, w_idx):
@@ -71,7 +74,7 @@
base.get_order(), w_instance=base)
return loop.flatiter_getitem(res, self.iter, state, step)
finally:
- self.state = self.iter.reset(self.state)
+ self.iter.reset(self.state, mutate=True)
def descr_setitem(self, space, w_idx, w_value):
if not (space.isinstance_w(w_idx, space.w_int) or
@@ -91,7 +94,7 @@
arr = convert_to_array(space, w_value)
loop.flatiter_setitem(space, dtype, arr, self.iter, state, step, length)
finally:
- self.state = self.iter.reset(self.state)
+ self.iter.reset(self.state, mutate=True)
W_FlatIterator.typedef = TypeDef("numpy.flatiter",
diff --git a/pypy/module/micronumpy/iterators.py b/pypy/module/micronumpy/iterators.py
--- a/pypy/module/micronumpy/iterators.py
+++ b/pypy/module/micronumpy/iterators.py
@@ -41,16 +41,6 @@
from pypy.module.micronumpy.base import W_NDimArray
from pypy.module.micronumpy.flagsobj import _update_contiguous_flags
-class OpFlag(object):
- def __init__(self):
- self.rw = ''
- self.broadcast = True
- self.force_contig = False
- self.force_align = False
- self.native_byte_order = False
- self.tmp_copy = ''
- self.allocate = False
-
class PureShapeIter(object):
def __init__(self, shape, idx_w):
@@ -87,26 +77,24 @@
class IterState(object):
- _immutable_fields_ = ['iterator', 'index', 'indices', 'offset']
+ _immutable_fields_ = ['iterator', '_indices']
def __init__(self, iterator, index, indices, offset):
self.iterator = iterator
self.index = index
- self.indices = indices
+ self._indices = indices
self.offset = offset
class ArrayIter(object):
_immutable_fields_ = ['contiguous', 'array', 'size', 'ndim_m1', 'shape_m1[*]',
'strides[*]', 'backstrides[*]', 'factors[*]',
- 'slice_shape', 'slice_stride', 'slice_backstride',
- 'track_index', 'operand_type', 'slice_operand_type']
+ 'track_index']
track_index = True
@jit.unroll_safe
- def __init__(self, array, size, shape, strides, backstrides, op_flags=OpFlag()):
- from pypy.module.micronumpy import concrete
+ def __init__(self, array, size, shape, strides, backstrides):
assert len(shape) == len(strides) == len(backstrides)
_update_contiguous_flags(array)
self.contiguous = (array.flags & NPY.ARRAY_C_CONTIGUOUS and
@@ -118,12 +106,6 @@
self.shape_m1 = [s - 1 for s in shape]
self.strides = strides
self.backstrides = backstrides
- self.slice_shape = 1
- self.slice_stride = -1
- if strides:
- self.slice_stride = strides[-1]
- self.slice_backstride = 1
- self.slice_operand_type = concrete.SliceArray
ndim = len(shape)
factors = [0] * ndim
@@ -133,32 +115,35 @@
else:
factors[ndim-i-1] = factors[ndim-i] * shape[ndim-i]
self.factors = factors
- if op_flags.rw == 'r':
- self.operand_type = concrete.ConcreteNonWritableArrayWithBase
- else:
- self.operand_type = concrete.ConcreteArrayWithBase
@jit.unroll_safe
- def reset(self, state=None):
+ def reset(self, state=None, mutate=False):
+ index = 0
if state is None:
indices = [0] * len(self.shape_m1)
else:
assert state.iterator is self
- indices = state.indices
+ indices = state._indices
for i in xrange(self.ndim_m1, -1, -1):
indices[i] = 0
- return IterState(self, 0, indices, self.array.start)
+ offset = self.array.start
+ if not mutate:
+ return IterState(self, index, indices, offset)
+ state.index = index
+ state.offset = offset
@jit.unroll_safe
- def next(self, state):
+ def next(self, state, mutate=False):
assert state.iterator is self
index = state.index
if self.track_index:
index += 1
- indices = state.indices
+ indices = state._indices
offset = state.offset
if self.contiguous:
offset += self.array.dtype.elsize
+ elif self.ndim_m1 == 0:
+ offset += self.strides[0]
else:
for i in xrange(self.ndim_m1, -1, -1):
idx = indices[i]
@@ -169,13 +154,18 @@
else:
indices[i] = 0
offset -= self.backstrides[i]
- return IterState(self, index, indices, offset)
+ if not mutate:
+ return IterState(self, index, indices, offset)
+ state.index = index
+ state.offset = offset
@jit.unroll_safe
def goto(self, index):
offset = self.array.start
if self.contiguous:
offset += index * self.array.dtype.elsize
+ elif self.ndim_m1 == 0:
+ offset += index * self.strides[0]
else:
current = index
for i in xrange(len(self.shape_m1)):
@@ -184,20 +174,20 @@
return IterState(self, index, None, offset)
@jit.unroll_safe
- def update(self, state):
+ def indices(self, state):
assert state.iterator is self
assert self.track_index
- if not self.contiguous:
- return state
+ indices = state._indices
+ if not (self.contiguous or self.ndim_m1 == 0):
+ return indices
current = state.index
- indices = state.indices
for i in xrange(len(self.shape_m1)):
if self.factors[i] != 0:
indices[i] = current / self.factors[i]
current %= self.factors[i]
else:
indices[i] = 0
- return IterState(self, state.index, indices, state.offset)
+ return indices
def done(self, state):
assert state.iterator is self
@@ -216,12 +206,6 @@
assert state.iterator is self
self.array.setitem(state.offset, elem)
- def getoperand(self, st, base):
- impl = self.operand_type
- res = impl([], self.array.dtype, self.array.order, [], [],
- self.array.storage, base)
- res.start = st.offset
- return res
def AxisIter(array, shape, axis, cumulative):
strides = array.get_strides()
@@ -245,42 +229,3 @@
size /= shape[axis]
shape[axis] = backstrides[axis] = 0
return ArrayIter(array, size, shape, array.strides, backstrides)
-
-class SliceIter(ArrayIter):
- '''
- used with external loops, getitem and setitem return a SliceArray
- view into the original array
- '''
- _immutable_fields_ = ['base', 'slice_shape[*]', 'slice_stride[*]', 'slice_backstride[*]']
-
- def __init__(self, array, size, shape, strides, backstrides, slice_shape,
- slice_stride, slice_backstride, op_flags, base):
- from pypy.module.micronumpy import concrete
- ArrayIter.__init__(self, array, size, shape, strides, backstrides, op_flags)
- self.slice_shape = slice_shape
- self.slice_stride = slice_stride
- self.slice_backstride = slice_backstride
- self.base = base
- if op_flags.rw == 'r':
- self.slice_operand_type = concrete.NonWritableSliceArray
- else:
- self.slice_operand_type = concrete.SliceArray
-
- def getitem(self, state):
- # XXX cannot be called - must return a boxed value
- assert False
-
- def getitem_bool(self, state):
- # XXX cannot be called - must return a boxed value
- assert False
-
- def setitem(self, state, elem):
- # XXX cannot be called - must return a boxed value
- assert False
-
- def getoperand(self, state, base):
- assert state.iterator is self
- impl = self.slice_operand_type
- arr = impl(state.offset, [self.slice_stride], [self.slice_backstride],
- [self.slice_shape], self.array, self.base)
- return arr
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
@@ -42,23 +42,38 @@
# TODO handle __array_priorities__ and maybe flip the order
+ if w_lhs.get_size() == 1:
+ w_left = w_lhs.get_scalar_value().convert_to(space, calc_dtype)
+ left_iter = left_state = None
+ else:
+ w_left = None
+ left_iter, left_state = w_lhs.create_iter(shape)
+ left_iter.track_index = False
+
+ if w_rhs.get_size() == 1:
+ w_right = w_rhs.get_scalar_value().convert_to(space, calc_dtype)
+ right_iter = right_state = None
+ else:
+ w_right = None
+ right_iter, right_state = w_rhs.create_iter(shape)
+ right_iter.track_index = False
+
if out is None:
out = W_NDimArray.from_shape(space, shape, res_dtype,
w_instance=lhs_for_subtype)
- left_iter, left_state = w_lhs.create_iter(shape)
- right_iter, right_state = w_rhs.create_iter(shape)
out_iter, out_state = out.create_iter(shape)
- left_iter.track_index = right_iter.track_index = False
shapelen = len(shape)
while not out_iter.done(out_state):
call2_driver.jit_merge_point(shapelen=shapelen, func=func,
calc_dtype=calc_dtype, res_dtype=res_dtype)
- w_left = left_iter.getitem(left_state).convert_to(space, calc_dtype)
- w_right = right_iter.getitem(right_state).convert_to(space, calc_dtype)
+ if left_iter:
+ w_left = left_iter.getitem(left_state).convert_to(space, calc_dtype)
+ left_state = left_iter.next(left_state)
+ if right_iter:
+ w_right = right_iter.getitem(right_state).convert_to(space, calc_dtype)
+ right_state = right_iter.next(right_state)
out_iter.setitem(out_state, func(calc_dtype, w_left, w_right).convert_to(
space, res_dtype))
- left_state = left_iter.next(left_state)
- right_state = right_iter.next(right_state)
out_state = out_iter.next(out_state)
return out
@@ -68,11 +83,12 @@
reds='auto')
def call1(space, shape, func, calc_dtype, res_dtype, w_obj, out):
+ obj_iter, obj_state = w_obj.create_iter(shape)
+ obj_iter.track_index = False
+
if out is None:
out = W_NDimArray.from_shape(space, shape, res_dtype, w_instance=w_obj)
- obj_iter, obj_state = w_obj.create_iter(shape)
out_iter, out_state = out.create_iter(shape)
- obj_iter.track_index = False
shapelen = len(shape)
while not out_iter.done(out_state):
call1_driver.jit_merge_point(shapelen=shapelen, func=func,
@@ -89,17 +105,14 @@
def setslice(space, shape, target, source):
if not shape:
- # XXX - simplify
- target_iter, target_state = target.create_iter(shape)
- source_iter, source_state = source.create_iter(shape)
dtype = target.dtype
- val = source_iter.getitem(source_state)
+ val = source.getitem(source.start)
if dtype.is_str_or_unicode():
val = dtype.coerce(space, val)
else:
val = val.convert_to(space, dtype)
- target_iter.setitem(target_state, val)
- return target
+ target.setitem(target.start, val)
+ return target
return _setslice(space, shape, target, source)
def _setslice(space, shape, target, source):
@@ -107,6 +120,7 @@
# array implementations, not arrays
target_iter, target_state = target.create_iter(shape)
source_iter, source_state = source.create_iter(shape)
+ source_iter.track_index = False
dtype = target.dtype
shapelen = len(shape)
while not target_iter.done(target_state):
@@ -152,6 +166,7 @@
def compute_reduce_cumulative(space, obj, out, calc_dtype, func, identity):
obj_iter, obj_state = obj.create_iter()
out_iter, out_state = out.create_iter()
+ out_iter.track_index = False
if identity is None:
cur_value = obj_iter.getitem(obj_state).convert_to(space, calc_dtype)
out_iter.setitem(out_state, cur_value)
@@ -225,10 +240,9 @@
state = x_state
return out
-axis_reduce__driver = jit.JitDriver(name='numpy_axis_reduce',
- greens=['shapelen',
- 'func', 'dtype'],
- reds='auto')
+axis_reduce_driver = jit.JitDriver(name='numpy_axis_reduce',
+ greens=['shapelen', 'func', 'dtype'],
+ reds='auto')
def do_axis_reduce(space, shape, func, arr, dtype, axis, out, identity, cumulative,
temp):
@@ -241,21 +255,24 @@
temp_iter = out_iter # hack
temp_state = out_state
arr_iter, arr_state = arr.create_iter()
+ arr_iter.track_index = False
if identity is not None:
identity = identity.convert_to(space, dtype)
shapelen = len(shape)
while not out_iter.done(out_state):
- axis_reduce__driver.jit_merge_point(shapelen=shapelen, func=func,
- dtype=dtype)
- assert not arr_iter.done(arr_state)
+ axis_reduce_driver.jit_merge_point(shapelen=shapelen, func=func,
+ dtype=dtype)
w_val = arr_iter.getitem(arr_state).convert_to(space, dtype)
- out_state = out_iter.update(out_state)
- if out_state.indices[axis] == 0:
+ arr_state = arr_iter.next(arr_state)
+
+ out_indices = out_iter.indices(out_state)
+ if out_indices[axis] == 0:
if identity is not None:
w_val = func(dtype, identity, w_val)
else:
cur = temp_iter.getitem(temp_state)
w_val = func(dtype, cur, w_val)
+
out_iter.setitem(out_state, w_val)
out_state = out_iter.next(out_state)
if cumulative:
@@ -263,7 +280,6 @@
temp_state = temp_iter.next(temp_state)
else:
temp_state = out_state
- arr_state = arr_iter.next(arr_state)
return out
@@ -382,9 +398,9 @@
while not arr_iter.done(arr_state):
nonzero_driver.jit_merge_point(shapelen=shapelen, dims=dims, dtype=dtype)
if arr_iter.getitem_bool(arr_state):
- arr_state = arr_iter.update(arr_state)
+ arr_indices = arr_iter.indices(arr_state)
for d in dims:
- res_iter.setitem(res_state, box(arr_state.indices[d]))
+ res_iter.setitem(res_state, box(arr_indices[d]))
res_state = res_iter.next(res_state)
arr_state = arr_iter.next(arr_state)
return res
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
@@ -1139,9 +1139,9 @@
from pypy.interpreter.mixedmodule import MixedModule
from pypy.module.micronumpy.concrete import SliceArray
- numpypy = space.getbuiltinmodule("_numpypy")
- assert isinstance(numpypy, MixedModule)
- multiarray = numpypy.get("multiarray")
+ _numpypy = space.getbuiltinmodule("_numpypy")
+ assert isinstance(_numpypy, MixedModule)
+ multiarray = _numpypy.get("multiarray")
assert isinstance(multiarray, MixedModule)
reconstruct = multiarray.get("_reconstruct")
parameters = space.newtuple([self.getclass(space), space.newtuple(
diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -6,7 +6,7 @@
from pypy.module.micronumpy import ufuncs, support, concrete
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
from pypy.module.micronumpy.descriptor import decode_w_dtype
-from pypy.module.micronumpy.iterators import ArrayIter, SliceIter, OpFlag
+from pypy.module.micronumpy.iterators import ArrayIter
from pypy.module.micronumpy.strides import (calculate_broadcast_strides,
shape_agreement, shape_agreement_multiple)
@@ -36,6 +36,16 @@
return ret
+class OpFlag(object):
+ def __init__(self):
+ self.rw = ''
+ self.broadcast = True
+ self.force_contig = False
+ self.force_align = False
+ self.native_byte_order = False
+ self.tmp_copy = ''
+ self.allocate = False
+
def parse_op_flag(space, lst):
op_flag = OpFlag()
for w_item in lst:
@@ -142,11 +152,73 @@
raise NotImplementedError('not implemented yet')
-def get_iter(space, order, arr, shape, dtype, op_flags):
+class OperandIter(ArrayIter):
+ _immutable_fields_ = ['slice_shape', 'slice_stride', 'slice_backstride',
+ 'operand_type', 'base']
+
+ def getitem(self, state):
+ # cannot be called - must return a boxed value
+ assert False
+
+ def getitem_bool(self, state):
+ # cannot be called - must return a boxed value
+ assert False
+
+ def setitem(self, state, elem):
+ # cannot be called - must return a boxed value
+ assert False
+
+
+class ConcreteIter(OperandIter):
+ def __init__(self, array, size, shape, strides, backstrides,
+ op_flags, base):
+ OperandIter.__init__(self, array, size, shape, strides, backstrides)
+ self.slice_shape = 1
+ self.slice_stride = -1
+ if strides:
+ self.slice_stride = strides[-1]
+ self.slice_backstride = 1
+ if op_flags.rw == 'r':
+ self.operand_type = concrete.ConcreteNonWritableArrayWithBase
+ else:
+ self.operand_type = concrete.ConcreteArrayWithBase
+ self.base = base
+
+ def getoperand(self, state):
+ assert state.iterator is self
+ impl = self.operand_type
+ res = impl([], self.array.dtype, self.array.order, [], [],
+ self.array.storage, self.base)
+ res.start = state.offset
+ return res
+
+
+class SliceIter(OperandIter):
+ def __init__(self, array, size, shape, strides, backstrides, slice_shape,
+ slice_stride, slice_backstride, op_flags, base):
+ OperandIter.__init__(self, array, size, shape, strides, backstrides)
+ self.slice_shape = slice_shape
+ self.slice_stride = slice_stride
+ self.slice_backstride = slice_backstride
+ if op_flags.rw == 'r':
+ self.operand_type = concrete.NonWritableSliceArray
+ else:
+ self.operand_type = concrete.SliceArray
+ self.base = base
+
+ def getoperand(self, state):
+ assert state.iterator is self
+ impl = self.operand_type
+ arr = impl(state.offset, [self.slice_stride], [self.slice_backstride],
+ [self.slice_shape], self.array, self.base)
+ return arr
+
+
+def get_iter(space, order, arr, shape, dtype, op_flags, base):
imp = arr.implementation
backward = is_backward(imp, order)
if arr.is_scalar():
- return ArrayIter(imp, 1, [], [], [], op_flags=op_flags)
+ return ConcreteIter(imp, 1, [], [], [], op_flags, base)
if (imp.strides[0] < imp.strides[-1] and not backward) or \
(imp.strides[0] > imp.strides[-1] and backward):
# flip the strides. Is this always true for multidimension?
@@ -161,7 +233,7 @@
backstrides = imp.backstrides
r = calculate_broadcast_strides(strides, backstrides, imp.shape,
shape, backward)
- return ArrayIter(imp, imp.get_size(), shape, r[0], r[1], op_flags=op_flags)
+ return ConcreteIter(imp, imp.get_size(), shape, r[0], r[1], op_flags, base)
def calculate_ndim(op_in, oa_ndim):
if oa_ndim >=0:
@@ -398,7 +470,7 @@
self.iters = []
for i in range(len(self.seq)):
it = get_iter(space, self.order, self.seq[i], self.shape,
- self.dtypes[i], self.op_flags[i])
+ self.dtypes[i], self.op_flags[i], self)
it.contiguous = False
self.iters.append((it, it.reset()))
@@ -437,7 +509,7 @@
return space.wrap(self)
def getitem(self, it, st):
- res = it.getoperand(st, self)
+ res = it.getoperand(st)
return W_NDimArray(res)
def descr_getitem(self, space, w_idx):
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -3,13 +3,13 @@
class AppTestNumSupport(BaseNumpyAppTest):
def test_zeros(self):
- from numpypy import zeros
+ from numpy import zeros
a = zeros(3)
assert len(a) == 3
assert a[0] == a[1] == a[2] == 0
def test_empty(self):
- from numpypy import empty
+ from numpy import empty
import gc
for i in range(1000):
a = empty(3)
@@ -26,26 +26,26 @@
"empty() returned a zeroed out array every time")
def test_where(self):
- from numpypy import where, ones, zeros, array
+ from numpy import where, ones, zeros, array
a = [1, 2, 3, 0, -3]
a = where(array(a) > 0, ones(5), zeros(5))
assert (a == [1, 1, 1, 0, 0]).all()
def test_where_differing_dtypes(self):
- from numpypy import array, ones, zeros, where
+ from numpy import array, ones, zeros, where
a = [1, 2, 3, 0, -3]
a = where(array(a) > 0, ones(5, dtype=int), zeros(5, dtype=float))
assert (a == [1, 1, 1, 0, 0]).all()
def test_where_broadcast(self):
- from numpypy import array, where
+ from numpy import array, where
a = where(array([[1, 2, 3], [4, 5, 6]]) > 3, [1, 1, 1], 2)
assert (a == [[2, 2, 2], [1, 1, 1]]).all()
a = where(True, [1, 1, 1], 2)
assert (a == [1, 1, 1]).all()
def test_where_errors(self):
- from numpypy import where, array
+ from numpy import where, array
raises(ValueError, "where([1, 2, 3], [3, 4, 5])")
raises(ValueError, "where([1, 2, 3], [3, 4, 5], [6, 7])")
assert where(True, 1, 2) == array(1)
@@ -58,14 +58,14 @@
# xxx
def test_where_invalidates(self):
- from numpypy import where, ones, zeros, array
+ from numpy import where, ones, zeros, array
a = array([1, 2, 3, 0, -3])
b = where(a > 0, ones(5), zeros(5))
a[0] = 0
assert (b == [1, 1, 1, 0, 0]).all()
def test_dot_basic(self):
- from numpypy import array, dot, arange
+ from numpy import array, dot, arange
a = array(range(5))
assert dot(a, a) == 30.0
@@ -100,7 +100,7 @@
assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
def test_dot_constant(self):
- from numpypy import array, dot
+ from numpy import array, dot
a = array(range(5))
b = a.dot(2.5)
for i in xrange(5):
@@ -111,7 +111,7 @@
assert c == 12.0
def test_dot_out(self):
- from numpypy import arange, dot
+ from numpy import arange, dot
a = arange(12).reshape(3, 4)
b = arange(12).reshape(4, 3)
out = arange(9).reshape(3, 3)
@@ -124,19 +124,19 @@
'right type, nr dimensions, and be a C-Array)')
def test_choose_basic(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])
r = array([2, 1, 0]).choose([a, b, c])
assert (r == [7, 5, 3]).all()
def test_choose_broadcast(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c])
assert (r == [13, 5, 3]).all()
def test_choose_out(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c], out=None)
assert (r == [13, 5, 3]).all()
@@ -146,7 +146,7 @@
assert (a == [13, 5, 3]).all()
def test_choose_modes(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
raises(ValueError, "array([3, 1, 0]).choose([a, b, c])")
raises(ValueError, "array([3, 1, 0]).choose([a, b, c], mode='raises')")
@@ -158,20 +158,20 @@
assert (r == [4, 5, 3]).all()
def test_choose_dtype(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1.2, 2, 3]), [4, 5, 6], 13
r = array([2, 1, 0]).choose([a, b, c])
assert r.dtype == float
def test_choose_dtype_out(self):
- from numpypy import array
+ from numpy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
x = array([0, 0, 0], dtype='i2')
r = array([2, 1, 0]).choose([a, b, c], out=x)
assert r.dtype == 'i2'
def test_put_basic(self):
- from numpypy import arange, array
+ from numpy import arange, array
a = arange(5)
a.put([0, 2], [-44, -55])
assert (a == array([-44, 1, -55, 3, 4])).all()
@@ -183,7 +183,7 @@
assert (a == array([0, 7, 2, 3, 4])).all()
def test_put_modes(self):
- from numpypy import array, arange
+ from numpy import array, arange
a = arange(5)
a.put(22, -5, mode='clip')
assert (a == array([0, 1, 2, 3, -5])).all()
diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -14,15 +14,12 @@
else:
from . import dummy_module as numpy
sys.modules['numpy'] = numpy
- sys.modules['numpypy'] = numpy
else:
import os
path = os.path.dirname(__file__) + '/dummy_module.py'
cls.space.appexec([cls.space.wrap(path)], """(path):
import imp
- numpy = imp.load_source('numpy', path)
- import sys
- sys.modules['numpypy'] = numpy
+ imp.load_source('numpy', path)
""")
cls.w_non_native_prefix = cls.space.wrap(NPY.OPPBYTE)
cls.w_native_prefix = cls.space.wrap(NPY.NATBYTE)
diff --git a/pypy/module/micronumpy/test/test_complex.py b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -132,13 +132,13 @@
cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
def test_fabs(self):
- from numpypy import fabs, dtype
+ from numpy import fabs, dtype
a = dtype('complex128').type(complex(-5., 5.))
raises(TypeError, fabs, a)
def test_fmax(self):
- from numpypy import fmax, array
+ from numpy import fmax, array
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -165,7 +165,7 @@
assert (fmax(a, b) == res).all()
def test_fmin(self):
- from numpypy import fmin, array
+ from numpy import fmin, array
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -192,11 +192,11 @@
assert (fmin(a, b) == res).all()
def test_signbit(self):
- from numpypy import signbit
+ from numpy import signbit
raises(TypeError, signbit, complex(1,1))
def test_reciprocal(self):
- from numpypy import array, reciprocal
+ from numpy import array, reciprocal
inf = float('inf')
nan = float('nan')
#complex
@@ -218,21 +218,21 @@
assert (a[0].imag - e.imag) < rel_err
def test_floorceiltrunc(self):
- from numpypy import array, floor, ceil, trunc
+ from numpy import array, floor, ceil, trunc
a = array([ complex(-1.4, -1.4), complex(-1.5, -1.5)])
raises(TypeError, floor, a)
raises(TypeError, ceil, a)
raises(TypeError, trunc, a)
def test_copysign(self):
- from numpypy import copysign, dtype
+ from numpy import copysign, dtype
complex128 = dtype('complex128').type
a = complex128(complex(-5., 5.))
b = complex128(complex(0., 0.))
raises(TypeError, copysign, a, b)
def test_exp2(self):
- from numpypy import array, exp2
+ from numpy import array, exp2
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -268,7 +268,7 @@
def test_expm1(self):
import math, cmath
- from numpypy import array, expm1
+ from numpy import array, expm1
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -307,7 +307,7 @@
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
def test_not_complex(self):
- from numpypy import (radians, deg2rad, degrees, rad2deg,
+ from numpy import (radians, deg2rad, degrees, rad2deg,
logaddexp, logaddexp2, fmod,
arctan2)
raises(TypeError, radians, complex(90,90))
@@ -320,7 +320,7 @@
raises (TypeError, fmod, complex(90,90), 3)
def test_isnan_isinf(self):
- from numpypy import isnan, isinf, array
+ from numpy import isnan, isinf, array
assert (isnan(array([0.2+2j, complex(float('inf'),0),
complex(0,float('inf')), complex(0,float('nan')),
complex(float('nan'), 0)], dtype=complex)) == \
@@ -333,7 +333,7 @@
def test_square(self):
- from numpypy import square
+ from numpy import square
assert square(complex(3, 4)) == complex(3,4) * complex(3, 4)
def test_power_simple(self):
@@ -364,8 +364,8 @@
self.rAlmostEqual(float(n_r_a[i].imag), float(p_r[i].imag), msg=msg)
def test_conjugate(self):
- from numpypy import conj, conjugate, dtype
- import numpypy as np
+ from numpy import conj, conjugate, dtype
+ import numpy as np
c0 = dtype('complex128').type(complex(2.5, 0))
c1 = dtype('complex64').type(complex(1, 2))
@@ -390,7 +390,7 @@
def test_logn(self):
import math, cmath
# log and log10 are tested in math (1:1 from rcomplex)
- from numpypy import log2, array, log1p
+ from numpy import log2, array, log1p
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
@@ -447,7 +447,7 @@
self.rAlmostEqual(t1, t2, rel_err=rel_err, msg=msg)
def test_logical_ops(self):
- from numpypy import logical_and, logical_or, logical_xor, logical_not
+ from numpy import logical_and, logical_or, logical_xor, logical_not
c1 = complex(1, 1)
c3 = complex(3, 0)
@@ -461,7 +461,7 @@
assert (logical_not([c1, c0]) == [False, True]).all()
def test_minimum(self):
- from numpypy import array, minimum
+ from numpy import array, minimum
a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -470,7 +470,7 @@
assert c[i] == min(a[i], b[i])
def test_maximum(self):
- from numpypy import array, maximum
+ from numpy import array, maximum
a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
@@ -480,10 +480,10 @@
def test_basic(self):
import sys
- from numpypy import (dtype, add, array, dtype,
+ from numpy import (dtype, add, array, dtype,
subtract as sub, multiply, divide, negative, absolute as abs,
floor_divide, real, imag, sign)
- from numpypy import (equal, not_equal, greater, greater_equal, less,
+ from numpy import (equal, not_equal, greater, greater_equal, less,
less_equal, isnan)
assert real(4.0) == 4.0
assert imag(0.0) == 0.0
@@ -579,7 +579,7 @@
assert repr(abs(inf_c)) == 'inf'
assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
# numpy actually raises an AttributeError,
- # but numpypy raises a TypeError
+ # but numpy.raises a TypeError
if '__pypy__' in sys.builtin_module_names:
exct, excm = TypeError, 'readonly attribute'
else:
@@ -592,7 +592,7 @@
assert(imag(c2) == 4.0)
def test_conj(self):
- from numpypy import array
+ from numpy import array
a = array([1 + 2j, 1 - 2j])
assert (a.conj() == [1 - 2j, 1 + 2j]).all()
@@ -603,7 +603,7 @@
if self.isWindows:
skip('windows does not support c99 complex')
import sys
- import numpypy as np
+ import numpy as np
rAlmostEqual = self.rAlmostEqual
for t, testcases in (
@@ -658,6 +658,6 @@
sys.stderr.write('\n')
def test_complexbox_to_pycomplex(self):
- from numpypy import dtype
+ from numpy import dtype
x = dtype('complex128').type(3.4j)
assert complex(x) == 3.4j
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
@@ -23,7 +23,7 @@
from numpy.core.multiarray import typeinfo
except ImportError:
# running on dummy module
- from numpypy import typeinfo
+ from numpy import typeinfo
assert typeinfo['Number'] == np.number
assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L,
-9223372036854775808L, np.longlong)
@@ -39,7 +39,7 @@
np.dtype('int').type)
def test_dtype_basic(self):
- from numpypy import dtype
+ from numpy import dtype
import sys
d = dtype('?')
@@ -104,7 +104,7 @@
assert d.shape == ()
def test_dtype_eq(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype("int8") == "int8"
assert "int8" == dtype("int8")
@@ -112,7 +112,7 @@
assert dtype(bool) == bool
def test_dtype_aliases(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype('bool8') is dtype('bool')
assert dtype('byte') is dtype('int8')
assert dtype('ubyte') is dtype('uint8')
@@ -132,7 +132,7 @@
assert dtype('clongdouble').num in (15, 16)
def test_dtype_with_types(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype(bool).num == 0
if self.ptr_size == 4:
@@ -156,7 +156,7 @@
assert dtype('complex').num == 15
def test_array_dtype_attr(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
a = array(range(5), long)
assert a.dtype is dtype(long)
@@ -182,7 +182,7 @@
assert np.dtype('S5').isbuiltin == 0
def test_repr_str(self):
- from numpypy import dtype
+ from numpy import dtype
b = dtype(int).newbyteorder().newbyteorder().byteorder
assert '.dtype' in repr(dtype)
d = dtype('?')
@@ -208,7 +208,7 @@
assert str(d) == "|V16"
def test_bool_array(self):
- from numpypy import array, False_, True_
+ from numpy import array, False_, True_
a = array([0, 1, 2, 2.5], dtype='?')
assert a[0] is False_
@@ -216,7 +216,7 @@
assert a[i] is True_
def test_copy_array_with_dtype(self):
- from numpypy import array, longlong, False_
+ from numpy import array, longlong, False_
a = array([0, 1, 2, 3], dtype=long)
# int on 64-bit, long in 32-bit
@@ -230,35 +230,35 @@
assert b[0] is False_
def test_zeros_bool(self):
- from numpypy import zeros, False_
+ from numpy import zeros, False_
a = zeros(10, dtype=bool)
for i in range(10):
assert a[i] is False_
def test_ones_bool(self):
- from numpypy import ones, True_
+ from numpy import ones, True_
a = ones(10, dtype=bool)
for i in range(10):
assert a[i] is True_
def test_zeros_long(self):
- from numpypy import zeros, longlong
+ from numpy import zeros, longlong
a = zeros(10, dtype=long)
for i in range(10):
assert isinstance(a[i], longlong)
assert a[1] == 0
def test_ones_long(self):
- from numpypy import ones, longlong
+ from numpy import ones, longlong
a = ones(10, dtype=long)
for i in range(10):
assert isinstance(a[i], longlong)
assert a[1] == 1
def test_overflow(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
assert array([128], 'b')[0] == -128
assert array([256], 'B')[0] == 0
assert array([32768], 'h')[0] == -32768
@@ -273,7 +273,7 @@
raises(OverflowError, "array([2**64], 'Q')")
def test_bool_binop_types(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
types = [
'?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd',
'e'
@@ -285,7 +285,7 @@
assert (a + array([0], t)).dtype is dtype(t)
def test_binop_types(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
tests = [('b','B','h'), ('b','h','h'), ('b','H','i'), ('b','i','i'),
('b','l','l'), ('b','q','q'), ('b','Q','d'), ('B','h','h'),
('B','H','H'), ('B','i','i'), ('B','I','I'), ('B','l','l'),
@@ -309,7 +309,7 @@
assert (d1, d2) == (d1, d2) and d3 is dtype(dout)
def test_add(self):
- import numpypy as np
+ import numpy as np
for dtype in ["int8", "int16", "I"]:
a = np.array(range(5), dtype=dtype)
b = a + a
@@ -325,22 +325,22 @@
assert len(d) == 2
def test_shape(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype(long).shape == ()
def test_cant_subclass(self):
- from numpypy import dtype
+ from numpy import dtype
# You can't subclass dtype
raises(TypeError, type, "Foo", (dtype,), {})
def test_can_subclass(self):
- import numpypy
- class xyz(numpypy.void):
+ import numpy
+ class xyz(numpy.void):
pass
assert True
def test_index(self):
- import numpypy as np
+ import numpy as np
for dtype in [np.int8, np.int16, np.int32, np.int64]:
a = np.array(range(10), dtype=dtype)
b = np.array([0] * 10, dtype=dtype)
@@ -348,7 +348,7 @@
a[idx] += 1
def test_hash(self):
- import numpypy as numpy
+ import numpy
for tp, value in [
(numpy.int8, 4),
(numpy.int16, 5),
@@ -392,9 +392,10 @@
t5 = dtype([('x', '<f4'), ('y', '<i4')])
t6 = dtype([('y', '<i4'), ('x', '<f4')])
assert hash(t5) != hash(t6)
+
def test_pickle(self):
import numpy as np
- from numpypy import array, dtype
+ from numpy import array, dtype
from cPickle import loads, dumps
a = array([1,2,3])
if self.ptr_size == 8:
@@ -407,7 +408,7 @@
assert np.dtype(('<f8', 2)).__reduce__() == (dtype, ('V16', 0, 1), (3, '|', (dtype('float64'), (2,)), None, None, 16, 1, 0))
def test_newbyteorder(self):
- import numpypy as np
+ import numpy as np
import sys
sys_is_le = sys.byteorder == 'little'
native_code = sys_is_le and '<' or '>'
@@ -479,7 +480,7 @@
class AppTestTypes(BaseAppTestDtypes):
def test_abstract_types(self):
- import numpypy as numpy
+ import numpy
raises(TypeError, numpy.generic, 0)
raises(TypeError, numpy.number, 0)
@@ -525,16 +526,16 @@
#assert a.dtype is numpy.dtype('|V4')
def test_new(self):
- import numpypy as np
+ import numpy as np
assert np.int_(4) == 4
assert np.float_(3.4) == 3.4
def test_pow(self):
- from numpypy import int_
+ from numpy import int_
assert int_(4) ** 2 == 16
def test_bool(self):
- import numpypy as numpy
+ import numpy
assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
assert numpy.bool_(3) is numpy.True_
@@ -549,7 +550,7 @@
assert numpy.bool_("False") is numpy.True_
def test_int8(self):
- import numpypy as numpy
+ import numpy
assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger,
numpy.integer, numpy.number,
@@ -573,7 +574,7 @@
assert numpy.int8('128') == -128
def test_uint8(self):
- import numpypy as numpy
+ import numpy
assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger,
numpy.integer, numpy.number,
@@ -598,7 +599,7 @@
assert numpy.uint8('256') == 0
def test_int16(self):
- import numpypy as numpy
+ import numpy
x = numpy.int16(3)
assert x == 3
@@ -640,7 +641,7 @@
assert numpy.uint32('4294967296') == 0
def test_int_(self):
- import numpypy as numpy
+ import numpy
assert numpy.int_ is numpy.dtype(int).type
assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger,
@@ -751,7 +752,7 @@
def test_complex_format(self):
import sys
- import numpypy as numpy
+ import numpy
for complex_ in (numpy.complex128, numpy.complex64,):
for real, imag, should in [
@@ -791,7 +792,7 @@
assert "{:g}".format(numpy.complex_(0.5+1.5j)) == '{:g}'.format(0.5+1.5j)
def test_complex(self):
- import numpypy as numpy
+ import numpy
assert numpy.complex_ is numpy.complex128
assert numpy.csingle is numpy.complex64
@@ -811,7 +812,7 @@
assert d.char == 'F'
def test_subclass_type(self):
- import numpypy as numpy
+ import numpy
class X(numpy.float64):
def m(self):
@@ -825,12 +826,12 @@
assert b.dtype.type is numpy.float64
def test_long_as_index(self):
- from numpypy import int_, float64
+ from numpy import int_, float64
assert (1, 2, 3)[int_(1)] == 2
raises(TypeError, lambda: (1, 2, 3)[float64(1)])
def test_int(self):
- from numpypy import int32, int64, int_
+ from numpy import int32, int64, int_
import sys
assert issubclass(int_, int)
if sys.maxint == (1<<31) - 1:
@@ -841,7 +842,7 @@
assert int_ is int64
def test_various_types(self):
- import numpypy as numpy
+ import numpy
assert numpy.int16 is numpy.short
assert numpy.int8 is numpy.byte
@@ -863,7 +864,7 @@
assert not issubclass(numpy.longfloat, numpy.float64)
def test_mro(self):
- import numpypy as numpy
+ import numpy
assert numpy.int16.__mro__ == (numpy.int16, numpy.signedinteger,
numpy.integer, numpy.number,
@@ -872,7 +873,7 @@
def test_operators(self):
from operator import truediv
- from numpypy import float64, int_, True_, False_
+ from numpy import float64, int_, True_, False_
assert 5 / int_(2) == int_(2)
assert truediv(int_(3), int_(2)) == float64(1.5)
assert truediv(3, int_(2)) == float64(1.5)
@@ -898,7 +899,7 @@
def test_alternate_constructs(self):
import numpy as np
- from numpypy import dtype
+ from numpy import dtype
nnp = self.non_native_prefix
byteorder = self.native_prefix
assert dtype('i8') == dtype(byteorder + 'i8') == dtype('=i8') == dtype(long)
@@ -921,7 +922,7 @@
assert d.str == '|S0'
def test_dtype_str(self):
- from numpypy import dtype
+ from numpy import dtype
byteorder = self.native_prefix
assert dtype('i8').str == byteorder + 'i8'
assert dtype('<i8').str == '<i8'
@@ -948,7 +949,7 @@
assert dtype(('f8', 2)).str == "|V16"
def test_intp(self):
- from numpypy import dtype
+ from numpy import dtype
for s in ['p', 'int']:
assert dtype(s) is dtype('intp')
for s in ['P', 'uint']:
@@ -967,16 +968,16 @@
assert dtype('P').name == 'uint64'
def test_alignment(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype('i4').alignment == 4
def test_isnative(self):
- from numpypy import dtype
+ from numpy import dtype
assert dtype('i4').isnative == True
assert dtype('>i8').isnative == False
def test_any_all_nonzero(self):
- import numpypy as numpy
+ import numpy
x = numpy.bool_(True)
assert x.any() is numpy.True_
assert x.all() is numpy.True_
@@ -999,7 +1000,7 @@
assert x.__nonzero__() is True
def test_ravel(self):
- from numpypy import float64, int8, array
+ from numpy import float64, int8, array
x = float64(42.5).ravel()
assert x.dtype == float64
assert (x == array([42.5])).all()
@@ -1022,7 +1023,7 @@
class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
def test_mro(self):
- from numpypy import str_, unicode_, character, flexible, generic
+ from numpy import str_, unicode_, character, flexible, generic
import sys
if '__pypy__' in sys.builtin_module_names:
assert str_.mro() == [str_, character, flexible, generic,
@@ -1036,7 +1037,7 @@
flexible, generic, object]
def test_str_dtype(self):
- from numpypy import dtype, str_
+ from numpy import dtype, str_
raises(TypeError, "dtype('Sx')")
for t in ['S8', '|S8', '=S8']:
@@ -1057,7 +1058,7 @@
assert d.str == '|S1'
def test_unicode_dtype(self):
- from numpypy import dtype, unicode_
+ from numpy import dtype, unicode_
raises(TypeError, "dtype('Ux')")
d = dtype('U8')
@@ -1069,11 +1070,11 @@
assert d.num == 19
def test_string_boxes(self):
- from numpypy import str_
+ from numpy import str_
assert isinstance(str_(3), str_)
def test_unicode_boxes(self):
- from numpypy import unicode_
+ from numpy import unicode_
import sys
if '__pypy__' in sys.builtin_module_names:
exc = raises(NotImplementedError, unicode_, 3)
@@ -1084,7 +1085,7 @@
def test_character_dtype(self):
import numpy as np
- from numpypy import array, character
+ from numpy import array, character
x = array([["A", "B"], ["C", "D"]], character)
assert (x == [["A", "B"], ["C", "D"]]).all()
d = np.dtype('c')
@@ -1097,7 +1098,7 @@
spaceconfig = dict(usemodules=["micronumpy", "struct", "binascii"])
def test_create(self):
- from numpypy import dtype, void
+ from numpy import dtype, void
raises(ValueError, "dtype([('x', int), ('x', float)])")
d = dtype([("x", "<i4"), ("y", "<f4"), ("z", "<u2"), ("v", "<f8")])
@@ -1156,7 +1157,7 @@
raises(NotImplementedError, np.dtype, d)
def test_create_subarrays(self):
- from numpypy import dtype
+ from numpy import dtype
d = dtype([("x", "float", (2,)), ("y", "int64", (2,))])
assert d.itemsize == 32
assert d.name == "void256"
@@ -1277,7 +1278,7 @@
assert repr(d) == "dtype([('f0', '<f8'), ('f1', '<f8')])"
def test_pickle_record(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
from cPickle import loads, dumps
d = dtype([("x", "int32"), ("y", "int32"), ("z", "int32"), ("value", float)])
@@ -1288,7 +1289,7 @@
assert new_d.__reduce__() == d.__reduce__()
def test_pickle_record_subarrays(self):
- from numpypy import array, dtype
+ from numpy import array, dtype
from cPickle import loads, dumps
d = dtype([("x", "int32", (3,)), ("y", "int32", (2,)), ("z", "int32", (4,)), ("value", float, (5,))])
@@ -1320,7 +1321,7 @@
cls.w_check_non_native = cls.space.wrap(interp2app(check_non_native))
def test_non_native(self):
- from numpypy import array
+ from numpy import array
a = array([1, 2, 3], dtype=self.non_native_prefix + 'i2')
assert a[0] == 1
assert (a + a)[1] == 4
@@ -1343,7 +1344,7 @@
class AppTestObjectDtypes(BaseNumpyAppTest):
def test_scalar_from_object(self):
- from numpypy import array
+ from numpy import array
import sys
class Polynomial(object):
pass
diff --git a/pypy/module/micronumpy/test/test_iterators.py b/pypy/module/micronumpy/test/test_iterators.py
--- a/pypy/module/micronumpy/test/test_iterators.py
+++ b/pypy/module/micronumpy/test/test_iterators.py
@@ -31,16 +31,14 @@
s = i.next(s)
assert s.offset == 3
assert not i.done(s)
- assert s.indices == [0,0]
- s = i.update(s)
- assert s.indices == [0,3]
+ assert s._indices == [0,0]
+ assert i.indices(s) == [0,3]
#cause a dimension overflow
s = i.next(s)
s = i.next(s)
assert s.offset == 5
- assert s.indices == [0,3]
- s = i.update(s)
- assert s.indices == [1,0]
+ assert s._indices == [0,3]
+ assert i.indices(s) == [1,0]
#Now what happens if the array is transposed? strides[-1] != 1
# therefore layout is non-contiguous
@@ -56,12 +54,12 @@
s = i.next(s)
assert s.offset == 9
assert not i.done(s)
- assert s.indices == [0,3]
+ assert s._indices == [0,3]
#cause a dimension overflow
s = i.next(s)
s = i.next(s)
assert s.offset == 1
- assert s.indices == [1,0]
+ assert s._indices == [1,0]
def test_iterator_goto(self):
shape = [3, 5]
@@ -74,9 +72,9 @@
assert not i.contiguous
s = i.reset()
assert s.index == 0
- assert s.indices == [0, 0]
+ assert s._indices == [0, 0]
assert s.offset == a.start
s = i.goto(11)
assert s.index == 11
- assert s.indices is None
+ assert s._indices is None
assert s.offset == a.start + 5
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
@@ -269,13 +269,13 @@
assert not a.flags['F']
def test_ndmin(self):
- from numpypy import array
+ from numpy import array
arr = array([[[1]]], ndmin=1)
assert arr.shape == (1, 1, 1)
def test_noop_ndmin(self):
- from numpypy import array
+ from numpy import array
arr = array([1], ndmin=3)
assert arr.shape == (1, 1, 1)
@@ -289,7 +289,7 @@
assert a.dtype == np.intp
def test_array_copy(self):
- from numpypy import array
+ from numpy import array
a = array(range(12)).reshape(3,4)
b = array(a, ndmin=4)
assert b.shape == (1, 1, 3, 4)
@@ -353,12 +353,12 @@
assert str(exc.value) == 'buffer is read-only'
def test_type(self):
- from numpypy import array
+ from numpy import array
ar = array(range(5))
assert type(ar) is type(ar + ar)
def test_ndim(self):
- from numpypy import array
+ from numpy import array
x = array(0.2)
assert x.ndim == 0
x = array([1, 2])
@@ -367,12 +367,12 @@
assert x.ndim == 2
x = array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
assert x.ndim == 3
- # numpy actually raises an AttributeError, but numpypy raises an
+ # numpy actually raises an AttributeError, but numpy.raises an
# TypeError
raises((TypeError, AttributeError), 'x.ndim = 3')
def test_zeros(self):
- from numpypy import zeros
+ from numpy import zeros
a = zeros(15)
# Check that storage was actually zero'd.
assert a[10] == 0.0
@@ -431,7 +431,7 @@
assert type(b) is np.ndarray
def test_size(self):
- from numpypy import array,arange,cos
+ from numpy import array,arange,cos
assert array(3).size == 1
a = array([1, 2, 3])
assert a.size == 3
@@ -440,13 +440,13 @@
assert ten == 10
def test_empty(self):
- from numpypy import empty
+ from numpy import empty
a = empty(2)
a[1] = 1.0
assert a[1] == 1.0
def test_ones(self):
- from numpypy import ones, dtype
+ from numpy import ones, dtype
a = ones(3)
assert len(a) == 3
assert a[0] == 1
@@ -458,7 +458,7 @@
assert b.dtype is dtype(complex)
def test_arange(self):
- from numpypy import arange, dtype
+ from numpy import arange, dtype
a = arange(3)
assert (a == [0, 1, 2]).all()
assert a.dtype is dtype(int)
@@ -480,7 +480,7 @@
assert arange(False, True, True).dtype is dtype(int)
def test_copy(self):
- from numpypy import arange, array
+ from numpy import arange, array
a = arange(5)
b = a.copy()
for i in xrange(5):
@@ -522,7 +522,7 @@
raises(NotImplementedError, a.copy, order=True)
def test_iterator_init(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
assert a[3] == 3
@@ -546,7 +546,7 @@
assert (a == [[1], [2]]).all()
def test_getitem(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
raises(IndexError, "a[5]")
a = a + a
@@ -555,14 +555,14 @@
raises(IndexError, "a[-6]")
def test_getitem_float(self):
- from numpypy import array
+ from numpy import array
a = array([1, 2, 3, 4])
assert a[1.2] == 2
assert a[1.6] == 2
assert a[-1.2] == 4
def test_getitem_tuple(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
raises(IndexError, "a[(1,2)]")
for i in xrange(5):
@@ -572,28 +572,28 @@
assert a[i] == b[i]
def test_getitem_nd(self):
- from numpypy import arange
+ from numpy import arange
a = arange(15).reshape(3, 5)
assert a[1, 3] == 8
assert a.T[1, 2] == 11
def test_getitem_obj_index(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
assert a[self.CustomIndexObject(1)] == 1
def test_getitem_obj_prefer_index_to_int(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
assert a[self.CustomIndexIntObject(0, 1)] == 0
def test_getitem_obj_int(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
assert a[self.CustomIntObject(1)] == 1
def test_setitem(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
a[-1] = 5.0
assert a[4] == 5.0
@@ -612,7 +612,7 @@
assert a[2] == -0.005
def test_setitem_tuple(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
raises(IndexError, "a[(1,2)] = [0,1]")
for i in xrange(5):
@@ -630,25 +630,25 @@
assert a[2] == 100
def test_setitem_obj_index(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
a[self.CustomIndexObject(1)] = 100
assert a[1] == 100
def test_setitem_obj_prefer_index_to_int(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
a[self.CustomIndexIntObject(0, 1)] = 100
assert a[0] == 100
def test_setitem_obj_int(self):
- from numpypy import arange
+ from numpy import arange
a = arange(10)
a[self.CustomIntObject(1)] = 100
assert a[1] == 100
def test_delitem(self):
- import numpypy as np
+ import numpy as np
a = np.arange(10)
exc = raises(ValueError, 'del a[2]')
assert exc.value.message == 'cannot delete array elements'
@@ -665,7 +665,7 @@
# numpy will swallow errors in __int__ and __index__ and
# just raise IndexError.
- from numpypy import arange
+ from numpy import arange
a = arange(10)
exc = raises(IndexError, "a[ErrorIndex()] == 0")
assert exc.value.message == 'cannot convert index to integer'
@@ -673,7 +673,7 @@
assert exc.value.message == 'cannot convert index to integer'
def test_setslice_array(self):
- from numpypy import array
+ from numpy import array
a = array(5)
exc = raises(ValueError, "a[:] = 4")
assert exc.value[0] == "cannot slice a 0-d array"
@@ -687,7 +687,7 @@
assert b[1] == 0.
def test_setslice_of_slice_array(self):
- from numpypy import array, zeros
+ from numpy import array, zeros
a = zeros(5)
a[::2] = array([9., 10., 11.])
assert a[0] == 9.
@@ -706,7 +706,7 @@
assert a[0] == 3.
def test_setslice_list(self):
- from numpypy import array
+ from numpy import array
a = array(range(5), float)
b = [0., 1.]
a[1:4:2] = b
@@ -714,7 +714,7 @@
assert a[3] == 1.
def test_setslice_constant(self):
- from numpypy import array
+ from numpy import array
a = array(range(5), float)
a[1:4:2] = 0.
assert a[1] == 0.
@@ -722,7 +722,7 @@
def test_newaxis(self):
import math
- from numpypy import array, cos, zeros, newaxis
+ from numpy import array, cos, zeros, newaxis
a = array(range(5))
b = array([range(5)])
assert (a[newaxis] == b).all()
@@ -743,7 +743,7 @@
assert o == 3
def test_newaxis_slice(self):
- from numpypy import array, newaxis
+ from numpy import array, newaxis
a = array(range(5))
b = array(range(1,5))
@@ -755,14 +755,14 @@
assert (a[newaxis,1:] == c).all()
def test_newaxis_assign(self):
- from numpypy import array, newaxis
+ from numpy import array, newaxis
a = array(range(5))
a[newaxis,1] = [2]
assert a[1] == 2
def test_newaxis_virtual(self):
- from numpypy import array, newaxis
+ from numpy import array, newaxis
a = array(range(5))
b = (a + a)[newaxis]
@@ -770,20 +770,20 @@
assert (b == c).all()
def test_newaxis_then_slice(self):
- from numpypy import array, newaxis
+ from numpy import array, newaxis
a = array(range(5))
b = a[newaxis]
assert b.shape == (1, 5)
assert (b[0,1:] == a[1:]).all()
def test_slice_then_newaxis(self):
- from numpypy import array, newaxis
+ from numpy import array, newaxis
a = array(range(5))
b = a[2:]
assert (b[newaxis] == [[2, 3, 4]]).all()
def test_scalar(self):
- from numpypy import array, dtype, int_
+ from numpy import array, dtype, int_
a = array(3)
exc = raises(IndexError, "a[0]")
assert exc.value[0] == "0-d arrays can't be indexed"
@@ -816,13 +816,13 @@
assert a == 2.5
def test_len(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
assert len(a) == 5
assert len(a + a) == 5
def test_shape(self):
- from numpypy import array
+ from numpy import array
a = array(range(5))
assert a.shape == (5,)
b = a + a
@@ -832,7 +832,7 @@
assert array([]).shape == (0,)
def test_set_shape(self):
- from numpypy import array, zeros
+ from numpy import array, zeros
a = array([])
raises(ValueError, "a.shape = []")
a = array(range(12))
@@ -855,7 +855,7 @@
raises(AttributeError, 'a.shape = 6')
def test_reshape(self):
- from numpypy import array, zeros
+ from numpy import array, zeros
for a in [array(1), array([1])]:
for s in [(), (1,)]:
b = a.reshape(s)
@@ -902,7 +902,7 @@
raises(NotImplementedError, a.reshape, (0,), order='F')
def test_slice_reshape(self):
- from numpypy import zeros, arange
+ from numpy import zeros, arange
a = zeros((4, 2, 3))
b = a[::2, :, :]
b.shape = (2, 6)
@@ -938,32 +938,32 @@
raises(ValueError, arange(10).reshape, (5, -1, -1))
def test_reshape_varargs(self):
- from numpypy import arange
+ from numpy import arange
z = arange(96).reshape(12, -1)
y = z.reshape(4, 3, 8)
assert y.shape == (4, 3, 8)
def test_scalar_reshape(self):
- from numpypy import array
+ from numpy import array
a = array(3)
assert a.reshape([1, 1]).shape == (1, 1)
assert a.reshape([1]).shape == (1,)
raises(ValueError, "a.reshape(3)")
def test_strides(self):
- from numpypy import array
+ from numpy import array
a = array([[1.0, 2.0],
[3.0, 4.0]])
assert a.strides == (16, 8)
assert a[1:].strides == (16, 8)
def test_strides_scalar(self):
- from numpypy import array
+ from numpy import array
a = array(42)
assert a.strides == ()
More information about the pypy-commit
mailing list