Commit 3bed371c authored by Kurt Smith's avatar Kurt Smith Committed by Mark Florisson

[mq]: memview-stuff

parent 4fd83ed2
......@@ -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)
......
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
......@@ -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:
......
......@@ -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
......
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')
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment