[pypy-commit] pypy default: merge heads
antocuni
noreply at buildbot.pypy.org
Thu Mar 22 17:32:11 CET 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r53919:7879ba98d7dd
Date: 2012-03-22 17:31 +0100
http://bitbucket.org/pypy/pypy/changeset/7879ba98d7dd/
Log: merge heads
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
@@ -306,6 +306,125 @@
else:
return multiarray.set_string_function(f, repr)
+def array_equal(a1, a2):
+ """
+ True if two arrays have the same shape and elements, False otherwise.
+
+ Parameters
+ ----------
+ a1, a2 : array_like
+ Input arrays.
+
+ Returns
+ -------
+ b : bool
+ Returns True if the arrays are equal.
+
+ See Also
+ --------
+ allclose: Returns True if two arrays are element-wise equal within a
+ tolerance.
+ array_equiv: Returns True if input arrays are shape consistent and all
+ elements equal.
+
+ Examples
+ --------
+ >>> np.array_equal([1, 2], [1, 2])
+ True
+ >>> np.array_equal(np.array([1, 2]), np.array([1, 2]))
+ True
+ >>> np.array_equal([1, 2], [1, 2, 3])
+ False
+ >>> np.array_equal([1, 2], [1, 4])
+ False
+
+ """
+ try:
+ a1, a2 = asarray(a1), asarray(a2)
+ except:
+ return False
+ if a1.shape != a2.shape:
+ return False
+ return bool((a1 == a2).all())
+
+def asarray(a, dtype=None, order=None, maskna=None, ownmaskna=False):
+ """
+ Convert the input to an array.
+
+ Parameters
+ ----------
+ a : array_like
+ Input data, in any form that can be converted to an array. This
+ includes lists, lists of tuples, tuples, tuples of tuples, tuples
+ of lists and ndarrays.
+ dtype : data-type, optional
+ By default, the data-type is inferred from the input data.
+ order : {'C', 'F'}, optional
+ Whether to use row-major ('C') or column-major ('F' for FORTRAN)
+ memory representation. Defaults to 'C'.
+ maskna : bool or None, optional
+ If this is set to True, it forces the array to have an NA mask.
+ If this is set to False, it forces the array to not have an NA
+ mask.
+ ownmaskna : bool, optional
+ If this is set to True, forces the array to have a mask which
+ it owns.
+
+ Returns
+ -------
+ out : ndarray
+ Array interpretation of `a`. No copy is performed if the input
+ is already an ndarray. If `a` is a subclass of ndarray, a base
+ class ndarray is returned.
+
+ See Also
+ --------
+ asanyarray : Similar function which passes through subclasses.
+ ascontiguousarray : Convert input to a contiguous array.
+ asfarray : Convert input to a floating point ndarray.
+ asfortranarray : Convert input to an ndarray with column-major
+ memory order.
+ asarray_chkfinite : Similar function which checks input for NaNs and Infs.
+ fromiter : Create an array from an iterator.
+ fromfunction : Construct an array by executing a function on grid
+ positions.
+
+ Examples
+ --------
+ Convert a list into an array:
+
+ >>> a = [1, 2]
+ >>> np.asarray(a)
+ array([1, 2])
+
+ Existing arrays are not copied:
+
+ >>> a = np.array([1, 2])
+ >>> np.asarray(a) is a
+ True
+
+ If `dtype` is set, array is copied only if dtype does not match:
+
+ >>> a = np.array([1, 2], dtype=np.float32)
+ >>> np.asarray(a, dtype=np.float32) is a
+ True
+ >>> np.asarray(a, dtype=np.float64) is a
+ False
+
+ Contrary to `asanyarray`, ndarray subclasses are not passed through:
+
+ >>> issubclass(np.matrix, np.ndarray)
+ True
+ >>> a = np.matrix([[1, 2]])
+ >>> np.asarray(a) is a
+ False
+ >>> np.asanyarray(a) is a
+ True
+
+ """
+ return array(a, dtype, copy=False, order=order,
+ maskna=maskna, ownmaskna=ownmaskna)
+
set_string_function(array_str, 0)
set_string_function(array_repr, 1)
diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst
--- a/pypy/doc/project-ideas.rst
+++ b/pypy/doc/project-ideas.rst
@@ -103,21 +103,13 @@
* A concurrent garbage collector (a lot of work)
-Remove the GIL
---------------
+STM, a.k.a. "remove the GIL"
+----------------------------
-This is a major task that requires lots of thinking. However, few subprojects
-can be potentially specified, unless a better plan can be thought out:
+Removing the GIL --- or more precisely, a GIL-less thread-less solution ---
+is `now work in progress.`__ Contributions welcome.
-* A thread-aware garbage collector
-
-* Better RPython primitives for dealing with concurrency
-
-* JIT passes to remove locks on objects
-
-* (maybe) implement locking in Python interpreter
-
-* alternatively, look at Software Transactional Memory
+.. __: http://pypy.org/tmdonate.html
Introduce new benchmarks
------------------------
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py b/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
@@ -142,3 +142,39 @@
assert str(b) == "[7 8 9]"
b = a[2:1, ]
assert str(b) == "[]"
+
+ def test_equal(self):
+ from _numpypy import array
+ from numpypy import array_equal
+
+ a = [1, 2, 3]
+ b = [1, 2, 3]
+
+ assert array_equal(a, b)
+ assert array_equal(a, array(b))
+ assert array_equal(array(a), b)
+ assert array_equal(array(a), array(b))
+
+ def test_not_equal(self):
+ from _numpypy import array
+ from numpypy import array_equal
+
+ a = [1, 2, 3]
+ b = [1, 2, 4]
+
+ assert not array_equal(a, b)
+ assert not array_equal(a, array(b))
+ assert not array_equal(array(a), b)
+ assert not array_equal(array(a), array(b))
+
+ def test_mismatched_shape(self):
+ from _numpypy import array
+ from numpypy import array_equal
+
+ a = [1, 2, 3]
+ b = [[1, 2, 3], [1, 2, 3]]
+
+ assert not array_equal(a, b)
+ assert not array_equal(a, array(b))
+ assert not array_equal(array(a), b)
+ assert not array_equal(array(a), array(b))
More information about the pypy-commit
mailing list