Justin Peel avatar Justin Peel committed 52e1f87

use longer strings to specify dtypes

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_dtype.py

 
 kind_dict = {'b': 0, 'u': 1, 'i': 1, 'f': 2, 'c': 2}
 
+# this probably doesn't contain all possibilities yet
+num_dict = {'b1': Bool_num, 'i1': Int8_num, 'i2': Int16_num, 'i4': Int32_num,
+            'i8': Int64_num, 'f4': Float32_num, 'f8': Float64_num, 
+            'f12': Float96_num,
+            'bool': Bool_num, 'bool8': Bool_num, 'int8': Int8_num,
+            'int16': Int16_num, 'int32': Int32_num, 'int64': Int64_num,
+            'float32': Float32_num, 'float64': Float64_num,
+            'float96': Float96_num}
+
 class Dtype(Wrappable):
     # attributes: type, kind, typeobj?(I think it should point to np.float64 or
     # the like), byteorder, flags, type_num, elsize, alignment, subarray,
             dtype = _dtype_list[typenum]
             if typenum != -1 and dtype is not None:
                 return _dtype_list[typenum]
-        # XXX: need to put in 2 letters strings
+        # XXX: can improve this part. will need to for endianness
+        if s in num_dict:
+            return _dtype_list[num_dict[s]]
         raise OperationError(space.w_ValueError,
                             space.wrap("type not recognized"))
     elif space.is_true(space.isinstance(w_string_or_type, space.w_type)):

pypy/module/micronumpy/test/test_dtypes.py

         d = dtype('l')
         assert d.num == 7
         assert d.kind == 'i'
+        assert dtype('int8').num == 1
+        assert dtype('i1').num == 1
 
     def test_dtype_with_types(self):
         from numpy import dtype
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.