diff options
30 files changed, 163 insertions, 149 deletions
diff --git a/.travis-make-py24-virtualenv.sh b/.travis-make-py24-virtualenv.sh index 625f8b7b7..972e2d26c 100755 --- a/.travis-make-py24-virtualenv.sh +++ b/.travis-make-py24-virtualenv.sh @@ -15,4 +15,11 @@ EOF ./configure --prefix=$PWD/install make make install -virtualenv -p install/bin/python2.4 --distribute $VIRTENV +# This is the last version of virtualenv to support python 2.4: +curl -O https://raw.github.com/pypa/virtualenv/1.7.2/virtualenv.py +# And this is the last version of pip to support python 2.4. If +# there's a file matching "^pip-.*(zip|tar.gz|tar.bz2|tgz|tbz)$" in +# the current directory then virtualenv will take that as the pip +# source distribution to install +curl -O http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz +install/bin/python2.4 ./virtualenv.py --distribute $VIRTENV @@ -12,9 +12,6 @@ Caveats: import os import sys import subprocess -import string - -import os.path as op # Ugly but necessary hack: import numpy here so that wscript in sub directories # will see this numpy and not an already installed one diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst index 0313b0ef8..ef2a0f9ee 100644 --- a/doc/source/user/c-info.ufunc-tutorial.rst +++ b/doc/source/user/c-info.ufunc-tutorial.rst @@ -150,7 +150,7 @@ the module. NULL }; - PyObject *PyInit_spam(void) + PyMODINIT_FUNC PyInit_spam(void) { PyObject *m; m = PyModule_Create(&moduledef); @@ -335,7 +335,7 @@ the primary thing that must be changed to create your own ufunc. NULL }; - PyObject *PyInit_npufunc(void) + PyMODINIT_FUNC PyInit_npufunc(void) { PyObject *m, *logit, *d; m = PyModule_Create(&moduledef); @@ -614,7 +614,7 @@ the primary thing that must be changed to create your own ufunc. NULL }; - PyObject *PyInit_npufunc(void) + PyMODINIT_FUNC PyInit_npufunc(void) { PyObject *m, *logit, *d; m = PyModule_Create(&moduledef); @@ -837,7 +837,7 @@ as well as all other properties of a ufunc. NULL }; - PyObject *PyInit_npufunc(void) + PyMODINIT_FUNC PyInit_npufunc(void) { PyObject *m, *logit, *d; m = PyModule_Create(&moduledef); diff --git a/numpy/__init__.py b/numpy/__init__.py index 0b5357632..8a09d2fec 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -169,3 +169,9 @@ else: __all__.extend(_mat.__all__) __all__.extend(lib.__all__) __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma']) + + # Filter annoying Cython warnings that serve no good purpose. + import warnings + warnings.filterwarnings("ignore", message="numpy.dtype size changed") + warnings.filterwarnings("ignore", message="numpy.ufunc size changed") + diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index a416559db..f94a6964a 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -3067,6 +3067,14 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('astype', requirements are satisfied, the input array is returned instead of a copy. + Returns + ------- + arr_t : ndarray + Unless `copy` is False and the other conditions for returning the input + array are satisfied (see description for `copy` input paramter), `arr_t` + is a new array of the same shape as the input array, with dtype, order + given by `dtype`, `order`. + Raises ------ ComplexWarning : diff --git a/numpy/build_utils/waf.py b/numpy/build_utils/waf.py index 051cf27e0..4ef71327c 100644 --- a/numpy/build_utils/waf.py +++ b/numpy/build_utils/waf.py @@ -123,9 +123,9 @@ int main() def check_type(self, type_name, **kw): code = r""" int main() { - if ((%(type_name)s *) 0) + if ((%(type_name)s *) 0) return 0; - if (sizeof (%(type_name)s)) + if (sizeof (%(type_name)s)) return 0; } """ % {"type_name": type_name} @@ -412,15 +412,15 @@ def check_ldouble_representation(conf, **kw): def post_check(self, *k, **kw): "set the variables after a test was run successfully" - is_success = 0 + is_success = False if kw['execute']: if kw['success'] is not None: - is_success = kw['success'] + if kw.get('define_ret', False): + is_success = kw['success'] + else: + is_success = (kw['success'] == 0) else: - if kw["success"] == 0: - is_success = 1 - else: - is_success = 0 + is_success = (kw['success'] == 0) def define_or_stuff(): nm = kw['define_name'] @@ -453,7 +453,7 @@ def post_check(self, *k, **kw): if isinstance(val, str): val = val.rstrip(os.path.sep) self.env.append_unique(k + '_' + kw['uselib_store'], val) - return is_success + return is_success @waflib.Configure.conf def define_with_comment(conf, define, value, comment=None, quote=True): diff --git a/numpy/core/bento.info b/numpy/core/bento.info index bf8ae3a81..9c8476eee 100644 --- a/numpy/core/bento.info +++ b/numpy/core/bento.info @@ -1,7 +1,7 @@ HookFile: bscript Library: - CompiledLibrary: npymath + CompiledLibrary: lib/npymath Sources: src/npymath/_signbit.c, src/npymath/ieee754.c.src, @@ -28,3 +28,6 @@ Library: Extension: scalarmath Sources: src/scalarmathmodule.c.src + Extension: _dotblas + Sources: + blasdot/_dotblas.c diff --git a/numpy/core/blasdot/_dotblas.c b/numpy/core/blasdot/_dotblas.c index a1a8da89f..c73dd6a47 100644 --- a/numpy/core/blasdot/_dotblas.c +++ b/numpy/core/blasdot/_dotblas.c @@ -1230,7 +1230,7 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit__dotblas(void) +PyMODINIT_FUNC PyInit__dotblas(void) #else #define RETVAL PyMODINIT_FUNC init_dotblas(void) diff --git a/numpy/core/bscript b/numpy/core/bscript index 1ded8eff3..f52c8c013 100644 --- a/numpy/core/bscript +++ b/numpy/core/bscript @@ -411,8 +411,7 @@ def pre_build(context): numpyconfig_h = context.local_node.declare(os.path.join("include", "numpy", "_numpyconfig.h")) context.register_outputs("numpy_gen_headers", "numpyconfig", [numpyconfig_h]) - context.tweak_library("npymath", - includes=["src/private", "src/npymath", "include"]) + context.tweak_library("lib/npymath", includes=["src/private", "src/npymath", "include"]) context.tweak_library("npysort", includes=[".", "src/private", "src/npysort"], @@ -507,5 +506,5 @@ def pre_build(context): def build_dotblas(extension): if bld.env.HAS_CBLAS: - return context.default_builder(extension, use="CBLAS") + return context.default_builder(extension, use="CBLAS", includes=["src/private"]) context.register_builder("_dotblas", build_dotblas) diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py index 8d7b83239..678303a2e 100644 --- a/numpy/core/code_generators/ufunc_docstrings.py +++ b/numpy/core/code_generators/ufunc_docstrings.py @@ -46,7 +46,7 @@ add_newdoc('numpy.core.umath', 'absolute', >>> import matplotlib.pyplot as plt - >>> x = np.linspace(-10, 10, 101) + >>> x = np.linspace(start=-10, stop=10, num=101) >>> plt.plot(x, np.absolute(x)) >>> plt.show() diff --git a/numpy/core/src/dummymodule.c b/numpy/core/src/dummymodule.c index 1d48709e9..e051cc6ff 100644 --- a/numpy/core/src/dummymodule.c +++ b/numpy/core/src/dummymodule.c @@ -1,4 +1,3 @@ - /* -*- c -*- */ /* @@ -32,7 +31,7 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if defined(NPY_PY3K) -PyObject *PyInit__dummy(void) { +PyMODINIT_FUNC PyInit__dummy(void) { PyObject *m; m = PyModule_Create(&moduledef); if (!m) { diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src index 0768ec0ca..9e46624bf 100644 --- a/numpy/core/src/multiarray/multiarray_tests.c.src +++ b/numpy/core/src/multiarray/multiarray_tests.c.src @@ -461,7 +461,7 @@ static struct PyModuleDef moduledef = { #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit_multiarray_tests(void) +PyMODINIT_FUNC PyInit_multiarray_tests(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 8bdcc2c20..29beb841c 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -459,7 +459,8 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays, PyTypeObject *subtype = &PyArray_Type; double priority = NPY_PRIORITY; int iarrays; - npy_intp shape[2], strides[2]; + npy_intp stride, sizes[NPY_MAXDIMS]; + npy_intp shape = 0; PyArray_Descr *dtype = NULL; PyArrayObject *ret = NULL; PyArrayObject_fields *sliding_view = NULL; @@ -470,19 +471,17 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays, return NULL; } - /* All the arrays must have the same total number of elements */ - shape[0] = narrays; - shape[1] = PyArray_SIZE(arrays[0]); - /* * Figure out the final concatenated shape starting from the first * array's shape. */ - for (iarrays = 1; iarrays < narrays; ++iarrays) { - if (PyArray_SIZE(arrays[iarrays]) != shape[1]) { + for (iarrays = 0; iarrays < narrays; ++iarrays) { + shape += sizes[iarrays] = PyArray_SIZE(arrays[iarrays]); + /* Check for overflow */ + if (shape < 0) { PyErr_SetString(PyExc_ValueError, - "all the input arrays must have same " - "number of elements"); + "total number of elements " + "too large to concatenate"); return NULL; } } @@ -504,15 +503,14 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays, return NULL; } - strides[1] = dtype->elsize; - strides[0] = strides[1] * shape[1]; + stride = dtype->elsize; /* Allocate the array for the result. This steals the 'dtype' reference. */ ret = (PyArrayObject *)PyArray_NewFromDescr(subtype, dtype, - 2, - shape, - strides, + 1, + &shape, + &stride, NULL, 0, NULL); @@ -530,9 +528,10 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays, Py_DECREF(ret); return NULL; } - /* Each array gets flattened into one slot along 'axis' */ - sliding_view->dimensions[0] = 1; + for (iarrays = 0; iarrays < narrays; ++iarrays) { + /* Adjust the window dimensions for this array */ + sliding_view->dimensions[0] = sizes[iarrays]; /* Copy the data for this array */ if (PyArray_CopyAsFlat((PyArrayObject *)sliding_view, arrays[iarrays], @@ -543,7 +542,7 @@ PyArray_ConcatenateFlattenedArrays(int narrays, PyArrayObject **arrays, } /* Slide to the start of the next window */ - sliding_view->data += sliding_view->strides[0]; + sliding_view->data += sliding_view->strides[0] * sizes[iarrays]; } Py_DECREF(sliding_view); @@ -3888,7 +3887,7 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit_multiarray(void) { +PyMODINIT_FUNC PyInit_multiarray(void) { #else #define RETVAL PyMODINIT_FUNC initmultiarray(void) { diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index 4b56c1510..3241f97b8 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -1998,7 +1998,7 @@ static struct PyModuleDef moduledef = { #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit_scalarmath(void) +PyMODINIT_FUNC PyInit_scalarmath(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/core/src/umath/umath_tests.c.src b/numpy/core/src/umath/umath_tests.c.src index 0ba13f15f..46d06288d 100644 --- a/numpy/core/src/umath/umath_tests.c.src +++ b/numpy/core/src/umath/umath_tests.c.src @@ -301,7 +301,7 @@ static struct PyModuleDef moduledef = { #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit_umath_tests(void) +PyMODINIT_FUNC PyInit_umath_tests(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c index 3cd193b23..97f6f042c 100644 --- a/numpy/core/src/umath/umathmodule.c +++ b/numpy/core/src/umath/umathmodule.c @@ -323,7 +323,7 @@ static struct PyModuleDef moduledef = { #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit_umath(void) +PyMODINIT_FUNC PyInit_umath(void) #else #define RETVAL PyMODINIT_FUNC initumath(void) diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index 17a9cbbde..2017ca7a3 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -1,6 +1,9 @@ -from numpy.testing import * -from numpy.core import array, atleast_1d, atleast_2d, atleast_3d, vstack, \ - hstack, newaxis +import warnings +import numpy as np +from numpy.testing import (TestCase, assert_, assert_raises, assert_equal, + assert_array_equal, run_module_suite) +from numpy.core import (array, arange, atleast_1d, atleast_2d, atleast_3d, + vstack, hstack, newaxis, concatenate) class TestAtleast1d(TestCase): def test_0D_array(self): @@ -141,5 +144,20 @@ class TestVstack(TestCase): desired = array([[1,2],[1,2]]) assert_array_equal(res,desired) +def test_concatenate_axis_None(): + a = np.arange(4, dtype=np.float64).reshape((2,2)) + b = range(3) + c = ['x'] + r = np.concatenate((a, a), axis=None) + assert_equal(r.dtype, a.dtype) + assert_equal(r.ndim, 1) + r = np.concatenate((a, b), axis=None) + assert_equal(r.size, a.size + len(b)) + assert_equal(r.dtype, a.dtype) + r = np.concatenate((a, b, c), axis=None) + d = array(['0', '1', '2', '3', + '0', '1', '2', 'x']) + assert_array_equal(r,d) + if __name__ == "__main__": run_module_suite() diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py index 49df885b6..bb832991f 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -251,7 +251,7 @@ class Gnu95FCompiler(GnuFCompiler): executables = { 'version_cmd' : ["<F90>", "--version"], 'compiler_f77' : [None, "-Wall", "-ffixed-form", - "-fno-second-underscore"] + _EXTRAFLAGS, + "-fno-second-underscore"] + _EXTRAFLAGS, 'compiler_f90' : [None, "-Wall", "-fno-second-underscore"] + _EXTRAFLAGS, 'compiler_fix' : [None, "-Wall", "-ffixed-form", "-fno-second-underscore"] + _EXTRAFLAGS, diff --git a/numpy/distutils/fcompiler/intel.py b/numpy/distutils/fcompiler/intel.py index 18ecc01e5..281bbe0cb 100644 --- a/numpy/distutils/fcompiler/intel.py +++ b/numpy/distutils/fcompiler/intel.py @@ -43,61 +43,18 @@ class IntelFCompiler(BaseIntelFCompiler): module_dir_switch = '-module ' # Don't remove ending space! module_include_switch = '-I' - def get_flags(self): - v = self.get_version() - if v >= '10.0': - # Use -fPIC instead of -KPIC. - pic_flags = ['-fPIC'] - else: - pic_flags = ['-KPIC'] - opt = pic_flags + ["-cm"] - return opt - def get_flags_free(self): return ["-FR"] + def get_flags(self): + return ['-fPIC'] + def get_flags_opt(self): - return ['-O1'] + #return ['-i8 -xhost -openmp -fp-model strict'] + return ['-xhost -openmp -fp-model strict'] def get_flags_arch(self): - v = self.get_version() - opt = [] - if cpu.has_fdiv_bug(): - opt.append('-fdiv_check') - if cpu.has_f00f_bug(): - opt.append('-0f_check') - if cpu.is_PentiumPro() or cpu.is_PentiumII() or cpu.is_PentiumIII(): - opt.extend(['-tpp6']) - elif cpu.is_PentiumM(): - opt.extend(['-tpp7','-xB']) - elif cpu.is_Pentium(): - opt.append('-tpp5') - elif cpu.is_PentiumIV() or cpu.is_Xeon(): - opt.extend(['-tpp7','-xW']) - if v and v <= '7.1': - if cpu.has_mmx() and (cpu.is_PentiumII() or cpu.is_PentiumIII()): - opt.append('-xM') - elif v and v >= '8.0': - if cpu.is_PentiumIII(): - opt.append('-xK') - if cpu.has_sse3(): - opt.extend(['-xP']) - elif cpu.is_PentiumIV(): - opt.append('-xW') - if cpu.has_sse2(): - opt.append('-xN') - elif cpu.is_PentiumM(): - opt.extend(['-xB']) - if (cpu.is_Xeon() or cpu.is_Core2() or cpu.is_Core2Extreme()) and cpu.getNCPUs()==2: - opt.extend(['-xT']) - if cpu.has_sse3() and (cpu.is_PentiumIV() or cpu.is_CoreDuo() or cpu.is_CoreSolo()): - opt.extend(['-xP']) - - if cpu.has_sse2(): - opt.append('-arch SSE2') - elif cpu.has_sse(): - opt.append('-arch SSE') - return opt + return [] def get_flags_linker_so(self): opt = FCompiler.get_flags_linker_so(self) @@ -111,7 +68,7 @@ class IntelFCompiler(BaseIntelFCompiler): opt.remove('-shared') except ValueError: idx = 0 - opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup'] + opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup', '-Wl,-framework,Python'] return opt class IntelItaniumFCompiler(IntelFCompiler): @@ -144,7 +101,7 @@ class IntelEM64TFCompiler(IntelFCompiler): executables = { 'version_cmd' : None, - 'compiler_f77' : [None, "-FI", "-w90", "-w95"], + 'compiler_f77' : [None, "-FI"], 'compiler_fix' : [None, "-FI"], 'compiler_f90' : [None], 'linker_so' : ['<F90>', "-shared"], @@ -152,11 +109,15 @@ class IntelEM64TFCompiler(IntelFCompiler): 'ranlib' : ["ranlib"] } + def get_flags(self): + return ['-fPIC'] + + def get_flags_opt(self): + #return ['-i8 -xhost -openmp -fp-model strict'] + return ['-xhost -openmp -fp-model strict'] + def get_flags_arch(self): - opt = [] - if cpu.is_PentiumIV() or cpu.is_Xeon(): - opt.extend(['-tpp7', '-xW']) - return opt + return [] # Is there no difference in the version string between the above compilers # and the Visual compilers? diff --git a/numpy/distutils/fcompiler/pathf95.py b/numpy/distutils/fcompiler/pathf95.py index c92653ba7..29881f4cf 100644 --- a/numpy/distutils/fcompiler/pathf95.py +++ b/numpy/distutils/fcompiler/pathf95.py @@ -4,33 +4,33 @@ compilers = ['PathScaleFCompiler'] class PathScaleFCompiler(FCompiler): - compiler_type = 'pathf95' - description = 'PathScale Fortran Compiler' - version_pattern = r'PathScale\(TM\) Compiler Suite: Version (?P<version>[\d.]+)' + compiler_type = 'pathf95' + description = 'PathScale Fortran Compiler' + version_pattern = r'PathScale\(TM\) Compiler Suite: Version (?P<version>[\d.]+)' - executables = { - 'version_cmd' : ["pathf95", "-version"], - 'compiler_f77' : ["pathf95", "-fixedform"], - 'compiler_fix' : ["pathf95", "-fixedform"], - 'compiler_f90' : ["pathf95"], - 'linker_so' : ["pathf95", "-shared"], - 'archiver' : ["ar", "-cr"], - 'ranlib' : ["ranlib"] - } - pic_flags = ['-fPIC'] - module_dir_switch = '-module ' # Don't remove ending space! - module_include_switch = '-I' + executables = { + 'version_cmd' : ["pathf95", "-version"], + 'compiler_f77' : ["pathf95", "-fixedform"], + 'compiler_fix' : ["pathf95", "-fixedform"], + 'compiler_f90' : ["pathf95"], + 'linker_so' : ["pathf95", "-shared"], + 'archiver' : ["ar", "-cr"], + 'ranlib' : ["ranlib"] + } + pic_flags = ['-fPIC'] + module_dir_switch = '-module ' # Don't remove ending space! + module_include_switch = '-I' - def get_flags_opt(self): - return ['-O3'] - def get_flags_debug(self): - return ['-g'] + def get_flags_opt(self): + return ['-O3'] + def get_flags_debug(self): + return ['-g'] if __name__ == '__main__': - from distutils import log - log.set_verbosity(2) - #compiler = PathScaleFCompiler() - from numpy.distutils.fcompiler import new_fcompiler - compiler = new_fcompiler(compiler='pathf95') - compiler.customize() - print compiler.get_version() + from distutils import log + log.set_verbosity(2) + #compiler = PathScaleFCompiler() + from numpy.distutils.fcompiler import new_fcompiler + compiler = new_fcompiler(compiler='pathf95') + compiler.customize() + print compiler.get_version() diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index 4956e5740..72ee4f7a4 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -260,7 +260,7 @@ cppmacros['len..']="""\ """ needs['f2py_size']=['stdarg.h'] cfuncs['f2py_size']="""\ -int f2py_size(PyArrayObject* var, ...) +static int f2py_size(PyArrayObject* var, ...) { npy_int sz = 0; npy_int dim; diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py index 83f5811e5..9d943e884 100644 --- a/numpy/f2py/rules.py +++ b/numpy/f2py/rules.py @@ -186,7 +186,7 @@ static struct PyModuleDef moduledef = { #if PY_VERSION_HEX >= 0x03000000 #define RETVAL m -PyObject *PyInit_#modulename#(void) { +PyMODINIT_FUNC PyInit_#modulename#(void) { #else #define RETVAL PyMODINIT_FUNC init#modulename#(void) { diff --git a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c index e75a667eb..9a21f2420 100644 --- a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +++ b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c @@ -132,7 +132,7 @@ static struct PyModuleDef moduledef = { #if PY_VERSION_HEX >= 0x03000000 #define RETVAL m -PyObject *PyInit_test_array_from_pyobj_ext(void) { +PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) { #else #define RETVAL PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) { diff --git a/numpy/fft/fftpack_litemodule.c b/numpy/fft/fftpack_litemodule.c index 7652ac0e2..499c72828 100644 --- a/numpy/fft/fftpack_litemodule.c +++ b/numpy/fft/fftpack_litemodule.c @@ -326,7 +326,7 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if PY_MAJOR_VERSION >= 3 #define RETVAL m -PyObject *PyInit_fftpack_lite(void) +PyMODINIT_FUNC PyInit_fftpack_lite(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 247f16560..e32492958 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -660,7 +660,7 @@ def piecewise(x, condlist, funclist, *args, **kw): -------- Define the sigma function, which is -1 for ``x < 0`` and +1 for ``x >= 0``. - >>> x = np.arange(6) - 2.5 + >>> x = np.linspace(-2.5, 2.5, 6) >>> np.piecewise(x, [x < 0, x >= 0], [-1, 1]) array([-1., -1., -1., 1., 1., 1.]) @@ -2827,7 +2827,7 @@ def sinc(x): Examples -------- - >>> x = np.arange(-20., 21.)/5. + >>> x = np.linspace(-4, 4, 41) >>> np.sinc(x) array([ -3.89804309e-17, -4.92362781e-02, -8.40918587e-02, -8.90384387e-02, -5.84680802e-02, 3.89804309e-17, @@ -2856,7 +2856,7 @@ def sinc(x): It works in 2-D as well: - >>> x = np.arange(-200., 201.)/50. + >>> x = np.linspace(-4, 4, 401) >>> xx = np.outer(x, x) >>> plt.imshow(np.sinc(xx)) <matplotlib.image.AxesImage object at 0x...> @@ -3591,19 +3591,21 @@ def insert(arr, obj, values, axis=None): slobj = [slice(None)]*ndim N = arr.shape[axis] newshape = list(arr.shape) - if isinstance(obj, (int, long, integer)): + if isinstance(obj, (int, long, integer)): if (obj < 0): obj += N if obj < 0 or obj > N: raise ValueError( "index (%d) out of range (0<=index<=%d) "\ "in dimension %d" % (obj, N, axis)) - - if isinstance(values, (int, long, integer)): - obj = [obj] + if isscalar(values): + obj = [obj] else: - obj = [obj] * len(values) - + values = asarray(values) + if ndim > values.ndim: + obj = [obj] + else: + obj = [obj] * len(values) elif isinstance(obj, slice): # turn it into a range object diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index d389b7f8e..41caca962 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -1708,7 +1708,7 @@ static struct PyModuleDef moduledef = { #if defined(NPY_PY3K) #define RETVAL m -PyObject *PyInit__compiled_base(void) +PyMODINIT_FUNC PyInit__compiled_base(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 7c1b01345..da3eb2b84 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -147,6 +147,15 @@ class TestInsert(TestCase): assert_equal(insert(a, [1, 1, 1], [1, 2, 3]), [1, 1, 2, 3, 2, 3]) assert_equal(insert(a, 1,[1,2,3]), [1, 1, 2, 3, 2, 3]) assert_equal(insert(a,[1,2,3],9),[1,9,2,9,3,9]) + b = np.array([0, 1], dtype=np.float64) + assert_equal(insert(b, 0, b[0]), [0., 0., 1.]) + def test_multidim(self): + a = [[1, 1, 1]] + r = [[2, 2, 2], + [1, 1, 1]] + assert_equal(insert(a, 0, [2, 2, 2], axis=0), r) + assert_equal(insert(a, 0, 2, axis=0), r) + assert_equal(insert(a, 2, 2, axis=1), [[1, 1, 2, 1]]) class TestAmax(TestCase): def test_basic(self): diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c index cc6238239..3e1790a18 100644 --- a/numpy/linalg/lapack_litemodule.c +++ b/numpy/linalg/lapack_litemodule.c @@ -848,7 +848,7 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if PY_MAJOR_VERSION >= 3 #define RETVAL m -PyObject *PyInit_lapack_lite(void) +PyMODINIT_FUNC PyInit_lapack_lite(void) #else #define RETVAL PyMODINIT_FUNC diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c index 78187c50e..032379515 100644 --- a/numpy/numarray/_capi.c +++ b/numpy/numarray/_capi.c @@ -3394,7 +3394,7 @@ static struct PyModuleDef moduledef = { NULL }; -PyObject *PyInit__capi(void) +PyMODINIT_FUNC PyInit__capi(void) #else #define RETVAL diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 7d9163e61..ee40cce69 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -360,7 +360,13 @@ class TestRandomDist(TestCase): desired = np.array([[ 2.46852460439034849e+03, 1.41286880810518346e+03], [ 5.28287797029485181e+07, 6.57720981047328785e+07], [ 1.40840323350391515e+02, 1.98390255135251704e+05]]) - np.testing.assert_array_almost_equal(actual, desired, decimal=15) + # For some reason on 32-bit x86 Ubuntu 12.10 the [1, 0] entry in this + # matrix differs by 24 nulps. Discussion: + # http://mail.scipy.org/pipermail/numpy-discussion/2012-September/063801.html + # Consensus is that this is probably some gcc quirk that affects + # rounding but not in any important way, so we just use a looser + # tolerance on this test: + np.testing.assert_array_almost_equal_nulp(actual, desired, nulp=30) def test_poisson(self): np.random.seed(self.seed) |