Commit 3e37c134 authored by Mark Florisson's avatar Mark Florisson

Merge branch 'release'

parents 9e583f02 1eabb1c6
...@@ -4429,7 +4429,9 @@ class AttributeNode(ExprNode): ...@@ -4429,7 +4429,9 @@ class AttributeNode(ExprNode):
# attribute. # attribute.
pass pass
# NumPy hack # NumPy hack
if obj_type.is_extension_type and obj_type.objstruct_cname == 'PyArrayObject': if (getattr(self.obj, 'type', None) and
obj_type.is_extension_type and
obj_type.objstruct_cname == 'PyArrayObject'):
from NumpySupport import numpy_transform_attribute_node from NumpySupport import numpy_transform_attribute_node
replacement_node = numpy_transform_attribute_node(self) replacement_node = numpy_transform_attribute_node(self)
# Since we can't actually replace our node yet, we only grasp its # Since we can't actually replace our node yet, we only grasp its
......
...@@ -1795,6 +1795,8 @@ class AnalyseExpressionsTransform(CythonTransform): ...@@ -1795,6 +1795,8 @@ class AnalyseExpressionsTransform(CythonTransform):
if type.is_extension_type and type.objstruct_cname == 'PyArrayObject': if type.is_extension_type and type.objstruct_cname == 'PyArrayObject':
from NumpySupport import numpy_transform_attribute_node from NumpySupport import numpy_transform_attribute_node
node = numpy_transform_attribute_node(node) node = numpy_transform_attribute_node(node)
self.visitchildren(node)
return node return node
class FindInvalidUseOfFusedTypes(CythonTransform): class FindInvalidUseOfFusedTypes(CythonTransform):
......
...@@ -107,7 +107,7 @@ typedef struct { ...@@ -107,7 +107,7 @@ typedef struct {
/////////////// GetAndReleaseBuffer /////////////// /////////////// GetAndReleaseBuffer ///////////////
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
PyObject *getbuffer_cobj = NULL; PyObject *getbuffer_cobj;
#if PY_VERSION_HEX >= 0x02060000 #if PY_VERSION_HEX >= 0x02060000
if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
...@@ -130,6 +130,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -130,6 +130,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#else #else
func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj);
#endif #endif
Py_DECREF(getbuffer_cobj);
if (!func) if (!func)
goto fail; goto fail;
...@@ -144,13 +145,13 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -144,13 +145,13 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#if PY_VERSION_HEX < 0x02060000 #if PY_VERSION_HEX < 0x02060000
fail: fail:
#endif #endif
Py_XDECREF(getbuffer_cobj);
return -1; return -1;
} }
static void __Pyx_ReleaseBuffer(Py_buffer *view) { static void __Pyx_ReleaseBuffer(Py_buffer *view) {
PyObject* obj = view->obj; PyObject *obj = view->obj;
PyObject *releasebuffer_cobj = NULL; PyObject *releasebuffer_cobj;
if (!obj) return; if (!obj) return;
...@@ -179,6 +180,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { ...@@ -179,6 +180,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj);
#endif #endif
Py_DECREF(releasebuffer_cobj);
if (!func) if (!func)
goto fail; goto fail;
...@@ -197,7 +200,6 @@ fail: ...@@ -197,7 +200,6 @@ fail:
PyErr_WriteUnraisable(obj); PyErr_WriteUnraisable(obj);
nofail: nofail:
Py_XDECREF(releasebuffer_cobj);
Py_DECREF(obj); Py_DECREF(obj);
view->obj = NULL; view->obj = NULL;
} }
......
...@@ -55,24 +55,16 @@ def test_copy_to(): ...@@ -55,24 +55,16 @@ def test_copy_to():
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
''' '''
cdef int[:,:,:] from_mvs, to_mvs cdef int[:, :, :] from_mvs, to_mvs
from_mvs = np.arange(8, dtype=np.int32).reshape(2,2,2) from_mvs = np.arange(8, dtype=np.int32).reshape(2,2,2)
cdef int *from_dta = <int*>from_mvs._data cdef int *from_data = <int *> from_mvs._data
for i in range(2*2*2): print ' '.join(str(from_data[i]) for i in range(2*2*2))
print from_dta[i],
print
# for i in range(2*2*2):
# from_dta[i] = i
to_mvs = array((2,2,2), sizeof(int), 'i') to_mvs = array((2,2,2), sizeof(int), 'i')
to_mvs[...] = from_mvs to_mvs[...] = from_mvs
cdef int *to_data = <int*>to_mvs._data cdef int *to_data = <int*>to_mvs._data
for i in range(2*2*2): print ' '.join(str(from_data[i]) for i in range(2*2*2))
print from_dta[i], print ' '.join(str(to_data[i]) for i in range(2*2*2))
print
for i in range(2*2*2):
print to_data[i],
print
@testcase @testcase
def test_overlapping_copy(): def test_overlapping_copy():
......
# (disabled) hack to avoid C compiler warnings about unused functions in the NumPy header files # hack to avoid C compiler warnings about unused functions in the NumPy header files
##cdef extern from *: cdef extern from *:
## bint FALSE "0" bint FALSE "0"
## void import_array() void import_array()
## void import_umath1(void* ret) # void import_umath()
##
##if FALSE: if FALSE:
## import_array() import_array()
## import_umath1(NULL) # import_umath()
...@@ -243,9 +243,12 @@ ctypedef td_h_short td_h_cy_short ...@@ -243,9 +243,12 @@ ctypedef td_h_short td_h_cy_short
cdef void dealloc_callback(void *data): cdef void dealloc_callback(void *data):
print "deallocating..." print "deallocating..."
def index(array array): def build_numarray(array array):
array.callback_free_data = dealloc_callback array.callback_free_data = dealloc_callback
print np.asarray(array)[3, 2] return np.asarray(array)
def index(array array):
print build_numarray(array)[3, 2]
@testcase_numpy_1_5 @testcase_numpy_1_5
def test_coerce_to_numpy(): def test_coerce_to_numpy():
...@@ -254,7 +257,7 @@ def test_coerce_to_numpy(): ...@@ -254,7 +257,7 @@ def test_coerce_to_numpy():
generated format strings. generated format strings.
>>> test_coerce_to_numpy() >>> test_coerce_to_numpy()
(97, 98, 600L, 700, 800) [97, 98, 600, 700, 800]
deallocating... deallocating...
(600, 700) (600, 700)
deallocating... deallocating...
...@@ -359,7 +362,9 @@ def test_coerce_to_numpy(): ...@@ -359,7 +362,9 @@ def test_coerce_to_numpy():
# #
### Create a NumPy array and see if our element can be correctly retrieved ### Create a NumPy array and see if our element can be correctly retrieved
# #
index(<MyStruct[:4, :5]> <MyStruct *> mystructs) mystruct_array = build_numarray(<MyStruct[:4, :5]> <MyStruct *> mystructs)
print [int(x) for x in mystruct_array[3, 2]]
del mystruct_array
index(<SmallStruct[:4, :5]> <SmallStruct *> smallstructs) index(<SmallStruct[:4, :5]> <SmallStruct *> smallstructs)
index(<NestedStruct[:4, :5]> <NestedStruct *> nestedstructs) index(<NestedStruct[:4, :5]> <NestedStruct *> nestedstructs)
index(<PackedStruct[:4, :5]> <PackedStruct *> packedstructs) index(<PackedStruct[:4, :5]> <PackedStruct *> packedstructs)
......
...@@ -176,12 +176,23 @@ try: ...@@ -176,12 +176,23 @@ try:
ValueError: Buffer dtype mismatch, expected 'int' but got 'float' in 'DoubleInt.y' ValueError: Buffer dtype mismatch, expected 'int' but got 'float' in 'DoubleInt.y'
>>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=False)))) >>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=False))))
array([(22, 23)], [(22, 23)]
dtype=[('f0', '|i1'), ('f1', '!i4')])
>>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
The output changed in Python 3:
>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
array([(22, 23)], array([(22, 23)],
dtype=[('f0', '|i1'), ('', '|V3'), ('f1', '!i4')]) dtype=[('f0', '|i1'), ('', '|V3'), ('f1', '!i4')])
->
array([(22, 23)],
dtype={'names':['f0','f1'], 'formats':['i1','!i4'], 'offsets':[0,4], 'itemsize':8, 'aligned':True})
>>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
[(22, 23)]
>>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=True)))) #doctest: +ELLIPSIS >>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=True)))) #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
...@@ -444,12 +455,13 @@ cdef packed struct PartiallyPackedStruct2: ...@@ -444,12 +455,13 @@ cdef packed struct PartiallyPackedStruct2:
def test_packed_align(np.ndarray[PackedStruct] arr): def test_packed_align(np.ndarray[PackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
arr[0].b = 23 arr[0].b = 23
return repr(arr).replace('<', '!').replace('>', '!') return list(arr)
def test_unpacked_align(np.ndarray[UnpackedStruct] arr): def test_unpacked_align(np.ndarray[UnpackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
arr[0].b = 23 arr[0].b = 23
return repr(arr).replace('<', '!').replace('>', '!') # return repr(arr).replace('<', '!').replace('>', '!')
return list(arr)
def test_partially_packed_align(np.ndarray[PartiallyPackedStruct] arr): def test_partially_packed_align(np.ndarray[PartiallyPackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment