summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.py6
-rw-r--r--numpy/add_newdocs.py8
-rw-r--r--numpy/build_utils/waf.py18
-rw-r--r--numpy/core/bento.info5
-rw-r--r--numpy/core/bscript5
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py2
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c33
-rw-r--r--numpy/core/tests/test_shape_base.py24
-rw-r--r--numpy/distutils/fcompiler/gnu.py2
-rw-r--r--numpy/distutils/fcompiler/intel.py71
-rw-r--r--numpy/distutils/fcompiler/pathf95.py52
-rw-r--r--numpy/lib/function_base.py20
-rw-r--r--numpy/lib/tests/test_function_base.py9
-rw-r--r--numpy/random/tests/test_random.py8
14 files changed, 137 insertions, 126 deletions
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/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/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index e45b1d89e..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);
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/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/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/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)