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
aa1917cf
Commit
aa1917cf
authored
Nov 01, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-2644' of
https://github.com/aparamon/cython
into aparamon-fix-2644
parents
d774524e
41f1d2e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletion
+38
-1
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+1
-1
tests/memoryview/memoryview.pyx
tests/memoryview/memoryview.pyx
+37
-0
No files found.
Cython/Utility/MemoryView.pyx
View file @
aa1917cf
...
...
@@ -426,7 +426,7 @@ cdef class memoryview(object):
cdef
is_slice
(
self
,
obj
):
if
not
isinstance
(
obj
,
memoryview
):
try
:
obj
=
memoryview
(
obj
,
self
.
flags
|
PyBUF_ANY_CONTIGUOUS
,
obj
=
memoryview
(
obj
,
self
.
flags
&
~
PyBUF_WRITABLE
|
PyBUF_ANY_CONTIGUOUS
,
self
.
dtype_is_object
)
except
TypeError
:
return
None
...
...
tests/memoryview/memoryview.pyx
View file @
aa1917cf
...
...
@@ -14,6 +14,9 @@ from cpython.object cimport PyObject
from
cpython.ref
cimport
Py_INCREF
,
Py_DECREF
cimport
cython
import
array
as
pyarray
from
libc.stdlib
cimport
malloc
,
free
cdef
extern
from
"Python.h"
:
cdef
int
PyBUF_C_CONTIGUOUS
...
...
@@ -1083,3 +1086,37 @@ def optimised_index_of_slice(int[:,:,:] arr, int x, int y, int z):
print
(
arr
[
x
,
y
,
z
],
arr
[
x
][:][:][
y
][:][:][
z
])
print
(
arr
[
x
,
y
,
z
],
arr
[:][
x
][:][
y
][:][:][
z
])
print
(
arr
[
x
,
y
,
z
],
arr
[:,
:][
x
][:,
:][
y
][:][
z
])
def
test_assign_from_byteslike
(
byteslike
):
# Once http://python3statement.org is accepted, should be just
# >>> test_assign_from_byteslike(bytes(b'hello'))
# b'hello'
# ...
"""
>>> print(test_assign_from_byteslike(bytes(b'hello')).decode())
hello
>>> print(test_assign_from_byteslike(bytearray(b'howdy')).decode())
howdy
"""
# fails on Python 2.7- with
# TypeError: an integer is required
# >>> print(test_assign_from_byteslike(pyarray.array('B', b'aloha')).decode())
# aloha
# fails on Python 2.6- with
# NameError: name 'memoryview' is not defined
# >>> print(test_assign_from_byteslike(memoryview(b'bye!!')).decode())
# bye!!
def
assign
(
m
):
m
[:]
=
byteslike
cdef
void
*
buf
cdef
unsigned
char
[:]
mview
buf
=
malloc
(
5
)
try
:
mview
=
<
unsigned
char
[:
5
]
>
(
buf
)
assign
(
mview
)
return
(
<
unsigned
char
*>
buf
)[:
5
]
finally
:
free
(
buf
)
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