[pypy-commit] pypy default: merged upstream
alex_gaynor
noreply at buildbot.pypy.org
Tue Nov 5 16:25:28 CET 2013
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r67852:b51a1a27936a
Date: 2013-11-05 07:24 -0800
http://bitbucket.org/pypy/pypy/changeset/b51a1a27936a/
Log: merged upstream
diff --git a/lib-python/2.7/string.py b/lib-python/2.7/string.py
--- a/lib-python/2.7/string.py
+++ b/lib-python/2.7/string.py
@@ -66,16 +66,17 @@
must be of the same length.
"""
- if len(fromstr) != len(tostr):
+ n = len(fromstr)
+ if n != len(tostr):
raise ValueError, "maketrans arguments must have same length"
- global _idmapL
- if not _idmapL:
- _idmapL = list(_idmap)
- L = _idmapL[:]
- fromstr = map(ord, fromstr)
- for i in range(len(fromstr)):
- L[fromstr[i]] = tostr[i]
- return ''.join(L)
+ # this function has been rewritten to suit PyPy better; it is
+ # almost 10x faster than the original.
+ buf = bytearray(256)
+ for i in range(256):
+ buf[i] = i
+ for i in range(n):
+ buf[ord(fromstr[i])] = tostr[i]
+ return str(buf)
diff --git a/pypy/module/__pypy__/interp_builders.py b/pypy/module/__pypy__/interp_builders.py
--- a/pypy/module/__pypy__/interp_builders.py
+++ b/pypy/module/__pypy__/interp_builders.py
@@ -4,6 +4,7 @@
from pypy.interpreter.typedef import TypeDef
from rpython.rlib.rstring import UnicodeBuilder, StringBuilder
from rpython.tool.sourcetools import func_with_new_name
+from rpython.rlib import jit
def create_builder(name, strtype, builder_cls):
@@ -23,10 +24,20 @@
def descr__new__(space, w_subtype, size=-1):
return W_Builder(space, size)
+ @jit.unroll_safe
+ def _append_multiple_chars(self, s):
+ for c in s:
+ self.builder.append(c)
+
@unwrap_spec(s=strtype)
def descr_append(self, space, s):
self._check_done(space)
- self.builder.append(s)
+ if jit.is_constant(len(s)) and len(s) < 5:
+ self._append_multiple_chars(s)
+ # the same but annotated as char
+ self.builder.append(s[0])
+ else:
+ self.builder.append(s)
@unwrap_spec(s=strtype, start=int, end=int)
def descr_append_slice(self, space, s, start, end):
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -249,6 +249,12 @@
v = self.convert_to(self.get_dtype(space))
return self.get_dtype(space).itemtype.round(v, decimals)
+ def descr_astype(self, space, w_dtype):
+ from pypy.module.micronumpy.interp_dtype import W_Dtype
+ dtype = space.interp_w(W_Dtype,
+ space.call_function(space.gettypefor(W_Dtype), w_dtype))
+ return self.convert_to(dtype)
+
def descr_view(self, space, w_dtype):
from pypy.module.micronumpy.interp_dtype import W_Dtype
dtype = space.interp_w(W_Dtype,
@@ -259,6 +265,9 @@
raise OperationError(space.w_NotImplementedError, space.wrap(
"view not implelemnted yet"))
+ def descr_self(self, space):
+ return self
+
def descr_get_dtype(self, space):
return self.get_dtype(space)
@@ -516,12 +525,17 @@
ravel = interp2app(W_GenericBox.descr_ravel),
round = interp2app(W_GenericBox.descr_round),
conjugate = interp2app(W_GenericBox.descr_conjugate),
+ astype = interp2app(W_GenericBox.descr_astype),
view = interp2app(W_GenericBox.descr_view),
+ squeeze = interp2app(W_GenericBox.descr_self),
dtype = GetSetProperty(W_GenericBox.descr_get_dtype),
itemsize = GetSetProperty(W_GenericBox.descr_get_itemsize),
+ nbytes = GetSetProperty(W_GenericBox.descr_get_itemsize),
shape = GetSetProperty(W_GenericBox.descr_get_shape),
+ strides = GetSetProperty(W_GenericBox.descr_get_shape),
ndim = GetSetProperty(W_GenericBox.descr_get_ndim),
+ T = GetSetProperty(W_GenericBox.descr_self),
)
W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -56,13 +56,32 @@
assert b.round() == 1.0
assert b.round(decimals=5) is b
+ def test_astype(self):
+ import numpy as np
+ a = np.bool_(True).astype(np.float32)
+ assert type(a) is np.float32
+ assert a == 1.0
+ a = np.bool_(True).astype('int32')
+ assert type(a) is np.int32
+ assert a == 1
+
+ def test_squeeze(self):
+ import numpy as np
+ assert np.True_.squeeze() is np.True_
+ a = np.float32(1.0)
+ assert a.squeeze() is a
+ raises(TypeError, a.squeeze, 2)
+
def test_attributes(self):
import numpypy as np
value = np.dtype('int64').type(12345)
assert value.dtype == np.dtype('int64')
assert value.itemsize == 8
+ assert value.nbytes == 8
assert value.shape == ()
+ assert value.strides == ()
assert value.ndim == 0
+ assert value.T is value
def test_complex_scalar_complex_cast(self):
import numpy as np
More information about the pypy-commit
mailing list