@@ -160,6 +160,34 @@ def test_array_to_file():
160
160
assert_array_equal (data_back , np .zeros (arr .shape ))
161
161
162
162
163
+ def test_a2f_big_scalers ():
164
+ # Check that clip works even for overflowing scalers / data
165
+ info = np .finfo (np .float32 )
166
+ arr = np .array ([info .min , np .nan , info .max ], dtype = np .float32 )
167
+ str_io = BytesIO ()
168
+ # Intercept causes overflow - does routine scale correctly?
169
+ array_to_file (arr , str_io , np .int8 , intercept = np .float32 (2 ** 120 ))
170
+ data_back = array_from_file (arr .shape , np .int8 , str_io )
171
+ assert_array_equal (data_back , [- 128 , 0 , 127 ])
172
+ # Scales also if mx, mn specified?
173
+ str_io .seek (0 )
174
+ array_to_file (arr , str_io , np .int8 , mn = info .min , mx = info .max ,
175
+ intercept = np .float32 (2 ** 120 ))
176
+ data_back = array_from_file (arr .shape , np .int8 , str_io )
177
+ assert_array_equal (data_back , [- 128 , 0 , 127 ])
178
+ # And if slope causes overflow?
179
+ str_io .seek (0 )
180
+ array_to_file (arr , str_io , np .int8 , divslope = np .float32 (0.5 ))
181
+ data_back = array_from_file (arr .shape , np .int8 , str_io )
182
+ assert_array_equal (data_back , [- 128 , 0 , 127 ])
183
+ # with mn, mx specified?
184
+ str_io .seek (0 )
185
+ array_to_file (arr , str_io , np .int8 , mn = info .min , mx = info .max ,
186
+ divslope = np .float32 (0.5 ))
187
+ data_back = array_from_file (arr .shape , np .int8 , str_io )
188
+ assert_array_equal (data_back , [- 128 , 0 , 127 ])
189
+
190
+
163
191
def write_return (data , fileobj , out_dtype , * args , ** kwargs ):
164
192
fileobj .truncate (0 )
165
193
array_to_file (data , fileobj , out_dtype , * args , ** kwargs )
0 commit comments