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
ed516fb9
Commit
ed516fb9
authored
Jan 17, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid with gil blocks in memoryview code (for performance)
parent
8f6abe21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
17 deletions
+27
-17
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+27
-17
No files found.
Cython/Utility/MemoryView.pyx
View file @
ed516fb9
...
...
@@ -709,15 +709,13 @@ cdef int slice_memviewslice({{memviewslice_name}} *src,
if
start
<
0
:
start
+=
shape
if
not
0
<=
start
<
shape
:
with
gil
:
raise
IndexError
(
"Index out of bounds (axis %d)"
)
_err_dim
(
IndexError
,
"Index out of bounds (axis %d)"
,
dim
)
else
:
# index is a slice
negative_step
=
have_step
!=
0
and
step
<
0
if
have_step
and
step
==
0
:
with
gil
:
raise
ValueError
(
"Step may not be zero (axis %d)"
%
dim
)
_err_dim
(
ValueError
,
"Step may not be zero (axis %d)"
,
dim
)
# check our bounds and set defaults
if
have_start
:
...
...
@@ -778,9 +776,8 @@ cdef int slice_memviewslice({{memviewslice_name}} *src,
if
new_ndim
==
0
:
dst
.
data
=
(
<
char
**>
dst
.
data
)[
0
]
+
suboffset
else
:
with
gil
:
raise
IndexError
(
"All dimensions preceding dimension %d "
"must be indexed and not sliced"
%
dim
)
_err_dim
(
IndexError
,
"All dimensions preceding dimension %d "
"must be indexed and not sliced"
,
dim
)
else
:
suboffset_dim
[
0
]
=
new_ndim
...
...
@@ -837,8 +834,7 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) nogil except 0:
shape
[
i
],
shape
[
j
]
=
shape
[
j
],
shape
[
i
]
if
memslice
.
suboffsets
[
i
]
>=
0
or
memslice
.
suboffsets
[
j
]
>=
0
:
with
gil
:
raise
ValueError
(
"Cannot transpose memoryview with indirect dimensions"
)
_err
(
ValueError
,
"Cannot transpose memoryview with indirect dimensions"
)
return
1
...
...
@@ -1082,8 +1078,7 @@ cdef void *copy_data_to_temp({{memviewslice_name}} *src,
result
=
malloc
(
size
)
if
not
result
:
with
gil
:
raise
MemoryError
_err
(
MemoryError
,
NULL
)
# tmpslice[0] = src
tmpslice
.
data
=
<
char
*>
result
...
...
@@ -1107,6 +1102,25 @@ cdef void *copy_data_to_temp({{memviewslice_name}} *src,
return
result
# Use 'with gil' functions and avoid 'with gil' blocks, as the code within the blocks
# has temporaries that need the GIL to clean up
@
cname
(
'__pyx_memoryview_err_extents'
)
cdef
int
_err_extents
(
int
i
,
Py_ssize_t
extent1
,
Py_ssize_t
extent2
)
except
-
1
with
gil
:
raise
ValueError
(
"got differing extents in dimension %d (got %d and %d)"
%
(
i
,
extent1
,
extent2
))
@
cname
(
'__pyx_memoryview_err_dim'
)
cdef
int
_err_dim
(
object
error
,
char
*
msg
,
int
dim
)
except
-
1
with
gil
:
raise
error
(
msg
%
dim
)
@
cname
(
'__pyx_memoryview_err'
)
cdef
int
_err
(
object
error
,
char
*
msg
)
except
-
1
with
gil
:
if
msg
!=
NULL
:
raise
error
(
msg
)
else
:
raise
error
@
cname
(
'__pyx_memoryview_copy_contents'
)
cdef
int
memoryview_copy_contents
({{
memviewslice_name
}}
src
,
{{
memviewslice_name
}}
dst
,
...
...
@@ -1136,14 +1150,10 @@ cdef int memoryview_copy_contents({{memviewslice_name}} src,
broadcasting
=
True
src
.
strides
[
i
]
=
0
else
:
with
gil
:
raise
ValueError
(
"got differing extents in dimension %d "
"(got %d and %d)"
%
(
i
,
dst
.
shape
[
i
],
src
.
shape
[
i
]))
_err_extents
(
i
,
dst
.
shape
[
i
],
src
.
shape
[
i
])
if
src
.
suboffsets
[
i
]
>=
0
:
with
gil
:
raise
ValueError
(
"Dimension %d is not direct"
%
i
)
_err_dim
(
ValueError
,
"Dimension %d is not direct"
,
i
)
if
slices_overlap
(
&
src
,
&
dst
,
ndim
,
itemsize
):
# slices overlap, copy to temp, copy temp to dst
...
...
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