InclusiveScanの兄弟・姉妹関数となるのがExclusiveScanです。
実装例は以下のようになります。InclusiveScanとの違いは出力を比較して見ていただければ分かるかと思います。
CLExclusiveScanKernelTest.py.
import pyopencl.array as clarr import pyopencl as cl import numpy as np ctx = cl.Context(cl.get_platforms()[0].get_devices(cl.device_type.GPU)) queue = cl.CommandQueue(ctx) from pyopencl.scan import ExclusiveScanKernel iscan = ExclusiveScanKernel(ctx, np.int32, "a+b", "0") a = np.arange(10).astype(np.int32) a_mem = clarr.to_device(queue, a) iscan(a_mem) print(a_mem.get())
出力.
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/komatsu/PycharmProjects/MyPythonProject/CLExclusiveScanKernelTest.py [ 0 0 1 3 6 10 15 21 28 36]
include::pyopencl-sort.asciidoc[]j
Copyright 2018-2019, by Masaki Komatsu