diff --git a/pytools/__init__.py b/pytools/__init__.py index 97f98f609b57610fc6adc7b97c0627c2a2f79ea5..7e9be32652520fc36590cd5281457922064910ff 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -1256,8 +1256,16 @@ if __name__ == "__main__": # numpy dtype mangling -------------------------------------------------------- -def common_dtype(dtypes): - return argmax2((dtype, dtype.num) for dtype in dtypes) +def common_dtype(dtypes, default=None): + dtypes = list(dtypes) + if dtypes: + return argmax2((dtype, dtype.num) for dtype in dtypes) + else: + if default is not None: + return default + else: + raise ValueError( + "cannot find common dtype of empty dtype list")