Skip to content

[WIP] backport from master to the 1.7.x release branch #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Sep 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a1561c2
[FIX] Add missing header so separate compilation works again
njsmith Jul 18, 2012
d72280f
Fix tests for empty shape, strides and suboffsets on Python 3.3
cgohlke Jul 29, 2012
470486b
Copy bytes object when unpickling an array
rlamy Jul 31, 2012
a022015
Re-enable unpickling optimization for large py3k bytes objects.
rlamy Aug 3, 2012
d67785b
FIX: Fixes the PyUnicodeObject problem in py-3.3
certik Jul 27, 2012
8141e1e
FIX: Make sure the tests produce valid unicode
certik Aug 3, 2012
d5d6894
Fix memory leak in concatenate.
Jul 30, 2012
31660d0
Follow the C guidelines
certik Aug 3, 2012
99c9397
Use PyUnicode_DecodeUTF32()
certik Aug 3, 2012
77da3f8
Allow long numbers in numpy.rec.array formats string
cgohlke Aug 6, 2012
24da7f6
Add test for long numbers in numpy.rec.array formats string
cgohlke Aug 7, 2012
5cb80f8
Add test for long number in shape specifier of dtype string
cgohlke Aug 8, 2012
fbad4a7
Remove test_recarray_from_long_formats
cgohlke Aug 8, 2012
3930881
BUG: fix bento build.
cournape Aug 10, 2012
416af9a
pavement.py: rename "yop" to "atlas"
certik Aug 14, 2012
7583adc
MAINT: silence DeprecationWarning in np.safe_eval().
Aug 22, 2012
996a9fb
FIX: bug in np.where and recarray swapping
certik Aug 30, 2012
124a608
Fix returned copy
jayvius Aug 31, 2012
f65ff87
FIX: simplify the import statement
certik Aug 31, 2012
7b5dba0
BUG: Fix ticket #1588/gh issue #398, refcount error in clip
mwiebe Aug 31, 2012
1ee4a00
BUG: Add a test for Ticket #1588
certik Aug 31, 2012
ca29849
BUG: Add a test for Ticket #2189
certik Aug 31, 2012
2f28db6
FIX: Add a test for Ticket #2066
certik Aug 31, 2012
5a471b5
Improve ndindex execution speed.
stefanv Aug 27, 2012
3dc3b1b
Retain backward compatibility. Enforce C order.
stefanv Sep 2, 2012
6e3e289
FIX: Regenerate mtrand.c with Cython 0.17
certik Sep 2, 2012
cb0de72
REF: remove unused imports in bscript.
cournape Aug 26, 2012
095a3ab
BUG: forgot to build _dotblas in bento build.
cournape Aug 26, 2012
6da087e
BUG: fix custom post_check.
cournape Aug 27, 2012
07e02d0
BUG: fix npymath install location.
cournape Sep 3, 2012
8460514
BUG: Fix for issues #378 and #392
87 Sep 6, 2012
9ee9984
TST: Add extra test for multidimensional inserts.
87 Sep 6, 2012
65ec87e
TST: Add test for boolean insert
87 Sep 7, 2012
d01354e
FIX: loosen numerical tolerance in test_pareto()
njsmith Sep 7, 2012
fcacdcc
FIX: use py24-compatible version of virtualenv on Travis
njsmith Sep 7, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis-make-py24-virtualenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions bscript
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions numpy/build_utils/waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -453,7 +453,7 @@ def define_or_stuff():
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):
Expand Down
9 changes: 6 additions & 3 deletions numpy/core/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _reconstruct(subtype, shape, dtype):

format_re = re.compile(asbytes(
r'(?P<order1>[<>|=]?)'
r'(?P<repeats> *[(]?[ ,0-9]*[)]? *)'
r'(?P<repeats> *[(]?[ ,0-9L]*[)]? *)'
r'(?P<order2>[<>|=]?)'
r'(?P<dtype>[A-Za-z0-9.]*(?:\[[a-zA-Z0-9,.]+\])?)'))
sep_re = re.compile(asbytes(r'\s*,\s*'))
Expand Down Expand Up @@ -285,7 +285,7 @@ def _newnames(datatype, order):
# Given an array with fields and a sequence of field names
# construct a new array with just those fields copied over
def _index_fields(ary, fields):
from multiarray import empty, dtype
from multiarray import empty, dtype, array
dt = ary.dtype

names = [name for name in fields if name in dt.names]
Expand All @@ -295,7 +295,10 @@ def _index_fields(ary, fields):
view_dtype = {'names':names, 'formats':formats, 'offsets':offsets, 'itemsize':dt.itemsize}
view = ary.view(dtype=view_dtype)

return view.copy()
# Return a copy for now until behavior is fully deprecated
# in favor of returning view
copy_dtype = {'names':view_dtype['names'], 'formats':view_dtype['formats']}
return array(view, dtype=copy_dtype, copy=True)

# Given a string containing a PEP 3118 format specifier,
# construct a Numpy dtype
Expand Down
5 changes: 4 additions & 1 deletion numpy/core/bento.info
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HookFile: bscript

Library:
CompiledLibrary: npymath
CompiledLibrary: lib/npymath
Sources:
src/npymath/_signbit.c,
src/npymath/ieee754.c.src,
Expand All @@ -28,3 +28,6 @@ Library:
Extension: scalarmath
Sources:
src/scalarmathmodule.c.src
Extension: _dotblas
Sources:
blasdot/_dotblas.c
7 changes: 3 additions & 4 deletions numpy/core/bscript
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -501,11 +500,11 @@ def pre_build(context):
use="npymath")
context.register_builder("umath", build_ufunc)

context.tweak_extension("scalarmath", use="npymath")
context.tweak_extension("scalarmath", use="npymath", includes=["src/private"])
context.tweak_extension("multiarray_tests", use="npymath", includes=["src/private"])
context.tweak_extension("umath_tests", use="npymath", includes=["src/private"])

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)
26 changes: 17 additions & 9 deletions numpy/core/src/multiarray/calculation.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
PyArrayObject *maxa = NULL;
PyArrayObject *mina = NULL;
PyArrayObject *newout = NULL, *newin = NULL;
PyArray_Descr *indescr, *newdescr;
PyArray_Descr *indescr = NULL, *newdescr = NULL;
char *max_data, *min_data;
PyObject *zero;

Expand All @@ -922,23 +922,24 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
/* Use the fast scalar clip function */

/* First we need to figure out the correct type */
indescr = NULL;
if (min != NULL) {
indescr = PyArray_DescrFromObject(min, NULL);
if (indescr == NULL) {
return NULL;
goto fail;
}
}
if (max != NULL) {
newdescr = PyArray_DescrFromObject(max, indescr);
Py_XDECREF(indescr);
indescr = NULL;
if (newdescr == NULL) {
return NULL;
goto fail;
}
}
else {
/* Steal the reference */
newdescr = indescr;
indescr = NULL;
}


Expand All @@ -950,8 +951,12 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
if (PyArray_ScalarKind(newdescr->type_num, NULL) >
PyArray_ScalarKind(PyArray_DESCR(self)->type_num, NULL)) {
indescr = PyArray_PromoteTypes(newdescr, PyArray_DESCR(self));
if (indescr == NULL) {
goto fail;
}
func = indescr->f->fastclip;
if (func == NULL) {
Py_DECREF(indescr);
return _slow_array_clip(self, min, max, out);
}
}
Expand All @@ -960,11 +965,13 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
Py_INCREF(indescr);
}
Py_DECREF(newdescr);
newdescr = NULL;

if (!PyDataType_ISNOTSWAPPED(indescr)) {
PyArray_Descr *descr2;
descr2 = PyArray_DescrNewByteorder(indescr, '=');
Py_DECREF(indescr);
indescr = NULL;
if (descr2 == NULL) {
goto fail;
}
Expand All @@ -973,16 +980,13 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o

/* Convert max to an array */
if (max != NULL) {
Py_INCREF(indescr);
maxa = (PyArrayObject *)PyArray_FromAny(max, indescr, 0, 0,
NPY_ARRAY_DEFAULT, NULL);
if (maxa == NULL) {
return NULL;
goto fail;
}
}
else {
/* Side-effect of PyArray_FromAny */
Py_DECREF(indescr);
}

/*
* If we are unsigned, then make sure min is not < 0
Expand Down Expand Up @@ -1147,6 +1151,8 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
func(PyArray_DATA(newin), PyArray_SIZE(newin), min_data, max_data, PyArray_DATA(newout));

/* Clean up temporary variables */
Py_XDECREF(indescr);
Py_XDECREF(newdescr);
Py_XDECREF(mina);
Py_XDECREF(maxa);
Py_DECREF(newin);
Expand All @@ -1155,6 +1161,8 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
return (PyObject *)out;

fail:
Py_XDECREF(indescr);
Py_XDECREF(newdescr);
Py_XDECREF(maxa);
Py_XDECREF(mina);
Py_XDECREF(newin);
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "arrayobject.h"

#include "npy_config.h"

Expand Down
5 changes: 3 additions & 2 deletions numpy/core/src/multiarray/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,8 +1587,9 @@ array_setstate(PyArrayObject *self, PyObject *args)
/* Check that the string is not interned */
if (!_IsAligned(self) || swap || PyString_CHECK_INTERNED(rawdata)) {
#else
/* Bytes are never interned */
if (!_IsAligned(self) || swap) {
/* Bytes should always be considered immutable, but we just grab the
* pointer if they are large, to save memory. */
if (!_IsAligned(self) || swap || (len <= 1000)) {
#endif
npy_intp num = PyArray_NBYTES(self);
fa->data = PyDataMem_NEW(num);
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ PyArray_Concatenate(PyObject *op, int axis)
for (iarrays = 0; iarrays < narrays; ++iarrays) {
Py_DECREF(arrays[iarrays]);
}
PyArray_free(arrays);

return (PyObject *)ret;

Expand All @@ -610,6 +611,7 @@ PyArray_Concatenate(PyObject *op, int axis)
for (iarrays = 0; iarrays < narrays; ++iarrays) {
Py_DECREF(arrays[iarrays]);
}
PyArray_free(arrays);

return NULL;
}
Expand Down
33 changes: 32 additions & 1 deletion numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)
if (outcode == NULL) {
return (PyObject *)r;
}
if (outcode->type_num == typecode->type_num) {
if (PyArray_EquivTypes(outcode, typecode)) {
if (!PyTypeNum_ISEXTENDED(typecode->type_num)
|| (outcode->elsize == typecode->elsize)) {
Py_DECREF(outcode);
Expand Down Expand Up @@ -641,6 +641,35 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
itemsize = (((itemsize - 1) >> 2) + 1) << 2;
}
}
#if PY_VERSION_HEX >= 0x03030000
if (type_num == NPY_UNICODE) {
PyObject *u, *args;
int byteorder;

#if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
byteorder = -1;
#elif NPY_BYTE_ORDER == NPY_BIG_ENDIAN
byteorder = +1;
#else
#error Endianness undefined ?
#endif
if (swap) byteorder *= -1;

u = PyUnicode_DecodeUTF32(data, itemsize, NULL, &byteorder);
if (u == NULL) {
return NULL;
}
args = Py_BuildValue("(O)", u);
if (args == NULL) {
Py_DECREF(u);
return NULL;
}
obj = type->tp_new(type, args, NULL);
Py_DECREF(u);
Py_DECREF(args);
return obj;
}
#endif
if (type->tp_itemsize != 0) {
/* String type */
obj = type->tp_alloc(type, itemsize);
Expand Down Expand Up @@ -672,6 +701,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
memcpy(destptr, data, itemsize);
return obj;
}
#if PY_VERSION_HEX < 0x03030000
else if (type_num == NPY_UNICODE) {
/* tp_alloc inherited from Python PyBaseObject_Type */
PyUnicodeObject *uni = (PyUnicodeObject*)obj;
Expand Down Expand Up @@ -743,6 +773,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
#endif
return obj;
}
#endif /* PY_VERSION_HEX < 0x03030000 */
else {
PyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;
vobj->base = NULL;
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,11 @@ finish:
*((npy_@name@ *)dest) = *((npy_@name@ *)src);
#elif @default@ == 1 /* unicode and strings */
if (itemsize == 0) { /* unicode */
#if PY_VERSION_HEX >= 0x03030000
itemsize = PyUnicode_GetLength(robj) * PyUnicode_KIND(robj);
#else
itemsize = ((PyUnicodeObject *)robj)->length * sizeof(Py_UNICODE);
#endif
}
memcpy(dest, src, itemsize);
/* @default@ == 2 won't get here */
Expand Down
5 changes: 5 additions & 0 deletions numpy/core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ def test_complex_dtype_repr(self):
assert_equal(repr(dt),
"dtype([('a', '<M8[D]'), ('b', '<m8[us]')])")

@dec.skipif(sys.version_info[0] > 2)
def test_dtype_str_with_long_in_shape(self):
# Pull request #376
dt = np.dtype('(1L,)i4')


class TestDtypeAttributeDeletion(object):

Expand Down
Loading