Skip to main content
Version: Next

Interface: Torch

torchlive/torch.Torch

Properties

channelsLast

channelsLast: "channelsLast"

Defined in

torchlive/torch.ts:594


contiguousFormat

contiguousFormat: "contiguousFormat"

Defined in

torchlive/torch.ts:595


double

double: "double"

Defined in

torchlive/torch.ts:580


float

float: "float"

Defined in

torchlive/torch.ts:581


float32

float32: "float32"

Defined in

torchlive/torch.ts:582


float64

float64: "float64"

Defined in

torchlive/torch.ts:583


int

int: "int"

Defined in

torchlive/torch.ts:584


int16

int16: "int16"

Defined in

torchlive/torch.ts:585


int32

int32: "int32"

Defined in

torchlive/torch.ts:586


int64

int64: "int64"

Defined in

torchlive/torch.ts:587


int8

int8: "int8"

Defined in

torchlive/torch.ts:588


jit

jit: JIT

JIT module

Defined in

torchlive/torch.ts:577


long

long: "long"

Defined in

torchlive/torch.ts:589


preserveFormat

preserveFormat: "preserveFormat"

Defined in

torchlive/torch.ts:596


short

short: "short"

Defined in

torchlive/torch.ts:590


uint8

uint8: "uint8"

Defined in

torchlive/torch.ts:591

Methods

arange

arange(end, options?): Tensor

Returns a 1-D tensor of size (end - 0) / 1 with values from the interval [0, end) taken with common difference step beginning from start.

https://pytorch.org/docs/1.11/generated/torch.arange.html

Parameters

NameTypeDescription
endnumberThe ending value for the set of points.
options?TensorOptions

Returns

Tensor

Defined in

torchlive/torch.ts:406

arange(start, end, options?): Tensor

Returns a 1-D tensor of size (end - start) / 1 with values from the interval [start, end) taken with common difference 1 beginning from start.

https://pytorch.org/docs/1.11/generated/torch.arange.html

Parameters

NameTypeDescription
startnumberThe starting value for the set of points.
endnumberThe ending value for the set of points.
options?TensorOptions

Returns

Tensor

Defined in

torchlive/torch.ts:418

arange(start, end, step, options?): Tensor

Returns a 1-D tensor of size (end - start) / step with values from the interval [start, end) taken with common difference step beginning from start.

https://pytorch.org/docs/1.11/generated/torch.arange.html

Parameters

NameTypeDescription
startnumberThe starting value for the set of points.
endnumberThe ending value for the set of points.
stepnumberThe gap between each pair of adjacent points.
options?TensorOptions

Returns

Tensor

Defined in

torchlive/torch.ts:431


cat

cat(tensors, options?): Tensor

Concatenate a list of tensors along the specified axis, which default to be axis 0

https://pytorch.org/docs/1.11/generated/torch.cat.html

Parameters

NameTypeDescription
tensorsTensor[]A sequence of Tensor to be concatenated.
options?Objectused to specify the dimenstion to concate.
options.dim?number-

Returns

Tensor

Defined in

torchlive/torch.ts:445


empty

empty(size, options?): Tensor

Returns a tensor filled with uninitialized data. The shape of the tensor is defined by the variable argument size.

https://pytorch.org/docs/1.11/generated/torch.empty.html

Parameters

NameTypeDescription
sizenumber[]A sequence of integers defining the shape of the output tensor.
options?TensorOptions-

Returns

Tensor

Defined in

torchlive/torch.ts:455


expand

expand(sizes): Tensor

Returns a new view of the tensor expanded to a larger size.

https://pytorch.org/docs/stable/generated/torch.Tensor.expand.html

Parameters

NameTypeDescription
sizesnumber[]The expanded size, eg: ([3, 4]).

Returns

Tensor

Defined in

torchlive/torch.ts:463


eye

eye(n, m?, options?): Tensor

