Coverage for kwave/utils/datautils.py: 27%

11 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-24 11:55 -0700

1import numpy as np 

2 

3 

4def get_smallest_possible_type(max_array_val, target_type_group, default=None): 

5 types = {'uint', 'int'} 

6 assert target_type_group in types 

7 

8 for bit_count in [8, 16, 32]: 

9 type_ = f'{target_type_group}{bit_count}' 

10 if max_array_val < intmax(type_): 

11 return type_ 

12 

13 return default 

14 

15 

16def intmax(dtype: str): 

17 return np.iinfo(getattr(np, dtype)).max