类型 TensorConstructor 定义了用于创建 CPU 张量实例的 'Tensor' 构造函数。

interface TensorConstructor {
    new TensorConstructornew (type, data, dims?): TypedTensor<"string">;
    new TensorConstructornew (type, data, dims?): TypedTensor<"bool">;
    new TensorConstructornew (type, data, dims?): TypedTensor<"uint8">;
    new TensorConstructornew <T>(type, data, dims?): TypedTensor<T>;
    new TensorConstructornew <T>(type, data, dims?): TypedTensor<T>;
    new TensorConstructornew (data, dims?): TypedTensor<"float32">;
    new TensorConstructornew (data, dims?): TypedTensor<"int8">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint8">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint8">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint16">;
    new TensorConstructornew (data, dims?): TypedTensor<"int16">;
    new TensorConstructornew (data, dims?): TypedTensor<"int32">;
    new TensorConstructornew (data, dims?): TypedTensor<"int64">;
    new TensorConstructornew (data, dims?): TypedTensor<"string">;
    new TensorConstructornew (data, dims?): TypedTensor<"bool">;
    new TensorConstructornew (data, dims?): TypedTensor<"float64">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint32">;
    new TensorConstructornew (data, dims?): TypedTensor<"uint64">;
    new TensorConstructornew (type, data, dims?): Tensor;
    new TensorConstructornew (data, dims?): Tensor;
    fromGpuBuffer<T>(buffer, options): TypedTensor<T>;
    fromImage(imageData, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(imageElement, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(urlSource, options?): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromImage(bitmap, options): Promise<TypedTensor<"float32"> | TypedTensor<"uint8">>;
    fromMLTensor<T>(tensor, options): TypedTensor<T>;
    fromPinnedBuffer<T>(type, buffer, dims?): TypedTensor<T>;
    fromTexture<T>(texture, options): TypedTensor<"float32">;
}

层级结构 (查看完整)

构造函数

  • 从给定的类型、数据和维度构造一个新的字符串张量对象。

    参数

    • type: "string"

      指定元素类型。

    • data: string[] | readonly string[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"string">

  • 从给定的类型、数据和维度构造一个新的布尔张量对象。

    参数

    • type: "bool"

      指定元素类型。

    • data: Uint8Array | readonly boolean[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"bool">

  • 从 Uint8ClampedArray、数据和维度构造一个新的 uint8 张量对象。

    参数

    • type: "uint8"

      指定元素类型。

    • data: Uint8ClampedArray

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint8">

  • 从给定的类型、数据和维度构造一个新的 64 位整数类型张量对象。

    类型参数

    • T extends "int64" | "uint64"

    参数

    • type: T

      指定元素类型。

    • data: readonly number[] | DataTypeMap[T] | readonly bigint[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<T>

  • 从给定的类型、数据和维度构造一个新的数值张量对象。

    类型参数

    • T extends "float32" | "uint8" | "int8" | "uint16" | "int16" | "int32" | "float16" | "float64" | "uint32" | "uint4" | "int4"

    参数

    • type: T

      指定元素类型。

    • data: readonly number[] | DataTypeMap[T]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<T>

  • 从给定的数据和维度构造一个新的 float32 张量对象。

    参数

    • data: Float32Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"float32">

  • 从给定的数据和维度构造一个新的 int8 张量对象。

    参数

    • data: Int8Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"int8">

  • 从给定的数据和维度构造一个新的 uint8 张量对象。

    参数

    • data: Uint8Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint8">

  • 从给定的数据和维度构造一个新的 uint8 张量对象。

    参数

    • data: Uint8ClampedArray

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint8">

  • 从给定的数据和维度构造一个新的 uint16 张量对象。

    参数

    • data: Uint16Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint16">

  • 从给定的数据和维度构造一个新的 int16 张量对象。

    参数

    • data: Int16Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"int16">

  • 从给定的数据和维度构造一个新的 int32 张量对象。

    参数

    • data: Int32Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"int32">

  • 从给定的数据和维度构造一个新的 int64 张量对象。

    参数

    • data: BigInt64Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"int64">

  • 从给定的数据和维度构造一个新的字符串张量对象。

    参数

    • data: readonly string[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"string">

  • 从给定的数据和维度构造一个新的布尔张量对象。

    参数

    • data: readonly boolean[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"bool">

  • 根据给定的数据和维度构造新的 float64 张量对象。

    参数

    • data: Float64Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"float64">

  • 根据给定的数据和维度构造新的 uint32 张量对象。

    参数

    • data: Uint32Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint32">

  • 根据给定的数据和维度构造新的 uint64 张量对象。

    参数

    • data: BigUint64Array

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 TypedTensor<"uint64">

  • 根据给定的类型、数据和维度构造新的张量对象。

    参数

    • type: keyof DataTypeMap

      指定元素类型。

    • data: readonly string[] | readonly number[] | DataType | readonly boolean[] | readonly bigint[]

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 Tensor

  • 根据给定的数据和维度构造新的张量对象。

    参数

    • data: DataType

      指定 CPU 张量数据。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,则假定为 1-D 张量。

    返回 Tensor

方法

  • 从 WebGPU buffer 创建张量

    类型参数

    参数

    • buffer: GpuBufferTypeFallback

      用于创建张量的 GPUBuffer 对象

    • options: TensorFromGpuBufferOptions<T>

      表示从 WebGPU buffer 创建张量的可选对象。

      选项包括以下属性

      • dataType: 张量的数据类型。如果省略,假定为 'float32'。
      • dims: 张量的维度。必需。
      • download: 一个可选函数,用于将张量数据从 GPU 下载到 CPU。如果省略,GPU 数据将无法下载。通常,此函数由 GPU 后端为推理输出提供。用户无需提供此函数。
      • dispose: 一个可选函数,用于处理(释放)GPU 上的张量数据。如果省略,GPU 数据将不会被处理。通常,此函数由 GPU 后端为推理输出提供。用户无需提供此函数。

    返回 TypedTensor<T>

    一个张量对象

  • 从 WebNN MLTensor 创建张量

    类型参数

    参数

    • tensor: MLTensorTypeFallback

      用于创建张量的 MLTensor 对象

    • options: TensorFromMLTensorOptions<T>

      表示从 WebNN MLTensor 创建张量的可选对象。

      选项包括以下属性

      • dataType: 张量的数据类型。如果省略,假定为 'float32'。
      • dims: 张量的维度。必需。
      • download: 一个可选函数,用于将张量数据从 MLTensor 下载到 CPU。如果省略,MLTensor 数据将无法下载。通常,此函数由 WebNN 后端为推理输出提供。用户无需提供此函数。
      • dispose: 一个可选函数,用于处理(释放)WebNN MLTensor 上的张量数据。如果省略,MLTensor 将不会被处理。通常,此函数由 WebNN 后端为推理输出提供。用户无需提供此函数。

    返回 TypedTensor<T>

    一个张量对象

  • 从预分配的 buffer 创建张量。此 buffer 将用作 pinned buffer。

    类型参数

    • T extends "float32" | "uint8" | "int8" | "uint16" | "int16" | "int32" | "int64" | "bool" | "float16" | "float64" | "uint32" | "uint64" | "uint4" | "int4"

    参数

    • type: T

      张量元素类型。

    • buffer: DataTypeMap[T]

      与类型对应的 TypedArray。

    • Optional dims: readonly number[]

      指定张量的维度。如果省略,假定为 1 维张量。

    返回 TypedTensor<T>

    一个张量对象

  • 从 WebGL texture 创建张量

    类型参数

    • T extends "float32" = "float32"

    参数

    • texture: WebGLTexture

      用于创建张量的 WebGLTexture 对象

    • options: TensorFromTextureOptions<T>

      表示从 WebGL texture 创建张量的可选对象。

      选项包括以下属性

      • width: texture 的宽度。必需。
      • height: texture 的高度。必需。
      • format: texture 的格式。如果省略,假定为 'RGBA'。
      • download: 一个可选函数,用于将张量数据从 GPU 下载到 CPU。如果省略,GPU 数据将无法下载。通常,此函数由 GPU 后端为推理输出提供。用户无需提供此函数。
      • dispose: 一个可选函数,用于处理(释放)GPU 上的张量数据。如果省略,GPU 数据将不会被处理。通常,此函数由 GPU 后端为推理输出提供。用户无需提供此函数。

    返回 TypedTensor<"float32">

    一个张量对象

使用 TypeDoc 生成