6464 '?' :0 , 'c' :0 , 'b' :0 , 'B' :0 ,
6565 'h' :0 , 'H' :0 , 'i' :0 , 'I' :0 ,
6666 'l' :0 , 'L' :0 , 'n' :0 , 'N' :0 ,
67- 'f' :0 , 'd' :0 , 'P' :0
67+ 'e' : 0 , ' f' :0 , 'd' :0 , 'P' :0
6868}
6969
7070# NumPy does not have 'n' or 'N':
8989 'i' :(- (1 << 31 ), 1 << 31 ), 'I' :(0 , 1 << 32 ),
9090 'l' :(- (1 << 31 ), 1 << 31 ), 'L' :(0 , 1 << 32 ),
9191 'q' :(- (1 << 63 ), 1 << 63 ), 'Q' :(0 , 1 << 64 ),
92- 'f' :(- (1 << 63 ), 1 << 63 ), 'd' :(- (1 << 1023 ), 1 << 1023 )
92+ 'e' :(- 65519 , 65520 ), 'f' :(- (1 << 63 ), 1 << 63 ),
93+ 'd' :(- (1 << 1023 ), 1 << 1023 )
9394}
9495
9596def native_type_range (fmt ):
@@ -98,6 +99,8 @@ def native_type_range(fmt):
9899 lh = (0 , 256 )
99100 elif fmt == '?' :
100101 lh = (0 , 2 )
102+ elif fmt == 'e' :
103+ lh = (- 65519 , 65520 )
101104 elif fmt == 'f' :
102105 lh = (- (1 << 63 ), 1 << 63 )
103106 elif fmt == 'd' :
@@ -125,7 +128,10 @@ def native_type_range(fmt):
125128 for fmt in fmtdict ['@' ]:
126129 fmtdict ['@' ][fmt ] = native_type_range (fmt )
127130
131+ # Format codes suppported by the memoryview object
128132MEMORYVIEW = NATIVE .copy ()
133+
134+ # Format codes suppported by array.array
129135ARRAY = NATIVE .copy ()
130136for k in NATIVE :
131137 if not k in "bBhHiIlLfd" :
@@ -164,7 +170,7 @@ def randrange_fmt(mode, char, obj):
164170 x = b'\x01 '
165171 if char == '?' :
166172 x = bool (x )
167- if char == 'f' or char == 'd ' :
173+ if char in 'efd ' :
168174 x = struct .pack (char , x )
169175 x = struct .unpack (char , x )[0 ]
170176 return x
@@ -2246,7 +2252,7 @@ def test_py_buffer_to_contiguous(self):
22462252 ###
22472253 ### Fortran output:
22482254 ### ---------------
2249- ### >>> fortran_buf = nd.tostring (order='F')
2255+ ### >>> fortran_buf = nd.tobytes (order='F')
22502256 ### >>> fortran_buf
22512257 ### b'\x00\x04\x08\x01\x05\t\x02\x06\n\x03\x07\x0b'
22522258 ###
@@ -2289,7 +2295,7 @@ def test_py_buffer_to_contiguous(self):
22892295 self .assertEqual (memoryview (y ), memoryview (nd ))
22902296
22912297 if numpy_array :
2292- self .assertEqual (b , na .tostring (order = 'C' ))
2298+ self .assertEqual (b , na .tobytes (order = 'C' ))
22932299
22942300 # 'F' request
22952301 if f == 0 : # 'C' to 'F'
@@ -2312,7 +2318,7 @@ def test_py_buffer_to_contiguous(self):
23122318 self .assertEqual (memoryview (y ), memoryview (nd ))
23132319
23142320 if numpy_array :
2315- self .assertEqual (b , na .tostring (order = 'F' ))
2321+ self .assertEqual (b , na .tobytes (order = 'F' ))
23162322
23172323 # 'A' request
23182324 if f == ND_FORTRAN :
@@ -2336,7 +2342,7 @@ def test_py_buffer_to_contiguous(self):
23362342 self .assertEqual (memoryview (y ), memoryview (nd ))
23372343
23382344 if numpy_array :
2339- self .assertEqual (b , na .tostring (order = 'A' ))
2345+ self .assertEqual (b , na .tobytes (order = 'A' ))
23402346
23412347 # multi-dimensional, non-contiguous input
23422348 nd = ndarray (list (range (12 )), shape = [3 , 4 ], flags = ND_WRITABLE | ND_PIL )
0 commit comments