Commit aad49345 authored by Mark Florisson's avatar Mark Florisson

Change memview access and packing modifier constants

parent f0b5aafa
...@@ -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)
......
...@@ -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")
...@@ -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 CompilerError(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')
......
...@@ -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:
......
...@@ -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')]
......
...@@ -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):
......
////////// 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
......
...@@ -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):
......
# 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
...@@ -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 axis packing mode> <strided and 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
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