Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r51462:c85a96246d2f
Date: 2012-01-18 20:04 +0100
http://bitbucket.org/pypy/pypy/changeset/c85a96246d2f/
Log: merge heads
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
@@ -62,7 +63,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:
@@ -107,7 +108,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(
@@ -116,7 +117,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(),
@@ -124,7 +125,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(),
@@ -132,7 +133,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(),
@@ -140,7 +141,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(),
@@ -148,7 +149,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(),
@@ -156,7 +157,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"
@@ -168,7 +169,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(
@@ -177,7 +178,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(),
@@ -185,7 +186,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(
@@ -194,7 +195,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(),
@@ -202,7 +203,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(),
@@ -212,6 +213,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_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -581,7 +581,7 @@
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)
@@ -590,6 +590,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(
@@ -682,6 +686,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)
@@ -788,7 +795,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
@@ -828,7 +835,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()
@@ -847,7 +854,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)
@@ -1061,6 +1068,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):
@@ -1273,6 +1283,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/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_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
@@ -1302,6 +1302,28 @@
assert isinstance(i['data'][0], int)
raises(TypeError, getattr, array(3), '__array_interface__')
+ 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
+
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
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
@@ -349,7 +349,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 """
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit