Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
3e37c134
Commit
3e37c134
authored
Mar 31, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release'
parents
9e583f02
1eabb1c6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
39 deletions
+54
-39
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-0
Cython/Utility/Buffer.c
Cython/Utility/Buffer.c
+7
-5
tests/run/memoryviewattrs.pyx
tests/run/memoryviewattrs.pyx
+6
-14
tests/run/numpy_common.pxi
tests/run/numpy_common.pxi
+9
-9
tests/run/numpy_memoryview.pyx
tests/run/numpy_memoryview.pyx
+9
-4
tests/run/numpy_test.pyx
tests/run/numpy_test.pyx
+18
-6
No files found.
Cython/Compiler/ExprNodes.py
View file @
3e37c134
...
...
@@ -4429,7 +4429,9 @@ class AttributeNode(ExprNode):
# attribute.
pass
# 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
replacement_node
=
numpy_transform_attribute_node
(
self
)
# Since we can't actually replace our node yet, we only grasp its
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
3e37c134
...
...
@@ -1795,6 +1795,8 @@ class AnalyseExpressionsTransform(CythonTransform):
if
type
.
is_extension_type
and
type
.
objstruct_cname
==
'PyArrayObject'
:
from
NumpySupport
import
numpy_transform_attribute_node
node
=
numpy_transform_attribute_node
(
node
)
self
.
visitchildren
(
node
)
return
node
class
FindInvalidUseOfFusedTypes
(
CythonTransform
):
...
...
Cython/Utility/Buffer.c
View file @
3e37c134
...
...
@@ -107,7 +107,7 @@ typedef struct {
/////////////// GetAndReleaseBuffer ///////////////
#if PY_MAJOR_VERSION < 3
static
int
__Pyx_GetBuffer
(
PyObject
*
obj
,
Py_buffer
*
view
,
int
flags
)
{
PyObject
*
getbuffer_cobj
=
NULL
;
PyObject
*
getbuffer_cobj
;
#if PY_VERSION_HEX >= 0x02060000
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) {
#else
func
=
(
getbufferproc
)
PyCObject_AsVoidPtr
(
getbuffer_cobj
);
#endif
Py_DECREF
(
getbuffer_cobj
);
if
(
!
func
)
goto
fail
;
...
...
@@ -144,13 +145,13 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#if PY_VERSION_HEX < 0x02060000
fail:
#endif
Py_XDECREF
(
getbuffer_cobj
);
return
-
1
;
}
static
void
__Pyx_ReleaseBuffer
(
Py_buffer
*
view
)
{
PyObject
*
obj
=
view
->
obj
;
PyObject
*
releasebuffer_cobj
=
NULL
;
PyObject
*
obj
=
view
->
obj
;
PyObject
*
releasebuffer_cobj
;
if
(
!
obj
)
return
;
...
...
@@ -179,6 +180,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
func
=
(
releasebufferproc
)
PyCObject_AsVoidPtr
(
releasebuffer_cobj
);
#endif
Py_DECREF
(
releasebuffer_cobj
);
if
(
!
func
)
goto
fail
;
...
...
@@ -197,7 +200,6 @@ fail:
PyErr_WriteUnraisable
(
obj
);
nofail:
Py_XDECREF
(
releasebuffer_cobj
);
Py_DECREF
(
obj
);
view
->
obj
=
NULL
;
}
...
...
tests/run/memoryviewattrs.pyx
View file @
3e37c134
...
...
@@ -55,24 +55,16 @@ def test_copy_to():
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
)
cdef
int
*
from_dta
=
<
int
*>
from_mvs
.
_data
for
i
in
range
(
2
*
2
*
2
):
print
from_dta
[
i
],
print
# for i in range(2*2*2):
# from_dta[i] = i
cdef
int
*
from_data
=
<
int
*>
from_mvs
.
_data
print
' '
.
join
(
str
(
from_data
[
i
])
for
i
in
range
(
2
*
2
*
2
))
to_mvs
=
array
((
2
,
2
,
2
),
sizeof
(
int
),
'i'
)
to_mvs
[...]
=
from_mvs
cdef
int
*
to_data
=
<
int
*>
to_mvs
.
_data
for
i
in
range
(
2
*
2
*
2
):
print
from_dta
[
i
],
print
for
i
in
range
(
2
*
2
*
2
):
print
to_data
[
i
],
print
print
' '
.
join
(
str
(
from_data
[
i
])
for
i
in
range
(
2
*
2
*
2
))
print
' '
.
join
(
str
(
to_data
[
i
])
for
i
in
range
(
2
*
2
*
2
))
@
testcase
def
test_overlapping_copy
():
...
...
tests/run/numpy_common.pxi
View file @
3e37c134
#
(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 *:
##
bint FALSE "0"
##
void import_array()
#
# void import_umath1(void* ret
)
##
##
if FALSE:
##
import_array()
#
# import_umath1(NULL
)
cdef
extern
from
*
:
bint
FALSE
"0"
void
import_array
()
#
void import_umath(
)
if
FALSE
:
import_array
()
#
import_umath(
)
tests/run/numpy_memoryview.pyx
View file @
3e37c134
...
...
@@ -243,9 +243,12 @@ ctypedef td_h_short td_h_cy_short
cdef
void
dealloc_callback
(
void
*
data
):
print
"deallocating..."
def
index
(
array
array
):
def
build_numarray
(
array
array
):
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
def
test_coerce_to_numpy
():
...
...
@@ -254,7 +257,7 @@ def test_coerce_to_numpy():
generated format strings.
>>> test_coerce_to_numpy()
(97, 98, 600L, 700, 800)
[97, 98, 600, 700, 800]
deallocating...
(600, 700)
deallocating...
...
...
@@ -359,7 +362,9 @@ def test_coerce_to_numpy():
#
### 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
(
<
NestedStruct
[:
4
,
:
5
]
>
<
NestedStruct
*>
nestedstructs
)
index
(
<
PackedStruct
[:
4
,
:
5
]
>
<
PackedStruct
*>
packedstructs
)
...
...
tests/run/numpy_test.pyx
View file @
3e37c134
...
...
@@ -176,12 +176,23 @@ try:
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))))
array([(22, 23)],
dtype=[('f0', '|i1'), ('f1', '!i4')])
>>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
[(22, 23)]
The output changed in Python 3:
>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
array([(22, 23)],
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
Traceback (most recent call last):
...
...
...
@@ -444,12 +455,13 @@ cdef packed struct PartiallyPackedStruct2:
def
test_packed_align
(
np
.
ndarray
[
PackedStruct
]
arr
):
arr
[
0
].
a
=
22
arr
[
0
].
b
=
23
return
repr
(
arr
).
replace
(
'<'
,
'!'
).
replace
(
'>'
,
'!'
)
return
list
(
arr
)
def
test_unpacked_align
(
np
.
ndarray
[
UnpackedStruct
]
arr
):
arr
[
0
].
a
=
22
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
):
arr
[
0
].
a
=
22
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment