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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
7c852f79
Commit
7c852f79
authored
May 08, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scalar slice assignment with different ndim than source object
parent
2e3a306d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
2 deletions
+63
-2
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+2
-2
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+61
-0
No files found.
Cython/Utility/MemoryView.pyx
View file @
7c852f79
...
...
@@ -402,7 +402,7 @@ cdef class memoryview(object):
get_slice_from_memview
(
dst
,
&
dst_slice
)[
0
],
src
.
ndim
,
dst
.
ndim
,
self
.
dtype_is_object
)
cdef
setitem_slice_assign_scalar
(
self
,
dst
,
value
):
cdef
setitem_slice_assign_scalar
(
self
,
memoryview
dst
,
value
):
cdef
int
array
[
128
]
cdef
void
*
tmp
=
NULL
cdef
void
*
item
...
...
@@ -431,7 +431,7 @@ cdef class memoryview(object):
# to disallow :)
if
self
.
view
.
suboffsets
!=
NULL
:
assert_direct_dimensions
(
self
.
view
.
suboffsets
,
self
.
view
.
ndim
)
slice_assign_scalar
(
dst_slice
,
self
.
view
.
ndim
,
self
.
view
.
itemsize
,
slice_assign_scalar
(
dst_slice
,
dst
.
view
.
ndim
,
self
.
view
.
itemsize
,
item
,
self
.
dtype_is_object
)
free
(
tmp
)
...
...
tests/run/memoryview.pyx
View file @
7c852f79
...
...
@@ -913,3 +913,64 @@ def test_acquire_memoryview_slice():
cdef
int
[:,
:]
c
=
b
print
b
[
2
,
4
]
print
c
[
2
,
4
]
class
SingleObject
(
object
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__str__
(
self
):
return
str
(
self
.
value
)
def
__eq__
(
self
,
other
):
return
self
.
value
==
getattr
(
other
,
'value'
,
None
)
or
self
.
value
==
other
def
test_assign_scalar
(
int
[:,
:]
m
):
"""
>>> A = IntMockBuffer("A", [0] * 100, shape=(10, 10))
>>> test_assign_scalar(A)
acquired A
1 1 1 4 1 6 1 1 1 1
2 2 2 4 2 6 2 2 2 2
3 3 3 4 3 6 3 3 3 3
1 1 1 4 1 6 1 1 1 1
5 5 5 5 5 6 5 5 5 5
1 1 1 4 1 6 1 1 1 1
released A
"""
m
[:,
:]
=
1
m
[
1
,
:]
=
2
m
[
2
,
:]
=
3
m
[:,
3
]
=
4
m
[
4
,
...]
=
5
m
[...,
5
]
=
6
for
i
in
range
(
6
):
print
" "
.
join
([
str
(
m
[
i
,
j
])
for
j
in
range
(
m
.
shape
[
1
])])
def
test_contig_scalar_to_slice_assignment
():
"""
>>> test_contig_scalar_to_slice_assignment()
14 14 14 14
20 20 20 20
"""
cdef
int
a
[
5
][
10
]
cdef
int
[:,
::
1
]
_m
=
a
m
=
_m
m
[...]
=
14
print
m
[
0
,
0
],
m
[
-
1
,
-
1
],
m
[
3
,
2
],
m
[
4
,
9
]
m
[:,
:]
=
20
print
m
[
0
,
0
],
m
[
-
1
,
-
1
],
m
[
3
,
2
],
m
[
4
,
9
]
def
test_dtype_object_scalar_assignment
():
"""
>>> test_dtype_object_scalar_assignment()
"""
cdef
object
[:]
m
=
array
((
10
,),
sizeof
(
PyObject
*
),
'O'
)
m
[:]
=
SingleObject
(
2
)
assert
m
[
0
]
==
m
[
4
]
==
m
[
-
1
]
==
2
(
<
object
>
m
)[:]
=
SingleObject
(
3
)
assert
m
[
0
]
==
m
[
4
]
==
m
[
-
1
]
==
3
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