[pypy-commit] pypy numpy-indexing-by-arrays-bool: merge default
fijal
noreply at buildbot.pypy.org
Fri Jan 20 15:19:33 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-indexing-by-arrays-bool
Changeset: r51523:3f86800ad9ba
Date: 2012-01-20 16:18 +0200
http://bitbucket.org/pypy/pypy/changeset/3f86800ad9ba/
Log: merge default
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -2,6 +2,9 @@
*.py[co]
*~
.*.swp
+.idea
+.project
+.pydevproject
syntax: regexp
^testresult$
diff --git a/lib_pypy/numpypy/__init__.py b/lib_pypy/numpypy/__init__.py
--- a/lib_pypy/numpypy/__init__.py
+++ b/lib_pypy/numpypy/__init__.py
@@ -1,2 +1,2 @@
from _numpypy import *
-from .fromnumeric import *
+from .core import *
diff --git a/lib_pypy/numpypy/core/__init__.py b/lib_pypy/numpypy/core/__init__.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -0,0 +1,1 @@
+from .fromnumeric import *
diff --git a/lib_pypy/numpypy/fromnumeric.py b/lib_pypy/numpypy/core/fromnumeric.py
rename from lib_pypy/numpypy/fromnumeric.py
rename to lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -85,7 +85,7 @@
array([4, 3, 6])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
# not deprecated --- copy if necessary, view otherwise
@@ -273,7 +273,7 @@
[-1, -2, -3, -4, -5]]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def repeat(a, repeats, axis=None):
@@ -315,7 +315,7 @@
[3, 4]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def put(a, ind, v, mode='raise'):
@@ -366,7 +366,7 @@
array([ 0, 1, 2, 3, -5])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def swapaxes(a, axis1, axis2):
@@ -410,7 +410,7 @@
[3, 7]]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def transpose(a, axes=None):
@@ -451,8 +451,11 @@
(2, 1, 3)
"""
- raise NotImplemented('Waiting on interp level method')
-
+ if axes is not None:
+ raise NotImplementedError('No "axes" arg yet.')
+ if not hasattr(a, 'T'):
+ a = numpypy.array(a)
+ return a.T
def sort(a, axis=-1, kind='quicksort', order=None):
"""
@@ -553,7 +556,7 @@
dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def argsort(a, axis=-1, kind='quicksort', order=None):
@@ -634,7 +637,7 @@
array([0, 1])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def argmax(a, axis=None):
@@ -753,7 +756,7 @@
array([0, 5, 1, 2])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def resize(a, new_shape):
@@ -794,7 +797,7 @@
[0, 1, 2, 3]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def squeeze(a):
@@ -821,7 +824,7 @@
(3,)
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def diagonal(a, offset=0, axis1=0, axis2=1):
@@ -905,7 +908,7 @@
[5, 7]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None):
@@ -964,7 +967,7 @@
(2, 3)
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def ravel(a, order='C'):
"""
@@ -1048,7 +1051,7 @@
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def nonzero(a):
@@ -1124,7 +1127,7 @@
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def shape(a):
@@ -1229,7 +1232,7 @@
array([2])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def clip(a, a_min, a_max, out=None):
@@ -1282,7 +1285,7 @@
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def sum(a, axis=None, dtype=None, out=None):
@@ -1365,7 +1368,7 @@
prod : equivalent function; see for details.
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def sometrue(a, axis=None, out=None):
@@ -1590,7 +1593,7 @@
[ 4, 9, 15]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def cumproduct(a, axis=None, dtype=None, out=None):
@@ -1603,7 +1606,7 @@
cumprod : equivalent function; see for details.
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def ptp(a, axis=None, out=None):
@@ -1644,7 +1647,7 @@
array([1, 1])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def amax(a, axis=None, out=None):
@@ -1873,7 +1876,7 @@
True
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def cumprod(a, axis=None, dtype=None, out=None):
@@ -1936,7 +1939,7 @@
[ 4, 20, 120]])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def ndim(a):
@@ -2054,7 +2057,7 @@
2
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def around(a, decimals=0, out=None):
@@ -2123,7 +2126,7 @@
array([ 0, 0, 0, 10])
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def round_(a, decimals=0, out=None):
@@ -2137,7 +2140,7 @@
around : equivalent function
"""
- raise NotImplemented('Waiting on interp level method')
+ raise NotImplementedError('Waiting on interp level method')
def mean(a, axis=None, dtype=None, out=None):
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -340,7 +340,7 @@
requires=[("objspace.std.builtinshortcut", True)]),
BoolOption("withidentitydict",
"track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not",
- default=True),
+ default=False),
]),
])
@@ -370,6 +370,7 @@
config.objspace.std.suggest(getattributeshortcut=True)
config.objspace.std.suggest(newshortcut=True)
config.objspace.std.suggest(withspecialisedtuple=True)
+ config.objspace.std.suggest(withidentitydict=True)
#if not IS_64_BITS:
# config.objspace.std.suggest(withsmalllong=True)
diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -1872,6 +1872,7 @@
values.append(descr)
values.append(self.cpu.get_latest_value_int(0))
values.append(self.cpu.get_latest_value_int(1))
+ values.append(token)
FUNC = self.FuncType([lltype.Signed, lltype.Signed], lltype.Void)
func_ptr = llhelper(lltype.Ptr(FUNC), maybe_force)
@@ -1902,7 +1903,8 @@
assert fail.identifier == 1
assert self.cpu.get_latest_value_int(0) == 1
assert self.cpu.get_latest_value_int(1) == 10
- assert values == [faildescr, 1, 10]
+ token = self.cpu.get_latest_force_token()
+ assert values == [faildescr, 1, 10, token]
def test_force_operations_returning_int(self):
values = []
@@ -1911,6 +1913,7 @@
self.cpu.force(token)
values.append(self.cpu.get_latest_value_int(0))
values.append(self.cpu.get_latest_value_int(2))
+ values.append(token)
return 42
FUNC = self.FuncType([lltype.Signed, lltype.Signed], lltype.Signed)
@@ -1944,7 +1947,8 @@
assert self.cpu.get_latest_value_int(0) == 1
assert self.cpu.get_latest_value_int(1) == 42
assert self.cpu.get_latest_value_int(2) == 10
- assert values == [1, 10]
+ token = self.cpu.get_latest_force_token()
+ assert values == [1, 10, token]
def test_force_operations_returning_float(self):
values = []
@@ -1953,6 +1957,7 @@
self.cpu.force(token)
values.append(self.cpu.get_latest_value_int(0))
values.append(self.cpu.get_latest_value_int(2))
+ values.append(token)
return 42.5
FUNC = self.FuncType([lltype.Signed, lltype.Signed], lltype.Float)
@@ -1988,7 +1993,8 @@
x = self.cpu.get_latest_value_float(1)
assert longlong.getrealfloat(x) == 42.5
assert self.cpu.get_latest_value_int(2) == 10
- assert values == [1, 10]
+ token = self.cpu.get_latest_force_token()
+ assert values == [1, 10, token]
def test_call_to_c_function(self):
from pypy.rlib.libffi import CDLL, types, ArgChain, FUNCFLAG_CDECL
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -108,6 +108,10 @@
w_result = state.codec_search_cache.get(normalized_encoding, None)
if w_result is not None:
return w_result
+ return _lookup_codec_loop(space, encoding, normalized_encoding)
+
+def _lookup_codec_loop(space, encoding, normalized_encoding):
+ state = space.fromcache(CodecState)
if state.codec_need_encodings:
w_import = space.getattr(space.builtin, space.wrap("__import__"))
# registers new codecs
diff --git a/pypy/module/_codecs/test/test_ztranslation.py b/pypy/module/_codecs/test/test_ztranslation.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_codecs/test/test_ztranslation.py
@@ -0,0 +1,5 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+
+def test__codecs_translates():
+ checkmodule('_codecs')
diff --git a/pypy/module/cpyext/include/patchlevel.h b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -29,7 +29,7 @@
#define PY_VERSION "2.7.1"
/* PyPy version as a string */
-#define PYPY_VERSION "1.7.1"
+#define PYPY_VERSION "1.8.1"
/* Subversion Revision number of this file (not of the repository).
* Empty since Mercurial migration. */
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -70,6 +70,7 @@
("exp", "exp"),
("fabs", "fabs"),
("floor", "floor"),
+ ("ceil", "ceil"),
("greater", "greater"),
("greater_equal", "greater_equal"),
("less", "less"),
@@ -92,7 +93,6 @@
appleveldefs = {
'average': 'app_numpy.average',
- 'mean': 'app_numpy.mean',
'sum': 'app_numpy.sum',
'min': 'app_numpy.min',
'identity': 'app_numpy.identity',
@@ -101,5 +101,4 @@
'e': 'app_numpy.e',
'pi': 'app_numpy.pi',
'arange': 'app_numpy.arange',
- 'reshape': 'app_numpy.reshape',
}
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -11,23 +11,20 @@
def average(a):
# This implements a weighted average, for now we don't implement the
# weighting, just the average part!
- return mean(a)
+ if not hasattr(a, "mean"):
+ a = _numpypy.array(a)
+ return a.mean()
def identity(n, dtype=None):
- a = _numpypy.zeros((n,n), dtype=dtype)
+ a = _numpypy.zeros((n, n), dtype=dtype)
for i in range(n):
a[i][i] = 1
return a
-def mean(a, axis=None):
- if not hasattr(a, "mean"):
- a = _numpypy.array(a)
- return a.mean(axis)
-
def sum(a,axis=None):
'''sum(a, axis=None)
Sum of array elements over a given axis.
-
+
Parameters
----------
a : array_like
@@ -35,7 +32,7 @@
axis : integer, optional
Axis over which the sum is taken. By default `axis` is None,
and all elements are summed.
-
+
Returns
-------
sum_along_axis : ndarray
@@ -43,7 +40,7 @@
axis removed. If `a` is a 0-d array, or if `axis` is None, a scalar
is returned. If an output array is specified, a reference to
`out` is returned.
-
+
See Also
--------
ndarray.sum : Equivalent method.
@@ -79,40 +76,3 @@
arr[j] = i
i += step
return arr
-
-
-def reshape(a, shape):
- '''reshape(a, newshape)
- Gives a new shape to an array without changing its data.
-
- Parameters
- ----------
- a : array_like
- Array to be reshaped.
- newshape : int or tuple of ints
- The new shape should be compatible with the original shape. If
- an integer, then the result will be a 1-D array of that length.
- One shape dimension can be -1. In this case, the value is inferred
- from the length of the array and remaining dimensions.
-
- Returns
- -------
- reshaped_array : ndarray
- This will be a new view object if possible; otherwise, it will
- be a copy.
-
-
- See Also
- --------
- ndarray.reshape : Equivalent method.
-
- Notes
- -----
-
- It is not always possible to change the shape of an array without
- copying the data. If you want an error to be raise if the data is copied,
- you should assign the new shape to the shape attribute of the array
-'''
- if not hasattr(a, 'reshape'):
- a = _numpypy.array(a)
- return a.reshape(shape)
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
@@ -20,7 +20,7 @@
class W_Dtype(Wrappable):
_immutable_fields_ = ["itemtype", "num", "kind"]
- def __init__(self, itemtype, num, kind, name, char, w_box_type, alternate_constructors=[]):
+ def __init__(self, itemtype, num, kind, name, char, w_box_type, alternate_constructors=[], aliases=[]):
self.itemtype = itemtype
self.num = num
self.kind = kind
@@ -28,6 +28,7 @@
self.char = char
self.w_box_type = w_box_type
self.alternate_constructors = alternate_constructors
+ self.aliases = aliases
def malloc(self, length):
# XXX find out why test_zjit explodes with tracking of allocations
@@ -66,7 +67,7 @@
elif space.isinstance_w(w_dtype, space.w_str):
name = space.str_w(w_dtype)
for dtype in cache.builtin_dtypes:
- if dtype.name == name or dtype.char == name:
+ if dtype.name == name or dtype.char == name or name in dtype.aliases:
return dtype
else:
for dtype in cache.builtin_dtypes:
@@ -117,7 +118,7 @@
kind=BOOLLTR,
name="bool",
char="?",
- w_box_type = space.gettypefor(interp_boxes.W_BoolBox),
+ w_box_type=space.gettypefor(interp_boxes.W_BoolBox),
alternate_constructors=[space.w_bool],
)
self.w_int8dtype = W_Dtype(
@@ -126,7 +127,7 @@
kind=SIGNEDLTR,
name="int8",
char="b",
- w_box_type = space.gettypefor(interp_boxes.W_Int8Box)
+ w_box_type=space.gettypefor(interp_boxes.W_Int8Box)
)
self.w_uint8dtype = W_Dtype(
types.UInt8(),
@@ -134,7 +135,7 @@
kind=UNSIGNEDLTR,
name="uint8",
char="B",
- w_box_type = space.gettypefor(interp_boxes.W_UInt8Box),
+ w_box_type=space.gettypefor(interp_boxes.W_UInt8Box),
)
self.w_int16dtype = W_Dtype(
types.Int16(),
@@ -142,7 +143,7 @@
kind=SIGNEDLTR,
name="int16",
char="h",
- w_box_type = space.gettypefor(interp_boxes.W_Int16Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Int16Box),
)
self.w_uint16dtype = W_Dtype(
types.UInt16(),
@@ -150,7 +151,7 @@
kind=UNSIGNEDLTR,
name="uint16",
char="H",
- w_box_type = space.gettypefor(interp_boxes.W_UInt16Box),
+ w_box_type=space.gettypefor(interp_boxes.W_UInt16Box),
)
self.w_int32dtype = W_Dtype(
types.Int32(),
@@ -158,7 +159,7 @@
kind=SIGNEDLTR,
name="int32",
char="i",
- w_box_type = space.gettypefor(interp_boxes.W_Int32Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Int32Box),
)
self.w_uint32dtype = W_Dtype(
types.UInt32(),
@@ -166,7 +167,7 @@
kind=UNSIGNEDLTR,
name="uint32",
char="I",
- w_box_type = space.gettypefor(interp_boxes.W_UInt32Box),
+ w_box_type=space.gettypefor(interp_boxes.W_UInt32Box),
)
if LONG_BIT == 32:
name = "int32"
@@ -178,7 +179,7 @@
kind=SIGNEDLTR,
name=name,
char="l",
- w_box_type = space.gettypefor(interp_boxes.W_LongBox),
+ w_box_type=space.gettypefor(interp_boxes.W_LongBox),
alternate_constructors=[space.w_int],
)
self.w_ulongdtype = W_Dtype(
@@ -187,7 +188,7 @@
kind=UNSIGNEDLTR,
name="u" + name,
char="L",
- w_box_type = space.gettypefor(interp_boxes.W_ULongBox),
+ w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
)
self.w_int64dtype = W_Dtype(
types.Int64(),
@@ -195,7 +196,7 @@
kind=SIGNEDLTR,
name="int64",
char="q",
- w_box_type = space.gettypefor(interp_boxes.W_Int64Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Int64Box),
alternate_constructors=[space.w_long],
)
self.w_uint64dtype = W_Dtype(
@@ -204,7 +205,7 @@
kind=UNSIGNEDLTR,
name="uint64",
char="Q",
- w_box_type = space.gettypefor(interp_boxes.W_UInt64Box),
+ w_box_type=space.gettypefor(interp_boxes.W_UInt64Box),
)
self.w_float32dtype = W_Dtype(
types.Float32(),
@@ -212,7 +213,7 @@
kind=FLOATINGLTR,
name="float32",
char="f",
- w_box_type = space.gettypefor(interp_boxes.W_Float32Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Float32Box),
)
self.w_float64dtype = W_Dtype(
types.Float64(),
@@ -222,6 +223,7 @@
char="d",
w_box_type = space.gettypefor(interp_boxes.W_Float64Box),
alternate_constructors=[space.w_float],
+ aliases=["float"],
)
self.builtin_dtypes = [
diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -177,6 +177,8 @@
offset += self.strides[i]
break
else:
+ if i == self.dim:
+ first_line = True
indices[i] = 0
offset -= self.backstrides[i]
else:
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
@@ -308,11 +308,11 @@
descr_rmod = _binop_right_impl("mod")
def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
- def impl(self, space, w_dim=None):
- if space.is_w(w_dim, space.w_None):
- w_dim = space.wrap(-1)
+ def impl(self, space, w_axis=None):
+ if space.is_w(w_axis, space.w_None):
+ w_axis = space.wrap(-1)
return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
- self, True, promote_to_largest, w_dim)
+ self, True, promote_to_largest, w_axis)
return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
descr_sum = _reduce_ufunc_impl("add")
@@ -652,19 +652,19 @@
)
return w_result
- def descr_mean(self, space, w_dim=None):
- if space.is_w(w_dim, space.w_None):
- w_dim = space.wrap(-1)
+ def descr_mean(self, space, w_axis=None):
+ if space.is_w(w_axis, space.w_None):
+ w_axis = space.wrap(-1)
w_denom = space.wrap(self.size)
else:
- dim = space.int_w(w_dim)
+ dim = space.int_w(w_axis)
w_denom = space.wrap(self.shape[dim])
- return space.div(self.descr_sum_promote(space, w_dim), w_denom)
+ return space.div(self.descr_sum_promote(space, w_axis), w_denom)
def descr_var(self, space):
# var = mean((values - mean(values)) ** 2)
w_res = self.descr_sub(space, self.descr_mean(space, space.w_None))
- assert isinstance(w_res, BaseArray)
+ assert isinstance(w_res, BaseArray)
w_res = w_res.descr_pow(space, space.wrap(2))
assert isinstance(w_res, BaseArray)
return w_res.descr_mean(space, space.w_None)
@@ -673,6 +673,10 @@
# std(v) = sqrt(var(v))
return interp_ufuncs.get(space).sqrt.call(space, [self.descr_var(space)])
+ def descr_fill(self, space, w_value):
+ concr = self.get_concrete_or_scalar()
+ concr.fill(space, w_value)
+
def descr_nonzero(self, space):
if self.size > 1:
raise OperationError(space.w_ValueError, space.wrap(
@@ -765,6 +769,9 @@
def copy(self, space):
return Scalar(self.dtype, self.value)
+ def fill(self, space, w_value):
+ self.value = self.dtype.coerce(space, w_value)
+
def create_sig(self):
return signature.ScalarSignature(self.dtype)
@@ -870,7 +877,7 @@
Intermediate class for performing binary operations.
"""
_immutable_fields_ = ['left', 'right']
-
+
def __init__(self, ufunc, name, shape, calc_dtype, res_dtype, left, right):
VirtualArray.__init__(self, name, shape, res_dtype)
self.ufunc = ufunc
@@ -910,7 +917,7 @@
def __init__(self, shape, dtype, left, right):
Call2.__init__(self, None, 'sliceloop', shape, dtype, dtype, left,
right)
-
+
def create_sig(self):
lsig = self.left.create_sig()
rsig = self.right.create_sig()
@@ -929,7 +936,7 @@
when we'll make AxisReduce lazy
"""
_immutable_fields_ = ['left', 'right']
-
+
def __init__(self, ufunc, name, shape, dtype, left, right, dim):
Call2.__init__(self, ufunc, name, shape, dtype, dtype,
left, right)
@@ -1001,14 +1008,14 @@
if size < 1:
builder.append('[]')
return
- elif size == 1:
- builder.append(dtype.itemtype.str_format(self.getitem(0)))
- return
if size > 1000:
# Once this goes True it does not go back to False for recursive
# calls
use_ellipsis = True
ndims = len(self.shape)
+ if ndims == 0:
+ builder.append(dtype.itemtype.str_format(self.getitem(0)))
+ return
i = 0
builder.append('[')
if ndims > 1:
@@ -1143,6 +1150,9 @@
array.setslice(space, self)
return array
+ def fill(self, space, w_value):
+ self.setslice(space, scalar_w(space, self.dtype, w_value))
+
class ViewArray(ConcreteArray):
def create_sig(self):
@@ -1366,6 +1376,8 @@
var = interp2app(BaseArray.descr_var),
std = interp2app(BaseArray.descr_std),
+ fill = interp2app(BaseArray.descr_fill),
+
copy = interp2app(BaseArray.descr_copy),
reshape = interp2app(BaseArray.descr_reshape),
tolist = interp2app(BaseArray.descr_tolist),
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
@@ -457,6 +457,7 @@
("fabs", "fabs", 1, {"promote_to_float": True}),
("floor", "floor", 1, {"promote_to_float": True}),
+ ("ceil", "ceil", 1, {"promote_to_float": True}),
("exp", "exp", 1, {"promote_to_float": True}),
('sqrt', 'sqrt', 1, {'promote_to_float': True}),
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
@@ -166,14 +166,11 @@
# You can't subclass dtype
raises(TypeError, type, "Foo", (dtype,), {})
- def test_new(self):
- import _numpypy as np
- assert np.int_(4) == 4
- assert np.float_(3.4) == 3.4
+ def test_aliases(self):
+ from _numpypy import dtype
- def test_pow(self):
- from _numpypy import int_
- assert int_(4) ** 2 == 16
+ assert dtype("float") is dtype(float)
+
class AppTestTypes(BaseNumpyAppTest):
def test_abstract_types(self):
@@ -189,6 +186,15 @@
raises(TypeError, numpy.floating, 0)
raises(TypeError, numpy.inexact, 0)
+ def test_new(self):
+ import _numpypy as np
+ assert np.int_(4) == 4
+ assert np.float_(3.4) == 3.4
+
+ def test_pow(self):
+ from _numpypy import int_
+ assert int_(4) ** 2 == 16
+
def test_bool(self):
import _numpypy as numpy
@@ -318,7 +324,7 @@
else:
raises(OverflowError, numpy.int64, 9223372036854775807)
raises(OverflowError, numpy.int64, '9223372036854775807')
-
+
raises(OverflowError, numpy.int64, 9223372036854775808)
raises(OverflowError, numpy.int64, '9223372036854775808')
diff --git a/pypy/module/micronumpy/test/test_module.py b/pypy/module/micronumpy/test/test_module.py
--- a/pypy/module/micronumpy/test/test_module.py
+++ b/pypy/module/micronumpy/test/test_module.py
@@ -2,16 +2,11 @@
class AppTestNumPyModule(BaseNumpyAppTest):
- def test_mean(self):
- from _numpypy import array, mean
- assert mean(array(range(5))) == 2.0
- assert mean(range(5)) == 2.0
-
def test_average(self):
from _numpypy import array, average
assert average(range(10)) == 4.5
assert average(array(range(10))) == 4.5
-
+
def test_sum(self):
from _numpypy import array, sum
assert sum(range(10)) == 45
@@ -21,7 +16,7 @@
from _numpypy import array, min
assert min(range(10)) == 0
assert min(array(range(10))) == 0
-
+
def test_max(self):
from _numpypy import array, max
assert max(range(10)) == 9
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
@@ -728,15 +728,16 @@
assert d[1] == 12
def test_mean(self):
- from _numpypy import array, mean
+ from _numpypy import array
a = array(range(5))
assert a.mean() == 2.0
assert a[:4].mean() == 1.5
a = array(range(105)).reshape(3, 5, 7)
- b = mean(a, axis=0)
- b[0,0]==35.
+ b = a.mean(axis=0)
+ b[0, 0]==35.
+ assert a.mean(axis=0)[0, 0] == 35
assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all()
- assert (mean(a, 2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
+ assert (a.mean(2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
def test_sum(self):
from _numpypy import array
@@ -757,6 +758,7 @@
assert array([]).sum() == 0.0
raises(ValueError, 'array([]).max()')
assert (a.sum(0) == [30, 35, 40]).all()
+ assert (a.sum(axis=0) == [30, 35, 40]).all()
assert (a.sum(1) == [3, 12, 21, 30, 39]).all()
assert (a.max(0) == [12, 13, 14]).all()
assert (a.max(1) == [2, 5, 8, 11, 14]).all()
@@ -771,6 +773,8 @@
assert ((a + a).T.sum(2).T == (a + a).sum(0)).all()
assert (a.reshape(1,-1).sum(0) == range(105)).all()
assert (a.reshape(1,-1).sum(1) == 5460)
+ assert (array([[1,2],[3,4]]).prod(0) == [3, 8]).all()
+ assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all()
def test_identity(self):
from _numpypy import identity, array
@@ -1312,6 +1316,26 @@
raises(IndexError,'arange(3)[array([-15])]')
assert arange(3)[array(1)] == 1
+ def test_fill(self):
+ from _numpypy import array
+ a = array([1, 2, 3])
+ a.fill(10)
+ assert (a == [10, 10, 10]).all()
+ a.fill(False)
+ assert (a == [0, 0, 0]).all()
+ b = a[:1]
+ b.fill(4)
+ assert (b == [4]).all()
+ assert (a == [4, 0, 0]).all()
+
+ c = b + b
+ c.fill(27)
+ assert (c == [27]).all()
+
+ d = array(10)
+ d.fill(100)
+ assert d == 100
+
def test_array_indexing_bool(self):
from _numpypy import arange
a = arange(10)
@@ -1329,6 +1353,8 @@
a[a & 1 == 1] = array([8, 9, 10])
assert (a == [[0, 8], [2, 9], [4, 10]]).all()
+
+
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
import struct
@@ -1467,9 +1493,11 @@
assert repr(a) == "array(0.0)"
a = array(0.2)
assert repr(a) == "array(0.2)"
+ a = array([2])
+ assert repr(a) == "array([2])"
def test_repr_multi(self):
- from _numpypy import arange, zeros
+ from _numpypy import arange, zeros, array
a = zeros((3, 4))
assert repr(a) == '''array([[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
@@ -1492,6 +1520,9 @@
[498, 999],
[499, 1000],
[500, 1001]])'''
+ a = arange(2).reshape((2,1))
+ assert repr(a) == '''array([[0],
+ [1]])'''
def test_repr_slice(self):
from _numpypy import array, zeros
@@ -1576,18 +1607,3 @@
a = arange(0, 0.8, 0.1)
assert len(a) == 8
assert arange(False, True, True).dtype is dtype(int)
-
-
-class AppTestRanges(BaseNumpyAppTest):
- def test_app_reshape(self):
- from _numpypy import arange, array, dtype, reshape
- a = arange(12)
- b = reshape(a, (3, 4))
- assert b.shape == (3, 4)
- a = range(12)
- b = reshape(a, (3, 4))
- assert b.shape == (3, 4)
- a = array(range(105)).reshape(3, 5, 7)
- assert a.reshape(1, -1).shape == (1, 105)
- assert a.reshape(1, 1, -1).shape == (1, 1, 105)
- assert a.reshape(-1, 1, 1).shape == (105, 1, 1)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -190,14 +190,24 @@
for i in range(3):
assert c[i] == a[i] - b[i]
- def test_floor(self):
- from _numpypy import array, floor
-
- reference = [-2.0, -1.0, 0.0, 1.0, 1.0]
- a = array([-1.4, -1.0, 0.0, 1.0, 1.4])
+ def test_floorceil(self):
+ from _numpypy import array, floor, ceil
+ import math
+ reference = [-2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0]
+ a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
b = floor(a)
for i in range(5):
assert b[i] == reference[i]
+ reference = [-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0]
+ a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5])
+ b = ceil(a)
+ assert (reference == b).all()
+ inf = float("inf")
+ data = [1.5, 2.9999, -1.999, inf]
+ results = [math.floor(x) for x in data]
+ assert (floor(data) == results).all()
+ results = [math.ceil(x) for x in data]
+ assert (ceil(data) == results).all()
def test_copysign(self):
from _numpypy import array, copysign
@@ -238,7 +248,7 @@
assert b[i] == math.sin(a[i])
a = sin(array([True, False], dtype=bool))
- assert abs(a[0] - sin(1)) < 1e-7 # a[0] will be less precise
+ assert abs(a[0] - sin(1)) < 1e-7 # a[0] will be less precise
assert a[1] == 0.0
def test_cos(self):
@@ -259,7 +269,6 @@
for i in range(len(a)):
assert b[i] == math.tan(a[i])
-
def test_arcsin(self):
import math
from _numpypy import array, arcsin
@@ -283,7 +292,6 @@
for i in range(len(a)):
assert b[i] == math.acos(a[i])
-
a = array([-10, -1.5, -1.01, 1.01, 1.5, 10, float('nan'), float('inf'), float('-inf')])
b = arccos(a)
for f in b:
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -350,7 +350,8 @@
self.check_trace_count(1)
self.check_simple_loop({'getinteriorfield_raw': 2, 'float_add': 1,
'setinteriorfield_raw': 1, 'int_add': 2,
- 'int_eq': 1, 'guard_false': 1, 'jump': 1})
+ 'int_eq': 1, 'guard_false': 1, 'jump': 1,
+ 'arraylen_gc': 1})
def define_virtual_slice():
return """
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
@@ -391,6 +391,10 @@
return math.floor(v)
@simple_unary_op
+ def ceil(self, v):
+ return math.ceil(v)
+
+ @simple_unary_op
def exp(self, v):
try:
return math.exp(v)
diff --git a/pypy/module/pypyjit/__init__.py b/pypy/module/pypyjit/__init__.py
--- a/pypy/module/pypyjit/__init__.py
+++ b/pypy/module/pypyjit/__init__.py
@@ -11,6 +11,7 @@
'set_optimize_hook': 'interp_resop.set_optimize_hook',
'set_abort_hook': 'interp_resop.set_abort_hook',
'ResOperation': 'interp_resop.WrappedOp',
+ 'DebugMergePoint': 'interp_resop.DebugMergePoint',
'Box': 'interp_resop.WrappedBox',
}
diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py
--- a/pypy/module/pypyjit/interp_resop.py
+++ b/pypy/module/pypyjit/interp_resop.py
@@ -1,5 +1,6 @@
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
+ interp_attrproperty, interp_attrproperty_w)
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import unwrap_spec, interp2app, NoneNotWrapped
from pypy.interpreter.pycode import PyCode
@@ -10,6 +11,7 @@
from pypy.jit.metainterp.resoperation import rop, AbstractResOp
from pypy.rlib.nonconst import NonConstant
from pypy.rlib import jit_hooks
+from pypy.module.pypyjit.interp_jit import pypyjitdriver
class Cache(object):
in_recursion = False
@@ -111,13 +113,24 @@
def wrap_oplist(space, logops, operations, ops_offset=None):
l_w = []
+ jitdrivers_sd = logops.metainterp_sd.jitdrivers_sd
for op in operations:
if ops_offset is None:
ofs = -1
else:
ofs = ops_offset.get(op, 0)
- l_w.append(WrappedOp(jit_hooks._cast_to_gcref(op), ofs,
- logops.repr_of_resop(op)))
+ if op.opnum == rop.DEBUG_MERGE_POINT:
+ jd_sd = jitdrivers_sd[op.getarg(0).getint()]
+ greenkey = op.getarglist()[2:]
+ repr = jd_sd.warmstate.get_location_str(greenkey)
+ w_greenkey = wrap_greenkey(space, jd_sd.jitdriver, greenkey, repr)
+ l_w.append(DebugMergePoint(space, jit_hooks._cast_to_gcref(op),
+ logops.repr_of_resop(op),
+ jd_sd.jitdriver.name,
+ w_greenkey))
+ else:
+ l_w.append(WrappedOp(jit_hooks._cast_to_gcref(op), ofs,
+ logops.repr_of_resop(op)))
return l_w
class WrappedBox(Wrappable):
@@ -150,6 +163,15 @@
llres = res.llbox
return WrappedOp(jit_hooks.resop_new(num, args, llres), offset, repr)
+ at unwrap_spec(repr=str, jd_name=str)
+def descr_new_dmp(space, w_tp, w_args, repr, jd_name, w_greenkey):
+ args = [space.interp_w(WrappedBox, w_arg).llbox for w_arg in
+ space.listview(w_args)]
+ num = rop.DEBUG_MERGE_POINT
+ return DebugMergePoint(space,
+ jit_hooks.resop_new(num, args, jit_hooks.emptyval()),
+ repr, jd_name, w_greenkey)
+
class WrappedOp(Wrappable):
""" A class representing a single ResOperation, wrapped nicely
"""
@@ -182,6 +204,25 @@
box = space.interp_w(WrappedBox, w_box)
jit_hooks.resop_setresult(self.op, box.llbox)
+class DebugMergePoint(WrappedOp):
+ def __init__(self, space, op, repr_of_resop, jd_name, w_greenkey):
+ WrappedOp.__init__(self, op, -1, repr_of_resop)
+ self.w_greenkey = w_greenkey
+ self.jd_name = jd_name
+
+ def get_pycode(self, space):
+ if self.jd_name == pypyjitdriver.name:
+ return space.getitem(self.w_greenkey, space.wrap(0))
+ raise OperationError(space.w_AttributeError, space.wrap("This DebugMergePoint doesn't belong to the main Python JitDriver"))
+
+ def get_bytecode_no(self, space):
+ if self.jd_name == pypyjitdriver.name:
+ return space.getitem(self.w_greenkey, space.wrap(1))
+ raise OperationError(space.w_AttributeError, space.wrap("This DebugMergePoint doesn't belong to the main Python JitDriver"))
+
+ def get_jitdriver_name(self, space):
+ return space.wrap(self.jd_name)
+
WrappedOp.typedef = TypeDef(
'ResOperation',
__doc__ = WrappedOp.__doc__,
@@ -195,3 +236,15 @@
WrappedOp.descr_setresult)
)
WrappedOp.acceptable_as_base_class = False
+
+DebugMergePoint.typedef = TypeDef(
+ 'DebugMergePoint', WrappedOp.typedef,
+ __new__ = interp2app(descr_new_dmp),
+ greenkey = interp_attrproperty_w("w_greenkey", cls=DebugMergePoint),
+ pycode = GetSetProperty(DebugMergePoint.get_pycode),
+ bytecode_no = GetSetProperty(DebugMergePoint.get_bytecode_no),
+ jitdriver_name = GetSetProperty(DebugMergePoint.get_jitdriver_name),
+)
+DebugMergePoint.acceptable_as_base_class = False
+
+
diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py
--- a/pypy/module/pypyjit/policy.py
+++ b/pypy/module/pypyjit/policy.py
@@ -127,7 +127,7 @@
'imp', 'sys', 'array', '_ffi', 'itertools', 'operator',
'posix', '_socket', '_sre', '_lsprof', '_weakref',
'__pypy__', 'cStringIO', '_collections', 'struct',
- 'mmap', 'marshal']:
+ 'mmap', 'marshal', '_codecs']:
if modname == 'pypyjit' and 'interp_resop' in rest:
return False
return True
diff --git a/pypy/module/pypyjit/test/test_jit_hook.py b/pypy/module/pypyjit/test/test_jit_hook.py
--- a/pypy/module/pypyjit/test/test_jit_hook.py
+++ b/pypy/module/pypyjit/test/test_jit_hook.py
@@ -92,6 +92,7 @@
cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
cls.w_int_add_num = space.wrap(rop.INT_ADD)
+ cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
cls.orig_oplist = oplist
@@ -117,6 +118,10 @@
assert elem[2][2] == False
assert len(elem[3]) == 4
int_add = elem[3][0]
+ dmp = elem[3][1]
+ assert isinstance(dmp, pypyjit.DebugMergePoint)
+ assert dmp.pycode is self.f.func_code
+ assert dmp.greenkey == (self.f.func_code, 0, False)
#assert int_add.name == 'int_add'
assert int_add.num == self.int_add_num
self.on_compile_bridge()
@@ -211,3 +216,18 @@
assert op.getarg(0).getint() == 4
op.result = box
assert op.result.getint() == 1
+
+ def test_creation_dmp(self):
+ from pypyjit import DebugMergePoint, Box
+
+ def f():
+ pass
+
+ op = DebugMergePoint([Box(0)], 'repr', 'pypyjit', (f.func_code, 0, 0))
+ assert op.bytecode_no == 0
+ assert op.pycode is f.func_code
+ assert repr(op) == 'repr'
+ assert op.jitdriver_name == 'pypyjit'
+ assert op.num == self.dmp_num
+ op = DebugMergePoint([Box(0)], 'repr', 'notmain', ('str',))
+ raises(AttributeError, 'op.pycode')
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -10,7 +10,7 @@
CPYTHON_VERSION = (2, 7, 1, "final", 42) #XXX # sync patchlevel.h
CPYTHON_API_VERSION = 1013 #XXX # sync with include/modsupport.h
-PYPY_VERSION = (1, 7, 1, "dev", 0) #XXX # sync patchlevel.h
+PYPY_VERSION = (1, 8, 1, "dev", 0) #XXX # sync patchlevel.h
if platform.name == 'msvc':
COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600)
diff --git a/lib_pypy/numpypy/test/test_fromnumeric.py b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
rename from lib_pypy/numpypy/test/test_fromnumeric.py
rename to pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/lib_pypy/numpypy/test/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -1,7 +1,7 @@
-
from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-class AppTestFromNumeric(BaseNumpyAppTest):
+
+class AppTestFromNumeric(BaseNumpyAppTest):
def test_argmax(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, arange, argmax
@@ -18,12 +18,12 @@
from numpypy import array, arange, argmin
a = arange(6).reshape((2,3))
assert argmin(a) == 0
- # assert (argmax(a, axis=0) == array([0, 0, 0])).all()
- # assert (argmax(a, axis=1) == array([0, 0])).all()
+ assert (argmin(a, axis=0) == array([0, 0, 0])).all()
+ assert (argmin(a, axis=1) == array([0, 0])).all()
b = arange(6)
b[1] = 0
assert argmin(b) == 0
-
+
def test_shape(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, identity, shape
@@ -44,7 +44,7 @@
# assert (sum([[0, 1], [0, 5]], axis=1) == array([1, 5])).all()
# If the accumulator is too small, overflow occurs:
# assert ones(128, dtype=int8).sum(dtype=int8) == -128
-
+
def test_amin(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, arange, amin
@@ -86,14 +86,14 @@
assert ndim([[1,2,3],[4,5,6]]) == 2
assert ndim(array([[1,2,3],[4,5,6]])) == 2
assert ndim(1) == 0
-
+
def test_rank(self):
# tests taken from numpy/core/fromnumeric.py docstring
from numpypy import array, rank
assert rank([[1,2,3],[4,5,6]]) == 2
assert rank(array([[1,2,3],[4,5,6]])) == 2
assert rank(1) == 0
-
+
def test_var(self):
from numpypy import array, var
a = array([[1,2],[3,4]])
@@ -107,3 +107,31 @@
assert std(a) == 1.1180339887498949
# assert (std(a, axis=0) == array([ 1., 1.])).all()
# assert (std(a, axis=1) == array([ 0.5, 0.5]).all()
+
+ def test_mean(self):
+ from numpypy import array, mean
+ assert mean(array(range(5))) == 2.0
+ assert mean(range(5)) == 2.0
+
+ def test_reshape(self):
+ from numpypy import arange, array, dtype, reshape
+ a = arange(12)
+ b = reshape(a, (3, 4))
+ assert b.shape == (3, 4)
+ a = range(12)
+ b = reshape(a, (3, 4))
+ assert b.shape == (3, 4)
+ a = array(range(105)).reshape(3, 5, 7)
+ assert reshape(a, (1, -1)).shape == (1, 105)
+ assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
+ assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
+
+ def test_transpose(self):
+ from numpypy import arange, array, transpose, ones
+ x = arange(4).reshape((2,2))
+ assert (transpose(x) == array([[0, 2],[1, 3]])).all()
+ # Once axes argument is implemented, add more tests
+ raises(NotImplementedError, "transpose(x, axes=(1, 0, 2))")
+ # x = ones((1, 2, 3))
+ # assert transpose(x, (1, 0, 2)).shape == (2, 1, 3)
+
diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -64,6 +64,12 @@
check(', '.join([u'a']), u'a')
check(', '.join(['a', u'b']), u'a, b')
check(u', '.join(['a', 'b']), u'a, b')
+ try:
+ u''.join([u'a', 2, 3])
+ except TypeError, e:
+ assert 'sequence item 1' in str(e)
+ else:
+ raise Exception("DID NOT RAISE")
if sys.version_info >= (2,3):
def test_contains_ex(self):
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -201,7 +201,7 @@
return space.newbool(container.find(item) != -1)
def unicode_join__Unicode_ANY(space, w_self, w_list):
- list_w = space.unpackiterable(w_list)
+ list_w = space.listview(w_list)
size = len(list_w)
if size == 0:
@@ -216,22 +216,21 @@
def _unicode_join_many_items(space, w_self, list_w, size):
self = w_self._value
- sb = UnicodeBuilder()
+ prealloc_size = len(self) * (size - 1)
+ for i in range(size):
+ try:
+ prealloc_size += len(space.unicode_w(list_w[i]))
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ raise operationerrfmt(space.w_TypeError,
+ "sequence item %d: expected string or Unicode", i)
+ sb = UnicodeBuilder(prealloc_size)
for i in range(size):
if self and i != 0:
sb.append(self)
w_s = list_w[i]
- if isinstance(w_s, W_UnicodeObject):
- # shortcut for performance
- sb.append(w_s._value)
- else:
- try:
- sb.append(space.unicode_w(w_s))
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- raise operationerrfmt(space.w_TypeError,
- "sequence item %d: expected string or Unicode", i)
+ sb.append(space.unicode_w(w_s))
return space.wrap(sb.build())
def hash__Unicode(space, w_uni):
diff --git a/pypy/rlib/jit_hooks.py b/pypy/rlib/jit_hooks.py
--- a/pypy/rlib/jit_hooks.py
+++ b/pypy/rlib/jit_hooks.py
@@ -52,7 +52,10 @@
from pypy.jit.metainterp.history import ResOperation
args = [_cast_to_box(llargs[i]) for i in range(len(llargs))]
- res = _cast_to_box(llres)
+ if llres:
+ res = _cast_to_box(llres)
+ else:
+ res = None
return _cast_to_gcref(ResOperation(no, args, res))
@register_helper(annmodel.SomePtr(llmemory.GCREF))
diff --git a/pypy/rlib/longlong2float.py b/pypy/rlib/longlong2float.py
--- a/pypy/rlib/longlong2float.py
+++ b/pypy/rlib/longlong2float.py
@@ -79,19 +79,23 @@
longlong2float = rffi.llexternal(
"pypy__longlong2float", [rffi.LONGLONG], rffi.DOUBLE,
_callable=longlong2float_emulator, compilation_info=eci,
- _nowrapper=True, elidable_function=True, sandboxsafe=True)
+ _nowrapper=True, elidable_function=True, sandboxsafe=True,
+ oo_primitive="pypy__longlong2float")
float2longlong = rffi.llexternal(
"pypy__float2longlong", [rffi.DOUBLE], rffi.LONGLONG,
_callable=float2longlong_emulator, compilation_info=eci,
- _nowrapper=True, elidable_function=True, sandboxsafe=True)
+ _nowrapper=True, elidable_function=True, sandboxsafe=True,
+ oo_primitive="pypy__float2longlong")
uint2singlefloat = rffi.llexternal(
"pypy__uint2singlefloat", [rffi.UINT], rffi.FLOAT,
_callable=uint2singlefloat_emulator, compilation_info=eci,
- _nowrapper=True, elidable_function=True, sandboxsafe=True)
+ _nowrapper=True, elidable_function=True, sandboxsafe=True,
+ oo_primitive="pypy__uint2singlefloat")
singlefloat2uint = rffi.llexternal(
"pypy__singlefloat2uint", [rffi.FLOAT], rffi.UINT,
_callable=singlefloat2uint_emulator, compilation_info=eci,
- _nowrapper=True, elidable_function=True, sandboxsafe=True)
+ _nowrapper=True, elidable_function=True, sandboxsafe=True,
+ oo_primitive="pypy__singlefloat2uint")
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -420,7 +420,7 @@
vobj.concretetype.TO._gckind == 'gc')
else:
from pypy.rpython.ootypesystem import ootype
- ok = isinstance(vobj.concretetype, ootype.Instance)
+ ok = isinstance(vobj.concretetype, (ootype.Instance, ootype.BuiltinType))
if not ok:
from pypy.rpython.error import TyperError
raise TyperError("compute_unique_id() cannot be applied to"
diff --git a/pypy/rpython/lltypesystem/rclass.py b/pypy/rpython/lltypesystem/rclass.py
--- a/pypy/rpython/lltypesystem/rclass.py
+++ b/pypy/rpython/lltypesystem/rclass.py
@@ -510,7 +510,13 @@
ctype = inputconst(Void, self.object_type)
cflags = inputconst(Void, flags)
vlist = [ctype, cflags]
- vptr = llops.genop('malloc', vlist,
+ cnonmovable = self.classdef.classdesc.read_attribute(
+ '_alloc_nonmovable_', Constant(False))
+ if cnonmovable.value:
+ opname = 'malloc_nonmovable'
+ else:
+ opname = 'malloc'
+ vptr = llops.genop(opname, vlist,
resulttype = Ptr(self.object_type))
ctypeptr = inputconst(CLASSTYPE, self.rclass.getvtable())
self.setfield(vptr, '__class__', ctypeptr, llops)
diff --git a/pypy/rpython/lltypesystem/rtuple.py b/pypy/rpython/lltypesystem/rtuple.py
--- a/pypy/rpython/lltypesystem/rtuple.py
+++ b/pypy/rpython/lltypesystem/rtuple.py
@@ -27,6 +27,10 @@
def newtuple(cls, llops, r_tuple, items_v):
# items_v should have the lowleveltype of the internal reprs
+ assert len(r_tuple.items_r) == len(items_v)
+ for r_item, v_item in zip(r_tuple.items_r, items_v):
+ assert r_item.lowleveltype == v_item.concretetype
+ #
if len(r_tuple.items_r) == 0:
return inputconst(Void, ()) # a Void empty tuple
c1 = inputconst(Void, r_tuple.lowleveltype.TO)
diff --git a/pypy/rpython/ootypesystem/ootype.py b/pypy/rpython/ootypesystem/ootype.py
--- a/pypy/rpython/ootypesystem/ootype.py
+++ b/pypy/rpython/ootypesystem/ootype.py
@@ -512,6 +512,7 @@
"ll_append_char": Meth([CHARTP], Void),
"ll_append": Meth([STRINGTP], Void),
"ll_build": Meth([], STRINGTP),
+ "ll_getlength": Meth([], Signed),
})
self._setup_methods({})
@@ -1376,6 +1377,9 @@
def _cast_to_object(self):
return make_object(self)
+ def _identityhash(self):
+ return object.__hash__(self)
+
class _string(_builtin_type):
def __init__(self, STRING, value = ''):
@@ -1543,6 +1547,9 @@
else:
return make_unicode(u''.join(self._buf))
+ def ll_getlength(self):
+ return self.ll_build().ll_strlen()
+
class _null_string_builder(_null_mixin(_string_builder), _string_builder):
def __init__(self, STRING_BUILDER):
self.__dict__["_TYPE"] = STRING_BUILDER
diff --git a/pypy/rpython/ootypesystem/rbuilder.py b/pypy/rpython/ootypesystem/rbuilder.py
--- a/pypy/rpython/ootypesystem/rbuilder.py
+++ b/pypy/rpython/ootypesystem/rbuilder.py
@@ -21,6 +21,10 @@
builder.ll_append_char(char)
@staticmethod
+ def ll_getlength(builder):
+ return builder.ll_getlength()
+
+ @staticmethod
def ll_append(builder, string):
builder.ll_append(string)
diff --git a/pypy/rpython/rrange.py b/pypy/rpython/rrange.py
--- a/pypy/rpython/rrange.py
+++ b/pypy/rpython/rrange.py
@@ -204,7 +204,10 @@
v_index = hop.gendirectcall(self.ll_getnextindex, v_enumerate)
hop2 = hop.copy()
hop2.args_r = [self.r_baseiter]
+ r_item_src = self.r_baseiter.r_list.external_item_repr
+ r_item_dst = hop.r_result.items_r[1]
v_item = self.r_baseiter.rtype_next(hop2)
+ v_item = hop.llops.convertvar(v_item, r_item_src, r_item_dst)
return hop.r_result.newtuple(hop.llops, hop.r_result,
[v_index, v_item])
diff --git a/pypy/rpython/test/test_rbuilder.py b/pypy/rpython/test/test_rbuilder.py
--- a/pypy/rpython/test/test_rbuilder.py
+++ b/pypy/rpython/test/test_rbuilder.py
@@ -124,9 +124,5 @@
pass
class TestOOtype(BaseTestStringBuilder, OORtypeMixin):
- def test_string_getlength(self):
- py.test.skip("getlength(): not implemented on ootype")
- def test_unicode_getlength(self):
- py.test.skip("getlength(): not implemented on ootype")
def test_append_charpsize(self):
py.test.skip("append_charpsize(): not implemented on ootype")
diff --git a/pypy/rpython/test/test_rbuiltin.py b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -463,6 +463,31 @@
assert x1 == intmask(x0)
assert x3 == intmask(x2)
+ def test_id_on_builtins(self):
+ from pypy.rlib.objectmodel import compute_unique_id
+ from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
+ def fn():
+ return (compute_unique_id("foo"),
+ compute_unique_id(u"bar"),
+ compute_unique_id([1]),
+ compute_unique_id({"foo": 3}),
+ compute_unique_id(StringBuilder()),
+ compute_unique_id(UnicodeBuilder()))
+ res = self.interpret(fn, [])
+ for id in self.ll_unpack_tuple(res, 6):
+ assert isinstance(id, (int, r_longlong))
+
+ def test_uniqueness_of_id_on_strings(self):
+ from pypy.rlib.objectmodel import compute_unique_id
+ def fn(s1, s2):
+ return (compute_unique_id(s1), compute_unique_id(s2))
+
+ s1 = "foo"
+ s2 = ''.join(['f','oo'])
+ res = self.interpret(fn, [self.string_to_ll(s1), self.string_to_ll(s2)])
+ i1, i2 = self.ll_unpack_tuple(res, 2)
+ assert i1 != i2
+
def test_cast_primitive(self):
from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
def llf(u):
diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py
--- a/pypy/rpython/test/test_rclass.py
+++ b/pypy/rpython/test/test_rclass.py
@@ -1130,6 +1130,18 @@
assert sorted([u]) == [6] # 32-bit types
assert sorted([i, r, d, l]) == [2, 3, 4, 5] # 64-bit types
+ def test_nonmovable(self):
+ for (nonmovable, opname) in [(True, 'malloc_nonmovable'),
+ (False, 'malloc')]:
+ class A(object):
+ _alloc_nonmovable_ = nonmovable
+ def f():
+ return A()
+ t, typer, graph = self.gengraph(f, [])
+ assert summary(graph) == {opname: 1,
+ 'cast_pointer': 1,
+ 'setfield': 1}
+
class TestOOtype(BaseTestRclass, OORtypeMixin):
diff --git a/pypy/rpython/test/test_rrange.py b/pypy/rpython/test/test_rrange.py
--- a/pypy/rpython/test/test_rrange.py
+++ b/pypy/rpython/test/test_rrange.py
@@ -169,6 +169,22 @@
res = self.interpret(fn, [2])
assert res == 789
+ def test_enumerate_instances(self):
+ class A:
+ pass
+ def fn(n):
+ a = A()
+ b = A()
+ a.k = 10
+ b.k = 20
+ for i, x in enumerate([a, b]):
+ if i == n:
+ return x.k
+ return 5
+ res = self.interpret(fn, [1])
+ assert res == 20
+
+
class TestLLtype(BaseTestRrange, LLRtypeMixin):
from pypy.rpython.lltypesystem import rrange
diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -140,13 +140,15 @@
bytecode_name = None
is_bytecode = True
inline_level = None
+ has_dmp = False
def parse_code_data(self, arg):
m = re.search('<code object ([<>\w]+)[\.,] file \'(.+?)\'[\.,] line (\d+)> #(\d+) (\w+)',
arg)
if m is None:
# a non-code loop, like StrLiteralSearch or something
- self.bytecode_name = arg
+ if arg:
+ self.bytecode_name = arg
else:
self.name, self.filename, lineno, bytecode_no, self.bytecode_name = m.groups()
self.startlineno = int(lineno)
@@ -218,7 +220,7 @@
self.inputargs = inputargs
self.chunks = chunks
for chunk in self.chunks:
- if chunk.filename is not None:
+ if chunk.bytecode_name is not None:
self.startlineno = chunk.startlineno
self.filename = chunk.filename
self.name = chunk.name
diff --git a/pypy/tool/jitlogparser/test/test_parser.py b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -283,3 +283,13 @@
assert loops[-1].count == 1234
assert loops[1].count == 123
assert loops[2].count == 12
+
+def test_parse_nonpython():
+ loop = parse("""
+ []
+ debug_merge_point(0, 'random')
+ debug_merge_point(0, '<code object f. file 'x.py'. line 2> #15 COMPARE_OP')
+ """)
+ f = Function.from_operations(loop.operations, LoopStorage())
+ assert f.chunks[-1].filename == 'x.py'
+ assert f.filename is None
diff --git a/pypy/translator/jvm/builtin.py b/pypy/translator/jvm/builtin.py
--- a/pypy/translator/jvm/builtin.py
+++ b/pypy/translator/jvm/builtin.py
@@ -84,6 +84,9 @@
(ootype.StringBuilder.__class__, "ll_build"):
jvm.Method.v(jStringBuilder, "toString", (), jString),
+ (ootype.StringBuilder.__class__, "ll_getlength"):
+ jvm.Method.v(jStringBuilder, "length", (), jInt),
+
(ootype.String.__class__, "ll_hash"):
jvm.Method.v(jString, "hashCode", (), jInt),
diff --git a/pypy/translator/jvm/database.py b/pypy/translator/jvm/database.py
--- a/pypy/translator/jvm/database.py
+++ b/pypy/translator/jvm/database.py
@@ -358,7 +358,7 @@
ootype.Unsigned:jvm.PYPYSERIALIZEUINT,
ootype.SignedLongLong:jvm.LONGTOSTRINGL,
ootype.UnsignedLongLong: jvm.PYPYSERIALIZEULONG,
- ootype.Float:jvm.DOUBLETOSTRINGD,
+ ootype.Float:jvm.PYPYSERIALIZEDOUBLE,
ootype.Bool:jvm.PYPYSERIALIZEBOOLEAN,
ootype.Void:jvm.PYPYSERIALIZEVOID,
ootype.Char:jvm.PYPYESCAPEDCHAR,
diff --git a/pypy/translator/jvm/metavm.py b/pypy/translator/jvm/metavm.py
--- a/pypy/translator/jvm/metavm.py
+++ b/pypy/translator/jvm/metavm.py
@@ -92,6 +92,7 @@
CASTS = {
# FROM TO
(ootype.Signed, ootype.UnsignedLongLong): jvm.I2L,
+ (ootype.Unsigned, ootype.UnsignedLongLong): jvm.I2L,
(ootype.SignedLongLong, ootype.Signed): jvm.L2I,
(ootype.UnsignedLongLong, ootype.Unsigned): jvm.L2I,
(ootype.UnsignedLongLong, ootype.Signed): jvm.L2I,
diff --git a/pypy/translator/jvm/opcodes.py b/pypy/translator/jvm/opcodes.py
--- a/pypy/translator/jvm/opcodes.py
+++ b/pypy/translator/jvm/opcodes.py
@@ -101,6 +101,7 @@
'jit_force_virtualizable': Ignore,
'jit_force_virtual': DoNothing,
'jit_force_quasi_immutable': Ignore,
+ 'jit_is_virtual': PushPrimitive(ootype.Bool, False),
'debug_assert': [], # TODO: implement?
'debug_start_traceback': Ignore,
diff --git a/pypy/translator/jvm/src/pypy/PyPy.java b/pypy/translator/jvm/src/pypy/PyPy.java
--- a/pypy/translator/jvm/src/pypy/PyPy.java
+++ b/pypy/translator/jvm/src/pypy/PyPy.java
@@ -283,6 +283,14 @@
}
}
+ public double pypy__longlong2float(long l) {
+ return Double.longBitsToDouble(l);
+ }
+
+ public long pypy__float2longlong(double d) {
+ return Double.doubleToRawLongBits(d);
+ }
+
public double ooparse_float(String s) {
try {
return Double.parseDouble(s);
@@ -353,6 +361,19 @@
return "False";
}
+ public static String serialize_double(double d) {
+ if (Double.isNaN(d)) {
+ return "float(\"nan\")";
+ } else if (Double.isInfinite(d)) {
+ if (d > 0)
+ return "float(\"inf\")";
+ else
+ return "float(\"-inf\")";
+ } else {
+ return Double.toString(d);
+ }
+ }
+
private static String format_char(char c) {
String res = "\\x";
if (c <= 0x0F) res = res + "0";
diff --git a/pypy/translator/jvm/test/runtest.py b/pypy/translator/jvm/test/runtest.py
--- a/pypy/translator/jvm/test/runtest.py
+++ b/pypy/translator/jvm/test/runtest.py
@@ -56,6 +56,7 @@
# CLI could-be duplicate
class JvmGeneratedSourceWrapper(object):
+
def __init__(self, gensrc):
""" gensrc is an instance of JvmGeneratedSource """
self.gensrc = gensrc
diff --git a/pypy/translator/jvm/test/test_builder.py b/pypy/translator/jvm/test/test_builder.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/jvm/test/test_builder.py
@@ -0,0 +1,7 @@
+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rpython.test.test_rbuilder import BaseTestStringBuilder
+import py
+
+class TestJvmStringBuilder(JvmTest, BaseTestStringBuilder):
+ def test_append_charpsize(self):
+ py.test.skip("append_charpsize(): not implemented on ootype")
diff --git a/pypy/translator/jvm/test/test_longlong2float.py b/pypy/translator/jvm/test/test_longlong2float.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/jvm/test/test_longlong2float.py
@@ -0,0 +1,20 @@
+from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.rlib.longlong2float import *
+from pypy.rlib.test.test_longlong2float import enum_floats
+from pypy.rlib.test.test_longlong2float import fn as float2longlong2float
+import py
+
+class TestLongLong2Float(JvmTest):
+
+ def test_float2longlong_and_longlong2float(self):
+ def func(f):
+ return float2longlong2float(f)
+
+ for f in enum_floats():
+ assert repr(f) == repr(self.interpret(func, [f]))
+
+ def test_uint2singlefloat(self):
+ py.test.skip("uint2singlefloat is not implemented in ootype")
+
+ def test_singlefloat2uint(self):
+ py.test.skip("singlefloat2uint is not implemented in ootype")
diff --git a/pypy/translator/jvm/typesystem.py b/pypy/translator/jvm/typesystem.py
--- a/pypy/translator/jvm/typesystem.py
+++ b/pypy/translator/jvm/typesystem.py
@@ -955,6 +955,7 @@
PYPYSERIALIZEUINT = Method.s(jPyPy, 'serialize_uint', (jInt,), jString)
PYPYSERIALIZEULONG = Method.s(jPyPy, 'serialize_ulonglong', (jLong,),jString)
PYPYSERIALIZEVOID = Method.s(jPyPy, 'serialize_void', (), jString)
+PYPYSERIALIZEDOUBLE = Method.s(jPyPy, 'serialize_double', (jDouble,), jString)
PYPYESCAPEDCHAR = Method.s(jPyPy, 'escaped_char', (jChar,), jString)
PYPYESCAPEDUNICHAR = Method.s(jPyPy, 'escaped_unichar', (jChar,), jString)
PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString)
diff --git a/pypy/translator/oosupport/test_template/cast.py b/pypy/translator/oosupport/test_template/cast.py
--- a/pypy/translator/oosupport/test_template/cast.py
+++ b/pypy/translator/oosupport/test_template/cast.py
@@ -13,6 +13,9 @@
def to_longlong(x):
return r_longlong(x)
+def to_ulonglong(x):
+ return r_ulonglong(x)
+
def uint_to_int(x):
return intmask(x)
@@ -56,6 +59,9 @@
def test_unsignedlonglong_to_unsigned4(self):
self.check(to_uint, [r_ulonglong(18446744073709551615l)]) # max 64 bit num
+ def test_unsigned_to_usignedlonglong(self):
+ self.check(to_ulonglong, [r_uint(42)])
+
def test_uint_to_int(self):
self.check(uint_to_int, [r_uint(sys.maxint+1)])
More information about the pypy-commit
mailing list