Arrays¶
| Name | What it does |
|---|---|
Shape |
the dimensions of an array field |
DType |
the element type of an array field |
SupportsDLPack |
an object a DLPack library can import; a field annotated with it reads back sharedbox's own array |
register_array_type |
makes fields of another array type read back through that library's from_dlpack |
Shape
dataclass
¶
Dimensions of an array field, fixed when the class is defined.
It goes in the annotation, as in
Annotated[numpy.ndarray, Shape(480, 640), DType("uint8")].
Raises:
| Type | Description |
|---|---|
ValueError
|
Unless there are 1 to 8 dimensions, each an |
DType
dataclass
¶
Element type of an array field.
It takes a name as numpy spells it ("float32", "bfloat16",
"complex64", "bool"), a numpy.dtype or scalar type, or a
torch.dtype.
Raises:
| Type | Description |
|---|---|
ValueError
|
For an element type DLPack cannot describe. |
SupportsDLPack
¶
Bases: Protocol
An object another library can import through DLPack, such as numpy.from_dlpack takes.
A field annotated with it reads back sharedbox's own array object, which implements it.
register_array_type
¶
Read fields annotated with array_type back through from_dlpack.
from_dlpack receives the array a read copied out of the box and
returns one of array_type. Register before defining a class that
names the type; numpy and torch need no registration.