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
aad49345
Commit
aad49345
authored
Jul 24, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change memview access and packing modifier constants
parent
f0b5aafa
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
84 additions
and
64 deletions
+84
-64
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+1
-5
Cython/Compiler/CythonScope.py
Cython/Compiler/CythonScope.py
+1
-1
Cython/Compiler/MemoryView.py
Cython/Compiler/MemoryView.py
+29
-32
Cython/Compiler/Pipeline.py
Cython/Compiler/Pipeline.py
+1
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+0
-1
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+8
-8
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+2
-0
Cython/Utils.py
Cython/Utils.py
+1
-2
tests/compile/memview_declaration.pyx
tests/compile/memview_declaration.pyx
+30
-4
tests/run/cythonscope.pyx
tests/run/cythonscope.pyx
+11
-11
No files found.
Cython/Compiler/Code.py
View file @
aad49345
...
@@ -60,7 +60,7 @@ class UtilityCodeBase(object):
...
@@ -60,7 +60,7 @@ class UtilityCodeBase(object):
def
_add_utility
(
cls
,
utility
,
type
,
lines
,
begin_lineno
):
def
_add_utility
(
cls
,
utility
,
type
,
lines
,
begin_lineno
):
if
utility
:
if
utility
:
# Remember line numbers as least until after templating
# Remember line numbers as least until after templating
code
=
''
*
begin_lineno
+
''
.
join
(
lines
)
code
=
'
\
n
'
*
begin_lineno
+
''
.
join
(
lines
)
if
type
==
'Proto'
:
if
type
==
'Proto'
:
utility
[
0
]
=
code
utility
[
0
]
=
code
...
@@ -97,10 +97,6 @@ class UtilityCodeBase(object):
...
@@ -97,10 +97,6 @@ class UtilityCodeBase(object):
f
.
close
()
f
.
close
()
for
lineno
,
line
in
enumerate
(
all_lines
):
for
lineno
,
line
in
enumerate
(
all_lines
):
# apparently 'line' may be without trailing newline
# (NormalisedNewlineStream.readlines())
line
=
line
.
rstrip
()
+
'
\
n
'
m
=
re
.
search
(
regex
,
line
)
m
=
re
.
search
(
regex
,
line
)
if
m
:
if
m
:
cls
.
_add_utility
(
utility
,
type
,
lines
,
begin_lineno
)
cls
.
_add_utility
(
utility
,
type
,
lines
,
begin_lineno
)
...
...
Cython/Compiler/CythonScope.py
View file @
aad49345
...
@@ -129,6 +129,6 @@ cython_test_extclass_utility_code = \
...
@@ -129,6 +129,6 @@ cython_test_extclass_utility_code = \
cythonview_testscope_utility_code
=
load_testscope_utility
(
"View.TestScope"
)
cythonview_testscope_utility_code
=
load_testscope_utility
(
"View.TestScope"
)
view_utility_code
=
MemoryView
.
load_memview_cy_utility
(
view_utility_code
=
MemoryView
.
load_memview_cy_utility
(
"MemoryView"
,
requires
=
(
Buffer
.
GetAndReleaseBufferUtilityCode
(),))
"
View.
MemoryView"
,
requires
=
(
Buffer
.
GetAndReleaseBufferUtilityCode
(),))
cython_array_utility_code
=
MemoryView
.
load_memview_cy_utility
(
"CythonArray"
)
cython_array_utility_code
=
MemoryView
.
load_memview_cy_utility
(
"CythonArray"
)
Cython/Compiler/MemoryView.py
View file @
aad49345
...
@@ -30,20 +30,20 @@ memview_full_access = "PyBUF_FULL"
...
@@ -30,20 +30,20 @@ memview_full_access = "PyBUF_FULL"
#memview_strided_access = "PyBUF_STRIDED"
#memview_strided_access = "PyBUF_STRIDED"
memview_strided_access
=
"PyBUF_RECORDS"
memview_strided_access
=
"PyBUF_RECORDS"
MEMVIEW_DIRECT
=
1
MEMVIEW_DIRECT
=
'__Pyx_MEMVIEW_DIRECT'
MEMVIEW_PTR
=
2
MEMVIEW_PTR
=
'__Pyx_MEMVIEW_PTR'
MEMVIEW_FULL
=
4
MEMVIEW_FULL
=
'__Pyx_MEMVIEW_FULL'
MEMVIEW_CONTIG
=
8
MEMVIEW_CONTIG
=
'__Pyx_MEMVIEW_CONTIG'
MEMVIEW_STRIDED
=
16
MEMVIEW_STRIDED
=
'__Pyx_MEMVIEW_STRIDED'
MEMVIEW_FOLLOW
=
32
MEMVIEW_FOLLOW
=
'__Pyx_MEMVIEW_FOLLOW'
_spec_to_const
=
{
_spec_to_const
=
{
'direct'
:
MEMVIEW_DIRECT
,
'ptr'
:
MEMVIEW_PTR
,
'full'
:
MEMVIEW_FULL
,
'contig'
:
MEMVIEW_CONTIG
,
'contig'
:
MEMVIEW_CONTIG
,
'strided'
:
MEMVIEW_STRIDED
,
'strided'
:
MEMVIEW_STRIDED
,
'follow'
:
MEMVIEW_FOLLOW
,
'follow'
:
MEMVIEW_FOLLOW
,
'direct'
:
MEMVIEW_DIRECT
,
'ptr'
:
MEMVIEW_PTR
,
'full'
:
MEMVIEW_FULL
}
}
memview_name
=
u'memoryview'
memview_name
=
u'memoryview'
...
@@ -54,7 +54,8 @@ memviewslice_cname = u'__Pyx_memviewslice'
...
@@ -54,7 +54,8 @@ memviewslice_cname = u'__Pyx_memviewslice'
def
specs_to_code
(
specs
):
def
specs_to_code
(
specs
):
arr
=
[]
arr
=
[]
for
access
,
packing
in
specs
:
for
access
,
packing
in
specs
:
arr
.
append
(
"(%s | %s)"
%
(
_spec_to_const
[
access
],
_spec_to_const
[
packing
]))
arr
.
append
(
"(%s | %s)"
%
(
_spec_to_const
[
access
],
_spec_to_const
[
packing
]))
return
arr
return
arr
def
put_init_entry
(
mv_cname
,
code
):
def
put_init_entry
(
mv_cname
,
code
):
...
@@ -563,36 +564,19 @@ def get_axes_specs(env, axes):
...
@@ -563,36 +564,19 @@ def get_axes_specs(env, axes):
# all others are cf_packing.
# all others are cf_packing.
axes_specs
.
append
((
cf_access
,
'contig'
))
axes_specs
.
append
((
cf_access
,
'contig'
))
elif
isinstance
(
axis
.
step
,
IntBinopNode
):
if
is_c_contig
or
is_f_contig
:
raise
CompileError
(
axis
.
step
.
pos
,
CF_ERR
)
if
axis
.
step
.
operator
!=
u'&'
:
raise
CompileError
(
axis
.
step
.
pos
,
NOT_AMP_ERR
)
operand1
,
operand2
=
axis
.
step
.
operand1
,
axis
.
step
.
operand2
spec1
,
spec2
=
[
_get_resolved_spec
(
env
,
op
)
for
op
in
(
operand1
,
operand2
)]
if
spec1
in
access_specs
and
spec2
in
packing_specs
:
axes_specs
.
append
((
spec1
.
name
,
spec2
.
name
))
elif
spec2
in
access_specs
and
spec1
in
packing_specs
:
axes_specs
.
append
((
spec2
.
name
,
spec1
.
name
))
else
:
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
elif
isinstance
(
axis
.
step
,
(
NameNode
,
AttributeNode
)):
elif
isinstance
(
axis
.
step
,
(
NameNode
,
AttributeNode
)):
if
is_c_contig
or
is_f_contig
:
if
is_c_contig
or
is_f_contig
:
raise
CompileError
(
axis
.
step
.
pos
,
CF_ERR
)
raise
CompileError
(
axis
.
step
.
pos
,
CF_ERR
)
resolved_spec
=
_get_resolved_spec
(
env
,
axis
.
step
)
if
resolved_spec
in
access_specs
:
entry
=
_get_resolved_spec
(
env
,
axis
.
step
)
axes_specs
.
append
((
resolved_spec
.
name
,
default_packing
))
if
entry
.
name
in
view_constant_to_access_packing
:
elif
resolved_spec
in
packing_specs
:
axes_specs
.
append
(
view_constant_to_access_packing
[
entry
.
name
])
axes_specs
.
append
((
default_access
,
resolved_spec
.
name
))
else
:
else
:
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
raise
Compile
r
Error
(
axis
.
step
.
pos
,
INVALID_ERR
)
else
:
else
:
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
validate_axes_specs
(
axes
[
0
].
start
.
pos
,
axes_specs
)
validate_axes_specs
(
axes
[
0
].
start
.
pos
,
axes_specs
)
return
axes_specs
return
axes_specs
...
@@ -636,6 +620,19 @@ def get_mode(specs):
...
@@ -636,6 +620,19 @@ def get_mode(specs):
return
'strided'
return
'strided'
view_constant_to_access_packing
=
{
'generic'
:
(
'full'
,
'strided'
),
'strided'
:
(
'direct'
,
'strided'
),
'indirect'
:
(
'ptr'
,
'strided'
),
'generic_contiguous'
:
(
'full'
,
'contig'
),
'contiguous'
:
(
'direct'
,
'contig'
),
'indirect_contiguous'
:
(
'ptr'
,
'contig'
),
}
def
get_access_packing
(
view_scope_constant
):
if
view_scope_constant
.
name
==
'generic'
:
return
'full'
,
def
validate_axes_specs
(
pos
,
specs
):
def
validate_axes_specs
(
pos
,
specs
):
packing_specs
=
(
'contig'
,
'strided'
,
'follow'
)
packing_specs
=
(
'contig'
,
'strided'
,
'follow'
)
...
...
Cython/Compiler/Pipeline.py
View file @
aad49345
...
@@ -192,6 +192,7 @@ def create_pipeline(context, mode, exclude_classes=()):
...
@@ -192,6 +192,7 @@ def create_pipeline(context, mode, exclude_classes=()):
FinalOptimizePhase
(
context
),
FinalOptimizePhase
(
context
),
GilCheck
(),
GilCheck
(),
UseUtilityCodeDefinitions
(
context
),
UseUtilityCodeDefinitions
(
context
),
# PrintTree(),
]
]
filtered_stages
=
[]
filtered_stages
=
[]
for
s
in
stages
:
for
s
in
stages
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
aad49345
...
@@ -435,7 +435,6 @@ class MemoryViewSliceType(PyrexType):
...
@@ -435,7 +435,6 @@ class MemoryViewSliceType(PyrexType):
cname
=
'suboffsets'
,
cname
=
'suboffsets'
,
is_cdef
=
1
)
is_cdef
=
1
)
mangle_dtype
=
MemoryView
.
mangle_dtype_name
(
self
.
dtype
)
ndim
=
len
(
self
.
axes
)
ndim
=
len
(
self
.
axes
)
to_axes_c
=
[(
'direct'
,
'contig'
)]
to_axes_c
=
[(
'direct'
,
'contig'
)]
...
...
Cython/Utility/MemoryView.pyx
View file @
aad49345
...
@@ -134,7 +134,7 @@ cdef class array:
...
@@ -134,7 +134,7 @@ cdef class array:
cdef
array
array_cwrapper
(
tuple
shape
,
Py_ssize_t
itemsize
,
char
*
format
,
char
*
mode
):
cdef
array
array_cwrapper
(
tuple
shape
,
Py_ssize_t
itemsize
,
char
*
format
,
char
*
mode
):
return
array
(
shape
,
itemsize
,
format
,
mode
.
decode
(
'ASCII'
))
return
array
(
shape
,
itemsize
,
format
,
mode
.
decode
(
'ASCII'
))
########## MemoryView ##########
##########
View.
MemoryView ##########
# from cpython cimport ...
# from cpython cimport ...
cdef
extern
from
"pythread.h"
:
cdef
extern
from
"pythread.h"
:
...
@@ -159,14 +159,14 @@ cdef class Enum(object):
...
@@ -159,14 +159,14 @@ cdef class Enum(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
self
.
name
return
self
.
name
cdef
generic
=
Enum
(
"<strided and direct or indirect>"
)
cdef
strided
=
Enum
(
"<strided and direct>"
)
# default
cdef
indirect
=
Enum
(
"<strided and indirect>"
)
cdef
generic_contiguous
=
Enum
(
"<contiguous and direct or indirect>"
)
cdef
contiguous
=
Enum
(
"<contiguous and direct>"
)
cdef
indirect_contiguous
=
Enum
(
"<contiguous and indirect>"
)
cdef
strided
=
Enum
(
"<strided axis packing mode>"
)
# 'follow' is implied when the first or last axis is ::1
cdef
contig
=
Enum
(
"<contig axis packing mode>"
)
cdef
follow
=
Enum
(
"<follow axis packing mode>"
)
cdef
direct
=
Enum
(
"<direct axis access mode>"
)
cdef
ptr
=
Enum
(
"<ptr axis access mode>"
)
cdef
full
=
Enum
(
"<full axis access mode>"
)
@
cname
(
'__pyx_memoryview'
)
@
cname
(
'__pyx_memoryview'
)
cdef
class
memoryview
(
object
):
cdef
class
memoryview
(
object
):
...
...
Cython/Utility/MemoryView_C.c
View file @
aad49345
////////// MemviewSliceStruct.proto //////////
////////// MemviewSliceStruct.proto //////////
/* memoryview slice struct */
/* memoryview slice struct */
typedef
struct
{
typedef
struct
{
...
@@ -11,6 +12,7 @@ typedef struct {
...
@@ -11,6 +12,7 @@ typedef struct {
Py_ssize_t
suboffsets
[{{
max_dims
}}];
Py_ssize_t
suboffsets
[{{
max_dims
}}];
}
{{
memviewslice_name
}};
}
{{
memviewslice_name
}};
////////// MemviewSliceInit.proto //////////
////////// MemviewSliceInit.proto //////////
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
...
...
Cython/Utils.py
View file @
aad49345
...
@@ -131,8 +131,7 @@ class NormalisedNewlineStream(object):
...
@@ -131,8 +131,7 @@ class NormalisedNewlineStream(object):
content
.
append
(
data
)
content
.
append
(
data
)
data
=
self
.
read
(
0x1000
)
data
=
self
.
read
(
0x1000
)
# TODO: FIXME: Shouldn't this return lines with their newline appended??
return
u''
.
join
(
content
).
splitlines
(
True
)
return
u''
.
join
(
content
).
split
(
u'
\
n
'
)
io
=
None
io
=
None
if
sys
.
version_info
>=
(
2
,
6
):
if
sys
.
version_info
>=
(
2
,
6
):
...
...
tests/compile/memview_declaration.pyx
View file @
aad49345
# mode: compile
# mode: compile
cimport
cython
cimport
cython
from
cython.view
cimport
contig
as
foo
,
full
as
bar
#, follow
#
from cython.view cimport contig as foo, full as bar #, follow
from
cython
cimport
view
from
cython
cimport
view
from
cython.view
cimport
(
generic
,
strided
,
indirect
,
generic_contiguous
,
contiguous
,
indirect_contiguous
)
cdef
char
[:]
one_dim
cdef
char
[:]
one_dim
cdef
char
[:,:,:]
three_dim
cdef
char
[:,:,:]
three_dim
...
@@ -14,6 +16,30 @@ cdef unsigned short int[::1] c_and_fort
...
@@ -14,6 +16,30 @@ cdef unsigned short int[::1] c_and_fort
cdef
long
long
[
0x0
::
0x1
,
00
:,
-
0
:,
0
:]
fort_contig0
cdef
long
long
[
0x0
::
0x1
,
00
:,
-
0
:,
0
:]
fort_contig0
cdef
unsigned
long
[
0
:,
0
:,
0
:,
0
::
0x0001
]
c_contig0
cdef
unsigned
long
[
0
:,
0
:,
0
:,
0
::
0x0001
]
c_contig0
#cdef float[::foo & bar, ::cython.view.direct & cython.view.follow] view4 # shrug
cdef
int
[::
generic
,
::
generic
]
a1
cdef
int
[::
view
.
full
&
foo
]
view3
cdef
int
[::
strided
,
::
generic
]
a2
cdef
int
[::
view
.
ptr
&
view
.
strided
]
view1000
cdef
int
[::
indirect
,
::
generic
]
a3
cdef
int
[::
generic
,
::
strided
]
a4
cdef
int
[::
strided
,
::
strided
]
a5
cdef
int
[::
indirect
,
::
strided
]
a6
cdef
int
[::
generic
,
::
indirect
]
a7
cdef
int
[::
strided
,
::
indirect
]
a8
cdef
int
[::
indirect
,
::
indirect
]
a9
cdef
int
[::
generic
,
::
generic_contiguous
]
a10
cdef
int
[::
strided
,
::
generic_contiguous
]
a11
cdef
int
[::
indirect
,
::
generic_contiguous
]
a12
cdef
int
[::
generic
,
::
contiguous
]
a13
cdef
int
[::
strided
,
::
contiguous
]
a14
cdef
int
[::
indirect
,
::
contiguous
]
a15
cdef
int
[::
generic
,
::
indirect_contiguous
]
a16
cdef
int
[::
strided
,
::
indirect_contiguous
]
a17
cdef
int
[::
indirect
,
::
indirect_contiguous
]
a18
cdef
int
[::
generic
,
::]
a19
cdef
int
[::
strided
,
:]
a20
cdef
int
[::
indirect
,
:]
a21
cdef
int
[::
generic_contiguous
,
:]
a22
cdef
int
[::
contiguous
,
:]
a23
cdef
int
[::
indirect_contiguous
,
:]
a24
tests/run/cythonscope.pyx
View file @
aad49345
...
@@ -151,16 +151,16 @@ def test_cython_utility_dep():
...
@@ -151,16 +151,16 @@ def test_cython_utility_dep():
def
viewobjs
():
def
viewobjs
():
"""
"""
>>> viewobjs()
>>> viewobjs()
<strided a
xis packing mode
>
<strided a
nd direct or indirect
>
<
contig axis packing mode
>
<
strided and direct
>
<
follow axis packing mode
>
<
strided and indirect
>
<
direct axis access mode
>
<
contiguous and direct or indirect
>
<
ptr axis access mode
>
<
contiguous and direct
>
<
full axis access mode
>
<
contiguous and indirect
>
"""
"""
print
cython
.
view
.
generic
print
cython
.
view
.
strided
print
cython
.
view
.
strided
print
cython
.
view
.
contig
print
cython
.
view
.
indirect
print
cython
.
view
.
follow
print
cython
.
view
.
generic_contiguous
print
cython
.
view
.
direct
print
cython
.
view
.
contiguous
print
cython
.
view
.
ptr
print
cython
.
view
.
indirect_contiguous
print
cython
.
view
.
full
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