[Numpy-svn] r8477 - in trunk/numpy/core: src/multiarray tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri Jul 9 04:12:15 EDT 2010
Author: ptvirtan
Date: 2010-07-09 03:12:15 -0500 (Fri, 09 Jul 2010)
New Revision: 8477
Modified:
trunk/numpy/core/src/multiarray/convert_datatype.c
trunk/numpy/core/tests/test_regression.py
Log:
BUG: core: handle sizeof(double) == sizeof(longdouble) in PyArray_CanCastSafely (fixes #1539)
Thanks to Christoph Gohlke for the patch.
Modified: trunk/numpy/core/src/multiarray/convert_datatype.c
===================================================================
--- trunk/numpy/core/src/multiarray/convert_datatype.c 2010-07-09 08:12:04 UTC (rev 8476)
+++ trunk/numpy/core/src/multiarray/convert_datatype.c 2010-07-09 08:12:15 UTC (rev 8477)
@@ -634,13 +634,23 @@
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;
Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py 2010-07-09 08:12:04 UTC (rev 8476)
+++ trunk/numpy/core/tests/test_regression.py 2010-07-09 08:12:15 UTC (rev 8477)
@@ -1302,5 +1302,23 @@
# 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()
More information about the Numpy-svn
mailing list