Tensor
Last updated
Last updated
Helper module for Tensor
processing.
These functions and classes are only used internally, meaning an end-user shouldn’t need to access anything here.
static
⇒ Iterator
⇒ Tensor
⇒ number
⇒ Tensor
⇒ number
⇒ Array
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Array.<number>
⇒
⇒
⇒
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Array.<Tensor>
⇒
⇒ Array.<Array<number>>
⇒
inner
: Object
⇒ *
: any
: *
: *
Create a new Tensor or copy an existing Tensor.
...args
*
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.
Index into a Tensor object.
index
number
The index to access.
item
number
| bigint
The item to search for in the tensor
index
number
iterSize
number
iterDims
any
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()
.
Error
If the tensor has more than one element.
Convert tensor data to a n-dimensional JS list
Return a new Tensor with the sigmoid function applied to each element.
Applies the sigmoid function to the tensor in place.
Return a transposed version of this Tensor, according to the provided dimensions.
...dims
number
Dimensions to transpose.
Returns the sum of each row of the input tensor in the given dimension dim.
[dim]
number
The dimension or dimensions to reduce. If null
, all dimensions are reduced.
keepdim
boolean
false
Whether the output tensor has dim
retained or not.
Returns the matrix norm or vector norm of a given tensor.
[p]
number
| string
'fro'
The order of norm
[dim]
number
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.
[keepdim]
boolean
false
Whether the output tensors have dim retained or not.
Performs L_p
normalization of inputs over specified dimension. Operates in place.
[p]
number
2
The exponent value in the norm formulation
[dim]
number
1
The dimension to reduce
Performs L_p
normalization of inputs over specified dimension.
[p]
number
2
The exponent value in the norm formulation
[dim]
number
1
The dimension to reduce
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.
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.
[dim]
number
If given, the input will be squeezed only in the specified dimensions.
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.
dim
number
The index at which to insert the singleton dimension
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.
start_dim
number
0
the first dim to flatten
end_dim
number
the last dim to flatten
Returns a new tensor with the same data as the self
tensor but of a different shape
.
...dims
number
the desired size
Transposes a tensor according to the provided axes.
tensor
any
The input tensor to transpose.
axes
Array
The axes to transpose the tensor along.
Interpolates an Tensor to the given size.
input
Tensor
The input tensor to interpolate. Data must be channel-first (i.e., [c, h, w])
size
Array.<number>
The output size of the image
mode
string
The interpolation mode
align_corners
boolean
Whether to align corners.
Perform mean pooling of the last hidden state followed by a normalization step.
last_hidden_state
Tensor
Tensor of shape [batchSize, seqLength, embedDim]
attention_mask
Tensor
Tensor of shape [batchSize, seqLength]
Concatenates an array of tensors along a specified dimension.
tensors
Array.<Tensor>
The array of tensors to concatenate.
dim
number
The dimension to concatenate along.
Stack an array of tensors along a specified dimension.
tensors
Array.<Tensor>
The array of tensors to stack.
dim
number
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.
input
Tensor
the input tenso
dim
number
| null
the dimension to reduce. If None, all dimensions are reduced.
correction
number
difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.
keepdim
boolean
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.
input
Tensor
the input tensor.
dim
number
| null
the dimension to reduce.
keepdim
boolean
whether the output tensor has dim retained or not.
Measures similarity between two temporal sequences (e.g., input audio and output tokens to generate token-level timestamps).
matrix
Tensor
Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.
size
Array.<number>
A sequence of integers defining the shape of the output tensor.
Returns a tensor filled with the scalar value 1, with the same size as input.
tensor
Tensor
The size of input will determine size of the output tensor.
Reshapes a 1-dimensional array into an n-dimensional array, according to the provided dimensions.
data
Array.<T>
The input array to reshape.
dimensions
DIM
The target shape/dimensions.
Example
Copied
This creates a nested array of a given type and depth (see examples).
Copied
Example
Copied
Example
Copied
Kind: static class of
⇒ Iterator
⇒ Tensor
⇒ number
⇒ Tensor
⇒ number
⇒ Array
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒
⇒ Tensor
⇒ Tensor
⇒ Tensor
⇒ Array.<number>
⇒
⇒
⇒
⇒ Tensor
Kind: instance method of
Returns: Iterator
- An iterator object for iterating over the tensor data in row-major order.
Kind: instance method of
Returns: Tensor
- The data at the specified index.
Kind: instance method of
Returns: number
- The index of the first occurrence of item in the tensor data.
Kind: instance method of
Kind: instance method of
Returns: number
- The value of this tensor as a standard JavaScript Number.
Throws:
Kind: instance method of
Kind: instance method of
Returns: Tensor
- The tensor with the sigmoid function applied.
Kind: instance method of
Returns: Tensor
- Returns this
.
Kind: instance method of
Returns: Tensor
- The transposed tensor.
Kind: instance method of Returns: The summed tensor
Kind: instance method of
Returns: Tensor
- The norm of the tensor.
Kind: instance method of
Returns: Tensor
- this
for operation chaining.
Kind: instance method of
Returns: Tensor
- The normalized tensor.
Kind: instance method of
Returns: Array.<number>
- The stride of this tensor.
Kind: instance method of Returns: The squeezed tensor
In-place version of @see
Kind: instance method of
Kind: instance method of Returns: The unsqueezed tensor
In-place version of @see
Kind: instance method of
In-place version of @see
Kind: instance method of
Kind: instance method of Returns: The flattened tensor.
Kind: instance method of
Returns: Tensor
- The tensor with the same data but different shape
Kind: static method of
Returns: Tensor
- The transposed tensor.
Kind: static method of
Returns: Tensor
- The interpolated tensor.
Kind: static method of
Returns: Tensor
- Returns a new Tensor of shape [batchSize, embedDim].
Kind: static method of
Returns: Tensor
- The concatenated tensor.
Kind: static method of
Returns: Tensor
- The stacked tensor.
Kind: static method of
Returns: Array.<Tensor>
- A tuple of (std, mean) tensors.
Kind: static method of Returns: A new tensor with means taken along the specified dimension.
Kind: static method of
Kind: static method of
Kind: static method of Returns: The ones tensor.
Kind: inner constant of
Kind: inner method of
Returns: *
- The reshaped array.
Kind: inner property of
Kind: inner typedef of
Kind: inner typedef of Example