diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-07-09 08:12:15 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-07-09 08:12:15 +0000 |
commit | 7d2d320f2da7d65bdeb773594c2e9d1979b4eb4d (patch) | |
tree | 61f887a6421cb646da386e8dcb06213ccb1b360d | |
parent | 2f15b16db2ef171d8730f76f6c97b6f67983255a (diff) | |
download | numpy-7d2d320f2da7d65bdeb773594c2e9d1979b4eb4d.tar.gz |
BUG: core: handle sizeof(double) == sizeof(longdouble) in PyArray_CanCastSafely (fixes #1539)
Thanks to Christoph Gohlke for the patch.
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 18 |
2 files changed, 29 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index ea43a4233..ca56b1e2e 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -634,13 +634,23 @@ PyArray_CanCastSafely(int fromtype, int totype) if (PyTypeNum_ISCOMPLEX(totype)) { return (telsize >> 1) >= felsize; } + else if (PyTypeNum_ISFLOAT(totype) && (telsize == felsize)) { + /* On some systems, double == longdouble */ + return 1; + } else { return totype > fromtype; } case PyArray_CFLOAT: case PyArray_CDOUBLE: case PyArray_CLONGDOUBLE: - return totype > fromtype; + if (PyTypeNum_ISCOMPLEX(totype) && (telsize == felsize)) { + /* On some systems, double == longdouble */ + return 1; + } + else { + return totype > fromtype; + } case PyArray_STRING: case PyArray_UNICODE: return totype > fromtype; diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 9efebbac9..3dc1a653e 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1302,5 +1302,23 @@ class TestRegression(TestCase): # Ticket #1345: the following should not cause a crash np.fromstring(asbytes('aa, aa, 1.0'), sep=',') + def test_issue1539(self): + dtypes = [x for x in np.typeDict.values() + if (issubclass(x, np.number) + and not issubclass(x, np.timeinteger))] + a = np.array([], dtypes[0]) + failures = [] + for x in dtypes: + b = a.astype(x) + for y in dtypes: + c = a.astype(y) + try: + np.dot(b, c) + except TypeError, e: + failures.append((x, y)) + if failures: + raise AssertionError("Failures: %r" % failures) + + if __name__ == "__main__": run_module_suite() |