-
public abstract class TensorRepresentation of an ExecuTorch Tensor. Behavior is similar to PyTorch's tensor objects.
Most tensors will be constructed as
Tensor.fromBlob(data, shape), wheredatacan be an array or a direct Buffer (of the proper subclass). Helper methods are provided to allocate buffers properly.To access Tensor data, see dtype, shape, and various
dataAs*properties.When constructing
Tensorobjects withdataas an array, it is not specified whether this data is copied or retained as a reference so it is recommended not to modify it after constructing.datapassed as a Buffer is not copied, so it can be modified between Module calls to avoid reallocation. Data retrieved fromTensorobjects may be copied or may be a reference to theTensor's internal data buffer.shapeis always copied.Warning: These APIs are experimental and subject to change without notice
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classTensor.Companion
-
Field Summary
Fields Modifier and Type Field Description private final ByteArraydataAsByteArrayprivate final ShortArraydataAsShortArrayprivate final ByteArraydataAsUnsignedByteArrayprivate final IntArraydataAsIntArrayprivate final FloatArraydataAsFloatArrayprivate final LongArraydataAsLongArrayprivate final DoubleArraydataAsDoubleArray
-
Method Summary
Modifier and Type Method Description ByteArraygetDataAsByteArray()ShortArraygetDataAsShortArray()ByteArraygetDataAsUnsignedByteArray()IntArraygetDataAsIntArray()FloatArraygetDataAsFloatArray()LongArraygetDataAsLongArray()DoubleArraygetDataAsDoubleArray()final Longnumel()Returns the number of elements in this tensor. final LongArrayshape()Returns the shape of this tensor. abstract DTypedtype()final IntegerdtypeJniCode()UnitcopyDataInto(FloatBuffer dst)Copies the tensor's data into a caller-provided FloatBuffer, avoiding the per-call allocation that dataAsFloatArray performs. UnitcopyDataInto(ByteBuffer dst)UnitcopyDataInto(IntBuffer dst)UnitcopyDataInto(LongBuffer dst)UnitcopyDataInto(DoubleBuffer dst)UnitcopyDataInto(ShortBuffer dst)UnitcopyDataIntoUnsigned(ByteBuffer dst)BuffergetRawDataBuffer()final ByteArraytoByteArray()Serializes a Tensorinto a byte array.-
-
Method Detail
-
getDataAsByteArray
ByteArray getDataAsByteArray()
-
getDataAsShortArray
ShortArray getDataAsShortArray()
-
getDataAsUnsignedByteArray
ByteArray getDataAsUnsignedByteArray()
-
getDataAsIntArray
IntArray getDataAsIntArray()
-
getDataAsFloatArray
FloatArray getDataAsFloatArray()
-
getDataAsLongArray
LongArray getDataAsLongArray()
-
getDataAsDoubleArray
DoubleArray getDataAsDoubleArray()
-
dtypeJniCode
final Integer dtypeJniCode()
-
copyDataInto
Unit copyDataInto(FloatBuffer dst)
Copies the tensor's data into a caller-provided FloatBuffer, avoiding the per-call allocation that dataAsFloatArray performs.
Supported by float32 (zero-copy bulk put) and float16 (per-element half-to-float widening). For raw fp16 bits without widening, use copyDataInto(ShortBuffer).
-
copyDataInto
Unit copyDataInto(ByteBuffer dst)
-
copyDataInto
Unit copyDataInto(IntBuffer dst)
-
copyDataInto
Unit copyDataInto(LongBuffer dst)
-
copyDataInto
Unit copyDataInto(DoubleBuffer dst)
-
copyDataInto
Unit copyDataInto(ShortBuffer dst)
-
copyDataIntoUnsigned
Unit copyDataIntoUnsigned(ByteBuffer dst)
-
getRawDataBuffer
Buffer getRawDataBuffer()
-
toByteArray
final ByteArray toByteArray()
Serializes a
Tensorinto a byte array. Note: This method is experimental and subject to change without notice. This does NOT support list type.
-
-
-
-