From d9ea5ed4f3575accad4d4ecb043453e537eeac20 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 22 Jun 2009 21:39:18 -0400
Subject: [PATCH] common_dtype: Allow specifying a default dtype.

---
 pytools/__init__.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pytools/__init__.py b/pytools/__init__.py
index 97f98f6..7e9be32 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")
 
 
 
-- 
GitLab