@huggingface/transformers 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +376 -0
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +30741 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.js +33858 -0
- package/dist/transformers.js.map +1 -0
- package/dist/transformers.min.cjs +173 -0
- package/dist/transformers.min.cjs.map +1 -0
- package/dist/transformers.min.js +231 -0
- package/dist/transformers.min.js.map +1 -0
- package/package.json +92 -0
- package/src/backends/onnx.js +151 -0
- package/src/configs.js +360 -0
- package/src/env.js +152 -0
- package/src/generation/configuration_utils.js +381 -0
- package/src/generation/logits_process.js +716 -0
- package/src/generation/logits_sampler.js +204 -0
- package/src/generation/parameters.js +35 -0
- package/src/generation/stopping_criteria.js +156 -0
- package/src/generation/streamers.js +212 -0
- package/src/models/whisper/common_whisper.js +151 -0
- package/src/models/whisper/generation_whisper.js +89 -0
- package/src/models.js +7028 -0
- package/src/ops/registry.js +92 -0
- package/src/pipelines.js +3341 -0
- package/src/processors.js +2614 -0
- package/src/tokenizers.js +4395 -0
- package/src/transformers.js +28 -0
- package/src/utils/audio.js +704 -0
- package/src/utils/constants.js +2 -0
- package/src/utils/core.js +149 -0
- package/src/utils/data-structures.js +445 -0
- package/src/utils/devices.js +11 -0
- package/src/utils/dtypes.js +62 -0
- package/src/utils/generic.js +35 -0
- package/src/utils/hub.js +671 -0
- package/src/utils/image.js +745 -0
- package/src/utils/maths.js +1050 -0
- package/src/utils/tensor.js +1378 -0
- package/types/backends/onnx.d.ts +26 -0
- package/types/backends/onnx.d.ts.map +1 -0
- package/types/configs.d.ts +59 -0
- package/types/configs.d.ts.map +1 -0
- package/types/env.d.ts +106 -0
- package/types/env.d.ts.map +1 -0
- package/types/generation/configuration_utils.d.ts +320 -0
- package/types/generation/configuration_utils.d.ts.map +1 -0
- package/types/generation/logits_process.d.ts +354 -0
- package/types/generation/logits_process.d.ts.map +1 -0
- package/types/generation/logits_sampler.d.ts +51 -0
- package/types/generation/logits_sampler.d.ts.map +1 -0
- package/types/generation/parameters.d.ts +47 -0
- package/types/generation/parameters.d.ts.map +1 -0
- package/types/generation/stopping_criteria.d.ts +81 -0
- package/types/generation/stopping_criteria.d.ts.map +1 -0
- package/types/generation/streamers.d.ts +81 -0
- package/types/generation/streamers.d.ts.map +1 -0
- package/types/models/whisper/common_whisper.d.ts +8 -0
- package/types/models/whisper/common_whisper.d.ts.map +1 -0
- package/types/models/whisper/generation_whisper.d.ts +76 -0
- package/types/models/whisper/generation_whisper.d.ts.map +1 -0
- package/types/models.d.ts +3845 -0
- package/types/models.d.ts.map +1 -0
- package/types/ops/registry.d.ts +11 -0
- package/types/ops/registry.d.ts.map +1 -0
- package/types/pipelines.d.ts +2403 -0
- package/types/pipelines.d.ts.map +1 -0
- package/types/processors.d.ts +917 -0
- package/types/processors.d.ts.map +1 -0
- package/types/tokenizers.d.ts +999 -0
- package/types/tokenizers.d.ts.map +1 -0
- package/types/transformers.d.ts +13 -0
- package/types/transformers.d.ts.map +1 -0
- package/types/utils/audio.d.ts +130 -0
- package/types/utils/audio.d.ts.map +1 -0
- package/types/utils/constants.d.ts +2 -0
- package/types/utils/constants.d.ts.map +1 -0
- package/types/utils/core.d.ts +91 -0
- package/types/utils/core.d.ts.map +1 -0
- package/types/utils/data-structures.d.ts +236 -0
- package/types/utils/data-structures.d.ts.map +1 -0
- package/types/utils/devices.d.ts +8 -0
- package/types/utils/devices.d.ts.map +1 -0
- package/types/utils/dtypes.d.ts +22 -0
- package/types/utils/dtypes.d.ts.map +1 -0
- package/types/utils/generic.d.ts +11 -0
- package/types/utils/generic.d.ts.map +1 -0
- package/types/utils/hub.d.ts +191 -0
- package/types/utils/hub.d.ts.map +1 -0
- package/types/utils/image.d.ts +119 -0
- package/types/utils/image.d.ts.map +1 -0
- package/types/utils/maths.d.ts +280 -0
- package/types/utils/maths.d.ts.map +1 -0
- package/types/utils/tensor.d.ts +392 -0
- package/types/utils/tensor.d.ts.map +1 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permutes a tensor according to the provided axes.
|
|
3
|
+
* @param {any} tensor The input tensor to permute.
|
|
4
|
+
* @param {Array} axes The axes to permute the tensor along.
|
|
5
|
+
* @returns {Tensor} The permuted tensor.
|
|
6
|
+
*/
|
|
7
|
+
export function permute(tensor: any, axes: any[]): Tensor;
|
|
8
|
+
/**
|
|
9
|
+
* Interpolates an Tensor to the given size.
|
|
10
|
+
* @param {Tensor} input The input tensor to interpolate. Data must be channel-first (i.e., [c, h, w])
|
|
11
|
+
* @param {number[]} size The output size of the image
|
|
12
|
+
* @param {string} mode The interpolation mode
|
|
13
|
+
* @param {boolean} align_corners Whether to align corners.
|
|
14
|
+
* @returns {Tensor} The interpolated tensor.
|
|
15
|
+
*/
|
|
16
|
+
export function interpolate(input: Tensor, [out_height, out_width]: number[], mode?: string, align_corners?: boolean): Tensor;
|
|
17
|
+
/**
|
|
18
|
+
* Down/up samples the input.
|
|
19
|
+
* Inspired by https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html.
|
|
20
|
+
* @param {Tensor} input the input tensor
|
|
21
|
+
* @param {Object} options the options for the interpolation
|
|
22
|
+
* @param {[number, number]|[number, number, number]|[number, number, number, number]} [options.size=null] output spatial size.
|
|
23
|
+
* @param {"bilinear"|"bicubic"} [options.mode='bilinear'] algorithm used for upsampling
|
|
24
|
+
* @returns {Promise<Tensor>} The interpolated tensor.
|
|
25
|
+
*/
|
|
26
|
+
export function interpolate_4d(input: Tensor, { size, mode, }?: {
|
|
27
|
+
size?: [number, number] | [number, number, number] | [number, number, number, number];
|
|
28
|
+
mode?: "bilinear" | "bicubic";
|
|
29
|
+
}): Promise<Tensor>;
|
|
30
|
+
/**
|
|
31
|
+
* Matrix product of two tensors.
|
|
32
|
+
* Inspired by https://pytorch.org/docs/stable/generated/torch.matmul.html
|
|
33
|
+
* @param {Tensor} a the first tensor to be multiplied
|
|
34
|
+
* @param {Tensor} b the second tensor to be multiplied
|
|
35
|
+
* @returns {Promise<Tensor>} The matrix product of the two tensors.
|
|
36
|
+
*/
|
|
37
|
+
export function matmul(a: Tensor, b: Tensor): Promise<Tensor>;
|
|
38
|
+
/**
|
|
39
|
+
* Computes the one dimensional Fourier transform of real-valued input.
|
|
40
|
+
* Inspired by https://pytorch.org/docs/stable/generated/torch.fft.rfft.html
|
|
41
|
+
* @param {Tensor} x the real input tensor
|
|
42
|
+
* @param {Tensor} a The dimension along which to take the one dimensional real FFT.
|
|
43
|
+
* @returns {Promise<Tensor>} the output tensor.
|
|
44
|
+
*/
|
|
45
|
+
export function rfft(x: Tensor, a: Tensor): Promise<Tensor>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the k largest elements of the given input tensor.
|
|
48
|
+
* Inspired by https://pytorch.org/docs/stable/generated/torch.topk.html
|
|
49
|
+
* @param {Tensor} x the input tensor
|
|
50
|
+
* @param {number} k the k in "top-k"
|
|
51
|
+
* @returns {Promise<[Tensor, Tensor]>} the output tuple of (Tensor, LongTensor) of top-k elements and their indices.
|
|
52
|
+
*/
|
|
53
|
+
export function topk(x: Tensor, k: number): Promise<[Tensor, Tensor]>;
|
|
54
|
+
/**
|
|
55
|
+
* Perform mean pooling of the last hidden state followed by a normalization step.
|
|
56
|
+
* @param {Tensor} last_hidden_state Tensor of shape [batchSize, seqLength, embedDim]
|
|
57
|
+
* @param {Tensor} attention_mask Tensor of shape [batchSize, seqLength]
|
|
58
|
+
* @returns {Tensor} Returns a new Tensor of shape [batchSize, embedDim].
|
|
59
|
+
*/
|
|
60
|
+
export function mean_pooling(last_hidden_state: Tensor, attention_mask: Tensor): Tensor;
|
|
61
|
+
/**
|
|
62
|
+
* Apply Layer Normalization for last certain number of dimensions.
|
|
63
|
+
* @param {Tensor} input The input tensor
|
|
64
|
+
* @param {number[]} normalized_shape input shape from an expected input of size
|
|
65
|
+
* @param {Object} options The options for the layer normalization
|
|
66
|
+
* @param {number} [options.eps=1e-5] A value added to the denominator for numerical stability.
|
|
67
|
+
* @returns {Tensor} The normalized tensor.
|
|
68
|
+
*/
|
|
69
|
+
export function layer_norm(input: Tensor, normalized_shape: number[], { eps, }?: {
|
|
70
|
+
eps?: number;
|
|
71
|
+
}): Tensor;
|
|
72
|
+
/**
|
|
73
|
+
* Concatenates an array of tensors along a specified dimension.
|
|
74
|
+
* @param {Tensor[]} tensors The array of tensors to concatenate.
|
|
75
|
+
* @param {number} dim The dimension to concatenate along.
|
|
76
|
+
* @returns {Tensor} The concatenated tensor.
|
|
77
|
+
*/
|
|
78
|
+
export function cat(tensors: Tensor[], dim?: number): Tensor;
|
|
79
|
+
/**
|
|
80
|
+
* Stack an array of tensors along a specified dimension.
|
|
81
|
+
* @param {Tensor[]} tensors The array of tensors to stack.
|
|
82
|
+
* @param {number} dim The dimension to stack along.
|
|
83
|
+
* @returns {Tensor} The stacked tensor.
|
|
84
|
+
*/
|
|
85
|
+
export function stack(tensors: Tensor[], dim?: number): Tensor;
|
|
86
|
+
/**
|
|
87
|
+
* Calculates the standard deviation and mean over the dimensions specified by dim. dim can be a single dimension or `null` to reduce over all dimensions.
|
|
88
|
+
* @param {Tensor} input the input tenso
|
|
89
|
+
* @param {number|null} dim the dimension to reduce. If None, all dimensions are reduced.
|
|
90
|
+
* @param {number} correction difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.
|
|
91
|
+
* @param {boolean} keepdim whether the output tensor has dim retained or not.
|
|
92
|
+
* @returns {Tensor[]} A tuple of (std, mean) tensors.
|
|
93
|
+
*/
|
|
94
|
+
export function std_mean(input: Tensor, dim?: number | null, correction?: number, keepdim?: boolean): Tensor[];
|
|
95
|
+
/**
|
|
96
|
+
* Returns the mean value of each row of the input tensor in the given dimension dim.
|
|
97
|
+
* @param {Tensor} input the input tensor.
|
|
98
|
+
* @param {number|null} dim the dimension to reduce.
|
|
99
|
+
* @param {boolean} keepdim whether the output tensor has dim retained or not.
|
|
100
|
+
* @returns {Tensor} A new tensor with means taken along the specified dimension.
|
|
101
|
+
*/
|
|
102
|
+
export function mean(input: Tensor, dim?: number | null, keepdim?: boolean): Tensor;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a tensor of size size filled with fill_value. The tensor's dtype is inferred from fill_value.
|
|
105
|
+
* @param {number[]} size A sequence of integers defining the shape of the output tensor.
|
|
106
|
+
* @param {number|bigint} fill_value The value to fill the output tensor with.
|
|
107
|
+
* @returns {Tensor} The filled tensor.
|
|
108
|
+
*/
|
|
109
|
+
export function full(size: number[], fill_value: number | bigint): Tensor;
|
|
110
|
+
export function full_like(tensor: any, fill_value: any): Tensor;
|
|
111
|
+
/**
|
|
112
|
+
* Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.
|
|
113
|
+
* @param {number[]} size A sequence of integers defining the shape of the output tensor.
|
|
114
|
+
* @returns {Tensor} The ones tensor.
|
|
115
|
+
*/
|
|
116
|
+
export function ones(size: number[]): Tensor;
|
|
117
|
+
/**
|
|
118
|
+
* Returns a tensor filled with the scalar value 1, with the same size as input.
|
|
119
|
+
* @param {Tensor} tensor The size of input will determine size of the output tensor.
|
|
120
|
+
* @returns {Tensor} The ones tensor.
|
|
121
|
+
*/
|
|
122
|
+
export function ones_like(tensor: Tensor): Tensor;
|
|
123
|
+
/**
|
|
124
|
+
* Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.
|
|
125
|
+
* @param {number[]} size A sequence of integers defining the shape of the output tensor.
|
|
126
|
+
* @returns {Tensor} The zeros tensor.
|
|
127
|
+
*/
|
|
128
|
+
export function zeros(size: number[]): Tensor;
|
|
129
|
+
/**
|
|
130
|
+
* Returns a tensor filled with the scalar value 0, with the same size as input.
|
|
131
|
+
* @param {Tensor} tensor The size of input will determine size of the output tensor.
|
|
132
|
+
* @returns {Tensor} The zeros tensor.
|
|
133
|
+
*/
|
|
134
|
+
export function zeros_like(tensor: Tensor): Tensor;
|
|
135
|
+
/**
|
|
136
|
+
* Quantizes the embeddings tensor to binary or unsigned binary precision.
|
|
137
|
+
* @param {Tensor} tensor The tensor to quantize.
|
|
138
|
+
* @param {'binary'|'ubinary'} precision The precision to use for quantization.
|
|
139
|
+
* @returns {Tensor} The quantized tensor.
|
|
140
|
+
*/
|
|
141
|
+
export function quantize_embeddings(tensor: Tensor, precision: 'binary' | 'ubinary'): Tensor;
|
|
142
|
+
/**
|
|
143
|
+
* @typedef {keyof typeof DataTypeMap} DataType
|
|
144
|
+
* @typedef {import('./maths.js').AnyTypedArray | any[]} DataArray
|
|
145
|
+
*/
|
|
146
|
+
export class Tensor {
|
|
147
|
+
/**
|
|
148
|
+
* Create a new Tensor or copy an existing Tensor.
|
|
149
|
+
* @param {[DataType, DataArray, number[]]|[ONNXTensor]} args
|
|
150
|
+
*/
|
|
151
|
+
constructor(...args: [DataType, DataArray, number[]] | [ONNXTensor]);
|
|
152
|
+
set dims(arg: number[]);
|
|
153
|
+
/** @type {number[]} Dimensions of the tensor. */
|
|
154
|
+
get dims(): number[];
|
|
155
|
+
/** @type {DataType} Type of the tensor. */
|
|
156
|
+
get type(): "string" | "int8" | "uint8" | "float32" | "uint16" | "int16" | "int32" | "int64" | "bool" | "float16" | "float64" | "uint32" | "uint64";
|
|
157
|
+
/** @type {DataArray} The data stored in the tensor. */
|
|
158
|
+
get data(): DataArray;
|
|
159
|
+
/** @type {number} The number of elements in the tensor. */
|
|
160
|
+
get size(): number;
|
|
161
|
+
/** @type {string} The location of the tensor data. */
|
|
162
|
+
get location(): string;
|
|
163
|
+
ort_tensor: ONNXTensor;
|
|
164
|
+
dispose(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Index into a Tensor object.
|
|
167
|
+
* @param {number} index The index to access.
|
|
168
|
+
* @returns {Tensor} The data at the specified index.
|
|
169
|
+
*/
|
|
170
|
+
_getitem(index: number): Tensor;
|
|
171
|
+
/**
|
|
172
|
+
* @param {number|bigint} item The item to search for in the tensor
|
|
173
|
+
* @returns {number} The index of the first occurrence of item in the tensor data.
|
|
174
|
+
*/
|
|
175
|
+
indexOf(item: number | bigint): number;
|
|
176
|
+
/**
|
|
177
|
+
* @param {number} index
|
|
178
|
+
* @param {number} iterSize
|
|
179
|
+
* @param {any} iterDims
|
|
180
|
+
* @returns {Tensor}
|
|
181
|
+
*/
|
|
182
|
+
_subarray(index: number, iterSize: number, iterDims: any): Tensor;
|
|
183
|
+
/**
|
|
184
|
+
* Returns the value of this tensor as a standard JavaScript Number. This only works
|
|
185
|
+
* for tensors with one element. For other cases, see `Tensor.tolist()`.
|
|
186
|
+
* @returns {number|bigint} The value of this tensor as a standard JavaScript Number.
|
|
187
|
+
* @throws {Error} If the tensor has more than one element.
|
|
188
|
+
*/
|
|
189
|
+
item(): number | bigint;
|
|
190
|
+
/**
|
|
191
|
+
* Convert tensor data to a n-dimensional JS list
|
|
192
|
+
* @returns {Array}
|
|
193
|
+
*/
|
|
194
|
+
tolist(): any[];
|
|
195
|
+
/**
|
|
196
|
+
* Return a new Tensor with the sigmoid function applied to each element.
|
|
197
|
+
* @returns {Tensor} The tensor with the sigmoid function applied.
|
|
198
|
+
*/
|
|
199
|
+
sigmoid(): Tensor;
|
|
200
|
+
/**
|
|
201
|
+
* Applies the sigmoid function to the tensor in place.
|
|
202
|
+
* @returns {Tensor} Returns `this`.
|
|
203
|
+
*/
|
|
204
|
+
sigmoid_(): Tensor;
|
|
205
|
+
/**
|
|
206
|
+
* Return a new Tensor with every element multiplied by a constant.
|
|
207
|
+
* @param {number} val The value to multiply by.
|
|
208
|
+
* @returns {Tensor} The new tensor.
|
|
209
|
+
*/
|
|
210
|
+
mul(val: number): Tensor;
|
|
211
|
+
/**
|
|
212
|
+
* Multiply the tensor by a constant in place.
|
|
213
|
+
* @param {number} val The value to multiply by.
|
|
214
|
+
* @returns {Tensor} Returns `this`.
|
|
215
|
+
*/
|
|
216
|
+
mul_(val: number): Tensor;
|
|
217
|
+
/**
|
|
218
|
+
* Return a new Tensor with every element divided by a constant.
|
|
219
|
+
* @param {number} val The value to divide by.
|
|
220
|
+
* @returns {Tensor} The new tensor.
|
|
221
|
+
*/
|
|
222
|
+
div(val: number): Tensor;
|
|
223
|
+
/**
|
|
224
|
+
* Divide the tensor by a constant in place.
|
|
225
|
+
* @param {number} val The value to divide by.
|
|
226
|
+
* @returns {Tensor} Returns `this`.
|
|
227
|
+
*/
|
|
228
|
+
div_(val: number): Tensor;
|
|
229
|
+
/**
|
|
230
|
+
* Return a new Tensor with every element added by a constant.
|
|
231
|
+
* @param {number} val The value to add by.
|
|
232
|
+
* @returns {Tensor} The new tensor.
|
|
233
|
+
*/
|
|
234
|
+
add(val: number): Tensor;
|
|
235
|
+
/**
|
|
236
|
+
* Add the tensor by a constant in place.
|
|
237
|
+
* @param {number} val The value to add by.
|
|
238
|
+
* @returns {Tensor} Returns `this`.
|
|
239
|
+
*/
|
|
240
|
+
add_(val: number): Tensor;
|
|
241
|
+
clone(): Tensor;
|
|
242
|
+
slice(...slices: any[]): Tensor;
|
|
243
|
+
/**
|
|
244
|
+
* Return a permuted version of this Tensor, according to the provided dimensions.
|
|
245
|
+
* @param {...number} dims Dimensions to permute.
|
|
246
|
+
* @returns {Tensor} The permuted tensor.
|
|
247
|
+
*/
|
|
248
|
+
permute(...dims: number[]): Tensor;
|
|
249
|
+
transpose(...dims: any[]): Tensor;
|
|
250
|
+
/**
|
|
251
|
+
* Returns the sum of each row of the input tensor in the given dimension dim.
|
|
252
|
+
*
|
|
253
|
+
* @param {number} [dim=null] The dimension or dimensions to reduce. If `null`, all dimensions are reduced.
|
|
254
|
+
* @param {boolean} keepdim Whether the output tensor has `dim` retained or not.
|
|
255
|
+
* @returns The summed tensor
|
|
256
|
+
*/
|
|
257
|
+
sum(dim?: number, keepdim?: boolean): Tensor;
|
|
258
|
+
/**
|
|
259
|
+
* Returns the matrix norm or vector norm of a given tensor.
|
|
260
|
+
* @param {number|string} [p='fro'] The order of norm
|
|
261
|
+
* @param {number} [dim=null] Specifies which dimension of the tensor to calculate the norm across.
|
|
262
|
+
* If dim is None, the norm will be calculated across all dimensions of input.
|
|
263
|
+
* @param {boolean} [keepdim=false] Whether the output tensors have dim retained or not.
|
|
264
|
+
* @returns {Tensor} The norm of the tensor.
|
|
265
|
+
*/
|
|
266
|
+
norm(p?: number | string, dim?: number, keepdim?: boolean): Tensor;
|
|
267
|
+
/**
|
|
268
|
+
* Performs `L_p` normalization of inputs over specified dimension. Operates in place.
|
|
269
|
+
* @param {number} [p=2] The exponent value in the norm formulation
|
|
270
|
+
* @param {number} [dim=1] The dimension to reduce
|
|
271
|
+
* @returns {Tensor} `this` for operation chaining.
|
|
272
|
+
*/
|
|
273
|
+
normalize_(p?: number, dim?: number): Tensor;
|
|
274
|
+
/**
|
|
275
|
+
* Performs `L_p` normalization of inputs over specified dimension.
|
|
276
|
+
* @param {number} [p=2] The exponent value in the norm formulation
|
|
277
|
+
* @param {number} [dim=1] The dimension to reduce
|
|
278
|
+
* @returns {Tensor} The normalized tensor.
|
|
279
|
+
*/
|
|
280
|
+
normalize(p?: number, dim?: number): Tensor;
|
|
281
|
+
/**
|
|
282
|
+
* Compute and return the stride of this tensor.
|
|
283
|
+
* Stride is the jump necessary to go from one element to the next one in the specified dimension dim.
|
|
284
|
+
* @returns {number[]} The stride of this tensor.
|
|
285
|
+
*/
|
|
286
|
+
stride(): number[];
|
|
287
|
+
/**
|
|
288
|
+
* Returns a tensor with all specified dimensions of input of size 1 removed.
|
|
289
|
+
*
|
|
290
|
+
* NOTE: The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other.
|
|
291
|
+
* If you would like a copy, use `tensor.clone()` before squeezing.
|
|
292
|
+
*
|
|
293
|
+
* @param {number} [dim=null] If given, the input will be squeezed only in the specified dimensions.
|
|
294
|
+
* @returns {Tensor} The squeezed tensor
|
|
295
|
+
*/
|
|
296
|
+
squeeze(dim?: number): Tensor;
|
|
297
|
+
/**
|
|
298
|
+
* In-place version of @see {@link Tensor.squeeze}
|
|
299
|
+
*/
|
|
300
|
+
squeeze_(dim?: any): this;
|
|
301
|
+
/**
|
|
302
|
+
* Returns a new tensor with a dimension of size one inserted at the specified position.
|
|
303
|
+
*
|
|
304
|
+
* NOTE: The returned tensor shares the same underlying data with this tensor.
|
|
305
|
+
*
|
|
306
|
+
* @param {number} dim The index at which to insert the singleton dimension
|
|
307
|
+
* @returns {Tensor} The unsqueezed tensor
|
|
308
|
+
*/
|
|
309
|
+
unsqueeze(dim?: number): Tensor;
|
|
310
|
+
/**
|
|
311
|
+
* In-place version of @see {@link Tensor.unsqueeze}
|
|
312
|
+
*/
|
|
313
|
+
unsqueeze_(dim?: any): this;
|
|
314
|
+
/**
|
|
315
|
+
* In-place version of @see {@link Tensor.flatten}
|
|
316
|
+
*/
|
|
317
|
+
flatten_(start_dim?: number, end_dim?: number): this;
|
|
318
|
+
/**
|
|
319
|
+
* Flattens input by reshaping it into a one-dimensional tensor.
|
|
320
|
+
* If `start_dim` or `end_dim` are passed, only dimensions starting with `start_dim`
|
|
321
|
+
* and ending with `end_dim` are flattened. The order of elements in input is unchanged.
|
|
322
|
+
* @param {number} start_dim the first dim to flatten
|
|
323
|
+
* @param {number} end_dim the last dim to flatten
|
|
324
|
+
* @returns {Tensor} The flattened tensor.
|
|
325
|
+
*/
|
|
326
|
+
flatten(start_dim?: number, end_dim?: number): Tensor;
|
|
327
|
+
/**
|
|
328
|
+
* Returns a new tensor with the same data as the `self` tensor but of a different `shape`.
|
|
329
|
+
* @param {...number} dims the desired size
|
|
330
|
+
* @returns {Tensor} The tensor with the same data but different shape
|
|
331
|
+
*/
|
|
332
|
+
view(...dims: number[]): Tensor;
|
|
333
|
+
neg_(): this;
|
|
334
|
+
neg(): Tensor;
|
|
335
|
+
/**
|
|
336
|
+
* In-place version of @see {@link Tensor.clamp}
|
|
337
|
+
*/
|
|
338
|
+
clamp_(min: any, max: any): this;
|
|
339
|
+
/**
|
|
340
|
+
* Clamps all elements in input into the range [ min, max ]
|
|
341
|
+
* @param {number} min lower-bound of the range to be clamped to
|
|
342
|
+
* @param {number} max upper-bound of the range to be clamped to
|
|
343
|
+
* @returns {Tensor} the output tensor.
|
|
344
|
+
*/
|
|
345
|
+
clamp(min: number, max: number): Tensor;
|
|
346
|
+
/**
|
|
347
|
+
* In-place version of @see {@link Tensor.round}
|
|
348
|
+
*/
|
|
349
|
+
round_(): this;
|
|
350
|
+
/**
|
|
351
|
+
* Rounds elements of input to the nearest integer.
|
|
352
|
+
* @returns {Tensor} the output tensor.
|
|
353
|
+
*/
|
|
354
|
+
round(): Tensor;
|
|
355
|
+
mean(dim?: any, keepdim?: boolean): Tensor;
|
|
356
|
+
/**
|
|
357
|
+
* Performs Tensor dtype conversion.
|
|
358
|
+
* @param {DataType} type The desired data type.
|
|
359
|
+
* @returns {Tensor} The converted tensor.
|
|
360
|
+
*/
|
|
361
|
+
to(type: DataType): Tensor;
|
|
362
|
+
/**
|
|
363
|
+
* Returns an iterator object for iterating over the tensor data in row-major order.
|
|
364
|
+
* If the tensor has more than one dimension, the iterator will yield subarrays.
|
|
365
|
+
* @returns {Iterator} An iterator object for iterating over the tensor data in row-major order.
|
|
366
|
+
*/
|
|
367
|
+
[Symbol.iterator](): Iterator<any, any, undefined>;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* This creates a nested array of a given type and depth (see examples).
|
|
371
|
+
*/
|
|
372
|
+
export type NestArray<T, Depth extends number, Acc extends never[] = []> = Acc['length'] extends Depth ? T : NestArray<T[], Depth, [...Acc, never]>;
|
|
373
|
+
export type DataType = keyof typeof DataTypeMap;
|
|
374
|
+
export type DataArray = import('./maths.js').AnyTypedArray | any[];
|
|
375
|
+
import { Tensor as ONNXTensor } from '../backends/onnx.js';
|
|
376
|
+
declare const DataTypeMap: Readonly<{
|
|
377
|
+
float32: Float32ArrayConstructor;
|
|
378
|
+
float16: Uint16ArrayConstructor;
|
|
379
|
+
float64: Float64ArrayConstructor;
|
|
380
|
+
string: ArrayConstructor;
|
|
381
|
+
int8: Int8ArrayConstructor;
|
|
382
|
+
uint8: Uint8ArrayConstructor;
|
|
383
|
+
int16: Int16ArrayConstructor;
|
|
384
|
+
uint16: Uint16ArrayConstructor;
|
|
385
|
+
int32: Int32ArrayConstructor;
|
|
386
|
+
uint32: Uint32ArrayConstructor;
|
|
387
|
+
int64: BigInt64ArrayConstructor;
|
|
388
|
+
uint64: BigUint64ArrayConstructor;
|
|
389
|
+
bool: Uint8ArrayConstructor;
|
|
390
|
+
}>;
|
|
391
|
+
export {};
|
|
392
|
+
//# sourceMappingURL=tensor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tensor.d.ts","sourceRoot":"","sources":["../../src/utils/tensor.js"],"names":[],"mappings":"AAovBA;;;;;GAKG;AACH,gCAJW,GAAG,gBAED,MAAM,CAKlB;AAGD;;;;;;;GAOG;AACH,mCANW,MAAM,2BACN,MAAM,EAAE,SACR,MAAM,kBACN,OAAO,GACL,MAAM,CAiBlB;AAGD;;;;;;;;GAQG;AACH,sCANW,MAAM;IAE+E,IAAI,GAAzF,CAAC,MAAM,EAAE,MAAM,CAAC,GAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAC3C,IAAI,GAAnC,UAAU,GAAC,SAAS;IAClB,QAAQ,MAAM,CAAC,CAuC3B;AAED;;;;;;GAMG;AACH,0BAJW,MAAM,KACN,MAAM,GACJ,QAAQ,MAAM,CAAC,CAK3B;AAED;;;;;;GAMG;AACH,wBAJW,MAAM,KACN,MAAM,GACJ,QAAQ,MAAM,CAAC,CAK3B;AAGD;;;;;;GAMG;AACH,wBAJW,MAAM,KACN,MAAM,GACJ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkBrC;AAED;;;;;GAKG;AACH,gDAJW,MAAM,kBACN,MAAM,GACJ,MAAM,CA2ClB;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