diff options
author | Mark Florisson <markflorisson88@gmail.com> | 2012-01-17 15:14:10 +0000 |
---|---|---|
committer | Mark Florisson <markflorisson88@gmail.com> | 2012-01-22 19:04:20 +0000 |
commit | ca91ec9b69b30a2c8bbb6db020a80db12af707f3 (patch) | |
tree | 55f3de0482e46ee413216156e7ebc8b90bc24544 /Cython/Compiler/MemoryView.py | |
parent | 017b73ae4a275f09223f48045a2a4e079f2cc027 (diff) | |
download | cython-ca91ec9b69b30a2c8bbb6db020a80db12af707f3.tar.gz |
slice assignment broadcasting & fix some bugs
Diffstat (limited to 'Cython/Compiler/MemoryView.py')
-rw-r--r-- | Cython/Compiler/MemoryView.py | 60 |
1 files changed, 12 insertions, 48 deletions
diff --git a/Cython/Compiler/MemoryView.py b/Cython/Compiler/MemoryView.py index 3bd25d70a..fca6b3ba7 100644 --- a/Cython/Compiler/MemoryView.py +++ b/Cython/Compiler/MemoryView.py @@ -431,57 +431,20 @@ def verify_direct_dimensions(node): for access, packing in node.type.axes: if access != 'direct': error(self.pos, "All dimensions must be direct") - return False - - return True - -def broadcast(src, dst, src_temp, dst_temp, code): - "Perform an in-place broadcast of slices src and dst" - if src.type.ndim != dst.type.ndim: - code.putln("__pyx_memoryview_broadcast_inplace(&%s, &%s, %d, %d);" % ( - src_temp, dst_temp, src.type.ndim, dst.type.ndim)) - return max(src.type.ndim, dst.type.ndim) - return src.type.ndim - -def copy_broadcast_memview_src_to_dst_inplace(src, dst, src_temp, dst_temp, code): +def copy_broadcast_memview_src_to_dst(src, dst, code): """ - It is hard to check for overlapping memory with indirect slices, - so we currently don't support them. + Copy the contents of slice src to slice dst. Does not support indirect + slices. """ - if not verify_direct_dimensions(src): return - if not verify_direct_dimensions(dst): return - - ndim = broadcast(src, dst, src_temp, dst_temp, code) - call = "%s(&%s, &%s, %d)" % (copy_src_to_dst_cname(), - src_temp, dst_temp, ndim) - code.putln(code.error_goto_if_neg(call, dst.pos)) - -def copy_broadcast_memview_src_to_dst(src, dst, code): - # Note: do not use code.funcstate.allocate_temp to allocate temps, as - # temps will be acquisition counted (so we would need new - # references, as any sudden exception would cause a jump leading to - # a decref before we can nullify our slice) - - src_tmp = None - dst_tmp = None - - code.begin_block() - - if src.type.ndim < dst.type.ndim and not src.result_in_temp(): - src_tmp = '__pyx_slice_tmp1' - code.putln("%s %s = %s;" % (memviewslice_cname, src_tmp, src.result())) - - if dst.type.ndim < src.type.ndim and not dst.result_in_temp(): - dst_tmp = '__pyx+_slice_tmp2' - code.putln("%s %s = %s;" % (memviewslice_cname, dst_tmp, dst.result())) - - copy_broadcast_memview_src_to_dst_inplace(src, dst, - src_tmp or src.result(), - dst_tmp or dst.result(), - code) + verify_direct_dimensions(src) + verify_direct_dimensions(dst) - code.end_block() + code.putln(code.error_goto_if_neg( + "%s(%s, %s, %d, %d)" % (copy_src_to_dst_cname(), + src.result(), dst.result(), + src.type.ndim, dst.type.ndim), + dst.pos)) def copy_c_or_fortran_cname(memview): if memview.is_c_contig: @@ -791,7 +754,8 @@ def load_memview_c_utility(util_code_name, context=None, **kwargs): context=context, **kwargs) def use_cython_array_utility_code(env): - env.global_scope().context.cython_scope.lookup('array_cwrapper').used = True + scope = env.global_scope().context.cython_scope + scope.lookup('array_cwrapper').used = True env.use_utility_code(cython_array_utility_code) context = { |