Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r48572:1847537fd4b5
Date: 2011-10-28 12:11 -0400
http://bitbucket.org/pypy/pypy/changeset/1847537fd4b5/
Log: make more of the micronumpy tests pass under -A
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
@@ -13,6 +13,9 @@
'empty': 'interp_numarray.zeros',
'ones': 'interp_numarray.ones',
'fromstring': 'interp_support.fromstring',
+
+ 'True_': 'space.w_True',
+ 'False_': 'space.w_False',
}
# ufuncs
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
@@ -32,11 +32,17 @@
return self.identity.wrap(space)
def descr_call(self, space, __args__):
- try:
- args_w = __args__.fixedunpack(self.argcount)
- except ValueError, e:
- raise OperationError(space.w_TypeError, space.wrap(str(e)))
- return self.call(space, args_w)
+ if __args__.keywords or len(__args__.arguments_w) < self.argcount:
+ raise OperationError(space.w_ValueError,
+ space.wrap("invalid number of arguments")
+ )
+ elif len(__args__.arguments_w) > self.argcount:
+ # The extra arguments should actually be the output array, but we
+ # don't support that yet.
+ raise OperationError(space.w_TypeError,
+ space.wrap("invalid number of arguments")
+ )
+ return self.call(space, __args__.arguments_w)
def descr_reduce(self, space, w_obj):
from pypy.module.micronumpy.interp_numarray import convert_to_array,
Scalar
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
@@ -36,37 +36,40 @@
assert str(d) == "bool"
def test_bool_array(self):
- from numpy import array
+ import numpy
- a = array([0, 1, 2, 2.5], dtype='?')
- assert a[0] is False
+ a = numpy.array([0, 1, 2, 2.5], dtype='?')
+ assert a[0] is numpy.False_
for i in xrange(1, 4):
- assert a[i] is True
+ assert a[i] is numpy.True_
def test_copy_array_with_dtype(self):
- from numpy import array
- a = array([0, 1, 2, 3], dtype=long)
+ import numpy
+
+ a = numpy.array([0, 1, 2, 3], dtype=long)
# int on 64-bit, long in 32-bit
assert isinstance(a[0], (int, long))
b = a.copy()
assert isinstance(b[0], (int, long))
- a = array([0, 1, 2, 3], dtype=bool)
- assert isinstance(a[0], bool)
+ a = numpy.array([0, 1, 2, 3], dtype=bool)
+ assert a[0] is numpy.False_
b = a.copy()
- assert isinstance(b[0], bool)
+ assert b[0] is numpy.False_
def test_zeros_bool(self):
- from numpy import zeros
- a = zeros(10, dtype=bool)
+ import numpy
+
+ a = numpy.zeros(10, dtype=bool)
for i in range(10):
- assert a[i] is False
+ assert a[i] is numpy.False_
def test_ones_bool(self):
- from numpy import ones
- a = ones(10, dtype=bool)
+ import numpy
+
+ a = numpy.ones(10, dtype=bool)
for i in range(10):
- assert a[i] is True
+ assert a[i] is numpy.True_
def test_zeros_long(self):
from numpy import zeros
@@ -77,7 +80,7 @@
def test_ones_long(self):
from numpy import ones
- a = ones(10, dtype=bool)
+ a = ones(10, dtype=long)
for i in range(10):
assert isinstance(a[i], (int, long))
assert a[1] == 1
@@ -96,8 +99,9 @@
def test_bool_binop_types(self):
from numpy import array, dtype
- types = ('?','b','B','h','H','i','I','l','L','q','Q','f','d')
- N = len(types)
+ types = [
+ '?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'
+ ]
a = array([True], '?')
for t in types:
assert (a + array([0], t)).dtype is dtype(t)
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
@@ -214,7 +214,7 @@
def test_add_other(self):
from numpy import array
a = array(range(5))
- b = array(reversed(range(5)))
+ b = array(range(4, -1, -1))
c = a + b
for i in range(5):
assert c[i] == 4
@@ -264,18 +264,19 @@
assert b[i] == i - 5
def test_mul(self):
- from numpy import array, dtype
- a = array(range(5))
+ import numpy
+
+ a = numpy.array(range(5))
b = a * a
for i in range(5):
assert b[i] == i * i
- a = array(range(5), dtype=bool)
+ a = numpy.array(range(5), dtype=bool)
b = a * a
- assert b.dtype is dtype(bool)
- assert b[0] is False
+ assert b.dtype is numpy.dtype(bool)
+ assert b[0] is numpy.False_
for i in range(1, 5):
- assert b[i] is True
+ assert b[i] is numpy.True_
def test_mul_constant(self):
from numpy import array
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
@@ -24,10 +24,10 @@
def test_wrong_arguments(self):
from numpy import add, sin
- raises(TypeError, add, 1)
+ raises(ValueError, add, 1)
raises(TypeError, add, 1, 2, 3)
raises(TypeError, sin, 1, 2)
- raises(TypeError, sin)
+ raises(ValueError, sin)
def test_single_item(self):
from numpy import negative, sign, minimum
@@ -357,4 +357,4 @@
(3.5, 3),
(3, 3.5),
]:
- assert ufunc(a, b) is func(a, b)
+ assert ufunc(a, b) == func(a, b)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit