Skip to content

Commit bf5ef2e

Browse files
committed
Merge pull request #2 from rudi-c/numpy
NumPy integration test
2 parents e1d16ce + 3387c95 commit bf5ef2e

File tree

3 files changed

+398
-5
lines changed

3 files changed

+398
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
[submodule "lib/virtualenv"]
1919
path = lib/virtualenv
2020
url = https://github.com/dropbox/virtualenv
21+
[submodule "lib/numpy"]
22+
path = lib/numpy
23+
url = https://github.com/numpy/numpy.git

integration/numpy_patch.patch

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
diff --git a/numpy/__init__.py b/numpy/__init__.py
2+
index d4ef54d..7a49dbd 100644
3+
--- a/numpy/__init__.py
4+
+++ b/numpy/__init__.py
5+
@@ -196,7 +196,7 @@ else:
6+
from . import linalg
7+
from . import fft
8+
from . import polynomial
9+
- from . import random
10+
+ # from . import random
11+
from . import ctypeslib
12+
from . import ma
13+
from . import matrixlib as _mat
14+
@@ -218,7 +218,8 @@ else:
15+
__all__.extend(core.__all__)
16+
__all__.extend(_mat.__all__)
17+
__all__.extend(lib.__all__)
18+
- __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
19+
+ __all__.extend(['linalg', 'fft', 'ctypeslib', 'ma'])
20+
+ # __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
21+
22+
# Filter annoying Cython warnings that serve no good purpose.
23+
import warnings
24+
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
25+
index a28b5a8..28b948b 100644
26+
--- a/numpy/core/arrayprint.py
27+
+++ b/numpy/core/arrayprint.py
28+
@@ -609,7 +609,8 @@ class FloatFormat(object):
29+
else:
30+
return self.special_fmt % ('-' + _inf_str,)
31+
32+
- s = self.format % x
33+
+ # s = self.format % x
34+
+ s = "%#+3.0f" % x
35+
if self.large_exponent:
36+
# 3-digit exponent
37+
expsign = s[-3]
38+
diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h
39+
index fbaaeac..cb4adbb 100644
40+
--- a/numpy/core/include/numpy/ndarrayobject.h
41+
+++ b/numpy/core/include/numpy/ndarrayobject.h
42+
@@ -117,7 +117,8 @@ extern "C" CONFUSE_EMACS
43+
#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), val, \
44+
PyArray_NBYTES(obj))
45+
46+
-#define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
47+
+//#define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
48+
+#define PyArray_REFCOUNT(obj) 0
49+
#define NPY_REFCOUNT PyArray_REFCOUNT
50+
#define NPY_MAX_ELSIZE (2 * NPY_SIZEOF_LONGDOUBLE)
51+
52+
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
53+
index 8403ee2..0bc2d4d 100644
54+
--- a/numpy/core/include/numpy/ndarraytypes.h
55+
+++ b/numpy/core/include/numpy/ndarraytypes.h
56+
@@ -931,11 +931,18 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
57+
#if NPY_ALLOW_THREADS
58+
#define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
59+
#define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
60+
+#define NPY_BEGIN_THREADS do {_save = NULL;} while (0);
61+
+/*
62+
#define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
63+
+*/
64+
#define NPY_END_THREADS do { if (_save) \
65+
{ PyEval_RestoreThread(_save); _save = NULL;} } while (0);
66+
#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if (loop_size > 500) \
67+
+ { _save = NULL;} } while (0);
68+
+/*
69+
+#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if (loop_size > 500) \
70+
{ _save = PyEval_SaveThread();} } while (0);
71+
+*/
72+
73+
#define NPY_BEGIN_THREADS_DESCR(dtype) \
74+
do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \
75+
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
76+
index 5a1e2f4..6f1cd62 100644
77+
--- a/numpy/core/src/multiarray/arraytypes.c.src
78+
+++ b/numpy/core/src/multiarray/arraytypes.c.src
79+
@@ -4469,6 +4469,11 @@ set_typeinfo(PyObject *dict)
80+
PyArray_Descr *dtype;
81+
PyObject *cobj, *key;
82+
83+
+ /* Pyston change: deal with static nonheap objects */
84+
+ for (i = 0; i < 24; i++) {
85+
+ PyGC_AddNonHeapRoot((PyObject*)_builtin_descrs[i], sizeof(PyArray_Descr));
86+
+ }
87+
+
88+
/*
89+
* Add cast functions for the new types
90+
*/
91+
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
92+
index 8ffeeda..5d43aab 100644
93+
--- a/numpy/core/src/multiarray/compiled_base.c
94+
+++ b/numpy/core/src/multiarray/compiled_base.c
95+
@@ -1336,13 +1336,13 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
96+
_ADDDOC(Type, new->tp_doc, new->tp_name);
97+
}
98+
else if (_TESTDOC2(MemberDescr)) {
99+
- _ADDDOC(MemberDescr, new->d_member->doc, new->d_member->name);
100+
+ //_ADDDOC(MemberDescr, new->d_member->doc, new->d_member->name);
101+
}
102+
else if (_TESTDOC2(GetSetDescr)) {
103+
- _ADDDOC(GetSetDescr, new->d_getset->doc, new->d_getset->name);
104+
+ //_ADDDOC(GetSetDescr, new->d_getset->doc, new->d_getset->name);
105+
}
106+
else if (_TESTDOC2(MethodDescr)) {
107+
- _ADDDOC(MethodDescr, new->d_method->ml_doc, new->d_method->ml_name);
108+
+ //_ADDDOC(MethodDescr, new->d_method->ml_doc, new->d_method->ml_name);
109+
}
110+
else {
111+
PyObject *doc_attr;
112+
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
113+
index 6155551..d488816 100644
114+
--- a/numpy/core/src/multiarray/multiarraymodule.c
115+
+++ b/numpy/core/src/multiarray/multiarraymodule.c
116+
@@ -4206,6 +4206,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
117+
initialize_casting_tables();
118+
initialize_numeric_types();
119+
120+
+ /* Pyston assumes PyType_Ready doesn't get called on Pyston classes
121+
if (PyType_Ready(&PyBool_Type) < 0) {
122+
return -1;
123+
}
124+
@@ -4226,6 +4227,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
125+
if (PyType_Ready(&PyUnicode_Type) < 0) {
126+
return -1;
127+
}
128+
+ */
129+
130+
#define SINGLE_INHERIT(child, parent) \
131+
Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type; \
132+
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
133+
index 71a82d7..a88edea 100644
134+
--- a/numpy/core/src/multiarray/scalarapi.c
135+
+++ b/numpy/core/src/multiarray/scalarapi.c
136+
@@ -712,10 +712,12 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
137+
if (PyTypeNum_ISFLEXIBLE(type_num)) {
138+
if (type_num == NPY_STRING) {
139+
destptr = PyString_AS_STRING(obj);
140+
+/*
141+
((PyStringObject *)obj)->ob_shash = -1;
142+
#if !defined(NPY_PY3K)
143+
((PyStringObject *)obj)->ob_sstate = SSTATE_NOT_INTERNED;
144+
#endif
145+
+*/
146+
memcpy(destptr, data, itemsize);
147+
return obj;
148+
}
149+
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
150+
index b5e0fde..8fa4dc2 100644
151+
--- a/numpy/core/src/multiarray/scalartypes.c.src
152+
+++ b/numpy/core/src/multiarray/scalartypes.c.src
153+
@@ -1673,7 +1673,7 @@ voidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)
154+
* However, as a special case, void-scalar assignment broadcasts
155+
* differently from ndarrays when assigning to an object field: Assignment
156+
* to an ndarray object field broadcasts, but assignment to a void-scalar
157+
- * object-field should not, in order to allow nested ndarrays.
158+
+ * object-field should not, in order to allow nested ndarrays.
159+
* These lines should then behave identically:
160+
*
161+
* b = np.zeros(1, dtype=[('x', 'O')])
162+
@@ -3479,7 +3479,8 @@ NPY_NO_EXPORT PyTypeObject Py@NAME@ArrType_Type = {
163+
0, /* ob_size */
164+
#endif
165+
"numpy." NAME_@name@ "@ex@", /* tp_name*/
166+
- sizeof(Py@NAME@ScalarObject), /* tp_basicsize*/
167+
+ sizeof(PyObject), /* tp_basicsize*/
168+
+ // sizeof(Py@NAME@ScalarObject), /* tp_basicsize*/
169+
0, /* tp_itemsize */
170+
0, /* tp_dealloc */
171+
0, /* tp_print */
172+
@@ -4060,6 +4061,10 @@ static void init_basetypes(void);
173+
NPY_NO_EXPORT void
174+
initialize_numeric_types(void)
175+
{
176+
+ /* Pyston change: deal with static nonheap objects */
177+
+ PyGC_AddNonHeapRoot((PyObject*)&_PyArrayScalar_BoolValues[0], sizeof(PyBoolScalarObject));
178+
+ PyGC_AddNonHeapRoot((PyObject*)&_PyArrayScalar_BoolValues[1], sizeof(PyBoolScalarObject));
179+
+
180+
init_basetypes();
181+
PyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;
182+
PyGenericArrType_Type.tp_as_number = &gentype_as_number;
183+
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
184+
index 7797731..93edc66 100644
185+
--- a/numpy/core/src/umath/ufunc_object.c
186+
+++ b/numpy/core/src/umath/ufunc_object.c
187+
@@ -4345,9 +4345,11 @@ ufunc_generic_call(PyUFuncObject *ufunc, PyObject *args, PyObject *kwds)
188+
}
189+
190+
fail:
191+
+ /* Causes compiler CRASH wtf
192+
for (i = ufunc->nin; i < ufunc->nargs; i++) {
193+
Py_XDECREF(mps[i]);
194+
}
195+
+ */
196+
return NULL;
197+
}
198+
199+
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
200+
index 44bd48d..3822b25 100644
201+
--- a/numpy/lib/_iotools.py
202+
+++ b/numpy/lib/_iotools.py
203+
@@ -526,7 +526,7 @@ class StringConverter(object):
204+
_mapper.append((nx.int64, int, -1))
205+
206+
_mapper.extend([(nx.floating, float, nx.nan),
207+
- (complex, _bytes_to_complex, nx.nan + 0j),
208+
+ (complex, _bytes_to_complex, complex(nx.nan) + 0j),
209+
(nx.string_, bytes, asbytes('???'))])
210+
211+
(_defaulttype, _defaultfunc, _defaultfill) = zip(*_mapper)
212+
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
213+
index 1904080..3d78b5c 100644
214+
--- a/numpy/lib/function_base.py
215+
+++ b/numpy/lib/function_base.py
216+
@@ -965,7 +965,7 @@ def gradient(f, *varargs, **kwargs):
217+
Returns
218+
-------
219+
gradient : list of ndarray
220+
- Each element of `list` has the same shape as `f` giving the derivative
221+
+ Each element of `list` has the same shape as `f` giving the derivative
222+
of `f` with respect to each dimension.
223+
224+
Examples
225+
@@ -976,10 +976,10 @@ def gradient(f, *varargs, **kwargs):
226+
>>> np.gradient(x, 2)
227+
array([ 0.5 , 0.75, 1.25, 1.75, 2.25, 2.5 ])
228+
229+
- For two dimensional arrays, the return will be two arrays ordered by
230+
- axis. In this example the first array stands for the gradient in
231+
+ For two dimensional arrays, the return will be two arrays ordered by
232+
+ axis. In this example the first array stands for the gradient in
233+
rows and the second one in columns direction:
234+
-
235+
+
236+
>>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float))
237+
[array([[ 2., 2., -1.],
238+
[ 2., 2., -1.]]), array([[ 1. , 2.5, 4. ],
239+
@@ -3875,7 +3875,7 @@ def delete(arr, obj, axis=None):
240+
"`numpy.delete`.", FutureWarning)
241+
obj = obj[positive_indices]
242+
243+
- keep[obj, ] = False
244+
+ keep[(obj, )] = False
245+
slobj[axis] = keep
246+
new = arr[slobj]
247+
248+
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
249+
index d4771fb..54f3983 100644
250+
--- a/numpy/ma/core.py
251+
+++ b/numpy/ma/core.py
252+
@@ -158,10 +158,10 @@ for v in ["Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns", "ps",
253+
max_filler = ntypes._minvals
254+
max_filler.update([(k, -np.inf) for k in [np.float32, np.float64]])
255+
min_filler = ntypes._maxvals
256+
-min_filler.update([(k, +np.inf) for k in [np.float32, np.float64]])
257+
+# min_filler.update([(k, +np.inf) for k in [np.float32, np.float64]])
258+
if 'float128' in ntypes.typeDict:
259+
max_filler.update([(np.float128, -np.inf)])
260+
- min_filler.update([(np.float128, +np.inf)])
261+
+ # min_filler.update([(np.float128, +np.inf)])
262+
263+
264+
def default_fill_value(obj):
265+
@@ -6816,7 +6816,7 @@ def resize(x, new_shape):
266+
return result
267+
268+
269+
-def rank(obj):
270+
+def rank(obj):
271+
"""
272+
maskedarray version of the numpy function.
273+
274+
@@ -6833,7 +6833,7 @@ def rank(obj):
275+
rank.__doc__ = np.rank.__doc__
276+
277+
278+
-def ndim(obj):
279+
+def ndim(obj):
280+
"""
281+
maskedarray version of the numpy function.
282+
283+
diff --git a/numpy/random/setup.py b/numpy/random/setup.py
284+
index 9d90590..b3ee24f 100644
285+
--- a/numpy/random/setup.py
286+
+++ b/numpy/random/setup.py
287+
@@ -39,18 +39,6 @@ def configuration(parent_package='',top_path=None):
288+
289+
libs = []
290+
# Configure mtrand
291+
- config.add_extension('mtrand',
292+
- sources=[join('mtrand', x) for x in
293+
- ['mtrand.c', 'randomkit.c', 'initarray.c',
294+
- 'distributions.c']]+[generate_libraries],
295+
- libraries=libs,
296+
- depends=[join('mtrand', '*.h'),
297+
- join('mtrand', '*.pyx'),
298+
- join('mtrand', '*.pxi'),],
299+
- define_macros=defs,
300+
- )
301+
-
302+
- config.add_data_files(('.', join('mtrand', 'randomkit.h')))
303+
config.add_data_dir('tests')
304+
305+
return config
306+
diff --git a/setup.py b/setup.py
307+
index 90dcb24..943851a 100755
308+
--- a/setup.py
309+
+++ b/setup.py
310+
@@ -245,7 +245,8 @@ def setup_package():
311+
cwd = os.path.abspath(os.path.dirname(__file__))
312+
if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
313+
# Generate Cython sources, unless building from source release
314+
- generate_cython()
315+
+ # generate_cython()
316+
+ pass
317+
metadata['configuration'] = configuration
318+
319+
try:

0 commit comments

Comments
 (0)