@@ -36,35 +36,17 @@ cdef int UAR_CDOUBLE = 15
36
36
cdef int UAR_TYPE_SENTINEL = 17
37
37
cdef int UAR_HALF = 23
38
38
39
- cdef str _make_typestr(int typenum):
40
- """
41
- Make typestring from type number
42
- """
43
- cdef type_to_str = [' |b1' , ' |i1' , ' |u1' , ' |i2' , ' |u2' ,
44
- ' |i4' , ' |u4' , ' |i4' , ' |u4' , ' |i8' , ' |u8' ,
45
- ' |f4' , ' |f8' , ' ' , ' |c8' , ' |c16' , ' ' ]
46
-
47
- if (typenum < 0 ):
48
- return " "
49
- if (typenum > 16 ):
50
- if (typenum == 23 ):
51
- return " |f2"
52
- return " "
53
-
54
- return type_to_str[typenum]
55
-
56
-
57
39
cdef int type_bytesize(int typenum):
58
40
"""
59
41
NPY_BOOL=0 : 1
60
42
NPY_BYTE=1 : 1
61
43
NPY_UBYTE=2 : 1
62
44
NPY_SHORT=3 : 2
63
45
NPY_USHORT=4 : 2
64
- NPY_INT=5 : 4
65
- NPY_UINT=6 : 4
66
- NPY_LONG=7 : 4
67
- NPY_ULONG=8 : 4
46
+ NPY_INT=5 : sizeof(int)
47
+ NPY_UINT=6 : sizeof(unsigned int)
48
+ NPY_LONG=7 : sizeof(long)
49
+ NPY_ULONG=8 : sizeof(unsigned long)
68
50
NPY_LONGLONG=9 : 8
69
51
NPY_ULONGLONG=10 : 8
70
52
NPY_FLOAT=11 : 4
@@ -76,7 +58,21 @@ cdef int type_bytesize(int typenum):
76
58
NPY_HALF=23 : 2
77
59
"""
78
60
cdef int * type_to_bytesize = [
79
- 1 , 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 , 8 , 8 , 4 , 8 , - 1 , 8 , 16 , - 1 ]
61
+ 1 ,
62
+ sizeof(char ),
63
+ sizeof(unsigned char ),
64
+ sizeof(short ),
65
+ sizeof(unsigned short ),
66
+ sizeof(int ),
67
+ sizeof(unsigned int ),
68
+ sizeof(long ),
69
+ sizeof(unsigned long ),
70
+ sizeof(long long ),
71
+ sizeof(unsigned long long ),
72
+ sizeof(float ),
73
+ sizeof(double ), - 1 ,
74
+ sizeof(float complex ),
75
+ sizeof(double complex ), - 1 ]
80
76
81
77
if typenum < 0 :
82
78
return - 1
@@ -88,6 +84,24 @@ cdef int type_bytesize(int typenum):
88
84
return type_to_bytesize[typenum]
89
85
90
86
87
+ cdef str _make_typestr(int typenum):
88
+ """
89
+ Make typestring from type number
90
+ """
91
+ cdef type_to_str = [" |b" , " |i" , " |u" , " |i" , " |u" ,
92
+ " |i" , " |u" , " |i" , " |u" , " |i" , " |u" ,
93
+ " |f" , " |f" , " " , " |c" , " |c" , " " ]
94
+
95
+ if (typenum < 0 ):
96
+ return " "
97
+ if (typenum > 16 ):
98
+ if (typenum == 23 ):
99
+ return " |f2"
100
+ return " "
101
+
102
+ return type_to_str[typenum] + str (type_bytesize(typenum))
103
+
104
+
91
105
cdef int typenum_from_format(str s) except * :
92
106
"""
93
107
Internal utility to convert string describing type format
0 commit comments