From fcad805d35a16efc4b9e42c9ef5950cf6c0693f2 Mon Sep 17 00:00:00 2001 From: gaikwadrahul8 <115997457+gaikwadrahul8@users.noreply.github.com> Date: Thu, 30 May 2024 05:45:25 +0530 Subject: [PATCH] Update supported TypedArray data types in tf.tensor in the documentation (#8287) * Update supported TypedArray data types in tf.tensor in the documentation * Address Exceeds maximum line length of 80 tslint error * Address Exceeds maximum line length of 80 tslint error again * Address no-consecutive-blank-lines tslint error --- tfjs-core/src/ops/tensor.ts | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tfjs-core/src/ops/tensor.ts b/tfjs-core/src/ops/tensor.ts index 9b664e07a07..b472ebdc662 100644 --- a/tfjs-core/src/ops/tensor.ts +++ b/tfjs-core/src/ops/tensor.ts @@ -172,28 +172,29 @@ import {makeTensor} from './tensor_ops_util'; * await tf.setBackend(savedBackend); * ``` * @param values The values of the tensor. Can be nested array of numbers, - * or a flat array, or a `TypedArray`, or a `WebGLData` object, or a - * `WebGPUData` object. If the values are strings, they will be encoded as utf-8 - * and kept as `Uint8Array[]`. If the values is a `WebGLData` object, the dtype - * could only be 'float32' or 'int32' and the object has to have: 1. texture, a - * `WebGLTexture`, the texture must share the same `WebGLRenderingContext` with - * TFJS's WebGL backend (you could create a custom WebGL backend from your - * texture's canvas) and the internal texture format for the input texture must - * be floating point or normalized integer; 2. height, the height of the - * texture; 3. width, the width of the texture; 4. channels, a non-empty subset - * of 'RGBA', indicating the values of which channels will be passed to the - * tensor, such as 'R' or 'BR' (The order of the channels affect the order of - * tensor values. ). (If the values passed from texture is less than the tensor - * size, zeros will be padded at the rear.). If the values is a `WebGPUData` - * object, the dtype could only be 'float32' or 'int32 and the object has to - * have: buffer, a `GPUBuffer`. The buffer must: 1. share the same `GPUDevice` - * with TFJS's WebGPU backend; 2. buffer.usage should at least support - * GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC; 3. buffer.size should not - * be smaller than the byte size of tensor shape. WebGPUData optionally supports - * zero copy by flag zeroCopy. When zeroCopy is false or undefined(default), - * this passing GPUBuffer can be destroyed after tensor is created. When - * zeroCopy is true, this GPUBuffer is bound directly by the tensor, so do not - * destroy this GPUBuffer until all access is done. + * or a flat array, or a `TypedArray`(At the moment it supports Uint8Array, + * Uint8ClampedArray, Int32Array, Float32Array) data types, or a `WebGLData` + * object, or a `WebGPUData` object. If the values are strings, they will be + * encoded as utf-8 and kept as `Uint8Array[]`. If the values is a `WebGLData` + * object, the dtype could only be 'float32' or 'int32' and the object has to + * have: 1. texture, a `WebGLTexture`, the texture must share the same + * `WebGLRenderingContext` with TFJS's WebGL backend (you could create a custom + * WebGL backend from your texture's canvas) and the internal texture format + * for the input texture must be floating point or normalized integer; 2. + * height, the height of the texture; 3. width, the width of the texture; 4. + * channels, a non-empty subset of 'RGBA', indicating the values of which + * channels will be passed to the tensor, such as 'R' or 'BR' (The order of the + * channels affect the order of tensor values. ). (If the values passed from + * texture is less than the tensor size, zeros will be padded at the rear.). If + * the values is a `WebGPUData` object, the dtype could only be 'float32' or + * 'int32 and the object has to have: buffer, a `GPUBuffer`. The buffer must: + * 1. share the same `GPUDevice` with TFJS's WebGPU backend; 2. buffer.usage + * should at least support GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC; 3. + * buffer.size should not be smaller than the byte size of tensor shape. + * WebGPUData optionally supports zero copy by flag zeroCopy. When zeroCopy is + * false or undefined(default),this passing GPUBuffer can be destroyed after + * tensor is created. When zeroCopy is true, this GPUBuffer is bound directly + * by the tensor, so do not destroy this GPUBuffer until all access is done. * @param shape The shape of the tensor. Optional. If not provided, * it is inferred from `values`. * @param dtype The data type. @@ -205,4 +206,4 @@ export function tensor( dtype?: DataType): Tensor { const inferredShape = inferShape(values, dtype); return makeTensor(values, shape, inferredShape, dtype) as Tensor; -} +} \ No newline at end of file