def test_calls_increase_itemsize_factor(self, mock_iibf): dt = np.int8 factor = 2 _ = iadt.get_minimal_dtype([dt], factor) assert mock_iibf.call_count == 1
def test_with_lists_of_different_arrays(self): dt_lists = [ [np.uint8, np.uint16], [np.uint8, np.uint32], [np.uint8, np.int8], [np.uint8, np.bool_], [np.int8, np.int16], [np.float16, np.float32], [np.uint8, np.float32], [np.uint8, np.int8, np.int16], [np.uint8, np.int8, np.bool_], [np.uint8, np.int8, np.float32], ] expecteds = [ np.uint16, np.uint32, np.int16, np.uint8, np.int16, np.float32, np.float32, np.int16, np.int16, np.float32 ] for dt_list, expected in zip(dt_lists, expecteds): expected = np.dtype(expected) dt_list = [np.dtype(dt) for dt in dt_list] dt_names = ", ".join([dt.name for dt in dt_list]) with self.subTest(dtypes=dt_names): promoted_dt = iadt.get_minimal_dtype(dt_list) assert promoted_dt.name == expected.name
def test_with_dtype_function(self): dt_funcs = [ np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64, np.float16, np.float32, np.float64, np.bool_ ] for dt_func in dt_funcs: with self.subTest(dtype=np.dtype(dt_func).name): inputs = [dt_func] promoted_dt = iadt.get_minimal_dtype(inputs) assert promoted_dt.name == np.dtype(dt_func).name
def test_with_lists_of_identical_dtypes(self): dts = [ np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64, np.float16, np.float32, np.float64, np.bool_ ] for dt in dts: dt = np.dtype(dt) for length in [1, 2, 3]: with self.subTest(dtype=dt.name, length=length): inputs = [dt for _ in range(length)] promoted_dt = iadt.get_minimal_dtype(inputs) assert promoted_dt.name == dt.name