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):
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)
......
......@@ -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")
......@@ -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 CompilerError(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')
......
......@@ -192,6 +192,7 @@ def create_pipeline(context, mode, exclude_classes=()):
FinalOptimizePhase(context),
GilCheck(),
UseUtilityCodeDefinitions(context),
# PrintTree(),
]
filtered_stages = []
for s in stages:
......
......@@ -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')]
......
......@@ -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):
......
////////// 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
......
......@@ -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):
......
# 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
......@@ -151,16 +151,16 @@ def test_cython_utility_dep():
def viewobjs():
"""
>>> viewobjs()
<strided axis packing mode>
<contig axis packing mode>
<follow axis packing mode>
<direct axis access mode>
<ptr axis access mode>
<full axis access mode>
<strided and 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
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