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
7d9fa927
Commit
7d9fa927
authored
Feb 14, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dedicated test file for read-only memory views.
parent
486421f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
tests/memoryview/numpy_memoryview_readonly.pyx
tests/memoryview/numpy_memoryview_readonly.pyx
+91
-0
No files found.
tests/memoryview/numpy_memoryview_readonly.pyx
0 → 100644
View file @
7d9fa927
# mode: run
# tag: readonly, const, numpy
import
numpy
as
np
def
new_array
():
return
np
.
arange
(
10
).
astype
(
'float'
)
ARRAY
=
new_array
()
cdef
getmax
(
double
[:]
x
):
"""Example code, should work with both
ro and rw memoryviews"""
cdef
double
max_val
=
-
float
(
'inf'
)
for
val
in
x
:
if
val
>
max_val
:
max_val
=
val
return
max_val
cdef
update_array
(
double
[:]
x
):
"""Modifying a ro memoryview should raise an error"""
x
[
0
]
=
23.
cdef
getconst
(
const
double
[:]
x
):
"""Should only accept ro memoryviews"""
return
x
[
0
]
def
test_mmview_rw
(
x
):
"""
>>> test_mmview_rw(ARRAY)
9.0
"""
return
getmax
(
x
)
def
test_mmview_ro
(
x
):
"""
>>> test_mmview_ro(new_array())
9.0
"""
x
.
setflags
(
write
=
False
)
assert
x
.
flags
.
writeable
is
False
return
getmax
(
x
)
def
test_update_mmview_rw
(
x
):
"""
>>> test_update_mmview_rw(new_array())
23.0
"""
update_array
(
x
)
return
x
[
0
]
def
test_update_mmview_ro
(
x
):
"""
>>> test_update_mmview_ro(new_array())
0.0
"""
x
.
setflags
(
write
=
False
)
assert
x
.
flags
.
writeable
is
False
try
:
update_array
(
x
)
except
ValueError
:
pass
else
:
assert
False
,
"RO error not raised!"
return
getconst
(
x
)
def
test_rw_call_getmax
(
double
[:]
x
):
"""
>>> test_rw_call_getmax(new_array())
23.0
"""
update_array
(
x
)
assert
getconst
(
x
)
==
23
return
getmax
(
x
)
def
test_const_mmview_ro
(
x
):
"""
>>> test_const_mmview_ro(new_array())
0.0
"""
x
.
setflags
(
write
=
False
)
assert
x
.
flags
.
writeable
is
False
return
getconst
(
x
)
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