[pypy-commit] pypy numpy-unify-methods: merge from default
mattip
noreply at buildbot.pypy.org
Mon Feb 25 23:12:16 CET 2013
Author: Matti Picus <matti.picus at gmail.com>
Branch: numpy-unify-methods
Changeset: r61797:40195bce7415
Date: 2013-02-25 22:39 +0200
http://bitbucket.org/pypy/pypy/changeset/40195bce7415/
Log: merge from default
diff too long, truncating to 2000 out of 9021 lines
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -35,39 +35,43 @@
^pypy/doc/config/.+\.rst$
^pypy/doc/basicblock\.asc$
^pypy/doc/.+\.svninfo$
-^pypy/translator/c/src/libffi_msvc/.+\.obj$
-^pypy/translator/c/src/libffi_msvc/.+\.dll$
-^pypy/translator/c/src/libffi_msvc/.+\.lib$
-^pypy/translator/c/src/libffi_msvc/.+\.exp$
-^pypy/translator/c/src/cjkcodecs/.+\.o$
-^pypy/translator/c/src/cjkcodecs/.+\.obj$
-^pypy/translator/jvm/\.project$
-^pypy/translator/jvm/\.classpath$
-^pypy/translator/jvm/eclipse-bin$
-^pypy/translator/jvm/src/pypy/.+\.class$
-^pypy/translator/benchmark/docutils$
-^pypy/translator/benchmark/templess$
-^pypy/translator/benchmark/gadfly$
-^pypy/translator/benchmark/mako$
-^pypy/translator/benchmark/bench-custom\.benchmark_result$
-^pypy/translator/benchmark/shootout_benchmarks$
-^pypy/translator/goal/pypy-translation-snapshot$
-^pypy/translator/goal/pypy-c
-^pypy/translator/goal/pypy-jvm
-^pypy/translator/goal/pypy-jvm.jar
-^pypy/translator/goal/.+\.exe$
-^pypy/translator/goal/.+\.dll$
-^pypy/translator/goal/target.+-c$
+^rpython/translator/c/src/libffi_msvc/.+\.obj$
+^rpython/translator/c/src/libffi_msvc/.+\.dll$
+^rpython/translator/c/src/libffi_msvc/.+\.lib$
+^rpython/translator/c/src/libffi_msvc/.+\.exp$
+^rpython/translator/c/src/cjkcodecs/.+\.o$
+^rpython/translator/c/src/cjkcodecs/.+\.obj$
+^rpython/translator/c/src/stacklet/.+\.o$
+^rpython/translator/c/src/.+\.o$
+^rpython/translator/jvm/\.project$
+^rpython/translator/jvm/\.classpath$
+^rpython/translator/jvm/eclipse-bin$
+^rpython/translator/jvm/src/pypy/.+\.class$
+^rpython/translator/benchmark/docutils$
+^rpython/translator/benchmark/templess$
+^rpython/translator/benchmark/gadfly$
+^rpython/translator/benchmark/mako$
+^rpython/translator/benchmark/bench-custom\.benchmark_result$
+^rpython/translator/benchmark/shootout_benchmarks$
+^rpython/translator/goal/target.+-c$
+^rpython/translator/goal/.+\.exe$
+^rpython/translator/goal/.+\.dll$
+^pypy/goal/pypy-translation-snapshot$
+^pypy/goal/pypy-c
+^pypy/goal/pypy-jvm
+^pypy/goal/pypy-jvm.jar
+^pypy/goal/.+\.exe$
+^pypy/goal/.+\.dll$
^pypy/_cache$
^pypy/doc/statistic/.+\.html$
^pypy/doc/statistic/.+\.eps$
^pypy/doc/statistic/.+\.pdf$
-^pypy/translator/cli/src/pypylib\.dll$
-^pypy/translator/cli/src/query\.exe$
-^pypy/translator/cli/src/main\.exe$
+^rpython/translator/cli/src/pypylib\.dll$
+^rpython/translator/cli/src/query\.exe$
+^rpython/translator/cli/src/main\.exe$
^lib_pypy/ctypes_config_cache/_.+_cache\.py$
^lib_pypy/ctypes_config_cache/_.+_.+_\.py$
-^pypy/translator/cli/query-descriptions$
+^rpython/translator/cli/query-descriptions$
^pypy/doc/discussion/.+\.html$
^include/.+\.h$
^include/.+\.inl$
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,5 +1,14 @@
-from _numpypy import *
-from .core import *
+import core
+from core import *
+import lib
+from lib import *
+
+from __builtin__ import bool, int, long, float, complex, object, unicode, str
+from core import abs, max, min
+
+__all__ = []
+__all__ += core.__all__
+__all__ += lib.__all__
import sys
sys.modules.setdefault('numpy', sys.modules['numpypy'])
diff --git a/lib_pypy/numpypy/core/__init__.py b/lib_pypy/numpypy/core/__init__.py
--- a/lib_pypy/numpypy/core/__init__.py
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -1,3 +1,14 @@
-from .fromnumeric import *
-from .numeric import *
-from .shape_base import *
+import numeric
+from numeric import *
+import fromnumeric
+from fromnumeric import *
+import shape_base
+from shape_base import *
+
+from fromnumeric import amax as max, amin as min
+from numeric import absolute as abs
+
+__all__ = []
+__all__ += numeric.__all__
+__all__ += fromnumeric.__all__
+__all__ += shape_base.__all__
diff --git a/lib_pypy/numpypy/core/_methods.py b/lib_pypy/numpypy/core/_methods.py
--- a/lib_pypy/numpypy/core/_methods.py
+++ b/lib_pypy/numpypy/core/_methods.py
@@ -1,11 +1,9 @@
# Array methods which are called by the both the C-code for the method
# and the Python code for the NumPy-namespace function
-#from numpy.core import multiarray as mu
-#from numpy.core import umath as um
-import _numpypy as mu
-um = mu
-from numpy.core.numeric import asanyarray
+import multiarray as mu
+import umath as um
+from numeric import asanyarray
def _amax(a, axis=None, out=None, keepdims=False):
return um.maximum.reduce(a, axis=axis,
diff --git a/lib_pypy/numpypy/core/arrayprint.py b/lib_pypy/numpypy/core/arrayprint.py
--- a/lib_pypy/numpypy/core/arrayprint.py
+++ b/lib_pypy/numpypy/core/arrayprint.py
@@ -13,9 +13,9 @@
# and by Travis Oliphant 2005-8-22 for numpy
import sys
-import _numpypy as _nt
-from _numpypy import maximum, minimum, absolute, not_equal, isnan, isinf
-#from _numpypy import format_longfloat, datetime_as_string, datetime_data
+import numerictypes as _nt
+from umath import maximum, minimum, absolute, not_equal, isnan, isinf
+#from multiarray import format_longfloat, datetime_as_string, datetime_data
from fromnumeric import ravel
@@ -294,12 +294,12 @@
#else:
format_function = formatdict['int']
elif issubclass(dtypeobj, _nt.floating):
- if issubclass(dtypeobj, _nt.longfloat):
+ if hasattr(_nt, 'longfloat') and issubclass(dtypeobj, _nt.longfloat):
format_function = formatdict['longfloat']
else:
format_function = formatdict['float']
elif issubclass(dtypeobj, _nt.complexfloating):
- if issubclass(dtypeobj, _nt.clongfloat):
+ if hasattr(_nt, 'clongfloat') and issubclass(dtypeobj, _nt.clongfloat):
format_function = formatdict['longcomplexfloat']
else:
format_function = formatdict['complexfloat']
diff --git a/lib_pypy/numpypy/core/fromnumeric.py b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -16,6 +16,7 @@
######################################################################
import numpypy
+import _numpypy
# Module containing non-deprecated functions borrowed from Numeric.
__docformat__ = "restructuredtext en"
@@ -274,7 +275,7 @@
[-1, -2, -3, -4, -5]]])
"""
- raise NotImplementedError('Waiting on interp level method')
+ return _numpypy.choose(a, choices, out, mode)
def repeat(a, repeats, axis=None):
@@ -316,7 +317,7 @@
[3, 4]])
"""
- raise NotImplementedError('Waiting on interp level method')
+ return _numpypy.repeat(a, repeats, axis)
def put(a, ind, v, mode='raise'):
@@ -1290,7 +1291,9 @@
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])
"""
- raise NotImplementedError('Waiting on interp level method')
+ if not hasattr(a, 'clip'):
+ a = numpypy.array(a)
+ return a.clip(a_min, a_max, out=out)
def sum(a, axis=None, dtype=None, out=None):
@@ -1360,10 +1363,9 @@
"""
assert dtype is None
- assert out is None
if not hasattr(a, "sum"):
a = numpypy.array(a)
- return a.sum(axis=axis)
+ return a.sum(axis=axis, out=out)
def product (a, axis=None, dtype=None, out=None):
@@ -1720,11 +1722,11 @@
4.0
"""
- assert axis is None
- assert out is None
if not hasattr(a, "max"):
a = numpypy.array(a)
- return a.max()
+ if a.size < 1:
+ return numpypy.array([])
+ return a.max(axis=axis, out=out)
def amin(a, axis=None, out=None):
@@ -1782,12 +1784,11 @@
0.0
"""
- # amin() is equivalent to min()
- assert axis is None
- assert out is None
if not hasattr(a, 'min'):
a = numpypy.array(a)
- return a.min()
+ if a.size < 1:
+ return numpypy.array([])
+ return a.min(axis=axis, out=out)
def alen(a):
"""
diff --git a/lib_pypy/numpypy/core/multiarray.py b/lib_pypy/numpypy/core/multiarray.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/multiarray.py
@@ -0,0 +1,1 @@
+from _numpypy.multiarray import *
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -1,13 +1,40 @@
+__all__ = [
+ 'newaxis', 'ufunc',
+ 'asarray', 'asanyarray', 'base_repr',
+ 'array_repr', 'array_str', 'set_string_function',
+ 'array_equal', 'outer', 'identity', 'little_endian',
+ 'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_',
+ ]
-from _numpypy import array, ndarray, int_, float_, bool_, flexible #, complex_# , longlong
-from _numpypy import concatenate
-from .fromnumeric import any
-import math
import sys
-import _numpypy as multiarray # ARGH
-from numpypy.core.arrayprint import array2string
+import multiarray
+from multiarray import *
+del set_string_function
+del typeinfo
+import umath
+from umath import *
+import numerictypes
+from numerictypes import *
+
+def extend_all(module):
+ adict = {}
+ for a in __all__:
+ adict[a] = 1
+ try:
+ mall = getattr(module, '__all__')
+ except AttributeError:
+ mall = [k for k in module.__dict__.keys() if not k.startswith('_')]
+ for a in mall:
+ if a not in adict:
+ __all__.append(a)
+
+extend_all(multiarray)
+__all__.remove('typeinfo')
+extend_all(umath)
+extend_all(numerictypes)
newaxis = None
+ufunc = type(sin)
# XXX this file to be reviewed
def seterr(**args):
@@ -118,6 +145,10 @@
res.append('-')
return ''.join(reversed(res or '0'))
+
+#Use numarray's printing function
+from arrayprint import array2string
+
_typelessdata = [int_, float_]#, complex_]
# XXX
#if issubclass(intc, int):
@@ -303,6 +334,11 @@
else:
return multiarray.set_string_function(f, repr)
+set_string_function(array_str, 0)
+set_string_function(array_repr, 1)
+
+little_endian = (sys.byteorder == 'little')
+
def array_equal(a1, a2):
"""
True if two arrays have the same shape and elements, False otherwise.
@@ -414,21 +450,6 @@
"""
return array(a, dtype, copy=False, order=order)
-set_string_function(array_str, 0)
-set_string_function(array_repr, 1)
-
-little_endian = (sys.byteorder == 'little')
-
-Inf = inf = infty = Infinity = PINF = float('inf')
-NINF = float('-inf')
-PZERO = 0.0
-NZERO = -0.0
-nan = NaN = NAN = float('nan')
-False_ = bool_(False)
-True_ = bool_(True)
-e = math.e
-pi = math.pi
-
def outer(a,b):
"""
Compute the outer product of two vectors.
@@ -501,3 +522,43 @@
a = asarray(a)
b = asarray(b)
return a.ravel()[:,newaxis]*b.ravel()[newaxis,:]
+
+def identity(n, dtype=None):
+ """
+ Return the identity array.
+
+ The identity array is a square array with ones on
+ the main diagonal.
+
+ Parameters
+ ----------
+ n : int
+ Number of rows (and columns) in `n` x `n` output.
+ dtype : data-type, optional
+ Data-type of the output. Defaults to ``float``.
+
+ Returns
+ -------
+ out : ndarray
+ `n` x `n` array with its main diagonal set to one,
+ and all other elements 0.
+
+ Examples
+ --------
+ >>> np.identity(3)
+ array([[ 1., 0., 0.],
+ [ 0., 1., 0.],
+ [ 0., 0., 1.]])
+
+ """
+ from numpy import eye
+ return eye(n, dtype=dtype)
+
+Inf = inf = infty = Infinity = PINF
+nan = NaN = NAN
+False_ = bool_(False)
+True_ = bool_(True)
+
+import fromnumeric
+from fromnumeric import *
+extend_all(fromnumeric)
diff --git a/lib_pypy/numpypy/core/numerictypes.py b/lib_pypy/numpypy/core/numerictypes.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/numerictypes.py
@@ -0,0 +1,1 @@
+from _numpypy.numerictypes import *
diff --git a/lib_pypy/numpypy/core/shape_base.py b/lib_pypy/numpypy/core/shape_base.py
--- a/lib_pypy/numpypy/core/shape_base.py
+++ b/lib_pypy/numpypy/core/shape_base.py
@@ -1,4 +1,6 @@
-import _numpypy
+__all__ = ['atleast_1d', 'atleast_2d', 'atleast_3d', 'vstack', 'hstack']
+
+import numeric as _nx
from numeric import array, asanyarray, newaxis
def atleast_1d(*arys):
@@ -221,7 +223,7 @@
[4]])
"""
- return _numpypy.concatenate(map(atleast_2d,tup),0)
+ return _nx.concatenate(map(atleast_2d,tup),0)
def hstack(tup):
"""
@@ -268,56 +270,6 @@
arrs = map(atleast_1d,tup)
# As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
if arrs[0].ndim == 1:
- return _numpypy.concatenate(arrs, 0)
+ return _nx.concatenate(arrs, 0)
else:
- return _numpypy.concatenate(arrs, 1)
-
-def dstack(tup):
- """
- Stack arrays in sequence depth wise (along third axis).
-
- Takes a sequence of arrays and stack them along the third axis
- to make a single array. Rebuilds arrays divided by `dsplit`.
- This is a simple way to stack 2D arrays (images) into a single
- 3D array for processing.
-
- Parameters
- ----------
- tup : sequence of arrays
- Arrays to stack. All of them must have the same shape along all
- but the third axis.
-
- Returns
- -------
- stacked : ndarray
- The array formed by stacking the given arrays.
-
- See Also
- --------
- vstack : Stack along first axis.
- hstack : Stack along second axis.
- concatenate : Join arrays.
- dsplit : Split array along third axis.
-
- Notes
- -----
- Equivalent to ``np.concatenate(tup, axis=2)``.
-
- Examples
- --------
- >>> a = np.array((1,2,3))
- >>> b = np.array((2,3,4))
- >>> np.dstack((a,b))
- array([[[1, 2],
- [2, 3],
- [3, 4]]])
-
- >>> a = np.array([[1],[2],[3]])
- >>> b = np.array([[2],[3],[4]])
- >>> np.dstack((a,b))
- array([[[1, 2]],
- [[2, 3]],
- [[3, 4]]])
-
- """
- return _numpypy.concatenate(map(atleast_3d,tup),2)
+ return _nx.concatenate(arrs, 1)
diff --git a/lib_pypy/numpypy/core/umath.py b/lib_pypy/numpypy/core/umath.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/umath.py
@@ -0,0 +1,12 @@
+from _numpypy.umath import *
+
+import math
+e = math.e
+pi = math.pi
+del math
+
+PZERO = 0.0
+NZERO = -0.0
+PINF = float('inf')
+NINF = float('-inf')
+NAN = float('nan')
diff --git a/lib_pypy/numpypy/lib/__init__.py b/lib_pypy/numpypy/lib/__init__.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/lib/__init__.py
@@ -0,0 +1,11 @@
+import function_base
+from function_base import *
+import shape_base
+from shape_base import *
+import twodim_base
+from twodim_base import *
+
+__all__ = []
+__all__ += function_base.__all__
+__all__ += shape_base.__all__
+__all__ += twodim_base.__all__
diff --git a/lib_pypy/numpypy/lib/function_base.py b/lib_pypy/numpypy/lib/function_base.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/lib/function_base.py
@@ -0,0 +1,10 @@
+__all__ = ['average']
+
+from ..core.numeric import array
+
+def average(a):
+ # This implements a weighted average, for now we don't implement the
+ # weighting, just the average part!
+ if not hasattr(a, "mean"):
+ a = array(a)
+ return a.mean()
diff --git a/lib_pypy/numpypy/lib/shape_base.py b/lib_pypy/numpypy/lib/shape_base.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/lib/shape_base.py
@@ -0,0 +1,54 @@
+__all__ = ['dstack']
+
+from ..core import numeric as _nx
+from ..core import atleast_3d
+
+def dstack(tup):
+ """
+ Stack arrays in sequence depth wise (along third axis).
+
+ Takes a sequence of arrays and stack them along the third axis
+ to make a single array. Rebuilds arrays divided by `dsplit`.
+ This is a simple way to stack 2D arrays (images) into a single
+ 3D array for processing.
+
+ Parameters
+ ----------
+ tup : sequence of arrays
+ Arrays to stack. All of them must have the same shape along all
+ but the third axis.
+
+ Returns
+ -------
+ stacked : ndarray
+ The array formed by stacking the given arrays.
+
+ See Also
+ --------
+ vstack : Stack along first axis.
+ hstack : Stack along second axis.
+ concatenate : Join arrays.
+ dsplit : Split array along third axis.
+
+ Notes
+ -----
+ Equivalent to ``np.concatenate(tup, axis=2)``.
+
+ Examples
+ --------
+ >>> a = np.array((1,2,3))
+ >>> b = np.array((2,3,4))
+ >>> np.dstack((a,b))
+ array([[[1, 2],
+ [2, 3],
+ [3, 4]]])
+
+ >>> a = np.array([[1],[2],[3]])
+ >>> b = np.array([[2],[3],[4]])
+ >>> np.dstack((a,b))
+ array([[[1, 2]],
+ [[2, 3]],
+ [[3, 4]]])
+
+ """
+ return _nx.concatenate(map(atleast_3d,tup),2)
diff --git a/lib_pypy/numpypy/lib/twodim_base.py b/lib_pypy/numpypy/lib/twodim_base.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/lib/twodim_base.py
@@ -0,0 +1,54 @@
+__all__ = ['eye']
+
+from ..core.numeric import zeros
+
+def eye(N, M=None, k=0, dtype=float):
+ """
+ Return a 2-D array with ones on the diagonal and zeros elsewhere.
+
+ Parameters
+ ----------
+ N : int
+ Number of rows in the output.
+ M : int, optional
+ Number of columns in the output. If None, defaults to `N`.
+ k : int, optional
+ Index of the diagonal: 0 (the default) refers to the main diagonal,
+ a positive value refers to an upper diagonal, and a negative value
+ to a lower diagonal.
+ dtype : data-type, optional
+ Data-type of the returned array.
+
+ Returns
+ -------
+ I : ndarray of shape (N,M)
+ An array where all elements are equal to zero, except for the `k`-th
+ diagonal, whose values are equal to one.
+
+ See Also
+ --------
+ identity : (almost) equivalent function
+ diag : diagonal 2-D array from a 1-D array specified by the user.
+
+ Examples
+ --------
+ >>> np.eye(2, dtype=int)
+ array([[1, 0],
+ [0, 1]])
+ >>> np.eye(3, k=1)
+ array([[ 0., 1., 0.],
+ [ 0., 0., 1.],
+ [ 0., 0., 0.]])
+
+ """
+ if M is None:
+ M = N
+ m = zeros((N, M), dtype=dtype)
+ if k >= M:
+ return m
+ if k >= 0:
+ i = k
+ else:
+ i = (-k) * M
+ m[:M-k].flat[i::M+1] = 1
+ return m
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -134,7 +134,7 @@
``ReferenceError`` at any place that uses them. (Or, better yet, don't use
``weakref.proxy()`` at all; use ``weakref.ref()``.)
-There are a few extra implications for the difference in the GC. Most
+There are a few extra implications from the difference in the GC. Most
notably, if an object has a ``__del__``, the ``__del__`` is never called more
than once in PyPy; but CPython will call the same ``__del__`` several times
if the object is resurrected and dies again. The ``__del__`` methods are
@@ -156,7 +156,7 @@
.. __: http://bugs.pypy.org/issue736
-Using the default GC called ``minimark``, the built-in function ``id()``
+Using the default GC (called ``minimark``), the built-in function ``id()``
works like it does in CPython. With other GCs it returns numbers that
are not real addresses (because an object can move around several times)
and calling it a lot can lead to performance problem.
@@ -286,7 +286,7 @@
-------------
* Hash randomization (``-R``) is ignored in PyPy. As documented in
- http://bugs.python.org/issue14621 , some of us believe it has no
+ http://bugs.python.org/issue14621, some of us believe it has no
purpose in CPython either.
* ``sys.setrecursionlimit(n)`` sets the limit only approximately,
diff --git a/pypy/doc/ctypes-implementation.rst b/pypy/doc/ctypes-implementation.rst
--- a/pypy/doc/ctypes-implementation.rst
+++ b/pypy/doc/ctypes-implementation.rst
@@ -38,7 +38,7 @@
in dynamic libraries through libffi. Freeing objects in most cases and making
sure that objects referring to each other are kept alive is responsibility of the higher levels.
-This module uses bindings to libffi which are defined in ``pypy/rlib/libffi.py``.
+This module uses bindings to libffi which are defined in ``rpython/rlib/libffi.py``.
We tried to keep this module as small as possible. It is conceivable
that other implementations (e.g. Jython) could use our ctypes
diff --git a/pypy/doc/discussion/improve-rpython.rst b/pypy/doc/discussion/improve-rpython.rst
--- a/pypy/doc/discussion/improve-rpython.rst
+++ b/pypy/doc/discussion/improve-rpython.rst
@@ -39,7 +39,7 @@
- Allocate variables on the stack, and pass their address ("by reference") to
llexternal functions. For a typical usage, see
- `pypy.rlib.rsocket.RSocket.getsockopt_int`.
+ `rpython.rlib.rsocket.RSocket.getsockopt_int`.
Extensible type system for llexternal
-------------------------------------
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -202,20 +202,20 @@
Be sure to enable it again if you need it!
-The PyPy translation tool chain
-===============================
+The RPython translation tool chain
+===================================
----------------------------------------------
-Can PyPy compile normal Python programs to C?
----------------------------------------------
+------------------------------------------------
+Can RPython compile normal Python programs to C?
+------------------------------------------------
-No, PyPy is not a Python compiler.
+No, RPython is not a Python compiler.
In Python, it is mostly impossible to *prove* anything about the types
that a program will manipulate by doing a static analysis. It should be
clear if you are familiar with Python, but if in doubt see [BRETT]_.
-If you want a fast Python program, please use our JIT_ instead.
+If you want a fast Python program, please use the PyPy JIT_ instead.
.. _JIT: jit/index.html
@@ -300,8 +300,8 @@
Do I have to rewrite my programs in RPython?
--------------------------------------------
-No. And you shouldn't try. First and foremost, RPython is a language
-that is designed to write interpreters in. It is a restricted subset of
+No, and you shouldn't try. First and foremost, RPython is a language
+designed for writing interpreters. It is a restricted subset of
Python. If you program is not an interpreter but tries to do "real
things", like use *any* part of the standard Python library or *any*
3rd-party library, then it is not RPython to start with. You should
@@ -381,8 +381,8 @@
No, you have to rebuild the entire interpreter. This means two things:
-* It is imperative to use test-driven development. You have to test
- exhaustively your module in pure Python, before even attempting to
+* It is imperative to use test-driven development. You have to exhaustively
+ test your module in pure Python, before even attempting to
translate it. Once you translate it, you should have only a few typing
issues left to fix, but otherwise the result should work out of the box.
diff --git a/pypy/doc/garbage_collection.rst b/pypy/doc/garbage_collection.rst
--- a/pypy/doc/garbage_collection.rst
+++ b/pypy/doc/garbage_collection.rst
@@ -42,7 +42,7 @@
Two arenas of equal size, with only one arena in use and getting filled
with new objects. When the arena is full, the live objects are copied
into the other arena using Cheney's algorithm. The old arena is then
-cleared. See `rpython/rtyper/memory/gc/semispace.py`_.
+cleared. See `rpython/memory/gc/semispace.py`_.
On Unix the clearing is done by reading ``/dev/zero`` into the arena,
which is extremely memory efficient at least on Linux: it lets the
@@ -55,7 +55,7 @@
Generational GC
---------------
-This is a two-generations GC. See `rpython/rtyper/memory/gc/generation.py`_.
+This is a two-generations GC. See `rpython/memory/gc/generation.py`_.
It is implemented as a subclass of the Semispace copying collector. It
adds a nursery, which is a chunk of the current semispace. Its size is
@@ -86,7 +86,7 @@
Each generation is collected much less often than the previous one. The
division of the generations is slightly more complicated than just
nursery / semispace / external; see the diagram at the start of the
-source code, in `rpython/rtyper/memory/gc/hybrid.py`_.
+source code, in `rpython/memory/gc/hybrid.py`_.
Mark & Compact GC
-----------------
@@ -161,7 +161,7 @@
to the old stage. The dying case 2 objects are immediately freed.
- The old stage is an area of memory containing old (small) objects. It
- is handled by `rpython/rtyper/memory/gc/minimarkpage.py`_. It is organized
+ is handled by `rpython/memory/gc/minimarkpage.py`_. It is organized
as "arenas" of 256KB or 512KB, subdivided into "pages" of 4KB or 8KB.
Each page can either be free, or contain small objects of all the same
size. Furthermore at any point in time each object location can be
diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst
--- a/pypy/doc/getting-started-dev.rst
+++ b/pypy/doc/getting-started-dev.rst
@@ -20,7 +20,7 @@
To start the interactive translator shell do::
- cd pypy
+ cd rpython
python bin/translatorshell.py
Test snippets of translatable code are provided in the file
diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst
--- a/pypy/doc/index.rst
+++ b/pypy/doc/index.rst
@@ -286,7 +286,7 @@
`rpython/rtyper/ootypesystem/`_ the `object-oriented type system`_
for OO backends
-`rpython/rtyper/memory/`_ the `garbage collector`_ construction
+`rpython/memory/`_ the `garbage collector`_ construction
framework
`rpython/translator/`_ translation_ backends and support code
diff --git a/pypy/doc/interpreter.rst b/pypy/doc/interpreter.rst
--- a/pypy/doc/interpreter.rst
+++ b/pypy/doc/interpreter.rst
@@ -25,7 +25,7 @@
compact bytecode format as CPython 2.7, with minor differences in the bytecode
set. Our bytecode compiler is
implemented as a chain of flexible passes (tokenizer, lexer, parser,
-abstract syntax tree builder, bytecode generator). The latter passes
+abstract syntax tree builder and bytecode generator). The latter passes
are based on the ``compiler`` package from the standard library of
CPython, with various improvements and bug fixes. The bytecode compiler
(living under `pypy/interpreter/astcompiler/`_) is now integrated and is
@@ -38,8 +38,8 @@
calling its ``frame.eval()`` method. This main entry point
initialize appropriate namespaces and then interprets each
bytecode instruction. Python's standard library contains
-the `lib-python/2.7/dis.py`_ module which allows to view
-the Virtual's machine bytecode instructions::
+the `lib-python/2.7/dis.py`_ module which allows to inspection
+of the virtual machine's bytecode instructions::
>>> import dis
>>> def f(x):
@@ -50,10 +50,10 @@
6 BINARY_ADD
7 RETURN_VALUE
-CPython as well as PyPy are stack-based virtual machines, i.e.
-they don't have registers but put object to and pull objects
+CPython and PyPy are stack-based virtual machines, i.e.
+they don't have registers but instead push object to and pull objects
from a stack. The bytecode interpreter is only responsible
-for implementing control flow and putting and pulling black
+for implementing control flow and pushing and pulling black
box objects to and from this value stack. The bytecode interpreter
does not know how to perform operations on those black box
(`wrapped`_) objects for which it delegates to the `object
@@ -75,8 +75,8 @@
on ``OperationErrors``.
The interpreter implementation offers mechanisms to allow a
-caller to be unaware if a particular function invocation leads
-to bytecode interpretation or is executed directly at
+caller to be unaware of whether a particular function invocation
+leads to bytecode interpretation or is executed directly at
interpreter-level. The two basic kinds of `Gateway classes`_
expose either an interpreter-level function to
application-level execution (``interp2app``) or allow
diff --git a/pypy/doc/stackless.rst b/pypy/doc/stackless.rst
--- a/pypy/doc/stackless.rst
+++ b/pypy/doc/stackless.rst
@@ -273,7 +273,7 @@
more information about them please see the documentation in the C source
at `rpython/translator/c/src/stacklet/stacklet.h`_.
-The module ``pypy.rlib.rstacklet`` is a thin wrapper around the above
+The module ``rpython.rlib.rstacklet`` is a thin wrapper around the above
functions. The key point is that new() and switch() always return a
fresh stacklet handle (or an empty one), and switch() additionally
consumes one. It makes no sense to have code in which the returned
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -18,6 +18,9 @@
.. branch: numpypy-longdouble
Long double support for numpypy
+.. branch: numpypy-disable-longdouble
+Since r_longdouble support is missing, disable all longdouble and derivative
+dtypes using ENABLED_LONG_DOUBLE = False
.. branch: numpypy-real-as-view
Convert real, imag from ufuncs to views. This involves the beginning of
view() functionality
@@ -68,3 +71,10 @@
.. branch: coding-guide-update-rlib-refs
.. branch: rlib-doc-rpython-refs
+.. branch: clean-up-remaining-pypy-rlib-refs
+
+.. branch: enumerate-rstr
+Support enumerate() over rstr types.
+
+.. branch: cleanup-numpypy-namespace
+Cleanup _numpypy and numpypy namespaces to more closely resemble numpy.
diff --git a/pypy/module/_cffi_backend/cbuffer.py b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -1,10 +1,11 @@
-from pypy.interpreter.error import operationerrfmt
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.buffer import RWBuffer
+from pypy.interpreter.error import operationerrfmt
from pypy.interpreter.gateway import unwrap_spec, interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
+from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
+
from rpython.rtyper.lltypesystem import rffi
-from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
class LLBuffer(RWBuffer):
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -2,18 +2,17 @@
Callbacks.
"""
import os
+
+from rpython.rlib import clibffi, rweakref, jit
+from rpython.rlib.objectmodel import compute_unique_id, keepalive_until_here
+from rpython.rtyper.lltypesystem import lltype, rffi
+
from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib.objectmodel import compute_unique_id, keepalive_until_here
-from rpython.rlib import clibffi, rweakref
-from rpython.rlib import jit
-
+from pypy.module._cffi_backend import cerrno, misc
from pypy.module._cffi_backend.cdataobj import W_CData
-from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN
-from pypy.module._cffi_backend.ctypefunc import W_CTypeFunc
+from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN, W_CTypeFunc
from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
from pypy.module._cffi_backend.ctypevoid import W_CTypeVoid
-from pypy.module._cffi_backend import cerrno, misc
# ____________________________________________________________
@@ -152,6 +151,7 @@
STDERR = 2
+
@jit.jit_callback("CFFI")
def invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata):
""" Callback specification.
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -1,11 +1,13 @@
import operator
+
+from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
+
+from rpython.rlib import objectmodel, rgc
+from rpython.rlib.objectmodel import keepalive_until_here, specialize
from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.objectmodel import keepalive_until_here, specialize
-from rpython.rlib import objectmodel, rgc
from rpython.tool.sourcetools import func_with_new_name
from pypy.module._cffi_backend import misc
diff --git a/pypy/module/_cffi_backend/cerrno.py b/pypy/module/_cffi_backend/cerrno.py
--- a/pypy/module/_cffi_backend/cerrno.py
+++ b/pypy/module/_cffi_backend/cerrno.py
@@ -1,5 +1,7 @@
import sys
+
from rpython.rlib import rposix
+
from pypy.interpreter.executioncontext import ExecutionContext
from pypy.interpreter.gateway import unwrap_spec
diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -2,18 +2,17 @@
Arrays.
"""
+from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef
+
from rpython.rtyper.lltypesystem import rffi
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import ovfcheck
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveChar
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUniChar
+from pypy.module._cffi_backend import cdataobj
from pypy.module._cffi_backend.ctypeptr import W_CTypePtrOrArray
-from pypy.module._cffi_backend import cdataobj
class W_CTypeArray(W_CTypePtrOrArray):
diff --git a/pypy/module/_cffi_backend/ctypeenum.py b/pypy/module/_cffi_backend/ctypeenum.py
--- a/pypy/module/_cffi_backend/ctypeenum.py
+++ b/pypy/module/_cffi_backend/ctypeenum.py
@@ -2,15 +2,11 @@
Enums.
"""
-from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.rarithmetic import intmask, r_ulonglong
from rpython.rlib.objectmodel import keepalive_until_here
-from rpython.rlib.objectmodel import specialize
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUnsigned
from pypy.module._cffi_backend import misc
+from pypy.module._cffi_backend.ctypeprim import (W_CTypePrimitiveSigned,
+ W_CTypePrimitiveUnsigned)
class _Mixin_Enum(object):
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -4,25 +4,21 @@
import sys
from pypy.interpreter.error import OperationError, operationerrfmt
+
+from rpython.rlib import jit, clibffi, jit_libffi
+from rpython.rlib.jit_libffi import (CIF_DESCRIPTION, CIF_DESCRIPTION_P,
+ FFI_TYPE, FFI_TYPE_P, FFI_TYPE_PP, SIZE_OF_FFI_ARG)
+from rpython.rlib.objectmodel import we_are_translated, instantiate
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib import jit, clibffi, jit_libffi
-from rpython.rlib.jit_libffi import CIF_DESCRIPTION, CIF_DESCRIPTION_P
-from rpython.rlib.jit_libffi import FFI_TYPE, FFI_TYPE_P, FFI_TYPE_PP
-from rpython.rlib.jit_libffi import SIZE_OF_FFI_ARG
-from rpython.rlib.objectmodel import we_are_translated, instantiate
-from rpython.rlib.objectmodel import keepalive_until_here
+from pypy.module._cffi_backend import ctypearray, cdataobj, cerrno
from pypy.module._cffi_backend.ctypeobj import W_CType
from pypy.module._cffi_backend.ctypeptr import W_CTypePtrBase, W_CTypePointer
from pypy.module._cffi_backend.ctypevoid import W_CTypeVoid
from pypy.module._cffi_backend.ctypestruct import W_CTypeStruct
-from pypy.module._cffi_backend.ctypestruct import W_CTypeStructOrUnion
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUnsigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveCharOrUniChar
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveFloat
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveLongDouble
-from pypy.module._cffi_backend import ctypearray, cdataobj, cerrno
+from pypy.module._cffi_backend.ctypeprim import (W_CTypePrimitiveSigned,
+ W_CTypePrimitiveUnsigned, W_CTypePrimitiveCharOrUniChar,
+ W_CTypePrimitiveFloat, W_CTypePrimitiveLongDouble)
class W_CTypeFunc(W_CTypePtrBase):
@@ -97,7 +93,6 @@
return self.space.wrap(clibffi.FFI_DEFAULT_ABI) # XXX
return W_CTypePtrBase._fget(self, attrchar)
-
def call(self, funcaddr, args_w):
if self.cif_descr:
# regular case: this function does not take '...' arguments
@@ -270,7 +265,6 @@
self.bufferp = rffi.ptradd(result, size)
return result
-
def fb_fill_type(self, ctype, is_result_type):
return ctype._get_ffi_type(self, is_result_type)
@@ -357,7 +351,6 @@
return ffistruct
-
def fb_build(self):
# Build a CIF_DESCRIPTION. Actually this computes the size and
# allocates a larger amount of data. It starts with a
@@ -387,7 +380,6 @@
if self.atypes:
self.atypes[i] = atype
-
def align_arg(self, n):
return (n + 7) & ~7
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -1,9 +1,8 @@
+from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.typedef import make_weakref_descr
-from pypy.interpreter.typedef import GetSetProperty, interp_attrproperty
+from pypy.interpreter.typedef import TypeDef, make_weakref_descr, GetSetProperty
+
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rlib.objectmodel import we_are_translated
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -3,13 +3,14 @@
"""
from pypy.interpreter.error import operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, rffi
+
from rpython.rlib.rarithmetic import r_uint, r_ulonglong, intmask
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.module._cffi_backend import cdataobj, misc
from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, misc
class W_CTypePrimitive(W_CType):
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -2,15 +2,15 @@
Pointers.
"""
-from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import wrap_oserror
-from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.interpreter.error import OperationError, operationerrfmt, wrap_oserror
+
+from rpython.rlib import rposix
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import ovfcheck
-from rpython.rlib import rposix
+from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
class W_CTypePtrOrArray(W_CType):
@@ -336,19 +336,22 @@
rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP)
-rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP,rffi.CCHARP], lltype.Void)
+rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP, rffi.CCHARP], lltype.Void)
rffi_fclose = rffi.llexternal("fclose", [rffi.CCHARP], rffi.INT)
class CffiFileObj(object):
_immutable_ = True
+
def __init__(self, fd, mode):
self.llf = rffi_fdopen(fd, mode)
if not self.llf:
raise OSError(rposix.get_errno(), "fdopen failed")
rffi_setbuf(self.llf, lltype.nullptr(rffi.CCHARP.TO))
+
def close(self):
rffi_fclose(self.llf)
+
def prepare_file_argument(space, fileobj):
fileobj.direct_flush()
if fileobj.cffi_fileobj is None:
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -3,15 +3,16 @@
"""
from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, rffi
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+
+from rpython.rlib import jit
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
-from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import rffi
+from pypy.module._cffi_backend import cdataobj, ctypeprim, misc
from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, ctypeprim, misc
class W_CTypeStructOrUnion(W_CType):
@@ -141,6 +142,7 @@
class W_CTypeStruct(W_CTypeStructOrUnion):
kind = "struct"
+
class W_CTypeUnion(W_CTypeStructOrUnion):
kind = "union"
@@ -241,8 +243,8 @@
#
value = misc.as_long_long(space, w_ob)
if isinstance(ctype, ctypeprim.W_CTypePrimitiveSigned):
- fmin = -(r_longlong(1) << (self.bitsize-1))
- fmax = (r_longlong(1) << (self.bitsize-1)) - 1
+ fmin = -(r_longlong(1) << (self.bitsize - 1))
+ fmax = (r_longlong(1) << (self.bitsize - 1)) - 1
if fmax == 0:
fmax = 1 # special case to let "int x:1" receive "1"
else:
diff --git a/pypy/module/_cffi_backend/libraryobj.py b/pypy/module/_cffi_backend/libraryobj.py
--- a/pypy/module/_cffi_backend/libraryobj.py
+++ b/pypy/module/_cffi_backend/libraryobj.py
@@ -1,9 +1,11 @@
from __future__ import with_statement
-from pypy.interpreter.error import OperationError, operationerrfmt
+
from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.error import operationerrfmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef
-from rpython.rtyper.lltypesystem import lltype, rffi
+
+from rpython.rtyper.lltypesystem import rffi
from rpython.rlib.rdynload import DLLHANDLE, dlopen, dlsym, dlclose, DLOpenError
from pypy.module._cffi_backend.cdataobj import W_CData
diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -1,10 +1,12 @@
from __future__ import with_statement
-from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+
+from pypy.interpreter.error import OperationError
+
+from rpython.rlib import jit
+from rpython.rlib.objectmodel import keepalive_until_here, specialize
from rpython.rlib.rarithmetic import r_uint, r_ulonglong, is_signed_integer_type
from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.objectmodel import keepalive_until_here, specialize
-from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
# ____________________________________________________________
@@ -43,14 +45,14 @@
def read_raw_unsigned_data(target, size):
for TP, TPP in _prim_unsigned_types:
if size == rffi.sizeof(TP):
- return rffi.cast(lltype.UnsignedLongLong, rffi.cast(TPP,target)[0])
+ return rffi.cast(lltype.UnsignedLongLong, rffi.cast(TPP, target)[0])
raise NotImplementedError("bad integer size")
def read_raw_ulong_data(target, size):
for TP, TPP in _prim_unsigned_types:
if size == rffi.sizeof(TP):
assert rffi.sizeof(TP) <= rffi.sizeof(lltype.Unsigned)
- return rffi.cast(lltype.Unsigned, rffi.cast(TPP,target)[0])
+ return rffi.cast(lltype.Unsigned, rffi.cast(TPP, target)[0])
raise NotImplementedError("bad integer size")
def read_raw_float_data(target, size):
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -1,12 +1,12 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import unwrap_spec
+
+from rpython.rlib.objectmodel import specialize
+from rpython.rlib.rarithmetic import ovfcheck
from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from rpython.rlib.rarithmetic import most_neg_value_of, most_pos_value_of
-from rpython.rlib.objectmodel import specialize
-from pypy.module._cffi_backend import ctypeobj, ctypeprim, ctypeptr, ctypearray
-from pypy.module._cffi_backend import ctypestruct, ctypevoid, ctypeenum
+from pypy.module._cffi_backend import (ctypeobj, ctypeprim, ctypeptr,
+ ctypearray, ctypestruct, ctypevoid, ctypeenum)
@specialize.memo()
@@ -167,7 +167,7 @@
#
if foffset < 0:
# align this field to its own 'falign' by inserting padding
- offset = (offset + falign - 1) & ~(falign-1)
+ offset = (offset + falign - 1) & ~(falign - 1)
else:
# a forced field position: ignore the offset just computed,
# except to know if we must set 'custom_field_pos'
@@ -178,7 +178,7 @@
fbitsize == 8 * ftype.size and not
isinstance(ftype, ctypeprim.W_CTypePrimitiveCharOrUniChar)):
fbitsize = -1
- if isinstance(ftype, ctypearray.W_CTypeArray) and ftype.length==0:
+ if isinstance(ftype, ctypearray.W_CTypeArray) and ftype.length == 0:
bitshift = ctypestruct.W_CField.BS_EMPTY_ARRAY
else:
bitshift = ctypestruct.W_CField.BS_REGULAR
@@ -241,7 +241,7 @@
# as 1 instead. But for ctypes support, we allow the manually-
# specified totalsize to be zero in this case.
if totalsize < 0:
- offset = (offset + alignment - 1) & ~(alignment-1)
+ offset = (offset + alignment - 1) & ~(alignment - 1)
totalsize = offset or 1
elif totalsize < offset:
raise operationerrfmt(space.w_TypeError,
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -631,6 +631,72 @@
return res
return None
+ def readline_w(self, space, w_limit=None):
+ self._check_init(space)
+ self._check_closed(space, "readline of closed file")
+
+ limit = convert_size(space, w_limit)
+
+ # First, try to find a line in the buffer. This can run
+ # unlocked because the calls to the C API are simple enough
+ # that they can't trigger any thread switch.
+ have = self._readahead()
+ if limit >= 0 and have > limit:
+ have = limit
+ for pos in range(self.pos, self.pos+have):
+ if self.buffer[pos] == '\n':
+ break
+ else:
+ pos = -1
+ if pos >= 0:
+ w_res = space.wrap(''.join(self.buffer[self.pos:pos+1]))
+ self.pos = pos + 1
+ return w_res
+ if have == limit:
+ w_res = space.wrap(''.join(self.buffer[self.pos:self.pos+have]))
+ self.pos += have
+ return w_res
+
+ written = 0
+ with self.lock:
+ # Now we try to get some more from the raw stream
+ chunks = []
+ if have > 0:
+ chunks.extend(self.buffer[self.pos:self.pos+have])
+ written += have
+ self.pos += have
+ if limit >= 0:
+ limit -= have
+ if self.writable:
+ self._flush_and_rewind_unlocked(space)
+
+ while True:
+ self._reader_reset_buf()
+ have = self._fill_buffer(space)
+ if have == 0:
+ break
+ if limit >= 0 and have > limit:
+ have = limit
+ pos = 0
+ found = False
+ while pos < have:
+ c = self.buffer[pos]
+ pos += 1
+ if c == '\n':
+ self.pos = pos
+ found = True
+ break
+ chunks.extend(self.buffer[0:pos])
+ if found:
+ break
+ if have == limit:
+ self.pos = have
+ break
+ written += have
+ if limit >= 0:
+ limit -= have
+ return space.wrap(''.join(chunks))
+
# ____________________________________________________
# Write methods
@@ -795,6 +861,7 @@
peek = interp2app(W_BufferedReader.peek_w),
read1 = interp2app(W_BufferedReader.read1_w),
raw = interp_attrproperty_w("w_raw", cls=W_BufferedReader),
+ readline = interp2app(W_BufferedReader.readline_w),
# from the mixin class
__repr__ = interp2app(W_BufferedReader.repr_w),
@@ -968,6 +1035,7 @@
read = interp2app(W_BufferedRandom.read_w),
peek = interp2app(W_BufferedRandom.peek_w),
read1 = interp2app(W_BufferedRandom.read1_w),
+ readline = interp2app(W_BufferedRandom.readline_w),
write = interp2app(W_BufferedRandom.write_w),
flush = interp2app(W_BufferedRandom.flush_w),
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -52,6 +52,25 @@
self.pos += size
return space.wrap(output)
+ def readline_w(self, space, w_limit=None):
+ self._check_closed(space)
+ limit = convert_size(space, w_limit)
+
+ cur_pos = self.pos
+ if limit < 0:
+ end_pos = self.string_size
+ else:
+ end_pos = min(cur_pos + limit, self.string_size)
+ while cur_pos != end_pos:
+ if self.buf[cur_pos] == '\n':
+ cur_pos += 1
+ break
+ cur_pos += 1
+
+ output = buffer2string(self.buf, self.pos, cur_pos)
+ self.pos = cur_pos
+ return space.wrap(output)
+
def read1_w(self, space, w_size):
return self.read_w(space, w_size)
@@ -209,6 +228,7 @@
read = interp2app(W_BytesIO.read_w),
read1 = interp2app(W_BytesIO.read1_w),
+ readline = interp2app(W_BytesIO.readline_w),
readinto = interp2app(W_BytesIO.readinto_w),
write = interp2app(W_BytesIO.write_w),
truncate = interp2app(W_BytesIO.truncate_w),
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -3,7 +3,6 @@
from pypy.interpreter.error import OperationError, wrap_oserror, wrap_oserror2
from rpython.rlib.rarithmetic import r_longlong
from rpython.rlib.rstring import StringBuilder
-from rpython.rlib.rposix import validate_fd
from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
import sys, os, stat, errno
from pypy.module._io.interp_iobase import W_RawIOBase, convert_size
@@ -154,7 +153,6 @@
fd_is_own = False
try:
if fd >= 0:
- validate_fd(fd)
try:
os.fstat(fd)
except OSError, e:
@@ -235,7 +233,6 @@
self.fd = -1
try:
- validate_fd(fd)
os.close(fd)
except OSError, e:
raise wrap_oserror(space, e,
diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py
--- a/pypy/module/_io/test/test_bufferedio.py
+++ b/pypy/module/_io/test/test_bufferedio.py
@@ -631,6 +631,19 @@
f.flush()
assert raw.getvalue() == b'1b\n2def\n3\n'
+ def test_readline(self):
+ import _io as io
+ with io.BytesIO(b"abc\ndef\nxyzzy\nfoo\x00bar\nanother line") as raw:
+ with io.BufferedRandom(raw, buffer_size=10) as f:
+ assert f.readline() == b"abc\n"
+ assert f.readline(10) == b"def\n"
+ assert f.readline(2) == b"xy"
+ assert f.readline(4) == b"zzy\n"
+ assert f.readline() == b"foo\x00bar\n"
+ assert f.readline(None) == b"another line"
+ raises(TypeError, f.readline, 5.3)
+
+
class TestNonReentrantLock:
spaceconfig = dict(usemodules=['thread'])
diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -75,3 +75,19 @@
b = _io.BytesIO("hello")
b.close()
raises(ValueError, b.readinto, bytearray("hello"))
+
+ def test_readline(self):
+ import _io
+ f = _io.BytesIO(b'abc\ndef\nxyzzy\nfoo\x00bar\nanother line')
+ assert f.readline() == b'abc\n'
+ assert f.readline(10) == b'def\n'
+ assert f.readline(2) == b'xy'
+ assert f.readline(4) == b'zzy\n'
+ assert f.readline() == b'foo\x00bar\n'
+ assert f.readline(None) == b'another line'
+ raises(TypeError, f.readline, 5.3)
+
+ def test_overread(self):
+ import _io
+ f = _io.BytesIO(b'abc')
+ assert f.readline(10) == b'abc'
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
@@ -1,14 +1,12 @@
from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module.micronumpy.interp_boxes import long_double_size
+from pypy.module.micronumpy.interp_boxes import long_double_size, ENABLED_LONG_DOUBLE
-class Module(MixedModule):
- applevel_name = '_numpypy'
-
+class MultiArrayModule(MixedModule):
+ appleveldefs = {'arange': 'app_numpy.arange'}
interpleveldefs = {
'ndarray': 'interp_numarray.W_NDimArray',
'dtype': 'interp_dtype.W_Dtype',
- 'ufunc': 'interp_ufuncs.W_Ufunc',
'array': 'interp_numarray.array',
'zeros': 'interp_numarray.zeros',
@@ -18,20 +16,17 @@
'fromstring': 'interp_support.fromstring',
'flatiter': 'interp_flatiter.W_FlatIterator',
'concatenate': 'interp_arrayops.concatenate',
- 'repeat': 'interp_arrayops.repeat',
'where': 'interp_arrayops.where',
'count_nonzero': 'interp_arrayops.count_nonzero',
'set_string_function': 'appbridge.set_string_function',
+ 'typeinfo': 'interp_dtype.get_dtype_cache(space).w_typeinfo',
+ }
- 'True_': 'types.Bool.True',
- 'False_': 'types.Bool.False',
- 'bool': 'space.w_bool',
- 'int': 'space.w_int',
-
- 'typeinfo': 'interp_dtype.get_dtype_cache(space).w_typeinfo',
-
+class NumericTypesModule(MixedModule):
+ appleveldefs = {}
+ interpleveldefs = {
'generic': 'interp_boxes.W_GenericBox',
'number': 'interp_boxes.W_NumberBox',
'integer': 'interp_boxes.W_IntegerBox',
@@ -62,8 +57,6 @@
'float16': 'interp_boxes.W_Float16Box',
'float32': 'interp_boxes.W_Float32Box',
'float64': 'interp_boxes.W_Float64Box',
- 'longdouble': 'interp_boxes.W_LongDoubleBox',
- 'longfloat': 'interp_boxes.W_LongDoubleBox',
'intp': 'types.IntP.BoxType',
'uintp': 'types.UIntP.BoxType',
'flexible': 'interp_boxes.W_FlexibleBox',
@@ -76,13 +69,33 @@
'complex_': 'interp_boxes.W_Complex128Box',
'complex128': 'interp_boxes.W_Complex128Box',
'complex64': 'interp_boxes.W_Complex64Box',
- 'clongdouble': 'interp_boxes.W_CLongDoubleBox',
- 'clongfloat': 'interp_boxes.W_CLongDoubleBox',
}
+ if ENABLED_LONG_DOUBLE:
+ long_double_dtypes = [
+ ('longdouble', 'interp_boxes.W_LongDoubleBox'),
+ ('longfloat', 'interp_boxes.W_LongDoubleBox'),
+ ('clongdouble', 'interp_boxes.W_CLongDoubleBox'),
+ ('clongfloat', 'interp_boxes.W_CLongDoubleBox'),
+ ]
+ if long_double_size == 16:
+ long_double_dtypes += [
+ ('float128', 'interp_boxes.W_Float128Box'),
+ ('complex256', 'interp_boxes.W_Complex256Box'),
+ ]
+ elif long_double_size == 12:
+ long_double_dtypes += [
+ ('float96', 'interp_boxes.W_Float96Box'),
+ ('complex192', 'interp_boxes.W_Complex192Box'),
+ ]
+ for dt, box in long_double_dtypes:
+ interpleveldefs[dt] = box
+
+class UMathModule(MixedModule):
+ appleveldefs = {}
+ interpleveldefs = {}
# ufuncs
for exposed, impl in [
- ("abs", "absolute"),
("absolute", "absolute"),
("add", "add"),
("arccos", "arccos"),
@@ -162,19 +175,16 @@
]:
interpleveldefs[exposed] = "interp_ufuncs.get(space).%s" % impl
- appleveldefs = {
- 'average': 'app_numpy.average',
- 'sum': 'app_numpy.sum',
- 'min': 'app_numpy.min',
- 'identity': 'app_numpy.identity',
- 'eye': 'app_numpy.eye',
- 'max': 'app_numpy.max',
- 'arange': 'app_numpy.arange',
+
+class Module(MixedModule):
+ applevel_name = '_numpypy'
+ appleveldefs = {}
+ interpleveldefs = {
+ 'choose': 'interp_arrayops.choose',
+ 'repeat': 'interp_arrayops.repeat',
}
-
-if long_double_size == 16:
- Module.interpleveldefs['float128'] = 'interp_boxes.W_Float128Box'
- Module.interpleveldefs['complex256'] = 'interp_boxes.W_Complex256Box'
-elif long_double_size == 12:
- Module.interpleveldefs['float96'] = 'interp_boxes.W_Float96Box'
- Module.interpleveldefs['complex192'] = 'interp_boxes.W_Complex192Box'
+ submodules = {
+ 'multiarray': MultiArrayModule,
+ 'numerictypes': NumericTypesModule,
+ 'umath': UMathModule,
+ }
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
@@ -2,82 +2,6 @@
import _numpypy
-def average(a):
- # This implements a weighted average, for now we don't implement the
- # weighting, just the average part!
- if not hasattr(a, "mean"):
- a = _numpypy.array(a)
- return a.mean()
-
-def identity(n, dtype=None):
- a = _numpypy.zeros((n, n), dtype=dtype)
- for i in range(n):
- a[i][i] = 1
- return a
-
-def eye(n, m=None, k=0, dtype=None):
- if m is None:
- m = n
- a = _numpypy.zeros((n, m), dtype=dtype)
- ni = 0
- mi = 0
-
- if k < 0:
- p = n + k
- ni = -k
- else:
- p = n - k
- mi = k
-
- while ni < n and mi < m:
- a[ni][mi] = 1
- ni += 1
- mi += 1
- return a
-
-def sum(a,axis=None, out=None):
- '''sum(a, axis=None)
- Sum of array elements over a given axis.
-
- Parameters
- ----------
- a : array_like
- Elements to sum.
- 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
- An array with the same shape as `a`, with the specified
- 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.
- '''
- # TODO: add to doc (once it's implemented): cumsum : Cumulative sum of array elements.
- if not hasattr(a, "sum"):
- a = _numpypy.array(a)
- return a.sum(axis=axis, out=out)
-
-def min(a, axis=None, out=None):
- if not hasattr(a, "min"):
- a = _numpypy.array(a)
- if a.size < 1:
- return _numpypy.array([])
- return a.min(axis=axis, out=out)
-
-def max(a, axis=None, out=None):
- if not hasattr(a, "max"):
- a = _numpypy.array(a)
- if a.size < 1:
- return _numpypy.array([])
- return a.max(axis=axis, out=out)
-
def arange(start, stop=None, step=1, dtype=None):
'''arange([start], stop[, step], dtype=None)
Generate values in the half-interval [start, stop).
@@ -86,9 +10,9 @@
stop = start
start = 0
if dtype is None:
- test = _numpypy.array([start, stop, step, 0])
+ test = _numpypy.multiarray.array([start, stop, step, 0])
dtype = test.dtype
- arr = _numpypy.zeros(int(math.ceil((stop - start) / step)), dtype=dtype)
+ arr = _numpypy.multiarray.zeros(int(math.ceil((stop - start) / step)), dtype=dtype)
i = start
for j in range(arr.size):
arr[j] = i
diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -106,33 +106,36 @@
args_w = [convert_to_array(space, w_arg) for w_arg in args_w]
dtype = args_w[0].get_dtype()
shape = args_w[0].get_shape()[:]
- if len(shape) <= axis:
+ _axis = axis
+ if axis < 0:
+ _axis = len(shape) + axis
+ if _axis < 0 or len(shape) <= _axis:
raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
for arr in args_w[1:]:
dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
arr.get_dtype())
- if len(arr.get_shape()) <= axis:
+ if _axis < 0 or len(arr.get_shape()) <= _axis:
raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
for i, axis_size in enumerate(arr.get_shape()):
- if len(arr.get_shape()) != len(shape) or (i != axis and axis_size != shape[i]):
+ if len(arr.get_shape()) != len(shape) or (i != _axis and axis_size != shape[i]):
raise OperationError(space.w_ValueError, space.wrap(
"all the input arrays must have same number of dimensions"))
- elif i == axis:
+ elif i == _axis:
shape[i] += axis_size
res = W_NDimArray.from_shape(shape, dtype, 'C')
chunks = [Chunk(0, i, 1, i) for i in shape]
axis_start = 0
for arr in args_w:
- if arr.get_shape()[axis] == 0:
+ if arr.get_shape()[_axis] == 0:
continue
- chunks[axis] = Chunk(axis_start, axis_start + arr.get_shape()[axis], 1,
- arr.get_shape()[axis])
+ chunks[_axis] = Chunk(axis_start, axis_start + arr.get_shape()[_axis], 1,
+ arr.get_shape()[_axis])
Chunks(chunks).apply(res).implementation.setslice(space, arr)
- axis_start += arr.get_shape()[axis]
+ axis_start += arr.get_shape()[_axis]
return res
@unwrap_spec(repeats=int)
-def repeat(space, w_arr, repeats, w_axis=None):
+def repeat(space, w_arr, repeats, w_axis):
arr = convert_to_array(space, w_arr)
if space.is_none(w_axis):
arr = arr.descr_flatten(space)
@@ -158,14 +161,21 @@
def count_nonzero(space, w_obj):
return space.wrap(loop.count_all_true(convert_to_array(space, w_obj)))
-def choose(space, arr, w_choices, out, mode):
+ at unwrap_spec(mode=str)
+def choose(space, w_arr, w_choices, w_out, mode):
+ arr = convert_to_array(space, w_arr)
choices = [convert_to_array(space, w_item) for w_item
in space.listview(w_choices)]
if not choices:
raise OperationError(space.w_ValueError,
space.wrap("choices list cannot be empty"))
- shape = shape_agreement_multiple(space, choices + [out])
- out = interp_dtype.dtype_agreement(space, choices, shape, out)
+ if space.is_none(w_out):
+ w_out = None
+ elif not isinstance(w_out, W_NDimArray):
+ raise OperationError(space.w_TypeError, space.wrap(
+ "return arrays must be of ArrayType"))
+ shape = shape_agreement_multiple(space, choices + [w_out])
+ out = interp_dtype.dtype_agreement(space, choices, shape, w_out)
dtype = out.get_dtype()
if mode not in MODES:
raise OperationError(space.w_ValueError,
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
@@ -16,10 +16,12 @@
MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
# Is this the proper place for this?
+ENABLED_LONG_DOUBLE = False
long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+
import os
if long_double_size == 8 and os.name == 'nt':
- # this is a lie, or maybe a wish
+ # this is a lie, or maybe a wish, MS fakes longdouble math with double
long_double_size = 12
@@ -335,7 +337,7 @@
descr__new__, _get_dtype = new_dtype_getter("complex128")
_COMPONENTS_BOX = W_Float64Box
-if long_double_size == 12:
+if ENABLED_LONG_DOUBLE and long_double_size == 12:
class W_Float96Box(W_FloatingBox, PrimitiveBox):
descr__new__, _get_dtype = new_dtype_getter("float96")
@@ -347,7 +349,7 @@
W_CLongDoubleBox = W_Complex192Box
-elif long_double_size == 16:
+elif ENABLED_LONG_DOUBLE and long_double_size == 16:
class W_Float128Box(W_FloatingBox, PrimitiveBox):
descr__new__, _get_dtype = new_dtype_getter("float128")
W_LongDoubleBox = W_Float128Box
@@ -358,7 +360,7 @@
W_CLongDoubleBox = W_Complex256Box
-else:
+elif ENABLED_LONG_DOUBLE:
W_LongDoubleBox = W_Float64Box
W_CLongDoubleBox = W_Complex64Box
@@ -526,7 +528,7 @@
__new__ = interp2app(W_Float64Box.descr__new__.im_func),
)
-if long_double_size == 12:
+if ENABLED_LONG_DOUBLE and long_double_size == 12:
W_Float96Box.typedef = TypeDef("float96", (W_FloatingBox.typedef),
__module__ = "numpypy",
@@ -540,7 +542,7 @@
imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
)
-elif long_double_size == 16:
+elif ENABLED_LONG_DOUBLE and long_double_size == 16:
W_Float128Box.typedef = TypeDef("float128", (W_FloatingBox.typedef),
__module__ = "numpypy",
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
@@ -164,8 +164,11 @@
def is_record_type(self):
return self.fields is not None
+ def is_str_or_unicode(self):
+ return (self.num == 18 or self.num == 19)
+
def is_flexible_type(self):
- return (self.num == 18 or self.num == 19 or self.num == 20)
+ return (self.is_str_or_unicode() or self.is_record_type())
def __repr__(self):
if self.fields is not None:
@@ -474,7 +477,7 @@
aliases=["complex"],
float_type = self.w_float64dtype,
)
- if interp_boxes.long_double_size == 12:
+ if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 12:
self.w_float96dtype = W_Dtype(
types.Float96(),
num=13,
@@ -497,7 +500,7 @@
)
self.w_longdouble = self.w_float96dtype
self.w_clongdouble = self.w_complex192dtype
- elif interp_boxes.long_double_size == 16:
+ elif interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 16:
self.w_float128dtype = W_Dtype(
types.Float128(),
num=13,
@@ -520,13 +523,13 @@
)
self.w_longdouble = self.w_float128dtype
self.w_clongdouble = self.w_complex256dtype
- else:
+ elif interp_boxes.ENABLED_LONG_DOUBLE:
self.w_float64dtype.aliases += ["longdouble", "longfloat"]
self.w_complex128dtype.aliases += ["clongdouble", "clongfloat"]
self.w_longdouble = self.w_float64dtype
self.w_clongdouble = self.w_complex128dtype
self.w_stringdtype = W_Dtype(
- types.StringType(1),
+ types.StringType(0),
num=18,
kind=STRINGLTR,
name='string',
@@ -596,23 +599,27 @@
char=UINTPLTR,
w_box_type = space.gettypefor(uintp_box),
)
+ float_dtypes = [self.w_float16dtype,
+ self.w_float32dtype, self.w_float64dtype,
+ ]
+ complex_dtypes = [self.w_complex64dtype, self.w_complex128dtype]
+ if interp_boxes.ENABLED_LONG_DOUBLE:
+ float_dtypes.append(self.w_longdouble)
+ complex_dtypes.append(self.w_clongdouble)
self.builtin_dtypes = [
self.w_booldtype,
self.w_int8dtype, self.w_uint8dtype,
self.w_int16dtype, self.w_uint16dtype,
self.w_longdtype, self.w_ulongdtype,
self.w_int32dtype, self.w_uint32dtype,
- self.w_int64dtype, self.w_uint64dtype,
- self.w_float16dtype,
- self.w_float32dtype, self.w_float64dtype, self.w_longdouble,
- self.w_complex64dtype, self.w_complex128dtype, self.w_clongdouble,
+ self.w_int64dtype, self.w_uint64dtype] + \
+ float_dtypes + complex_dtypes + [
self.w_stringdtype, self.w_unicodedtype, self.w_voiddtype,
self.w_intpdtype, self.w_uintpdtype,
]
self.float_dtypes_by_num_bytes = sorted(
(dtype.itemtype.get_element_size(), dtype)
- for dtype in [self.w_float16dtype, self.w_float32dtype,
- self.w_float64dtype, self.w_longdouble]
+ for dtype in float_dtypes
)
self.dtypes_by_num = {}
self.dtypes_by_name = {}
@@ -655,7 +662,6 @@
'LONGLONG': self.w_int64dtype,
'SHORT': self.w_int16dtype,
'VOID': self.w_voiddtype,
- 'LONGDOUBLE': self.w_longdouble,
'UBYTE': self.w_uint8dtype,
'UINTP': self.w_ulongdtype,
'ULONG': self.w_ulongdtype,
@@ -678,8 +684,11 @@
'USHORT': self.w_uint16dtype,
'FLOAT': self.w_float32dtype,
'BOOL': self.w_booldtype,
- 'CLONGDOUBLE': self.w_clongdouble,
}
+ if interp_boxes.ENABLED_LONG_DOUBLE:
+ typeinfo_full['LONGDOUBLE'] = self.w_longdouble
+ typeinfo_full['CLONGDOUBLE'] = self.w_clongdouble
+
typeinfo_partial = {
'Generic': interp_boxes.W_GenericBox,
'Character': interp_boxes.W_CharacterBox,
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
@@ -14,7 +14,7 @@
from pypy.module.micronumpy.appbridge import get_appbridge_cache
from pypy.module.micronumpy import loop
from pypy.module.micronumpy.dot import match_dot_shapes
More information about the pypy-commit
mailing list