summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c2
-rw-r--r--numpy/core/src/scalarmathmodule.c.src2
-rw-r--r--numpy/core/src/umath/loops.c.src30
-rw-r--r--numpy/core/src/umath/loops.h6
-rw-r--r--numpy/core/src/umath/loops.h.src2
-rw-r--r--numpy/core/src/umath/umathmodule.c.src27
-rw-r--r--numpy/core/tests/test_umath.py27
-rw-r--r--numpy/distutils/fcompiler/gnu.py18
-rw-r--r--numpy/distutils/mingw32ccompiler.py18
-rw-r--r--numpy/f2py/cb_rules.py4
-rw-r--r--numpy/f2py/cfuncs.py2
-rw-r--r--numpy/lib/tests/test_polynomial.py3
12 files changed, 113 insertions, 28 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 5cb62b82f..f93a45717 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -121,7 +121,7 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
#if PY_VERSION_HEX >= 0x02050000
ret = PyErr_WarnEx(cls,
"Casting complex values to real discards the imaginary "
- "part", 0);
+ "part", 1);
#else
ret = PyErr_Warn(cls,
"Casting complex values to real discards the imaginary "
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index 6261c4c73..6913f517d 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -990,7 +990,7 @@ emit_complexwarning()
#if PY_VERSION_HEX >= 0x02050000
return PyErr_WarnEx(cls,
"Casting complex values to real discards the imaginary "
- "part", 0);
+ "part", 1);
#else
return PyErr_Warn(cls,
"Casting complex values to real discards the imaginary "
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 850126482..c61d16ae4 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -1286,6 +1286,36 @@ NPY_NO_EXPORT void
*((@type@ *)op1) = ldexp@c@(in1, in2);
}
}
+
+NPY_NO_EXPORT void
+@TYPE@_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
+{
+ /*
+ * Additional loop to handle long integer inputs (cf. #866, #1633).
+ * long != int on many 64-bit platforms, so we need this second loop
+ * to handle the default integer type.
+ */
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const long in2 = *(long *)ip2;
+ if (((int)in2) == in2) {
+ /* Range OK */
+ *((@type@ *)op1) = ldexp@c@(in1, ((int)in2));
+ }
+ else {
+ /*
+ * Outside int range -- also ldexp will overflow in this case,
+ * given that exponent has less bits than int.
+ */
+ if (in2 > 0) {
+ *((@type@ *)op1) = ldexp@c@(in1, NPY_MAX_INT);
+ }
+ else {
+ *((@type@ *)op1) = ldexp@c@(in1, NPY_MIN_INT);
+ }
+ }
+ }
+}
#endif
#define @TYPE@_true_divide @TYPE@_divide
diff --git a/numpy/core/src/umath/loops.h b/numpy/core/src/umath/loops.h
index 59e9556c2..7cb4b22cc 100644
--- a/numpy/core/src/umath/loops.h
+++ b/numpy/core/src/umath/loops.h
@@ -1675,6 +1675,8 @@ FLOAT_frexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
#ifdef HAVE_LDEXPF
NPY_NO_EXPORT void
FLOAT_ldexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
+NPY_NO_EXPORT void
+FLOAT_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
#endif
#define FLOAT_true_divide FLOAT_divide
@@ -1827,6 +1829,8 @@ DOUBLE_frexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
#ifdef HAVE_LDEXP
NPY_NO_EXPORT void
DOUBLE_ldexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
+NPY_NO_EXPORT void
+DOUBLE_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
#endif
#define DOUBLE_true_divide DOUBLE_divide
@@ -1979,6 +1983,8 @@ LONGDOUBLE_frexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(fu
#ifdef HAVE_LDEXPL
NPY_NO_EXPORT void
LONGDOUBLE_ldexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
+NPY_NO_EXPORT void
+LONGDOUBLE_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
#endif
#define LONGDOUBLE_true_divide LONGDOUBLE_divide
diff --git a/numpy/core/src/umath/loops.h.src b/numpy/core/src/umath/loops.h.src
index ca3fb37ee..33dfe882e 100644
--- a/numpy/core/src/umath/loops.h.src
+++ b/numpy/core/src/umath/loops.h.src
@@ -268,6 +268,8 @@ NPY_NO_EXPORT void
#ifdef HAVE_LDEXP@C@
NPY_NO_EXPORT void
@TYPE@_ldexp(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
+NPY_NO_EXPORT void
+@TYPE@_ldexp_long(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func));
#endif
#define @TYPE@_true_divide @TYPE@_divide
diff --git a/numpy/core/src/umath/umathmodule.c.src b/numpy/core/src/umath/umathmodule.c.src
index 9694f521d..c3da9f3d3 100644
--- a/numpy/core/src/umath/umathmodule.c.src
+++ b/numpy/core/src/umath/umathmodule.c.src
@@ -164,6 +164,8 @@ static PyUFuncGenericFunction frexp_functions[] = {
};
static void * blank3_data[] = { (void *)NULL, (void *)NULL, (void *)NULL};
+static void * blank6_data[] = { (void *)NULL, (void *)NULL, (void *)NULL,
+ (void *)NULL, (void *)NULL, (void *)NULL};
static char frexp_signatures[] = {
#ifdef HAVE_FREXPF
PyArray_FLOAT, PyArray_FLOAT, PyArray_INT,
@@ -174,22 +176,35 @@ static char frexp_signatures[] = {
#endif
};
+#if NPY_SIZEOF_LONG == NPY_SIZEOF_INT
+#define LDEXP_LONG(typ) typ##_ldexp
+#else
+#define LDEXP_LONG(typ) typ##_ldexp_long
+#endif
+
static PyUFuncGenericFunction ldexp_functions[] = {
#ifdef HAVE_LDEXPF
FLOAT_ldexp,
+ LDEXP_LONG(FLOAT),
#endif
- DOUBLE_ldexp
+ DOUBLE_ldexp,
+ LDEXP_LONG(DOUBLE)
#ifdef HAVE_LDEXPL
- ,LONGDOUBLE_ldexp
+ ,
+ LONGDOUBLE_ldexp,
+ LDEXP_LONG(LONGDOUBLE)
#endif
};
static char ldexp_signatures[] = {
#ifdef HAVE_LDEXPF
PyArray_FLOAT, PyArray_INT, PyArray_FLOAT,
+ PyArray_FLOAT, PyArray_LONG, PyArray_FLOAT,
#endif
+ PyArray_DOUBLE, PyArray_INT, PyArray_DOUBLE,
PyArray_DOUBLE, PyArray_LONG, PyArray_DOUBLE
#ifdef HAVE_LDEXPL
+ ,PyArray_LONGDOUBLE, PyArray_INT, PyArray_LONGDOUBLE
,PyArray_LONGDOUBLE, PyArray_LONG, PyArray_LONGDOUBLE
#endif
};
@@ -213,14 +228,14 @@ InitOtherOperators(PyObject *dictionary) {
PyDict_SetItemString(dictionary, "frexp", f);
Py_DECREF(f);
- num = 1;
+ num = 2;
#ifdef HAVE_LDEXPL
- num += 1;
+ num += 2;
#endif
#ifdef HAVE_LDEXPF
- num += 1;
+ num += 2;
#endif
- f = PyUFunc_FromFuncAndData(ldexp_functions, blank3_data, ldexp_signatures, num,
+ f = PyUFunc_FromFuncAndData(ldexp_functions, blank6_data, ldexp_signatures, num,
2, 1, PyUFunc_None, "ldexp",
"Compute y = x1 * 2**x2.",0);
PyDict_SetItemString(dictionary, "ldexp", f);
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 2dace8c16..1245030a4 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -379,14 +379,29 @@ class TestArctan2SpecialValues(TestCase):
class TestLdexp(TestCase):
+ def _check_ldexp(self, tp):
+ assert_almost_equal(ncu.ldexp(np.array(2., np.float32),
+ np.array(3, tp)), 16.)
+ assert_almost_equal(ncu.ldexp(np.array(2., np.float64),
+ np.array(3, tp)), 16.)
+ assert_almost_equal(ncu.ldexp(np.array(2., np.longdouble),
+ np.array(3, tp)), 16.)
+
def test_ldexp(self):
+ # The default Python int type should work
assert_almost_equal(ncu.ldexp(2., 3), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int16)), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int32)), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(3, np.int16)), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(3, np.int32)), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.longdouble), np.array(3, np.int16)), 16.)
- assert_almost_equal(ncu.ldexp(np.array(2., np.longdouble), np.array(3, np.int32)), 16.)
+ # The following int types should all be accepted
+ self._check_ldexp(np.int8)
+ self._check_ldexp(np.int16)
+ self._check_ldexp(np.int32)
+ self._check_ldexp('i')
+ self._check_ldexp('l')
+
+ def test_ldexp_overflow(self):
+ imax = np.iinfo(np.dtype('l')).max
+ imin = np.iinfo(np.dtype('l')).min
+ assert_equal(ncu.ldexp(2., imax), np.inf)
+ assert_equal(ncu.ldexp(2., imin), 0)
class TestMaximum(TestCase):
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index 632c6d97a..dd1fbb2cc 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -224,7 +224,17 @@ class Gnu95FCompiler(GnuFCompiler):
v = self.gnu_version_match(version_string)
if not v or v[0] != 'gfortran':
return None
- return v[1]
+ v = v[1]
+ if v>='4.':
+ # gcc-4 series releases do not support -mno-cygwin option
+ pass
+ else:
+ # use -mno-cygwin flag for gfortran when Python is not Cygwin-Python
+ if sys.platform == 'win32':
+ for key in ['version_cmd', 'compiler_f77', 'compiler_f90',
+ 'compiler_fix', 'linker_so', 'linker_exe']:
+ self.executables[key].append('-mno-cygwin')
+ return v
# 'gfortran --version' results:
# XXX is the below right?
@@ -248,12 +258,6 @@ class Gnu95FCompiler(GnuFCompiler):
'linker_exe' : [None, "-Wall"]
}
- # use -mno-cygwin flag for g77 when Python is not Cygwin-Python
- if sys.platform == 'win32':
- for key in ['version_cmd', 'compiler_f77', 'compiler_f90',
- 'compiler_fix', 'linker_so', 'linker_exe']:
- executables[key].append('-mno-cygwin')
-
module_dir_switch = '-J'
module_include_switch = '-I'
diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py
index 907e0047c..f5d996490 100644
--- a/numpy/distutils/mingw32ccompiler.py
+++ b/numpy/distutils/mingw32ccompiler.py
@@ -104,11 +104,19 @@ class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
# bad consequences, like using Py_ModuleInit4 instead of
# Py_ModuleInit4_64, etc... So we add it here
if get_build_architecture() == 'AMD64':
- self.set_executables(
+ if self.gcc_version < "4.":
+ self.set_executables(
compiler='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall',
compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes',
linker_exe='gcc -g -mno-cygwin',
linker_so='gcc -g -mno-cygwin -shared')
+ else:
+ # gcc-4 series releases do not support -mno-cygwin option
+ self.set_executables(
+ compiler='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall',
+ compiler_so='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypes',
+ linker_exe='gcc -g',
+ linker_so='gcc -g -shared')
else:
if self.gcc_version <= "3.0.0":
self.set_executables(compiler='gcc -mno-cygwin -O2 -w',
@@ -116,11 +124,17 @@ class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
linker_exe='g++ -mno-cygwin',
linker_so='%s -mno-cygwin -mdll -static %s'
% (self.linker, entry_point))
- else:
+ elif self.gcc_version < "4.":
self.set_executables(compiler='gcc -mno-cygwin -O2 -Wall',
compiler_so='gcc -mno-cygwin -O2 -Wall -Wstrict-prototypes',
linker_exe='g++ -mno-cygwin',
linker_so='g++ -mno-cygwin -shared')
+ else:
+ # gcc-4 series releases do not support -mno-cygwin option
+ self.set_executables(compiler='gcc -O2 -Wall',
+ compiler_so='gcc -O2 -Wall -Wstrict-prototypes',
+ linker_exe='g++ ',
+ linker_so='g++ -shared')
# added for python2.3 support
# we can't pass it through set_executables because pre 2.2 would fail
self.compiler_cxx = ['g++']
diff --git a/numpy/f2py/cb_rules.py b/numpy/f2py/cb_rules.py
index 99742cb46..8e8320bfd 100644
--- a/numpy/f2py/cb_rules.py
+++ b/numpy/f2py/cb_rules.py
@@ -333,7 +333,7 @@ cb_arg_rules=[
'pyobjfrom':[{debugcapi:'\tfprintf(stderr,"debug-capi:cb:#varname#=\\"#showvalueformat#\\":%d:\\n",#varname_i#,#varname_i#_cb_len);'},
{isintent_in:"""\
\tif (#name#_nofargs>capi_i)
-\t\tif (PyTuple_SetItem((PyObject *)capi_arglist,capi_i++,pyobj_from_#ctype#1(#varname_i#)))
+\t\tif (PyTuple_SetItem((PyObject *)capi_arglist,capi_i++,pyobj_from_#ctype#1size(#varname_i#,#varname_i#_cb_len)))
\t\t\tgoto capi_fail;"""},
{isintent_inout:"""\
\tif (#name#_nofargs>capi_i) {
@@ -341,7 +341,7 @@ cb_arg_rules=[
\t\tif (PyTuple_SetItem((PyObject *)capi_arglist,capi_i++,pyarr_from_p_#ctype#1(#varname_i#,#varname_i#_cb_dims)))
\t\t\tgoto capi_fail;
\t}"""}],
- 'need':[{isintent_in:'pyobj_from_#ctype#1'},
+ 'need':[{isintent_in:'pyobj_from_#ctype#1size'},
{isintent_inout:'pyarr_from_p_#ctype#1'}],
'_check':l_and(isstring,isintent_nothide),
'_optional':''
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 722760ad0..56a193963 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -282,6 +282,8 @@ needs['pyobj_from_complex_float1']=['complex_float']
cppmacros['pyobj_from_complex_float1']='#define pyobj_from_complex_float1(v) (PyComplex_FromDoubles(v.r,v.i))'
needs['pyobj_from_string1']=['string']
cppmacros['pyobj_from_string1']='#define pyobj_from_string1(v) (PyString_FromString((char *)v))'
+needs['pyobj_from_string1size']=['string']
+cppmacros['pyobj_from_string1size']='#define pyobj_from_string1size(v,len) (PyString_FromStringAndSize((char *)v, len))'
needs['TRYPYARRAYTEMPLATE']=['PRINTPYOBJERR']
cppmacros['TRYPYARRAYTEMPLATE']="""\
/* New SciPy */
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 130d11dab..227413c19 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -17,9 +17,6 @@ poly1d([ 3., 2., 1.])
>>> print(poly1d([1.89999+2j, -3j, -5.12345678, 2+1j]))
3 2
(1.9 + 2j) x - 3j x - 5.123 x + (2 + 1j)
->>> print(poly1d([100e-90, 1.234567e-9j+3, -1234.999e8]))
- 2
-1e-88 x + (3 + 1.235e-09j) x - 1.235e+11
>>> print(poly1d([-3, -2, -1]))
2
-3 x - 2 x - 1