Skip to content

Commit fcad805

Browse files
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
1 parent 737b8f1 commit fcad805

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tfjs-core/src/ops/tensor.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,29 @@ import {makeTensor} from './tensor_ops_util';
172172
* await tf.setBackend(savedBackend);
173173
* ```
174174
* @param values The values of the tensor. Can be nested array of numbers,
175-
* or a flat array, or a `TypedArray`, or a `WebGLData` object, or a
176-
* `WebGPUData` object. If the values are strings, they will be encoded as utf-8
177-
* and kept as `Uint8Array[]`. If the values is a `WebGLData` object, the dtype
178-
* could only be 'float32' or 'int32' and the object has to have: 1. texture, a
179-
* `WebGLTexture`, the texture must share the same `WebGLRenderingContext` with
180-
* TFJS's WebGL backend (you could create a custom WebGL backend from your
181-
* texture's canvas) and the internal texture format for the input texture must
182-
* be floating point or normalized integer; 2. height, the height of the
183-
* texture; 3. width, the width of the texture; 4. channels, a non-empty subset
184-
* of 'RGBA', indicating the values of which channels will be passed to the
185-
* tensor, such as 'R' or 'BR' (The order of the channels affect the order of
186-
* tensor values. ). (If the values passed from texture is less than the tensor
187-
* size, zeros will be padded at the rear.). If the values is a `WebGPUData`
188-
* object, the dtype could only be 'float32' or 'int32 and the object has to
189-
* have: buffer, a `GPUBuffer`. The buffer must: 1. share the same `GPUDevice`
190-
* with TFJS's WebGPU backend; 2. buffer.usage should at least support
191-
* GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC; 3. buffer.size should not
192-
* be smaller than the byte size of tensor shape. WebGPUData optionally supports
193-
* zero copy by flag zeroCopy. When zeroCopy is false or undefined(default),
194-
* this passing GPUBuffer can be destroyed after tensor is created. When
195-
* zeroCopy is true, this GPUBuffer is bound directly by the tensor, so do not
196-
* destroy this GPUBuffer until all access is done.
175+
* or a flat array, or a `TypedArray`(At the moment it supports Uint8Array,
176+
* Uint8ClampedArray, Int32Array, Float32Array) data types, or a `WebGLData`
177+
* object, or a `WebGPUData` object. If the values are strings, they will be
178+
* encoded as utf-8 and kept as `Uint8Array[]`. If the values is a `WebGLData`
179+
* object, the dtype could only be 'float32' or 'int32' and the object has to
180+
* have: 1. texture, a `WebGLTexture`, the texture must share the same
181+
* `WebGLRenderingContext` with TFJS's WebGL backend (you could create a custom
182+
* WebGL backend from your texture's canvas) and the internal texture format
183+
* for the input texture must be floating point or normalized integer; 2.
184+
* height, the height of the texture; 3. width, the width of the texture; 4.
185+
* channels, a non-empty subset of 'RGBA', indicating the values of which
186+
* channels will be passed to the tensor, such as 'R' or 'BR' (The order of the
187+
* channels affect the order of tensor values. ). (If the values passed from
188+
* texture is less than the tensor size, zeros will be padded at the rear.). If
189+
* the values is a `WebGPUData` object, the dtype could only be 'float32' or
190+
* 'int32 and the object has to have: buffer, a `GPUBuffer`. The buffer must:
191+
* 1. share the same `GPUDevice` with TFJS's WebGPU backend; 2. buffer.usage
192+
* should at least support GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC; 3.
193+
* buffer.size should not be smaller than the byte size of tensor shape.
194+
* WebGPUData optionally supports zero copy by flag zeroCopy. When zeroCopy is
195+
* false or undefined(default),this passing GPUBuffer can be destroyed after
196+
* tensor is created. When zeroCopy is true, this GPUBuffer is bound directly
197+
* by the tensor, so do not destroy this GPUBuffer until all access is done.
197198
* @param shape The shape of the tensor. Optional. If not provided,
198199
* it is inferred from `values`.
199200
* @param dtype The data type.
@@ -205,4 +206,4 @@ export function tensor<R extends Rank>(
205206
dtype?: DataType): Tensor<R> {
206207
const inferredShape = inferShape(values, dtype);
207208
return makeTensor(values, shape, inferredShape, dtype) as Tensor<R>;
208-
}
209+
}

0 commit comments

Comments
 (0)