torch.TypedArray
export type TypedArray = Float32Array | Int32Array | Uint32Array | Int8Array | Uint8Array;Values
Float32ArrayInt32ArrayUint32ArrayInt8ArrayUint8Array
Union type of all supported TypedArray types for CPU tensor storage.
TypedArrays provide low-level byte buffer access and typed views into tensor data stored in memory. This union type covers all typed arrays that correspond to supported dtypes.
Supported TypedArray Types:
- Float32Array: 32-bit floating point storage (dtype 'float32')
- Int32Array: 32-bit signed integer storage (dtype 'int32')
- Uint32Array: 32-bit unsigned integer storage (dtype 'uint32')
- Int8Array: 8-bit signed integer storage (dtype 'int8')
- Uint8Array: 8-bit unsigned integer storage (dtype 'uint8', 'bool')
Use Cases:
- Direct memory access for CPU tensors
- Bulk data transfer to/from GPUs
- Inter-worker communication
- Serialization and binary export
- Performance-critical loops with typed data
Memory Layout:
- All arrays use native byte order (little-endian on most systems)
- Contiguous memory allocation
- Direct mapping to tensor shape via strides
Examples
// Get TypedArray from CPU tensor
const tensor = torch.randn([3, 4], { device: 'cpu' });
const data: TypedArray = tensor.data; // Float32Array for float32 dtype
// Direct memory access
for (let i = 0; i < data.length; i++) {
const value = data[i];
}
// Bulk operations
const buffer = new Float32Array([1, 2, 3, 4]);
const tensor = torch.from_buffer(buffer, [2, 2]);
// Transfer between arrays
const uint8Data = new Uint8Array([0, 128, 255]);
const tensor = torch.from_buffer(uint8Data, [3], { dtype: 'uint8' });