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
d88146d0
Commit
d88146d0
authored
Jan 25, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge cython array utility with memoryview utility
parent
23d7640e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
129 deletions
+101
-129
Cython/Compiler/CythonScope.py
Cython/Compiler/CythonScope.py
+3
-7
Cython/Compiler/MemoryView.py
Cython/Compiler/MemoryView.py
+8
-15
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+82
-105
tests/run/cymemoryview.pyx
tests/run/cymemoryview.pyx
+4
-1
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+4
-1
No files found.
Cython/Compiler/CythonScope.py
View file @
d88146d0
...
...
@@ -103,9 +103,6 @@ class CythonScope(ModuleScope):
cython_test_extclass_utility_code
.
declare_in_scope
(
self
,
cython_scope
=
self
)
MemoryView
.
cython_array_utility_code
.
declare_in_scope
(
self
,
cython_scope
=
self
)
#
# The view sub-scope
#
...
...
@@ -115,13 +112,12 @@ class CythonScope(ModuleScope):
viewscope
.
pxd_file_loaded
=
True
cythonview_testscope_utility_code
.
declare_in_scope
(
viewscope
,
cython_scope
=
self
)
viewscope
,
cython_scope
=
self
)
view_utility_scope
=
MemoryView
.
view_utility_code
.
declare_in_scope
(
viewscope
,
cython_scope
=
self
)
self
.
viewscope
,
cython_scope
=
self
)
# MemoryView.memview_fromslice_utility_code.from_scope = view_utility_scope
# MemoryView.memview_fromslice_utility_code.declare_in_scope(viewscope)
self
.
entries
[
"array"
]
=
view_utility_scope
.
lookup
(
"array"
)
def
create_cython_scope
(
context
):
...
...
Cython/Compiler/MemoryView.py
View file @
d88146d0
...
...
@@ -853,6 +853,10 @@ def _resolve_AttributeNode(env, node):
return
entry
#
### Utility loading
#
def
load_memview_cy_utility
(
util_code_name
,
context
=
None
,
**
kwargs
):
return
CythonUtilityCode
.
load
(
util_code_name
,
"MemoryView.pyx"
,
context
=
context
,
**
kwargs
)
...
...
@@ -865,9 +869,9 @@ def load_memview_c_utility(util_code_name, context=None, **kwargs):
context
=
context
,
**
kwargs
)
def
use_cython_array_utility_code
(
env
):
scope
=
env
.
global_scope
().
context
.
cython_scope
scope
.
lookup
(
'array_cwrapper'
).
used
=
True
env
.
use_utility_code
(
cython_array_utility_code
)
cython_
scope
=
env
.
global_scope
().
context
.
cython_scope
cython_scope
.
load_cythonscope
()
cython_scope
.
viewscope
.
lookup
(
'array_cwrapper'
).
used
=
True
context
=
{
'memview_struct_name'
:
memview_objstruct_cname
,
...
...
@@ -916,15 +920,4 @@ view_utility_code = load_memview_cy_utility(
copy_contents_new_utility
],
)
cython_array_utility_code
=
load_memview_cy_utility
(
"CythonArray"
,
context
=
context
,
requires
=
[
view_utility_code
])
copy_contents_new_utility
.
requires
.
append
(
cython_array_utility_code
)
# memview_fromslice_utility_code = load_memview_cy_utility(
# "MemviewFromSlice",
# context=context,
# requires=[view_utility_code],
# )
copy_contents_new_utility
.
requires
.
append
(
view_utility_code
)
\ No newline at end of file
Cython/Utility/MemoryView.pyx
View file @
d88146d0
##########
CythonArray
##########
##########
########## View.MemoryView ##########
##########
cdef
extern
from
"stdlib.h"
:
void
*
malloc
(
size_t
)
void
free
(
void
*
)
# This utility provides cython.array and cython.view.memoryview
import
cython
# from cpython cimport ...
cdef
extern
from
"Python.h"
:
int
PyIndex_Check
(
object
)
object
PyLong_FromVoidPtr
(
void
*
)
cdef
extern
from
"pythread.h"
:
ctypedef
void
*
PyThread_type_lock
PyThread_type_lock
PyThread_allocate_lock
()
void
PyThread_free_lock
(
PyThread_type_lock
)
int
PyThread_acquire_lock
(
PyThread_type_lock
,
int
mode
)
nogil
void
PyThread_release_lock
(
PyThread_type_lock
)
nogil
cdef
extern
from
"string.h"
:
void
*
memset
(
void
*
b
,
int
c
,
size_t
len
)
cdef
extern
from
*
:
int
__Pyx_GetBuffer
(
object
,
Py_buffer
*
,
int
)
except
-
1
void
__Pyx_ReleaseBuffer
(
Py_buffer
*
)
ctypedef
struct
PyObject
void
Py_INCREF
(
PyObject
*
)
void
Py_DECREF
(
PyObject
*
)
cdef
struct
__pyx_memoryview
"__pyx_memoryview_obj"
:
Py_buffer
view
PyObject
*
obj
ctypedef
struct
{{
memviewslice_name
}}:
__pyx_memoryview
*
memview
char
*
data
Py_ssize_t
shape
[{{
max_dims
}}]
Py_ssize_t
strides
[{{
max_dims
}}]
Py_ssize_t
suboffsets
[{{
max_dims
}}]
void
__PYX_INC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
void
__PYX_XDEC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
ctypedef
struct
__pyx_buffer
"Py_buffer"
:
PyObject
*
obj
PyObject
*
Py_None
cdef
enum
:
PyBUF_C_CONTIGUOUS
,
...
...
@@ -12,22 +53,36 @@ cdef extern from "Python.h":
PyBUF_ANY_CONTIGUOUS
PyBUF_FORMAT
PyBUF_WRITABLE
PyBUF_STRIDES
PyBUF_INDIRECT
PyBUF_RECORDS
ctypedef
struct
PyObject
PyObject
*
Py_None
void
Py_INCREF
(
PyObject
*
)
cdef
extern
from
*
:
ctypedef
int
__pyx_atomic_int
{{
memviewslice_name
}}
slice_copy_contig
"__pyx_memoryview_copy_new_contig"
(
__Pyx_memviewslice
*
from_mvs
,
char
*
mode
,
int
ndim
,
size_t
sizeof_dtype
,
int
contig_flag
,
bint
dtype_is_object
)
nogil
except
*
bint
slice_is_contig
"__pyx_memviewslice_is_contig"
(
{{
memviewslice_name
}}
*
mvs
,
char
order
,
int
ndim
)
nogil
bint
slices_overlap
"__pyx_slices_overlap"
({{
memviewslice_name
}}
*
slice1
,
{{
memviewslice_name
}}
*
slice2
,
int
ndim
,
size_t
itemsize
)
nogil
cdef
extern
from
*
:
object
__pyx_memoryview_new
(
object
obj
,
int
flags
,
bint
dtype_is_object
)
Py_ssize_t
fill_contig_strides_array
"__pyx_fill_contig_strides_array"
(
Py_ssize_t
*
shape
,
Py_ssize_t
*
strides
,
Py_ssize_t
stride
,
int
ndim
,
char
order
)
nogil
cdef
extern
from
"stdlib.h"
:
void
*
malloc
(
size_t
)
nogil
void
free
(
void
*
)
nogil
void
*
memcpy
(
void
*
dest
,
void
*
src
,
size_t
n
)
nogil
cdef
void
refcount_objects_in_slice
"__pyx_memoryview_refcount_objects_in_slice"
(
char
*
data
,
Py_ssize_t
*
shape
,
Py_ssize_t
*
strides
,
int
ndim
,
bint
inc
)
#
### cython.array class
#
@
cname
(
"__pyx_array"
)
cdef
class
array
:
...
...
@@ -154,14 +209,9 @@ cdef class array:
property
memview
:
@
cname
(
'__pyx_cython_array_get_memview'
)
def
__get__
(
self
):
# Make this a property as 'data' may be set after instantiation
#if self._memview is None:
# flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
# self._memview = __pyx_memoryview_new(self, flags)
#return self._memview
# Make this a property as 'self.data' may be set after instantiation
flags
=
PyBUF_ANY_CONTIGUOUS
|
PyBUF_FORMAT
|
PyBUF_WRITABLE
return
__pyx_memoryview_n
ew
(
self
,
flags
,
self
.
dtype_is_object
)
return
memoryvi
ew
(
self
,
flags
,
self
.
dtype_is_object
)
def
__getattr__
(
self
,
attr
):
...
...
@@ -189,90 +239,9 @@ cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format,
return
result
#################### View.MemoryView ####################
import
cython
# from cpython cimport ...
cdef
extern
from
"Python.h"
:
int
PyIndex_Check
(
object
)
object
PyLong_FromVoidPtr
(
void
*
)
cdef
extern
from
"pythread.h"
:
ctypedef
void
*
PyThread_type_lock
PyThread_type_lock
PyThread_allocate_lock
()
void
PyThread_free_lock
(
PyThread_type_lock
)
int
PyThread_acquire_lock
(
PyThread_type_lock
,
int
mode
)
nogil
void
PyThread_release_lock
(
PyThread_type_lock
)
nogil
cdef
extern
from
"string.h"
:
void
*
memset
(
void
*
b
,
int
c
,
size_t
len
)
cdef
extern
from
*
:
int
__Pyx_GetBuffer
(
object
,
Py_buffer
*
,
int
)
except
-
1
void
__Pyx_ReleaseBuffer
(
Py_buffer
*
)
ctypedef
struct
PyObject
void
Py_INCREF
(
PyObject
*
)
void
Py_DECREF
(
PyObject
*
)
cdef
struct
__pyx_memoryview
"__pyx_memoryview_obj"
:
Py_buffer
view
PyObject
*
obj
ctypedef
struct
{{
memviewslice_name
}}:
__pyx_memoryview
*
memview
char
*
data
Py_ssize_t
shape
[{{
max_dims
}}]
Py_ssize_t
strides
[{{
max_dims
}}]
Py_ssize_t
suboffsets
[{{
max_dims
}}]
void
__PYX_INC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
void
__PYX_XDEC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
ctypedef
struct
__pyx_buffer
"Py_buffer"
:
PyObject
*
obj
PyObject
*
Py_None
cdef
enum
:
PyBUF_C_CONTIGUOUS
,
PyBUF_F_CONTIGUOUS
,
PyBUF_ANY_CONTIGUOUS
PyBUF_FORMAT
PyBUF_WRITABLE
PyBUF_STRIDES
PyBUF_INDIRECT
PyBUF_RECORDS
cdef
extern
from
*
:
ctypedef
int
__pyx_atomic_int
{{
memviewslice_name
}}
slice_copy_contig
"__pyx_memoryview_copy_new_contig"
(
__Pyx_memviewslice
*
from_mvs
,
char
*
mode
,
int
ndim
,
size_t
sizeof_dtype
,
int
contig_flag
,
bint
dtype_is_object
)
nogil
except
*
bint
slice_is_contig
"__pyx_memviewslice_is_contig"
(
{{
memviewslice_name
}}
*
mvs
,
char
order
,
int
ndim
)
nogil
bint
slices_overlap
"__pyx_slices_overlap"
({{
memviewslice_name
}}
*
slice1
,
{{
memviewslice_name
}}
*
slice2
,
int
ndim
,
size_t
itemsize
)
nogil
cdef
extern
from
"stdlib.h"
:
void
*
malloc
(
size_t
)
nogil
void
free
(
void
*
)
nogil
void
*
memcpy
(
void
*
dest
,
void
*
src
,
size_t
n
)
nogil
@
cname
(
'__pyx_MemviewEnum'
)
cdef
class
Enum
(
object
):
cdef
object
name
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__repr__
(
self
):
return
self
.
name
#
### Memoryview constants and cython.view.memoryview class
#
# Disable generic_contiguous, as it makes trouble verifying contiguity:
# - 'contiguous' or '::1' means the dimension is contiguous with dtype
...
...
@@ -290,6 +259,14 @@ cdef class Enum(object):
# would mean you'd have assert dimension 0 to be indirect (and pointer contiguous) at runtime.
# So it doesn't bring any performance benefit, and it's only confusing.
@
cname
(
'__pyx_MemviewEnum'
)
cdef
class
Enum
(
object
):
cdef
object
name
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__repr__
(
self
):
return
self
.
name
cdef
generic
=
Enum
(
"<strided and direct or indirect>"
)
cdef
strided
=
Enum
(
"<strided and direct>"
)
# default
cdef
indirect
=
Enum
(
"<strided and indirect>"
)
...
...
tests/run/cymemoryview.pyx
View file @
d88146d0
...
...
@@ -6,7 +6,10 @@ u'''
'''
# from cython.view cimport memoryview
from
cython
cimport
array
,
PyBUF_C_CONTIGUOUS
from
cython
cimport
array
cdef
extern
from
"Python.h"
:
cdef
int
PyBUF_C_CONTIGUOUS
def
f
():
pass
...
...
tests/run/memoryview.pyx
View file @
d88146d0
...
...
@@ -8,9 +8,12 @@ u'''
'''
from
cython.view
cimport
memoryview
from
cython
cimport
array
,
PyBUF_C_CONTIGUOUS
from
cython
cimport
array
from
cython
cimport
view
cdef
extern
from
"Python.h"
:
cdef
int
PyBUF_C_CONTIGUOUS
include
"mockbuffers.pxi"
#
...
...
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