[pypy-commit] pypy default: issue #1005 -- accept 'float' as a dtype
alex_gaynor
noreply at buildbot.pypy.org
Wed Jan 18 18:15:27 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r51454:923df65f2286
Date: 2012-01-18 11:15 -0600
http://bitbucket.org/pypy/pypy/changeset/923df65f2286/
Log: issue #1005 -- accept 'float' as a dtype
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/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')
More information about the pypy-commit
mailing list