@@ -47,10 +47,8 @@ def get_castable_tensor(shape, dtype):
4747 else :
4848 # can't directly use min and max, because for int64_t, max - min
4949 # is greater than int64_t range and triggers UB.
50- dtype_info = torch .iinfo (dtype )
51- low = max (dtype_info .min , int (- 1e10 ))
52- high = min (dtype_info .max , int (1e10 ))
53- dtype_info = torch .iinfo (dtype )
50+ low = max (torch .iinfo (dtype ).min , int (- 1e10 ))
51+ high = min (torch .iinfo (dtype ).max , int (1e10 ))
5452 t = torch .empty (shape , dtype = torch .int64 ).random_ (low , high )
5553 return t .to (dtype )
5654
@@ -272,10 +270,12 @@ def test_numpy_array_interface(self, device):
272270 ]
273271 for tp , dtype in zip (types , dtypes ):
274272 if np .dtype (dtype ).kind == 'u' :
275- x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp )
273+ # .type expects a XxxTensor, which have no type hints on
274+ # purpose, so ignore during mypy type checking
275+ x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp ) # type: ignore
276276 array = np .array ([1 , 2 , 3 , 4 ], dtype = dtype )
277277 else :
278- x = torch .Tensor ([1 , - 2 , 3 , - 4 ]).type (tp )
278+ x = torch .Tensor ([1 , - 2 , 3 , - 4 ]).type (tp ) # type: ignore
279279 array = np .array ([1 , - 2 , 3 , - 4 ], dtype = dtype )
280280
281281 # Test __array__ w/o dtype argument
@@ -309,7 +309,7 @@ def test_numpy_array_interface(self, device):
309309 float_types = [torch .DoubleTensor , torch .FloatTensor ]
310310 float_dtypes = [np .float64 , np .float32 ]
311311 for tp , dtype in zip (float_types , float_dtypes ):
312- x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp )
312+ x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp ) # type: ignore
313313 array = np .array ([1 , 2 , 3 , 4 ], dtype = dtype )
314314 for func in ['sin' , 'sqrt' , 'ceil' ]:
315315 ufunc = getattr (np , func )
@@ -321,7 +321,7 @@ def test_numpy_array_interface(self, device):
321321
322322 # Test functions with boolean return value
323323 for tp , dtype in zip (types , dtypes ):
324- x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp )
324+ x = torch .Tensor ([1 , 2 , 3 , 4 ]).type (tp ) # type: ignore
325325 array = np .array ([1 , 2 , 3 , 4 ], dtype = dtype )
326326 geq2_x = np .greater_equal (x , 2 )
327327 geq2_array = np .greater_equal (array , 2 ).astype ('uint8' )
@@ -360,7 +360,7 @@ def test_parse_numpy_int(self, device):
360360 self .assertEqual (torch .ones ([2 , 2 , 2 , 2 ]).mean (scalar ), torch .ones ([2 , 2 , 2 , 2 ]).mean (np_val ))
361361
362362 # numpy integral type parses like a python int in custom python bindings:
363- self .assertEqual (torch .Storage (np_val ).size (), scalar )
363+ self .assertEqual (torch .Storage (np_val ).size (), scalar ) # type: ignore
364364
365365 tensor = torch .tensor ([2 ], dtype = torch .int )
366366 tensor [0 ] = np_val
0 commit comments