Returns a tensor filled with ones on the diagonal, and zeroes elsewhere. The shape of the tensor is defined by the arguments n and m.

https://pytorch.org/docs/1.11/generated/torch.eye.html

Parameters

NameTypeDescription
nnumberAn integer defining the number of rows in the result.
m?numberAn integer defining the number of columns in the result. Optional, defaults to n.
options?TensorOptions-

Returns

Tensor

Defined in

torchlive/torch.ts:473


fromBlob

fromBlob(blob, sizes?, options?): Tensor

Exposes the given data as a Tensor without taking ownership of the original data.

note

The function exists in JavaScript and C++ (torch::from_blob).

Parameters

NameTypeDescription
blobanyThe blob holding the data.
sizes?number[]Should specify the shape of the tensor, strides the stride
options?TensorOptionsTensor options in each dimension.

Returns

Tensor

Defined in

torchlive/torch.ts:489


logspace

logspace(start, end, steps, options?): Tensor

Returns a one-dimensional tensor of size steps whose values are evenly spaced from base^start to base^end, inclusive, on a logarithmic scale with base.

https://pytorch.org/docs/1.11/generated/torch.logspace.html

Parameters

NameTypeDescription
startnumberstarting value for the set of points
endnumberending value for the set of points
stepsnumbersize of the constructed tensor
options?TensorOptions & { base: number }object to customizing base and dtype. default to be {base: 10, dtype: torch.float32}

Returns

Tensor

Defined in

torchlive/torch.ts:501


ones

ones(size, options?): Tensor

Returns a tensor filled with the scalar value 1, with the shape defined by the argument size.

https://pytorch.org/docs/1.11/generated/torch.ones.html

Parameters

NameTypeDescription
sizenumber[]A sequence of integers defining the shape of the output tensor.
options?TensorOptionsTensor options.

Returns

Tensor

Defined in

torchlive/torch.ts:516


rand

rand(size, options?): Tensor

Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1).

Parameters

NameTypeDescription
sizenumber[]A sequence of integers defining the shape of the output tensor.
options?TensorOptionsTensor options.

Returns

Tensor

Defined in

torchlive/torch.ts:524


randint

randint(high, size): Tensor

Returns a tensor filled with random integers generated uniformly between 0 (inclusive) and high (exclusive).

https://pytorch.org/docs/1.11/generated/torch.randint.html

Parameters

NameTypeDescription
highnumberOne above the highest integer to be drawn from the distribution.
sizenumber[]A tuple defining the shape of the output tensor.

Returns

Tensor

Defined in

torchlive/torch.ts:534

randint(low, high, size): Tensor

Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive).

https://pytorch.org/docs/1.11/generated/torch.randint.html

Parameters

NameTypeDescription
lownumberLowest integer to be drawn from the distribution.
highnumberOne above the highest integer to be drawn from the distribution.
sizenumber[]A tuple defining the shape of the output tensor.

Returns

Tensor

Defined in

torchlive/torch.ts:545


randn

randn(size, options?): Tensor

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).

https://pytorch.org/docs/1.11/generated/torch.randn.html

Parameters

NameTypeDescription
sizenumber[]A sequence of integers defining the shape of the output tensor.
options?TensorOptionsTensor options.

Returns

Tensor

Defined in

torchlive/torch.ts:555


tensor

tensor(data, options?): Tensor

Constructs a tensor with no autograd history.

Parameters

NameTypeDescription
datanumber | ItemArrayTensor data as multi-dimensional array.
options?TensorOptionsTensor options.

Returns

Tensor

Defined in

torchlive/torch.ts:562


zeros

zeros(size, options?): Tensor

Returns a tensor filled with the scalar value 0, with the shape defined by the argument size.

https://pytorch.org/docs/1.11/generated/torch.zeros.html

Parameters

NameTypeDescription
sizenumber[]A sequence of integers defining the shape of the output tensor.
options?TensorOptionsTensor options.

Returns

Tensor

Defined in

torchlive/torch.ts:572