[pypy-commit] pypy default: Add Int16 dtype with tests
justinpeel
noreply at buildbot.pypy.org
Thu Sep 1 05:20:51 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch:
Changeset: r46966:4218de3c70f9
Date: 2011-08-31 21:20 -0600
http://bitbucket.org/pypy/pypy/changeset/4218de3c70f9/
Log: Add Int16 dtype with tests
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
@@ -286,6 +286,19 @@
class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype):
def unwrap(self, space, w_item):
return self.adapt_val(space.int_w(space.int(w_item)))
+assert W_Int8Dtype.num_bytes == 1
+
+W_Int16Dtype = create_low_level_dtype(
+ num = 3, kind = SIGNEDLTR, name = "int16",
+ aliases = ["int16"],
+ applevel_types = [],
+ T = rffi.SHORT,
+ valtype = rffi.SHORT._type,
+)
+class W_Int16Dtype(IntegerArithmeticDtype, W_Int16Dtype):
+ def unwrap(self, space, w_item):
+ return self.adapt_val(space.int_w(space.int(w_item)))
+assert W_Int16Dtype.num_bytes == 2
W_Int32Dtype = create_low_level_dtype(
num = 5, kind = SIGNEDLTR, name = "int32",
@@ -323,7 +336,7 @@
ALL_DTYPES = [
W_BoolDtype,
- W_Int8Dtype, W_Int32Dtype, W_Int64Dtype,
+ W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype,
W_Float64Dtype
]
@@ -353,4 +366,4 @@
kind = interp_attrproperty("kind", cls=W_Dtype),
shape = GetSetProperty(W_Dtype.descr_get_shape),
)
-W_Dtype.typedef.acceptable_as_base_class = False
\ No newline at end of file
+W_Dtype.typedef.acceptable_as_base_class = False
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
@@ -82,10 +82,20 @@
assert a[1] == 1
def test_add_int8(self):
- from numpy import array
+ from numpy import array, dtype
a = array(range(5), dtype="int8")
b = a + a
+ assert b.dtype is dtype("int8")
+ for i in range(5):
+ assert b[i] == i * 2
+
+ def test_add_int16(self):
+ from numpy import array, dtype
+
+ a = array(range(5), dtype="int16")
+ b = a + a
+ assert b.dtype is dtype("int16")
for i in range(5):
assert b[i] == i * 2
@@ -98,4 +108,4 @@
from numpy import dtype
# You can't subclass dtype
- raises(TypeError, type, "Foo", (dtype,), {})
\ No newline at end of file
+ raises(TypeError, type, "Foo", (dtype,), {})
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
@@ -84,6 +84,9 @@
a = array(range(5), dtype="int8")
assert str(a) == "[0 1 2 3 4]"
+ a = array(range(5), dtype="int16")
+ assert str(a) == "[0 1 2 3 4]"
+
def test_str_slice(self):
from numpy import array, zeros
a = array(range(5), float)
More information about the pypy-commit
mailing list