Interface: Tensor
torchlive/torch.Tensor
Indexable
▪ [index: number
]: Tensor
Access tensor with index.
const tensor = torch.rand([2]);
console.log(tensor.data, tensor[0].data);
// [0.8339180946350098, 0.17733973264694214], [0.8339180946350098]
https://pytorch.org/cppdocs/notes/tensor_indexing.html
Properties
dtype
• dtype: Dtype
A dtype is an string that represents the data type of a torch.Tensor.
https://pytorch.org/docs/1.11/tensor_attributes.html
Defined in
torchlive/torch.ts:236
shape
• shape: number
[]
Returns the size of the tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.size.html
Defined in
torchlive/torch.ts:274
Methods
abs
▸ abs(): Tensor
Computes the absolute value of each element in input.
https://pytorch.org/docs/1.11/generated/torch.Tensor.abs.html
Returns
Defined in
torchlive/torch.ts:145
add
▸ add(other
, options?
): Tensor
Add a scalar or tensor to this tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.add.html
Parameters
Name | Type | Description |
---|---|---|
other | number | Tensor | Scalar or tensor to be added to each element in this tensor. |
options? | Object | - |
options.alpha? | Number | The multiplier for other . Default: 1 . |
Returns
Defined in
torchlive/torch.ts:154
argmax
▸ argmax(options?
): Tensor
Returns the indices of the maximum value of all elements in the input tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.argmax.html
Parameters
Name | Type | Description |
---|---|---|
options? | Object | argmax Options as keywords argument in pytorch |
options.dim? | number | The dimension to reduce. If undefined , the argmax of the flattened input is returned. |
options.keepdim? | boolean | Whether the output tensor has dim retained or not. Ignored if dim is undefined . |
Returns
Defined in
torchlive/torch.ts:165
clamp
▸ clamp(min
, max?
): Tensor
Clamps all elements in input into the range [ min, max ]
.
If min
is undefined
, there is no lower bound. Or, if max
is undefined
there is no upper bound.
https://pytorch.org/docs/1.11/generated/torch.Tensor.clamp.html
Parameters
Name | Type | Description |
---|---|---|
min | number | Tensor | Lower-bound of the range to be clamped to |
max? | number | Tensor | Upper-bound of the range to be clamped to |
Returns
Defined in
torchlive/torch.ts:176
▸ clamp(options
): Tensor
Clamps all elements in input into the range [ min, max ]
.
If min
is undefined
, there is no lower bound. Or, if max
is undefined
there is no upper bound.
https://pytorch.org/docs/1.11/generated/torch.Tensor.clamp.html
Parameters
Name | Type | Description |
---|---|---|
options | Object | - |
options.max? | number | Tensor | Upper-bound of the range to be clamped to |
options.min? | number | Tensor | Lower-bound of the range to be clamped to |
Returns
Defined in
torchlive/torch.ts:187
contiguous
▸ contiguous(options?
): Tensor
Returns a contiguous in memory tensor containing the same data as this tensor. If this tensor is already in the specified memory format, this function returns this tensor.
Parameters
Name | Type | Description |
---|---|---|
options? | Object | - |
options.memoryFormat | MemoryFormat | The desired memory format of returned Tensor. Default: torch.contiguousFormat. https://pytorch.org/docs/1.11/generated/torch.Tensor.contiguous.html |
Returns
Defined in
torchlive/torch.ts:197
data
▸ data(): TypedArray
Returns the tensor data as TypedArray
buffer.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
A valid TypeScript expression is as follows:
torch.rand([2, 3]).data()[3];
The function only exists in JavaScript.
experimental
Returns
TypedArray
Defined in
torchlive/torch.ts:217
div
▸ div(other
, options?
): Tensor
Divides each element of the input input by the corresponding element of other.
https://pytorch.org/docs/1.11/generated/torch.Tensor.div.html
Parameters
Name | Type | Description |
---|---|---|
other | number | Tensor | Scalar or tensor that divides each element in this tensor. |
options? | Object | - |
options.roundingMode? | "trunc" | "floor" | Type of rounding applied to the result |
Returns
Defined in
torchlive/torch.ts:227
item
▸ item(): number
Returns the value of this tensor as a number
. This only works for
tensors with one element.
https://pytorch.org/docs/1.11/generated/torch.Tensor.item.html
Returns
number
Defined in
torchlive/torch.ts:243
mul
▸ mul(other
): Tensor
Multiplies input by other scalar or tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.mul.html
Parameters
Name | Type | Description |
---|---|---|
other | number | Tensor | Scalar or tensor multiplied with each element in this tensor. |
Returns
Defined in
torchlive/torch.ts:260
permute
▸ permute(dims
): Tensor
Returns a view of the original tensor input with its dimensions permuted.
https://pytorch.org/docs/1.11/generated/torch.Tensor.permute.html
Parameters
Name | Type | Description |
---|---|---|
dims | number [] | The desired ordering of dimensions. |
Returns
Defined in
torchlive/torch.ts:268
reshape
▸ reshape(shape
): Tensor
Returns a tensor with the same data and number of elements as input, but with the specified shape.
https://pytorch.org/docs/1.11/generated/torch.Tensor.reshape.html
Parameters
Name | Type | Description |
---|---|---|
shape | number [] | The new shape. |
Returns
Defined in
torchlive/torch.ts:252
size
▸ size(): number
[]
Returns the size of the tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.size.html
Returns
number
[]
Defined in
torchlive/torch.ts:280
softmax
▸ softmax(dim
): Tensor
Applies a softmax function. It is applied to all slices along dim, and
will re-scale them so that the elements lie in the range [0, 1]
and sum
to 1
.
https://pytorch.org/docs/1.11/generated/torch.nn.functional.softmax.html
Parameters
Name | Type | Description |
---|---|---|
dim | number | A dimension along which softmax will be computed. |
Returns
Defined in
torchlive/torch.ts:290
sqrt
▸ sqrt(): Tensor
Computes the square-root value of each element in input.
https://pytorch.org/docs/1.11/generated/torch.Tensor.sqrt.html
Returns
Defined in
torchlive/torch.ts:296
squeeze
▸ squeeze(dim?
): Tensor
Returns a tensor with all the dimensions of input of size 1 removed.
https://pytorch.org/docs/1.11/generated/torch.Tensor.squeeze.html
Parameters
Name | Type | Description |
---|---|---|
dim? | number | If given, the input will be squeezed only in this dimension. |
Returns
Defined in
torchlive/torch.ts:304
stride
▸ stride(): number
[]
Returns the stride of the tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.stride.html
Returns
number
[]
Defined in
torchlive/torch.ts:310
▸ stride(dim
): number
Returns the stride of the tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.stride.html
Parameters
Name | Type | Description |
---|---|---|
dim | number | The desired dimension in which stride is required. |
Returns
number
Defined in
torchlive/torch.ts:318
sub
▸ sub(other
, options?
): Tensor
Subtracts other from input.
https://pytorch.org/docs/1.11/generated/torch.Tensor.sub.html
Parameters
Name | Type | Description |
---|---|---|
other | number | Tensor | The scalar or tensor to subtract from input. |
options? | Object | - |
options.alpha? | Number | The multiplier for other . Default: 1 . |
Returns
Defined in
torchlive/torch.ts:327
sum
▸ sum(): Tensor
Returns the sum of all elements in the input tensor.
https://pytorch.org/docs/1.11/generated/torch.Tensor.sum.html
Returns
Defined in
torchlive/torch.ts:333
▸ sum(dim
, options?
): Tensor
Returns the sum of each row of the input tensor in the given dimension dim. If dim is a list of dimensions, reduce over all of them.
https://pytorch.org/docs/1.11/generated/torch.Tensor.sum.html
Parameters
Name | Type | Description |
---|---|---|
dim | number | number [] | The dimension or dimensions to reduce. |
options? | Object | - |
options.keepdim? | boolean | Whether the output tensor has dim retained or not. |
Returns
Defined in
torchlive/torch.ts:343
to
▸ to(options
): Tensor
Performs Tensor conversion.
https://pytorch.org/docs/1.11/generated/torch.Tensor.to.html
Parameters
Name | Type | Description |
---|---|---|
options | TensorOptions | Tensor options. |
Returns
Defined in
torchlive/torch.ts:351
topk
Returns the k largest elements of the given input tensor along a given dimension.
https://pytorch.org/docs/1.11/generated/torch.Tensor.topk.html
Parameters
Name | Type | Description |
---|---|---|
k | number | The k in "top-k" |
Returns
Defined in
torchlive/torch.ts:360
unsqueeze
▸ unsqueeze(dim
): Tensor
Returns a new tensor with a dimension of size one inserted at the specified position.
https://pytorch.org/docs/1.11/generated/torch.Tensor.unsqueeze.html
Parameters
Name | Type | Description |
---|---|---|
dim | number | The index at which to insert the singleton dimension. |
Returns
Defined in
torchlive/torch.ts:369