docarray.document.mixins.convert module#
- class docarray.document.mixins.convert.ConvertMixin[source]#
Bases:
object
Provide helper functions for
Document
to support conversion betweentensor
,text
andblob
.- convert_blob_to_tensor(dtype=None, count=-1, offset=0)[source]#
Assuming the
blob
is a _valid_ buffer of Numpy ndarray, settensor
accordingly.- Parameters:
dtype (
Optional
[str
]) – Data-type of the returned array; default: float.count (
int
) – Number of items to read.-1
means all data in the buffer.offset (
int
) – Start reading the buffer from this offset (in bytes); default: 0.
- Return type:
T
- Returns:
itself after processed
- convert_tensor_to_blob()[source]#
Convert
tensor
toblob
inplace.- Return type:
T
- Returns:
itself after processed
- convert_uri_to_datauri(charset='utf-8', base64=False)[source]#
Convert
uri
to dataURI and store it inuri
inplace.- Parameters:
charset (
str
) – charset may be any character set registered with IANAbase64 (
bool
) – used to encode arbitrary octet sequences into a form that satisfies the rules of 7bit. Designed to be efficient for non-text 8 bit and binary data. Sometimes used for text data that frequently uses non-US-ASCII characters.
- Return type:
T
- Returns:
itself after processed