Helper module for Tensor processing.
These functions and classes are only used internally, meaning an end-user shouldnβt need to access anything here.
utils/tensor.Tensor
Kind : static class of utils/tensorarrow-up-right
new Tensor(...args)
Create a new Tensor or copy an existing Tensor.
tensor.Symbol.iterator() β <code> Iterator </code>
Returns an iterator object for iterating over the tensor data in row-major order. If the tensor has more than one dimension, the iterator will yield subarrays.
Kind : instance method of Tensorarrow-up-right
Returns : Iterator - An iterator object for iterating over the tensor data in row-major order.
tensor._getitem(index) β <code> Tensor </code>
Index into a Tensor object.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The data at the specified index.
tensor.indexOf(item) β <code> number </code>
Kind : instance method of Tensorarrow-up-right
Returns : number - The index of the first occurrence of item in the tensor data.
The item to search for in the tensor
tensor._subarray(index, iterSize, iterDims) β <code> Tensor </code>
Kind : instance method of Tensorarrow-up-right
tensor.item() β <code> number </code>
Returns the value of this tensor as a standard JavaScript Number. This only works for tensors with one element. For other cases, see Tensor.tolist().
Kind : instance method of Tensorarrow-up-right
Returns : number - The value of this tensor as a standard JavaScript Number.
Throws :
Error If the tensor has more than one element.
tensor.tolist() β <code> Array </code>
Convert tensor data to a n-dimensional JS list
Kind : instance method of Tensorarrow-up-right
tensor.sigmoid() β <code> Tensor </code>
Return a new Tensor with the sigmoid function applied to each element.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The tensor with the sigmoid function applied.
tensor.sigmoid_() β <code> Tensor </code>
Applies the sigmoid function to the tensor in place.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - Returns this.
tensor.transpose(...dims) β <code> Tensor </code>
Return a transposed version of this Tensor, according to the provided dimensions.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The transposed tensor.
tensor.sum([dim], keepdim) β
Returns the sum of each row of the input tensor in the given dimension dim.
Kind : instance method of Tensorarrow-up-right
Returns : The summed tensor
Param
Type
Default
Description
The dimension or dimensions to reduce. If null, all dimensions are reduced.
Whether the output tensor has dim retained or not.
tensor.norm([p], [dim], [keepdim]) β <code> Tensor </code>
Returns the matrix norm or vector norm of a given tensor.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The norm of the tensor.
Param
Type
Default
Description
Specifies which dimension of the tensor to calculate the norm across. If dim is None, the norm will be calculated across all dimensions of input.
Whether the output tensors have dim retained or not.
tensor.normalize_([p], [dim]) β <code> Tensor </code>
Performs L_p normalization of inputs over specified dimension. Operates in place.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - this for operation chaining.
Param
Type
Default
Description
The exponent value in the norm formulation
tensor.normalize([p], [dim]) β <code> Tensor </code>
Performs L_p normalization of inputs over specified dimension.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The normalized tensor.
Param
Type
Default
Description
The exponent value in the norm formulation
tensor.stride() β <code> Array. < number > </code>
Compute and return the stride of this tensor. Stride is the jump necessary to go from one element to the next one in the specified dimension dim.
Kind : instance method of Tensorarrow-up-right
Returns : Array.<number> - The stride of this tensor.
tensor.squeeze([dim]) β
Returns a tensor with all specified dimensions of input of size 1 removed.
NOTE: The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other. If you would like a copy, use tensor.clone() before squeezing.
Kind : instance method of Tensorarrow-up-right
Returns : The squeezed tensor
Param
Type
Default
Description
If given, the input will be squeezed only in the specified dimensions.
tensor.squeeze_()
In-place version of @see Tensor.squeezearrow-up-right
Kind : instance method of Tensorarrow-up-right
tensor.unsqueeze(dim) β
Returns a new tensor with a dimension of size one inserted at the specified position.
NOTE: The returned tensor shares the same underlying data with this tensor.
Kind : instance method of Tensorarrow-up-right
Returns : The unsqueezed tensor
Param
Type
Default
Description
The index at which to insert the singleton dimension
tensor.unsqueeze_()
In-place version of @see Tensor.unsqueezearrow-up-right
Kind : instance method of Tensorarrow-up-right
tensor.flatten_()
In-place version of @see Tensor.flattenarrow-up-right
Kind : instance method of Tensorarrow-up-right
tensor.flatten(start_dim, end_dim) β
Flattens input by reshaping it into a one-dimensional tensor. If start_dim or end_dim are passed, only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is unchanged.
Kind : instance method of Tensorarrow-up-right
Returns : The flattened tensor.
Param
Type
Default
Description
tensor.view(...dims) β <code> Tensor </code>
Returns a new tensor with the same data as the self tensor but of a different shape.
Kind : instance method of Tensorarrow-up-right
Returns : Tensor - The tensor with the same data but different shape
utils/tensor.transpose(tensor, axes) β <code> Tensor </code>
Transposes a tensor according to the provided axes.
Kind : static method of utils/tensorarrow-up-right
Returns : Tensor - The transposed tensor.
The input tensor to transpose.
The axes to transpose the tensor along.
Interpolates an Tensor to the given size.
Kind : static method of utils/tensorarrow-up-right
Returns : Tensor - The interpolated tensor.
The input tensor to interpolate. Data must be channel-first (i.e., [c, h, w])
The output size of the image
Whether to align corners.
utils/tensor.mean_pooling(last_hidden_state, attention_mask) β <code> Tensor </code>
Perform mean pooling of the last hidden state followed by a normalization step.
Kind : static method of utils/tensorarrow-up-right
Returns : Tensor - Returns a new Tensor of shape [batchSize, embedDim].
Tensor of shape [batchSize, seqLength, embedDim]
Tensor of shape [batchSize, seqLength]
utils/tensor.cat(tensors, dim) β <code> Tensor </code>
Concatenates an array of tensors along a specified dimension.
Kind : static method of utils/tensorarrow-up-right
Returns : Tensor - The concatenated tensor.
The array of tensors to concatenate.
The dimension to concatenate along.
utils/tensor.stack(tensors, dim) β <code> Tensor </code>
Stack an array of tensors along a specified dimension.
Kind : static method of utils/tensorarrow-up-right
Returns : Tensor - The stacked tensor.
The array of tensors to stack.
The dimension to stack along.
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.
Kind : static method of utils/tensorarrow-up-right
Returns : Array.<Tensor> - A tuple of (std, mean) tensors.
the dimension to reduce. If None, all dimensions are reduced.
difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.
whether the output tensor has dim retained or not.
Returns the mean value of each row of the input tensor in the given dimension dim.
Kind : static method of utils/tensorarrow-up-right
Returns : A new tensor with means taken along the specified dimension.
whether the output tensor has dim retained or not.
utils/tensor.dynamicTimeWarping(matrix) β <code> Array. < Array < number > > </code>
Measures similarity between two temporal sequences (e.g., input audio and output tokens to generate token-level timestamps).
Kind : static method of utils/tensorarrow-up-right
utils/tensor.ones(size)
Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.
Kind : static method of utils/tensorarrow-up-right
A sequence of integers defining the shape of the output tensor.
utils/tensor.ones_like(tensor) β
Returns a tensor filled with the scalar value 1, with the same size as input.
Kind : static method of utils/tensorarrow-up-right
Returns : The ones tensor.
The size of input will determine size of the output tensor.
utils/tensor~ONNXTensor : <code> Object </code>
Kind : inner constant of utils/tensorarrow-up-right
utils/tensor~reshape(data, dimensions) β <code> * </code>
Reshapes a 1-dimensional array into an n-dimensional array, according to the provided dimensions.
Kind : inner method of utils/tensorarrow-up-right
Returns : * - The reshaped array.
The input array to reshape.
The target shape/dimensions.
Example
Copied
reshape~reshapedArray : <code> any </code>
Kind : inner property of reshapearrow-up-right
utils/tensor~DataArray : <code> * </code>
Kind : inner typedef of utils/tensorarrow-up-right
utils/tensor~NestArray : <code> * </code>
This creates a nested array of a given type and depth (see examples).
Kind : inner typedef of utils/tensorarrow-up-right
Example
Copied
Example
Copied
Example
Copied