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
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
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
87 additions
and
67 deletions
+87
-67
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
tests/run/memoryviewattrs.pyx
tests/run/memoryviewattrs.pyx
+3
-3
No files found.
Cython/Compiler/Code.py
View file @
aad49345
...
...
@@ -60,7 +60,7 @@ class UtilityCodeBase(object):
def
_add_utility
(
cls
,
utility
,
type
,
lines
,
begin_lineno
):
if
utility
:
# Remember line numbers as least until after templating
code
=
''
*
begin_lineno
+
''
.
join
(
lines
)
code
=
'
\
n
'
*
begin_lineno
+
''
.
join
(
lines
)
if
type
==
'Proto'
:
utility
[
0
]
=
code
...
...
@@ -97,10 +97,6 @@ class UtilityCodeBase(object):
f
.
close
()
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
)
if
m
:
cls
.
_add_utility
(
utility
,
type
,
lines
,
begin_lineno
)
...
...
Cython/Compiler/CythonScope.py
View file @
aad49345
...
...
@@ -129,6 +129,6 @@ cython_test_extclass_utility_code = \
cythonview_testscope_utility_code
=
load_testscope_utility
(
"View.TestScope"
)
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/Compiler/MemoryView.py
View file @
aad49345
...
...
@@ -30,20 +30,20 @@ memview_full_access = "PyBUF_FULL"
#memview_strided_access = "PyBUF_STRIDED"
memview_strided_access
=
"PyBUF_RECORDS"
MEMVIEW_DIRECT
=
1
MEMVIEW_PTR
=
2
MEMVIEW_FULL
=
4
MEMVIEW_CONTIG
=
8
MEMVIEW_STRIDED
=
16
MEMVIEW_FOLLOW
=
32
MEMVIEW_DIRECT
=
'__Pyx_MEMVIEW_DIRECT'
MEMVIEW_PTR
=
'__Pyx_MEMVIEW_PTR'
MEMVIEW_FULL
=
'__Pyx_MEMVIEW_FULL'
MEMVIEW_CONTIG
=
'__Pyx_MEMVIEW_CONTIG'
MEMVIEW_STRIDED
=
'__Pyx_MEMVIEW_STRIDED'
MEMVIEW_FOLLOW
=
'__Pyx_MEMVIEW_FOLLOW'
_spec_to_const
=
{
'direct'
:
MEMVIEW_DIRECT
,
'ptr'
:
MEMVIEW_PTR
,
'full'
:
MEMVIEW_FULL
,
'contig'
:
MEMVIEW_CONTIG
,
'strided'
:
MEMVIEW_STRIDED
,
'follow'
:
MEMVIEW_FOLLOW
,
'direct'
:
MEMVIEW_DIRECT
,
'ptr'
:
MEMVIEW_PTR
,
'full'
:
MEMVIEW_FULL
}
memview_name
=
u'memoryview'
...
...
@@ -54,7 +54,8 @@ memviewslice_cname = u'__Pyx_memviewslice'
def
specs_to_code
(
specs
):
arr
=
[]
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
def
put_init_entry
(
mv_cname
,
code
):
...
...
@@ -563,36 +564,19 @@ def get_axes_specs(env, axes):
# all others are cf_packing.
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
)):
if
is_c_contig
or
is_f_contig
:
raise
CompileError
(
axis
.
step
.
pos
,
CF_ERR
)
resolved_spec
=
_get_resolved_spec
(
env
,
axis
.
step
)
if
resolved_spec
in
access_specs
:
axes_specs
.
append
((
resolved_spec
.
name
,
default_packing
))
elif
resolved_spec
in
packing_specs
:
axes_specs
.
append
((
default_access
,
resolved_spec
.
name
))
entry
=
_get_resolved_spec
(
env
,
axis
.
step
)
if
entry
.
name
in
view_constant_to_access_packing
:
axes_specs
.
append
(
view_constant_to_access_packing
[
entry
.
name
])
else
:
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
raise
Compile
r
Error
(
axis
.
step
.
pos
,
INVALID_ERR
)
else
:
raise
CompileError
(
axis
.
step
.
pos
,
INVALID_ERR
)
validate_axes_specs
(
axes
[
0
].
start
.
pos
,
axes_specs
)
return
axes_specs
...
...
@@ -636,6 +620,19 @@ def get_mode(specs):
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
):
packing_specs
=
(
'contig'
,
'strided'
,
'follow'
)
...
...
Cython/Compiler/Pipeline.py
View file @
aad49345
...
...
@@ -192,6 +192,7 @@ def create_pipeline(context, mode, exclude_classes=()):
FinalOptimizePhase
(
context
),
GilCheck
(),
UseUtilityCodeDefinitions
(
context
),
# PrintTree(),
]
filtered_stages
=
[]
for
s
in
stages
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
aad49345
...
...
@@ -435,7 +435,6 @@ class MemoryViewSliceType(PyrexType):
cname
=
'suboffsets'
,
is_cdef
=
1
)
mangle_dtype
=
MemoryView
.
mangle_dtype_name
(
self
.
dtype
)
ndim
=
len
(
self
.
axes
)
to_axes_c
=
[(
'direct'
,
'contig'
)]
...
...
Cython/Utility/MemoryView.pyx
View file @
aad49345
...
...
@@ -134,7 +134,7 @@ cdef class array:
cdef
array
array_cwrapper
(
tuple
shape
,
Py_ssize_t
itemsize
,
char
*
format
,
char
*
mode
):
return
array
(
shape
,
itemsize
,
format
,
mode
.
decode
(
'ASCII'
))
########## MemoryView ##########
##########
View.
MemoryView ##########
# from cpython cimport ...
cdef
extern
from
"pythread.h"
:
...
...
@@ -159,14 +159,14 @@ cdef class Enum(object):
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>"
)
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>"
)
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>"
)
# 'follow' is implied when the first or last axis is ::1
@
cname
(
'__pyx_memoryview'
)
cdef
class
memoryview
(
object
):
...
...
Cython/Utility/MemoryView_C.c
View file @
aad49345
////////// MemviewSliceStruct.proto //////////
/* memoryview slice struct */
typedef
struct
{
...
...
@@ -11,6 +12,7 @@ typedef struct {
Py_ssize_t
suboffsets
[{{
max_dims
}}];
}
{{
memviewslice_name
}};
////////// MemviewSliceInit.proto //////////
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
...
...
Cython/Utils.py
View file @
aad49345
...
...
@@ -131,8 +131,7 @@ class NormalisedNewlineStream(object):
content
.
append
(
data
)
data
=
self
.
read
(
0x1000
)
# TODO: FIXME: Shouldn't this return lines with their newline appended??
return
u''
.
join
(
content
).
split
(
u'
\
n
'
)
return
u''
.
join
(
content
).
splitlines
(
True
)
io
=
None
if
sys
.
version_info
>=
(
2
,
6
):
...
...
tests/compile/memview_declaration.pyx
View file @
aad49345
# mode: compile
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.view
cimport
(
generic
,
strided
,
indirect
,
generic_contiguous
,
contiguous
,
indirect_contiguous
)
cdef
char
[:]
one_dim
cdef
char
[:,:,:]
three_dim
...
...
@@ -14,6 +16,30 @@ cdef unsigned short int[::1] c_and_fort
cdef
long
long
[
0x0
::
0x1
,
00
:,
-
0
:,
0
:]
fort_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
[::
view
.
full
&
foo
]
view3
cdef
int
[::
view
.
ptr
&
view
.
strided
]
view1000
cdef
int
[::
generic
,
::
generic
]
a1
cdef
int
[::
strided
,
::
generic
]
a2
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():
def
viewobjs
():
"""
>>> viewobjs()
<strided a
xis packing mode
>
<
contig axis packing mode
>
<
follow axis packing mode
>
<
direct axis access mode
>
<
ptr axis access mode
>
<
full axis access mode
>
<strided a
nd direct or indirect
>
<
strided and direct
>
<
strided and indirect
>
<
contiguous and direct or indirect
>
<
contiguous and direct
>
<
contiguous and indirect
>
"""
print
cython
.
view
.
generic
print
cython
.
view
.
strided
print
cython
.
view
.
contig
print
cython
.
view
.
follow
print
cython
.
view
.
direct
print
cython
.
view
.
ptr
print
cython
.
view
.
full
print
cython
.
view
.
indirect
print
cython
.
view
.
generic_contiguous
print
cython
.
view
.
contiguous
print
cython
.
view
.
indirect_contiguous
tests/run/memoryviewattrs.pyx
View file @
aad49345
...
...
@@ -54,7 +54,7 @@ def test_copy_to():
cdef
int
*
from_dta
=
<
int
*>
from_mvs
.
_data
for
i
in
range
(
2
*
2
*
2
):
print
from_dta
[
i
],
print
print
# for i in range(2*2*2):
# from_dta[i] = i
...
...
@@ -63,10 +63,10 @@ def test_copy_to():
cdef
int
*
to_data
=
<
int
*>
to_mvs
.
_data
for
i
in
range
(
2
*
2
*
2
):
print
from_dta
[
i
],
print
print
for
i
in
range
(
2
*
2
*
2
):
print
to_data
[
i
],
print
print
@
testcase
@
cython
.
nonecheck
(
True
)
...
...
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