Class Tensor
- All Implemented Interfaces:
AutoCloseable
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A class that encapsulates the construction axes of a Tensor. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionacos()
Returns a new tensor with the arccosine of the elements of input.acos_()
Computes the arccosine of the elements of input in place.add
(double other) Returns A + b.add
(float other) Returns A + b.Returns A + B.Returns A + alpha * B.add_
(double other) Returns A += b.add_
(float other) Returns A += b.Returns A += B.Returns A += alpha * B.Returns logical AND of two boolean tensors.Returns logical AND of two boolean tensors.static Tensor
arange
(double start, double end, double step) 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.static Tensor
arange
(float start, float end, float step) 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.static Tensor
arange
(int start, int end, int step) 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.static Tensor
arange
(long start, long end, long step) 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.argmax
(int dim, boolean keepDim) Returns the indices of the maximum value of a tensor across a dimension.asin()
Returns a new tensor with the arcsine of the elements of input.asin_()
Computes the arcsine of the elements of input in place.org.bytedeco.pytorch.Tensor
asTorch()
Returns the PyTorch tensor object.void
backward()
Computes the gradients.bernoulli_
(double p) Draws binary random numbers (0 or 1) from a Bernoulli distribution.int
Returns the byte value when the tensor holds a single value.clone()
void
close()
cos()
Returns a new tensor with the cosine of the elements of input.cos_()
Computes the cosine of the elements of input in place.detach()
Returns a new tensor, detached from the current graph.device()
Returns the device on which the tensor is.int
dim()
Returns the number of dimensions of tensor.div
(double other) Returns A / b.div
(float other) Returns A / b.Returns A / B element wisely.div_
(double other) Returns A /= b.div_
(float other) Returns A /= b.Returns A /= B element wisely.double
Returns the double value when the tensor holds a single value.dropout
(double p) Randomly zeroes some elements of the input tensor with probability p.dropout_
(double p) Randomly zeroes some elements in place with probability p.dtype()
Returns the element data type.static Tensor
empty
(long... shape) Returns a tensor with uninitialized data.static Tensor
empty
(Tensor.Options options, long... shape) Returns a tensor with uninitialized data.eq
(double other) Computes element-wise equality.eq
(int other) Computes element-wise equality.Computes element-wise equality.boolean
exp()
Returns the exponential of elements in the tensor.exp_()
Returns the exponential of elements in the tensor in place.static Tensor
eye
(long shape) Returns an identity matrix.static Tensor
eye
(Tensor.Options options, long shape) Returns an identity matrix.fill_
(double x) Fills this tensor with the specified value.fill_
(int x) Fills this tensor with the specified value.flatten()
Flattens the tensor by reshaping it into a one-dimensional tensor.flatten
(int startDim) Flattens the tensor by reshaping it into a one-dimensional tensor.flatten
(int startDim, int endDim) Flattens the tensor by reshaping it into a one-dimensional tensor.float
Returns the float value when the tensor holds a single value.Gathers values along an axis specified by dim.ge
(double other) Computes element-wise greater-than-or-equal-to comparison.ge
(int other) Computes element-wise greater-than-or-equal-to comparison.Computes element-wise greater-than-or-equal-to comparison.get
(int... indices) Returns a portion of tensor given the indices.get
(long... indices) Returns a portion of tensor given the indices.Returns a portion of tensor given the indices.Returns a portion of tensor given the indices.byte
getByte
(int... indices) Returns the byte value of element at given index.byte
getByte
(long... indices) Returns the byte value of element at given index.double
getDouble
(int... indices) Returns the double value of element at given index.double
getDouble
(long... indices) Returns the double value of element at given index.float
getFloat
(int... indices) Returns the float value of element at given index.float
getFloat
(long... indices) Returns the float value of element at given index.int
getInt
(int... indices) Returns the int value of element at given index.int
getInt
(long... indices) Returns the int value of element at given index.long
getLong
(int... indices) Returns the long value of element at given index.long
getLong
(long... indices) Returns the long value of element at given index.short
getShort
(int... indices) Returns the short value of element at given index.short
getShort
(long... indices) Returns the short value of element at given index.gt
(double other) Computes element-wise greater-than comparison.gt
(int other) Computes element-wise greater-than comparison.Computes element-wise greater-than comparison.int
intValue()
Returns the int value when the tensor holds a single value.le
(double other) Computes element-wise less-than-or-equal-to comparison.le
(int other) Computes element-wise less-than-or-equal-to comparison.Computes element-wise less-than-or-equal-to comparison.long
Returns the long value when the tensor holds a single value.lt
(double other) Computes element-wise less-than comparison.lt
(int other) Computes element-wise less-than comparison.Computes element-wise less-than comparison.Returns the matrix product of two tensors.mean()
Returns the mean of all elements in the tensor.mul
(double other) Returns A * b.mul
(float other) Returns A * b.Returns A * B element wisely.mul_
(double other) Returns A *= b.mul_
(float other) Returns A *= b.Returns A *= B element wisely.ne
(double other) Computes element-wise inequality.ne
(int other) Computes element-wise inequality.Computes element-wise inequality.newOnes
(long... shape) Returns a tensor filled with all ones.newZeros
(long... shape) Returns a tensor filled with all zeros.static org.bytedeco.pytorch.NoGradGuard
Disables gradient calculation.static Tensor
of
(byte[] data, long... shape) Returns a tensor with given data and shape.static Tensor
of
(double[] data, long... shape) Returns a tensor with given data and shape.static Tensor
of
(float[] data, long... shape) Returns a tensor with given data and shape.static Tensor
of
(int[] data, long... shape) Returns a tensor with given data and shape.static Tensor
of
(long[] data, long... shape) Returns a tensor with given data and shape.static Tensor
of
(short[] data, long... shape) Returns a tensor with given data and shape.static Tensor
ones
(long... shape) Returns a tensor filled with all ones.static Tensor
ones
(Tensor.Options options, long... shape) Returns a tensor filled with all ones.Returns logical OR of two boolean tensors.Returns logical OR of two boolean tensors.permute
(long... dims) Returns a view of the original tensor input with its dimensions permuted.void
print()
Prints the tensor on the standard output.Updates a portion of tensor.Updates a portion of tensor.put_
(byte x, int... indices) Updates an element in place.put_
(byte x, long... indices) Updates an element in place.put_
(double x, int... indices) Updates an element in place.put_
(double x, long... indices) Updates an element in place.put_
(float x, int... indices) Updates an element in place.put_
(float x, long... indices) Updates an element in place.put_
(int x, int... indices) Updates an element in place.put_
(int x, long... indices) Updates an element in place.put_
(long x, int... indices) Updates an element in place.put_
(long x, long... indices) Updates an element in place.put_
(short x, int... indices) Updates an element in place.put_
(short x, long... indices) Updates an element in place.Updates a portion of tensor in place.Updates a portion of tensor in place.static Tensor
rand
(long... shape) Returns a tensor filled with values drawn from a uniform distribution on [0, 1).static Tensor
rand
(Tensor.Options options, long... shape) Returns a tensor filled with values drawn from a uniform distribution on [0, 1).static Tensor
randn
(long... shape) Returns a tensor filled with values drawn from a unit normal distribution.static Tensor
randn
(Tensor.Options options, long... shape) Returns a tensor filled with values drawn from a unit normal distribution.boolean
Returns true if autograd should record operations on this tensor.requireGrad
(boolean required) Sets if autograd should record operations on this tensor.reshape
(long... shape) Returns a tensor with the same data and number of elements but with the specified shape.scatterReduce
(int dim, Tensor index, Tensor source, String reduce) Writes all values from the tensor src into this tensor at the indices specified in the index tensor.scatterReduce_
(int dim, Tensor index, Tensor source, String reduce) Writes all values from the tensor src into this tensor at the indices specified in the index tensor.long[]
shape()
Returns the shape of the tensor.int
Returns the short value when the tensor holds a single value.sin()
Returns a new tensor with the sine of the elements of input.sin_()
Computes the sine of the elements of input in place.long
size
(int dim) Returns the size of given dimension.sub
(double other) Returns A -= b.sub
(float other) Returns A - b.Returns A - B.Returns A - alpha * B.sub_
(double other) Returns A -= b.sub_
(float other) Returns A - b.Returns A -= B.Returns A -= alpha * B.sum()
Returns the sum of all elements in the tensor.Clone the tensor to a device.to
(Device device, ScalarType dtype) Clone the tensor to a device with a different data type.to
(ScalarType dtype) Clone the tensor with a different data type.topk
(int k) Returns the k largest elements.topk
(int k, int dim, boolean largest, boolean sorted) Returns the k largest elements along a given dimension.toString()
transpose
(long dim0, long dim1) Returns a tensor that is a transposed version of input.unsqueeze
(long dim) Returns a new tensor with a dimension of size one inserted at the specified position.Returns a tensor of elements selected from either input or other, depending on condition.Returns a tensor of elements selected from either input or other, depending on condition.static Tensor
zeros
(long... shape) Returns a tensor filled with all zeros.static Tensor
zeros
(Tensor.Options options, long... shape) Returns a tensor filled with all zeros.
-
Constructor Details
-
Tensor
public Tensor(org.bytedeco.pytorch.Tensor tensor) Constructor.- Parameters:
tensor
- PyTorch Tensor object.
-
-
Method Details
-
print
public void print()Prints the tensor on the standard output. -
equals
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
toString
-
clone
-
asTorch
public org.bytedeco.pytorch.Tensor asTorch()Returns the PyTorch tensor object.- Returns:
- the PyTorch tensor object.
-
requireGrad
Sets if autograd should record operations on this tensor.- Parameters:
required
- the flag indicating if autograd should record operations on this tensor.- Returns:
- this tensor.
-
requireGrad
public boolean requireGrad()Returns true if autograd should record operations on this tensor.- Returns:
- true if autograd should record operations on this tensor.
-
noGradGuard
public static org.bytedeco.pytorch.NoGradGuard noGradGuard()Disables gradient calculation. Disabling gradient calculation is useful for inference, when you are sure that you will not call backward. It will reduce memory consumption for computations that would otherwise have requireGrad(true).In this mode, the result of every computation will have requireGrad(false), even when the inputs have requireGrad(true).
This context manager is thread-local; it will not affect computation in other threads.
- Returns:
- no grad guard to be used with try-with scope.
-
detach
Returns a new tensor, detached from the current graph. The result will never require gradient.- Returns:
- a new tensor that doesn't require gradient.
-
to
Clone the tensor with a different data type.- Parameters:
dtype
- the element data type of new tensor.- Returns:
- The cloned tensor.
-
to
Clone the tensor to a device.- Parameters:
device
- the compute device of new tensor.- Returns:
- The cloned tensor.
-
to
Clone the tensor to a device with a different data type.- Parameters:
device
- the compute device of new tensor.dtype
- the element data type of new tensor.- Returns:
- The cloned tensor.
-
dtype
Returns the element data type.- Returns:
- the element data type.
-
device
Returns the device on which the tensor is.- Returns:
- the device.
-
dim
public int dim()Returns the number of dimensions of tensor.- Returns:
- the number of dimensions of tensor
-
shape
public long[] shape()Returns the shape of the tensor.- Returns:
- the shape of the tensor.
-
size
public long size(int dim) Returns the size of given dimension.- Parameters:
dim
- dimension index.- Returns:
- the size of given dimension.
-
reshape
Returns a tensor with the same data and number of elements but with the specified shape. This method returns a view if shape is compatible with the current shape.- Parameters:
shape
- the new shape of tensor.- Returns:
- the tensor with the specified shape.
-
flatten
Flattens the tensor by reshaping it into a one-dimensional tensor. This function may return the original object, a view, or copy.- Returns:
- the tensor with the specified shape.
-
flatten
Flattens the tensor by reshaping it into a one-dimensional tensor. Only dimensions starting with startDim and ending with endDim are flattened. The order of elements in input is unchanged. This function may return the original object, a view, or copy.- Parameters:
startDim
- the first dim to flatten.- Returns:
- the tensor with the specified shape.
-
flatten
Flattens the tensor by reshaping it into a one-dimensional tensor. Only dimensions starting with startDim and ending with endDim are flattened. The order of elements in input is unchanged. This function may return the original object, a view, or copy.- Parameters:
startDim
- the first dim to flatten.endDim
- the last dim to flatten- Returns:
- the tensor with the specified shape.
-
backward
public void backward()Computes the gradients. -
fill_
Fills this tensor with the specified value.- Parameters:
x
- the value.- Returns:
- this tensor.
-
fill_
Fills this tensor with the specified value.- Parameters:
x
- the value.- Returns:
- this tensor.
-
bernoulli_
Draws binary random numbers (0 or 1) from a Bernoulli distribution.- Parameters:
p
- Bernoulli probability.- Returns:
- this tensor.
-
permute
Returns a view of the original tensor input with its dimensions permuted.- Parameters:
dims
- The desired ordering of dimensions.- Returns:
- the permuted tensor.
-
put
Updates a portion of tensor.- Parameters:
source
- the new sub-tensor values.indices
- the indices along the dimensions.- Returns:
- the output tensor.
-
put
Updates a portion of tensor.- Parameters:
source
- the new sub-tensor value.index
- the sub-tensor index.- Returns:
- the output tensor.
-
put_
Updates a portion of tensor in place.- Parameters:
source
- the new sub-tensor values.indices
- the indices along the dimensions.- Returns:
- this tensor.
-
put_
Updates a portion of tensor in place.- Parameters:
source
- the new sub-tensor value.index
- the sub-tensor index.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
put_
Updates an element in place.- Parameters:
x
- the new element value.indices
- the element indices.- Returns:
- this tensor.
-
get
Returns a portion of tensor given the indices.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the sub-tensor.
-
get
Returns a portion of tensor given the indices.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the sub-tensor.
-
get
Returns a portion of tensor given the indices.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the sub-tensor.
-
get
Returns a portion of tensor given the indices.- Parameters:
index
- the tensor index.- Returns:
- the sub-tensor.
-
getByte
public byte getByte(int... indices) Returns the byte value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getByte
public byte getByte(long... indices) Returns the byte value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getShort
public short getShort(int... indices) Returns the short value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getShort
public short getShort(long... indices) Returns the short value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getInt
public int getInt(int... indices) Returns the int value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getInt
public int getInt(long... indices) Returns the int value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getLong
public long getLong(int... indices) Returns the long value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getLong
public long getLong(long... indices) Returns the long value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getFloat
public float getFloat(int... indices) Returns the float value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getFloat
public float getFloat(long... indices) Returns the float value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getDouble
public double getDouble(int... indices) Returns the double value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
getDouble
public double getDouble(long... indices) Returns the double value of element at given index.- Parameters:
indices
- the indices along the dimensions.- Returns:
- the element value.
-
byteValue
public int byteValue()Returns the byte value when the tensor holds a single value.- Returns:
- the byte value when the tensor holds a single value.
-
shortValue
public int shortValue()Returns the short value when the tensor holds a single value.- Returns:
- the short value when the tensor holds a single value.
-
intValue
public int intValue()Returns the int value when the tensor holds a single value.- Returns:
- the int value when the tensor holds a single value.
-
longValue
public long longValue()Returns the long value when the tensor holds a single value.- Returns:
- the long value when the tensor holds a single value.
-
floatValue
public float floatValue()Returns the float value when the tensor holds a single value.- Returns:
- the float value when the tensor holds a single value.
-
doubleValue
public double doubleValue()Returns the double value when the tensor holds a single value.- Returns:
- the double value when the tensor holds a single value.
-
unsqueeze
Returns a new tensor with a dimension of size one inserted at the specified position.The returned tensor shares the same underlying data with this tensor.
A dim value within the range [-input.dim() - 1, input.dim() + 1) can be used. Negative dim will correspond to unsqueeze() applied at dim = dim + input.dim() + 1.
- Parameters:
dim
- the index at which to insert the singleton dimension.- Returns:
- the output tensor.
-
transpose
Returns a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other.
If input is a sparse tensor then the resulting out tensor does not share the underlying storage with the input tensor.
If input is a sparse tensor with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.
- Parameters:
dim0
- the first dimension to be transposed.dim1
- the second dimension to be transposed.- Returns:
- the output tensor.
-
argmax
Returns the indices of the maximum value of a tensor across a dimension.- Parameters:
dim
- the dimension to reduce.keepDim
- whether the output tensor has dim retained or not.- Returns:
- the indices of the maximum value of a tensor across a dimension.
-
topk
Returns the k largest elements.- Parameters:
k
- the number of largest elements.- Returns:
- the values and indices of the largest k elements.
-
topk
Returns the k largest elements along a given dimension.- Parameters:
k
- the number of largest elements.dim
- the dimension to sort along.largest
- controls whether to return largest or smallest elements.sorted
- controls whether to return the elements in sorted order.- Returns:
- the values and indices of the largest k elements.
-
where
Returns a tensor of elements selected from either input or other, depending on condition.- Parameters:
condition
- a boolean tensor. When true (nonzero), yield input, otherwise yield other.input
- value selected at indices where condition is true.other
- value selected at indices where condition is false.- Returns:
- the output tensor.
-
where
Returns a tensor of elements selected from either input or other, depending on condition.- Parameters:
condition
- a boolean tensor. When true (nonzero), yield input, otherwise yield other.input
- value selected at indices where condition is true.other
- value selected at indices where condition is false.- Returns:
- the output tensor.
-
matmul
Returns the matrix product of two tensors.- Parameters:
other
- another tensor.- Returns:
- the matrix product of two tensors.
-
eq
Computes element-wise equality.- Parameters:
other
- the sclar to compare.- Returns:
- the output tensor.
-
eq
Computes element-wise equality.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
eq
Computes element-wise equality.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
ne
Computes element-wise inequality.- Parameters:
other
- the sclar to compare.- Returns:
- the output tensor.
-
ne
Computes element-wise inequality.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
ne
Computes element-wise inequality.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
lt
Computes element-wise less-than comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
lt
Computes element-wise less-than comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
lt
Computes element-wise less-than comparison.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
le
Computes element-wise less-than-or-equal-to comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
le
Computes element-wise less-than-or-equal-to comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
le
Computes element-wise less-than-or-equal-to comparison.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
gt
Computes element-wise greater-than comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
gt
Computes element-wise greater-than comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
gt
Computes element-wise greater-than comparison.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
ge
Computes element-wise greater-than-or-equal-to comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
ge
Computes element-wise greater-than-or-equal-to comparison.- Parameters:
other
- the scalar to compare.- Returns:
- the output tensor.
-
ge
Computes element-wise greater-than-or-equal-to comparison.- Parameters:
other
- the tensor to compare.- Returns:
- the output tensor.
-
sum
Returns the sum of all elements in the tensor.- Returns:
- the sum of all elements.
-
mean
Returns the mean of all elements in the tensor.- Returns:
- the mean of all elements.
-
exp
Returns the exponential of elements in the tensor.- Returns:
- the output tensor.
-
exp_
Returns the exponential of elements in the tensor in place.- Returns:
- this tensor.
-
scatterReduce
Writes all values from the tensor src into this tensor at the indices specified in the index tensor. For each value in src, its output index is specified by its index in src for dimension != dim and by the corresponding value in index for dimension = dim.This is the reverse operation of the manner described in gather().
- Parameters:
dim
- the axis along which to index.index
- the indices of elements to scatter, can be either empty or of the same dimensionality as src. When empty, the operation returns self unchanged.source
- the source elements to scatter and reduce.reduce
- the reduction operation to apply for non-unique indices ("sum", "prod", "mean", "amax", or "amin").- Returns:
- the output tensor.
-
scatterReduce_
Writes all values from the tensor src into this tensor at the indices specified in the index tensor. For each value in src, its output index is specified by its index in src for dimension != dim and by the corresponding value in index for dimension = dim.This is the reverse operation of the manner described in gather().
- Parameters:
dim
- the axis along which to index.index
- the indices of elements to scatter, can be either empty or of the same dimensionality as src. When empty, the operation returns self unchanged.source
- the source elements to scatter and reduce.reduce
- the reduction operation to apply for non-unique indices ("sum", "prod", "mean", "amax", or "amin").- Returns:
- this tensor.
-
gather
Gathers values along an axis specified by dim.- Parameters:
dim
- the axis along which to index.index
- the indices of elements to gather.- Returns:
- the output tensor.
-
add
Returns A + b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
add_
Returns A += b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
add
Returns A + b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
add_
Returns A += b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
add
Returns A + B.- Parameters:
other
- another tensor.- Returns:
- the output tensor.
-
add_
Returns A += B.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
add
Returns A + alpha * B.- Parameters:
other
- another tensor.alpha
- the scaling factor.- Returns:
- the output tensor.
-
add_
Returns A += alpha * B.- Parameters:
other
- another tensor.alpha
- the scaling factor.- Returns:
- this tensor.
-
sub
Returns A - b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
sub_
Returns A - b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
sub
Returns A -= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
sub_
Returns A -= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
sub
Returns A - B.- Parameters:
other
- another tensor.- Returns:
- the output tensor.
-
sub_
Returns A -= B.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
sub
Returns A - alpha * B.- Parameters:
other
- another tensor.alpha
- the scaling factor.- Returns:
- the output tensor.
-
sub_
Returns A -= alpha * B.- Parameters:
other
- another tensor.alpha
- the scaling factor.- Returns:
- this tensor.
-
mul
Returns A * b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
mul_
Returns A *= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
mul
Returns A * b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
mul_
Returns A *= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
mul
Returns A * B element wisely.- Parameters:
other
- another tensor.- Returns:
- the output tensor.
-
mul_
Returns A *= B element wisely.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
div
Returns A / b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
div_
Returns A /= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
div
Returns A / b.- Parameters:
other
- a scalar value.- Returns:
- the output tensor.
-
div_
Returns A /= b.- Parameters:
other
- a scalar value.- Returns:
- this tensor.
-
div
Returns A / B element wisely.- Parameters:
other
- another tensor.- Returns:
- the output tensor.
-
div_
Returns A /= B element wisely.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
cos
Returns a new tensor with the cosine of the elements of input.- Returns:
- a new tensor with the cosine of the elements of input.
-
cos_
Computes the cosine of the elements of input in place.- Returns:
- this tensor.
-
sin
Returns a new tensor with the sine of the elements of input.- Returns:
- a new tensor with the sine of the elements of input.
-
sin_
Computes the sine of the elements of input in place.- Returns:
- this tensor.
-
acos
Returns a new tensor with the arccosine of the elements of input.- Returns:
- a new tensor with the arccosine of the elements of input.
-
acos_
Computes the arccosine of the elements of input in place.- Returns:
- this tensor.
-
asin
Returns a new tensor with the arcsine of the elements of input.- Returns:
- a new tensor with the arcsine of the elements of input.
-
asin_
Computes the arcsine of the elements of input in place.- Returns:
- this tensor.
-
and
Returns logical AND of two boolean tensors.- Parameters:
other
- another tensor.- Returns:
- a new tensor of logical and results.
-
and_
Returns logical AND of two boolean tensors.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
or
Returns logical OR of two boolean tensors.- Parameters:
other
- another tensor.- Returns:
- a new tensor of logical and results.
-
or_
Returns logical OR of two boolean tensors.- Parameters:
other
- another tensor.- Returns:
- this tensor.
-
dropout
Randomly zeroes some elements of the input tensor with probability p.- Parameters:
p
- the probability of an element to be zeroed.- Returns:
- a new tensor after random dropouts.
-
dropout_
Randomly zeroes some elements in place with probability p.- Parameters:
p
- the probability of an element to be zeroed.- Returns:
- this tensor.
-
newZeros
Returns a tensor filled with all zeros. The returned Tensor has the data type and device as this tensor.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
newOnes
Returns a tensor filled with all ones. The returned Tensor has the data type and device as this tensor.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
eye
Returns an identity matrix.- Parameters:
shape
- the dimension of the resulting matrix.- Returns:
- the created tensor.
-
eye
Returns an identity matrix.- Parameters:
options
- Tensor creation options.shape
- the dimension of the resulting matrix.- Returns:
- the created tensor.
-
empty
Returns a tensor with uninitialized data.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
empty
Returns a tensor with uninitialized data.- Parameters:
options
- Tensor creation options.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
zeros
Returns a tensor filled with all zeros.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
zeros
Returns a tensor filled with all zeros.- Parameters:
options
- Tensor creation options.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
ones
Returns a tensor filled with all ones.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
ones
Returns a tensor filled with all ones.- Parameters:
options
- Tensor creation options.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
rand
Returns a tensor filled with values drawn from a uniform distribution on [0, 1).- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
rand
Returns a tensor filled with values drawn from a uniform distribution on [0, 1).- Parameters:
options
- Tensor creation options.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
randn
Returns a tensor filled with values drawn from a unit normal distribution.- Parameters:
shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
randn
Returns a tensor filled with values drawn from a unit normal distribution.- Parameters:
options
- Tensor creation options.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
arange
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.- Parameters:
start
- the starting value for the set of points.end
- the ending value for the set of points.step
- the gap between each pair of adjacent points.- Returns:
- a 1-D tensor.
-
arange
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.- Parameters:
start
- the starting value for the set of points.end
- the ending value for the set of points.step
- the gap between each pair of adjacent points.- Returns:
- a 1-D tensor.
-
arange
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.Note that step is subject to floating point rounding errors when comparing against end. To avoid inconsistency, we advise subtracting a small epsilon from end in such cases.
- Parameters:
start
- the starting value for the set of points.end
- the ending value for the set of points.step
- the gap between each pair of adjacent points.- Returns:
- a 1-D tensor.
-
arange
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.Note that step is subject to floating point rounding errors when comparing against end. To avoid inconsistency, we advise subtracting a small epsilon from end in such cases.
- Parameters:
start
- the starting value for the set of points.end
- the ending value for the set of points.step
- the gap between each pair of adjacent points.- Returns:
- a 1-D tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-
of
Returns a tensor with given data and shape.- Parameters:
data
- the initialization data.shape
- the dimensional shape of the resulting tensor.- Returns:
- the created tensor.
-