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
Kirill Smelkov
cython
Commits
8567f2c2
Commit
8567f2c2
authored
Feb 01, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge 0.22.x branch into master
parents
b8f99d46
e8c8482f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
21 deletions
+29
-21
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+19
-21
tests/memoryview/memoryview.pyx
tests/memoryview/memoryview.pyx
+10
-0
No files found.
Cython/Utility/MemoryView.pyx
View file @
8567f2c2
...
...
@@ -511,7 +511,7 @@ cdef class memoryview(object):
property
shape
:
@
cname
(
'__pyx_memoryview_get_shape'
)
def
__get__
(
self
):
return
tuple
([
self
.
view
.
shape
[
i
]
for
i
in
xrange
(
self
.
view
.
ndim
)
])
return
tuple
([
length
for
length
in
self
.
view
.
shape
[:
self
.
view
.
ndim
]
])
property
strides
:
@
cname
(
'__pyx_memoryview_get_strides'
)
...
...
@@ -520,15 +520,15 @@ cdef class memoryview(object):
# Note: we always ask for strides, so if this is not set it's a bug
raise
ValueError
(
"Buffer view does not expose strides"
)
return
tuple
([
s
elf
.
view
.
strides
[
i
]
for
i
in
xrange
(
self
.
view
.
ndim
)
])
return
tuple
([
s
tride
for
stride
in
self
.
view
.
strides
[:
self
.
view
.
ndim
]
])
property
suboffsets
:
@
cname
(
'__pyx_memoryview_get_suboffsets'
)
def
__get__
(
self
):
if
self
.
view
.
suboffsets
==
NULL
:
return
[
-
1
]
*
self
.
view
.
ndim
return
(
-
1
,)
*
self
.
view
.
ndim
return
tuple
([
s
elf
.
view
.
suboffsets
[
i
]
for
i
in
xrange
(
self
.
view
.
ndim
)
])
return
tuple
([
s
uboffset
for
suboffset
in
self
.
view
.
suboffsets
[:
self
.
view
.
ndim
]
])
property
ndim
:
@
cname
(
'__pyx_memoryview_get_ndim'
)
...
...
@@ -551,7 +551,7 @@ cdef class memoryview(object):
if
self
.
_size
is
None
:
result
=
1
for
length
in
self
.
shape
:
for
length
in
self
.
view
.
shape
[:
self
.
view
.
ndim
]
:
result
*=
length
self
.
_size
=
result
...
...
@@ -654,9 +654,8 @@ cdef tuple _unellipsify(object index, int ndim):
return
have_slices
or
nslices
,
tuple
(
result
)
cdef
assert_direct_dimensions
(
Py_ssize_t
*
suboffsets
,
int
ndim
):
cdef
int
i
for
i
in
range
(
ndim
):
if
suboffsets
[
i
]
>=
0
:
for
suboffset
in
suboffsets
[:
ndim
]:
if
suboffset
>=
0
:
raise
ValueError
(
"Indirect dimensions not supported"
)
#
...
...
@@ -987,9 +986,11 @@ cdef memoryview_fromslice({{memviewslice_name}} memviewslice,
result
.
view
.
shape
=
<
Py_ssize_t
*>
result
.
from_slice
.
shape
result
.
view
.
strides
=
<
Py_ssize_t
*>
result
.
from_slice
.
strides
# only set suboffsets if actually used, otherwise set to NULL to improve compatibility
result
.
view
.
suboffsets
=
NULL
for
i
in
range
(
ndim
)
:
if
result
.
from_slice
.
suboffsets
[
i
]
>=
0
:
for
suboffset
in
result
.
from_slice
.
suboffsets
[:
ndim
]
:
if
suboffset
>=
0
:
result
.
view
.
suboffsets
=
<
Py_ssize_t
*>
result
.
from_slice
.
suboffsets
break
...
...
@@ -1028,10 +1029,7 @@ cdef void slice_copy(memoryview memview, {{memviewslice_name}} *dst):
for
dim
in
range
(
memview
.
view
.
ndim
):
dst
.
shape
[
dim
]
=
shape
[
dim
]
dst
.
strides
[
dim
]
=
strides
[
dim
]
if
suboffsets
==
NULL
:
dst
.
suboffsets
[
dim
]
=
-
1
else
:
dst
.
suboffsets
[
dim
]
=
suboffsets
[
dim
]
dst
.
suboffsets
[
dim
]
=
suboffsets
[
dim
]
if
suboffsets
else
-
1
@
cname
(
'__pyx_memoryview_copy_object'
)
cdef
memoryview_copy
(
memoryview
memview
):
...
...
@@ -1295,21 +1293,21 @@ cdef int memoryview_copy_contents({{memviewslice_name}} src,
return
0
@
cname
(
'__pyx_memoryview_broadcast_leading'
)
cdef
void
broadcast_leading
({{
memviewslice_name
}}
*
slice
,
cdef
void
broadcast_leading
({{
memviewslice_name
}}
*
m
slice
,
int
ndim
,
int
ndim_other
)
nogil
:
cdef
int
i
cdef
int
offset
=
ndim_other
-
ndim
for
i
in
range
(
ndim
-
1
,
-
1
,
-
1
):
slice
.
shape
[
i
+
offset
]
=
slice
.
shape
[
i
]
slice
.
strides
[
i
+
offset
]
=
slice
.
strides
[
i
]
slice
.
suboffsets
[
i
+
offset
]
=
slice
.
suboffsets
[
i
]
mslice
.
shape
[
i
+
offset
]
=
m
slice
.
shape
[
i
]
mslice
.
strides
[
i
+
offset
]
=
m
slice
.
strides
[
i
]
mslice
.
suboffsets
[
i
+
offset
]
=
m
slice
.
suboffsets
[
i
]
for
i
in
range
(
offset
):
slice
.
shape
[
i
]
=
1
slice
.
strides
[
i
]
=
slice
.
strides
[
0
]
slice
.
suboffsets
[
i
]
=
-
1
m
slice
.
shape
[
i
]
=
1
mslice
.
strides
[
i
]
=
m
slice
.
strides
[
0
]
m
slice
.
suboffsets
[
i
]
=
-
1
#
### Take care of refcounting the objects in slices. Do this seperately from any copying,
...
...
tests/memoryview/memoryview.pyx
View file @
8567f2c2
...
...
@@ -1012,3 +1012,13 @@ def test_assignment_in_conditional_expression(bint left):
c
=
a
if
left
else
b
for
i
in
range
(
c
.
shape
[
0
]):
print
c
[
i
]
def
test_cpython_offbyone_issue_23349
():
"""
>>> print(test_cpython_offbyone_issue_23349())
testing
"""
cdef
unsigned
char
[:]
v
=
bytearray
(
b"testing"
)
# the following returns 'estingt' without the workaround
return
bytearray
(
v
).
decode
(
'ascii'
)
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