quadrants.lang.buffer_view#

Classes#

BufferView

A view into a sub-range [offset, offset+size) of an ndarray.

Module Contents#

class quadrants.lang.buffer_view.BufferView(arr, offset, size)[source]#

A view into a sub-range [offset, offset+size) of an ndarray.

Create via slice syntax:

view = data[:16]           # offset=0, size=16
view = data[8:24]          # offset=8, size=16

Or construct directly:

view = qd.BufferView(data, offset=16, size=32)

Subviews can be created from an existing view:

sub = view.subview(offset=4, size=8)

Annotate kernel/func parameters with BufferView[dtype] or plain BufferView:

@qd.kernel
def k(v: BufferView[qd.f32]):
    for i in range(v.size):
        v[i] *= 2.0
arr[source]#
offset[source]#
size[source]#
property shape[source]#

Returns the shape of this view as a tuple, e.g. (16,).

subview(offset, size)[source]#

Create a sub-range view within this view, with bounds checking.

Offsets are relative to this view’s start, not the ndarray’s:

a = data[8:24]          # offset=8, size=16 into data
b = a.subview(4, 8)     # offset=12, size=8 into data
subscript(*indices)[source]#
get_ndarray()[source]#

Returns the underlying ndarray (host-side only).