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
Xavier Thompson
cython
Commits
fcc76de6
Commit
fcc76de6
authored
Aug 08, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement len(memoryview) and allow its usage in nogil sections.
Closes #1733
parent
f68f694a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
4 deletions
+26
-4
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+9
-2
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+3
-0
tests/memoryview/memoryviewattrs.pyx
tests/memoryview/memoryviewattrs.pyx
+7
-0
tests/memoryview/memslice.pyx
tests/memoryview/memslice.pyx
+7
-2
No files found.
Cython/Compiler/Optimize.py
View file @
fcc76de6
...
...
@@ -2429,6 +2429,14 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
node
.
pos
,
"__Pyx_Py_UNICODE_strlen"
,
self
.
Pyx_Py_UNICODE_strlen_func_type
,
args
=
[
arg
],
is_temp
=
node
.
is_temp
)
elif
arg
.
type
.
is_memoryviewslice
:
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_size_t_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"memoryviewslice"
,
arg
.
type
,
None
)
],
nogil
=
True
)
new_node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_MemoryView_Len"
,
func_type
,
args
=
[
arg
],
is_temp
=
node
.
is_temp
)
elif
arg
.
type
.
is_pyobject
:
cfunc_name
=
self
.
_map_to_capi_len_function
(
arg
.
type
)
if
cfunc_name
is
None
:
...
...
@@ -2442,8 +2450,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
"object of type 'NoneType' has no len()"
)
new_node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
cfunc_name
,
self
.
PyObject_Size_func_type
,
args
=
[
arg
],
is_temp
=
node
.
is_temp
)
args
=
[
arg
],
is_temp
=
node
.
is_temp
)
elif
arg
.
type
.
is_unicode_char
:
return
ExprNodes
.
IntNode
(
node
.
pos
,
value
=
'1'
,
constant_result
=
1
,
type
=
node
.
type
)
...
...
Cython/Utility/MemoryView_C.c
View file @
fcc76de6
...
...
@@ -11,6 +11,9 @@ typedef struct {
Py_ssize_t
suboffsets
[{{
max_dims
}}];
}
{{
memviewslice_name
}};
// used for "len(memviewslice)"
#define __Pyx_MemoryView_Len(m) (m.shape[0])
/////////// Atomics.proto /////////////
...
...
tests/memoryview/memoryviewattrs.pyx
View file @
fcc76de6
...
...
@@ -279,6 +279,13 @@ def two_dee():
assert
len
(
arr
)
==
2
try
:
_
=
len
(
mv1
)
except
UnboundLocalError
:
pass
else
:
assert
False
,
"UnboundLocalError not raised for uninitialised memory view"
cdef
long
*
arr_data
arr_data
=
<
long
*>
arr
.
data
...
...
tests/memoryview/memslice.pyx
View file @
fcc76de6
...
...
@@ -1677,7 +1677,7 @@ cdef int cdef_nogil(int[:, :] a) nogil except 0:
for
j
in
range
(
b
.
shape
[
1
]):
b
[
i
,
j
]
=
-
b
[
i
,
j
]
return
1
return
len
(
a
)
@
testcase
def
test_nogil
():
...
...
@@ -1690,10 +1690,15 @@ def test_nogil():
released A
"""
_a
=
IntMockBuffer
(
"A"
,
range
(
4
*
9
),
shape
=
(
4
,
9
))
cdef
_nogil
(
_a
)
assert
cdef
_nogil
(
_a
)
==
4
cdef
int
[:,
:]
a
=
_a
print
a
[
2
,
7
]
cdef
int
length
with
nogil
:
length
=
cdef
_nogil
(
a
)
assert
length
==
4
@
testcase
def
test_convert_slicenode_to_indexnode
():
"""
...
...
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