diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 33 | ||||
-rw-r--r-- | numpy/core/tests/test_shape_base.py | 24 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/intel.py | 71 |
3 files changed, 53 insertions, 75 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 8bdcc2c20..07b7df726 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/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? |