Commits

Justin Peel  committed 779c6bc

Add UInt32 dtype

  • Participants
  • Parent commits a54cf95
  • Branches unsigned-dtypes

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_dtype.py

 from pypy.rpython.lltypesystem import lltype, rffi
 
 
+UNSIGNEDLTR = "u"
 SIGNEDLTR = "i"
 BOOLLTR = "b"
 FLOATINGLTR = "f"
 class W_Int32Dtype(IntegerArithmeticDtype, W_Int32Dtype):
     pass
 
+W_UInt32Dtype = create_low_level_dtype(
+    num = 6, kind = UNSIGNEDLTR, name = "uint32",
+    aliases = ["I"],
+    applevel_types = [],
+    T = rffi.UINT,
+    valtype = rffi.UINT._type,
+    expected_size = 4,
+)
+class W_UInt32Dtype(IntegerArithmeticDtype, W_UInt32Dtype):
+    pass
+
 W_Int64Dtype = create_low_level_dtype(
     num = 9, kind = SIGNEDLTR, name = "int64",
     aliases = [],
 
 ALL_DTYPES = [
     W_BoolDtype,
-    W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype,
+    W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_UInt32Dtype,
+    W_Int64Dtype,
     W_Float64Dtype
 ]
 

File pypy/module/micronumpy/test/test_dtypes.py

         for i in range(5):
             assert b[i] == i * 2
 
+    def test_add_uint32(self):
+        from numpy import array, dtype
+
+        a = array(range(5), dtype="I")
+        b = a + a
+        assert b.dtype is dtype("I")
+        for i in range(5):
+            assert b[i] == i * 2
+
     def test_shape(self):
         from numpy import dtype