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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
3bed371c
Commit
3bed371c
authored
Jul 11, 2009
by
Kurt Smith
Committed by
Mark Florisson
Sep 30, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[mq]: memview-stuff
parent
4fd83ed2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
1 deletion
+101
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-0
Cython/Compiler/MemoryView.py
Cython/Compiler/MemoryView.py
+41
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Compiler/Pipeline.py
Cython/Compiler/Pipeline.py
+4
-0
tests/run/cymemoryview.pyx
tests/run/cymemoryview.pyx
+15
-0
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+39
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
3bed371c
...
...
@@ -7809,6 +7809,7 @@ class CoerceFromPyTypeNode(CoercionNode):
CoercionNode
.
__init__
(
self
,
arg
)
self
.
type
=
result_type
self
.
is_temp
=
1
import
pdb
;
pdb
.
set_trace
()
if
not
result_type
.
create_from_py_utility_code
(
env
):
error
(
arg
.
pos
,
"Cannot convert Python object to '%s'"
%
result_type
)
...
...
Cython/Compiler/MemoryView.py
View file @
3bed371c
from
Errors
import
CompileError
from
ExprNodes
import
IntNode
,
NoneNode
,
IntBinopNode
,
NameNode
,
AttributeNode
from
Visitor
import
CythonTransform
START_ERR
=
"there must be nothing or the value 0 (zero) in the start slot."
STOP_ERR
=
"Axis specification only allowed in the 'stop' slot."
...
...
@@ -186,3 +187,43 @@ def _resolve_AttributeNode(env, node):
scope
=
scope
.
lookup
(
modname
).
as_module
return
scope
.
lookup
(
path
[
-
1
])
class
MemoryViewTransform
(
CythonTransform
):
memviews_exist
=
False
def
__call__
(
self
,
node
):
return
super
(
MemoryViewTransform
,
self
).
__call__
(
node
)
def
inspect_scope
(
self
,
node
,
scope
):
memviewvars
=
[
entry
for
name
,
entry
in
scope
.
entries
.
iteritems
()
if
entry
.
type
.
is_memoryview
]
if
memviewvars
:
self
.
memviews_exist
=
True
def
visit_FuncDefNode
(
self
,
node
):
# check for the existence of memview entries here.
self
.
inspect_scope
(
node
,
node
.
local_scope
)
self
.
visitchildren
(
node
)
return
node
def
visit_ModuleNode
(
self
,
node
):
# check for memviews here.
self
.
inspect_scope
(
node
,
node
.
scope
)
self
.
visitchildren
(
node
)
return
node
def
visit_ClassDefNode
(
self
,
node
):
# check for memviews in the class scope
if
hasattr
(
node
,
'scope'
):
scope
=
node
.
scope
else
:
scope
=
node
.
entry
.
type
.
scope
self
.
inspect_scope
(
node
,
scope
)
self
.
visitchildren
(
node
)
return
node
def
visit_SingleAssignmentNode
(
self
,
node
):
import
pdb
;
pdb
.
set_trace
()
return
node
Cython/Compiler/Nodes.py
View file @
3bed371c
...
...
@@ -964,7 +964,7 @@ class CVarDefNode(StatNode):
else
:
name_declarator
,
type
=
declarator
.
analyse
(
base_type
,
env
)
if
not
type
.
is_complete
():
if
not
(
self
.
visibility
==
'extern'
and
type
.
is_array
):
if
not
(
self
.
visibility
==
'extern'
and
type
.
is_array
or
type
.
is_memoryview
):
error
(
declarator
.
pos
,
"Variable type '%s' is incomplete"
%
type
)
if
self
.
visibility
==
'extern'
and
type
.
is_pyobject
:
...
...
Cython/Compiler/Pipeline.py
View file @
3bed371c
...
...
@@ -113,6 +113,9 @@ def create_pipeline(context, mode, exclude_classes=()):
from
Optimize
import
DropRefcountingTransform
from
Buffer
import
IntroduceBufferAuxiliaryVars
from
ModuleNode
import
check_c_declarations
,
check_c_declarations_pxd
from
MemoryView
import
MemoryViewTransform
from
ModuleNode
import
check_c_declarations
if
mode
==
'pxd'
:
_check_c_declarations
=
check_c_declarations_pxd
...
...
@@ -155,6 +158,7 @@ def create_pipeline(context, mode, exclude_classes=()):
# MarkAssignments(context),
MarkOverflowingArithmetic
(
context
),
IntroduceBufferAuxiliaryVars
(
context
),
MemoryViewTransform
(
context
),
_check_c_declarations
,
AnalyseExpressionsTransform
(
context
),
CreateClosureClasses
(
context
),
## After all lookups and type inference
...
...
tests/run/cymemoryview.pyx
0 → 100644
View file @
3bed371c
u'''
>>> f()
>>> g()
'''
# from cython.view cimport memoryview
from
cython
cimport
array
,
PyBUF_C_CONTIGUOUS
def
f
():
pass
# cdef array arr = array(shape=(10,10), itemsize=sizeof(int), format='i')
# cdef memoryview mv = memoryview(arr, PyBUF_C_CONTIGUOUS)
def
g
():
# cdef int[::1] mview = array((10,), itemsize=sizeof(int), format='i')
cdef
int
[::
1
]
mview
=
array
((
10
,),
itemsize
=
sizeof
(
int
),
format
=
'i'
)
tests/run/memoryview.pyx
0 → 100644
View file @
3bed371c
u'''
>>> f()
>>> g()
'''
# from cython.view cimport memoryview
from
cython
cimport
array
,
PyBUF_C_CONTIGUOUS
def
f
():
pass
# cdef array arr = array(shape=(10,10), itemsize=sizeof(int), format='i')
# cdef memoryview mv = memoryview(arr, PyBUF_C_CONTIGUOUS)
def
g
():
# cdef int[::1] mview = array((10,), itemsize=sizeof(int), format='i')
cdef
int
[::
1
]
mview
=
array
((
10
,),
itemsize
=
sizeof
(
int
),
format
=
'i'
)
cdef
class
Foo
:
cdef
int
[:]
mview
def
__init__
(
self
):
self
.
mview
=
array
((
10
,),
itemsize
=
sizeof
(
int
),
format
=
'i'
)
class
pyfoo
:
def
__init__
(
self
):
cdef
int
arr
[
10
]
# self.mview = array((10,), itemsize=sizeof(long), format='l')
self
.
mview
=
arr
cdef
cdg
():
cdef
double
[:]
dmv
=
array
((
10
,),
itemsize
=
sizeof
(
double
),
format
=
'd'
)
cdef
float
[:,:]
global_mv
=
array
((
10
,
10
),
itemsize
=
sizeof
(
float
),
format
=
'f'
)
def
call
():
cdg
()
f
=
Foo
()
pf
=
pyfoo
()
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