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
0b1b3f00
Commit
0b1b3f00
authored
Aug 21, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support acquiring slices from memoryviews
parent
e31c8f6f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
7 deletions
+62
-7
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+12
-5
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+1
-1
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+1
-1
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+48
-0
No files found.
Cython/Utility/MemoryView.pyx
View file @
0b1b3f00
...
...
@@ -119,11 +119,6 @@ cdef class array:
else
:
info
.
format
=
NULL
# info.obj = self
def
__releasebuffer__
(
self
,
Py_buffer
*
info
):
pass
def
__dealloc__
(
array
self
):
if
self
.
callback_free_data
!=
NULL
:
self
.
callback_free_data
(
self
.
data
)
...
...
@@ -183,6 +178,9 @@ cdef extern from *:
int
__Pyx_GetBuffer
(
object
,
Py_buffer
*
,
int
)
except
-
1
void
__Pyx_ReleaseBuffer
(
Py_buffer
*
)
void
Py_INCREF
(
object
)
void
Py_DECREF
(
object
)
ctypedef
struct
PyObject
cdef
struct
__pyx_memoryview
"__pyx_memoryview_obj"
:
...
...
@@ -224,6 +222,7 @@ cdef class memoryview(object):
cdef
PyThread_type_lock
lock
cdef
int
acquisition_count
cdef
Py_buffer
view
cdef
int
flags
def
__cinit__
(
memoryview
self
,
object
obj
,
int
flags
):
self
.
obj
=
obj
...
...
@@ -303,6 +302,10 @@ cdef class memoryview(object):
for
i
,
c
in
enumerate
(
bytesvalue
):
itemp
[
i
]
=
c
def
__getbuffer__
(
self
,
Py_buffer
*
info
,
int
flags
):
info
[
0
]
=
self
.
view
info
.
obj
=
self
property
T
:
@
cname
(
'__pyx_memoryview_transpose'
)
def
__get__
(
self
):
...
...
@@ -432,6 +435,7 @@ cdef memoryview memview_slice(memoryview memview, object indices):
else
:
return
memoryview_fromslice
(
&
dst
,
new_ndim
,
NULL
,
NULL
)
#
### Slicing in a single dimension of a memoryviewslice
#
...
...
@@ -673,6 +677,9 @@ cdef class _memoryviewslice(memoryview):
def
__get__
(
self
):
return
self
.
from_object
@
cname
(
'__pyx_memoryviewslice_check'
)
cdef
int
__pyx_memoryviewslice_check
(
obj
):
return
isinstance
(
obj
,
_memoryviewslice
)
@
cname
(
'__pyx_memoryview_fromslice'
)
cdef
memoryview_fromslice
({{
memviewslice_name
}}
*
memviewslice
,
...
...
Cython/Utility/MemoryView_C.c
View file @
0b1b3f00
...
...
@@ -259,7 +259,7 @@ no_fail:
}
static
CYTHON_INLINE
void
__pyx_fatalerror
(
char
*
fmt
,
...)
{
static
CYTHON_INLINE
void
__pyx_fatalerror
(
c
onst
c
har
*
fmt
,
...)
{
va_list
vargs
;
char
msg
[
200
];
...
...
Cython/Utility/TypeConversion.c
View file @
0b1b3f00
...
...
@@ -15,7 +15,7 @@ static {{struct_type_decl}} {{funcname}}(PyObject * o) {
{{
for
member
in
var_entries
:
}}
{{
py
:
attr
=
"result."
+
member
.
cname
}}
value
=
PyMapping_GetItemString
(
o
,
"{{member.name}}"
);
value
=
PyMapping_GetItemString
(
o
,
(
char
*
)
"{{member.name}}"
);
if
(
!
value
)
{
PyErr_SetString
(
PyExc_ValueError
,
"No value specified for struct "
"attribute '{{member.name}}'"
);
...
...
tests/run/memoryview.pyx
View file @
0b1b3f00
...
...
@@ -753,3 +753,51 @@ def test_oob():
"""
cdef
int
[:,
:]
a
=
IntMockBuffer
(
"A"
,
range
(
4
*
9
),
shape
=
(
4
,
9
))
print
a
[:,
20
]
def
test_acquire_memoryview
():
"""
>>> test_acquire_memoryview()
acquired A
22
<MemoryView of 'IntMockBuffer' object>
22
22
released A
"""
cdef
int
[:,
:]
a
=
IntMockBuffer
(
"A"
,
range
(
4
*
9
),
shape
=
(
4
,
9
))
cdef
object
b
=
a
print
a
[
2
,
4
]
# Make sure we don't have to keep this around
del
a
print
b
cdef
int
[:,
:]
c
=
b
print
b
[
2
,
4
]
print
c
[
2
,
4
]
def
test_acquire_memoryview_slice
():
"""
>>> test_acquire_memoryview_slice()
acquired A
31
<MemoryView of 'IntMockBuffer' object>
31
31
released A
"""
cdef
int
[:,
:]
a
=
IntMockBuffer
(
"A"
,
range
(
4
*
9
),
shape
=
(
4
,
9
))
a
=
a
[
1
:,
:
6
]
cdef
object
b
=
a
print
a
[
2
,
4
]
# Make sure we don't have to keep this around
del
a
print
b
cdef
int
[:,
:]
c
=
b
print
b
[
2
,
4
]
print
c
[
2
,
4
]
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