Tensor¶
- class
dragon.vm.torch.
Tensor
(
*args,
**kwargs
)[source]¶ A multi-dimensional array containing elements of a single data type.
To create a tensor from constant value, use
torch.tensor(...)
:# Create a constant tensor # The value is 1, dimensions is (0,) const_tensor = torch.tensor(1, dtype=torch.float32)
Besides, following initializers can also be used:
# Create an empty float32 tensor # The dimensions is (1, 2) empty_tensor = torch.empty(1, 2, dtype=torch.float32) # Create a float32 tensor filling ``one`` or ``zero`` ones = torch.ones(1, 2, dtype=torch.float32) zeros = torch.zeros(1, 2, dtype=torch.float32)
Construct a tensor with device and grad will sometimes be helpful:
# Initialize a weight and bias on the gpu:0, whose gradient should not be ignored weight = torch.ones(1, 2, device=torch.device('cuda', 0), requires_grad=True) bias = torch.tensor(0, device=torch.device('cuda', 0), requires_grad=True)
Be careful to store a tensor object, or the memory will not be free:
# The memory of ``my_tensor`` will be held # until the reference count decrease to zero my_object.tensors = [] my_object.tensors.append(my_tensor)
Properties¶
data¶
Tensor.
data
¶Return a data reference detaching the grad.
- Returns:
- dragon.vm.torch.Tensor – The data tensor.
device¶
Tensor.
device
¶Return the device of this tensor.
- Returns:
- dragon.vm.torch.device – The device.
grad¶
Tensor.
grad
¶Return the grad of this tensor.
- Returns:
- dragon.vm.torch.Tensor – The grad tensor.
is_leaf¶
Tensor.
is_leaf
¶Return whether tensor is a leaf.
- Returns:
- bool –
True
if this is a leaf tensor otherwiseFalse
.
Methods¶
abs¶
add¶
Tensor.
add
(other)[source]¶Compute the element-wise addition.
\[\text{out} = \text{self} + \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to add.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
add_¶
Tensor.
add_
(other)[source]¶Compute the element-wise addition.
\[\text{self} \mathrel{+}= \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to add.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
addmm¶
Tensor.
addmm
(
mat1,
mat2,
beta=1,
alpha=1
)[source]¶Add the result of matrix-matrix multiplication.
\[\text{out} = \alpha (\text{mat1} \times \text{mat2}) + \beta \text{self} \]- Parameters:
- mat1 (dragon.vm.torch.Tensor) – The first matrix.
- mat2 (dragon.vm.torch.Tensor) – The second matrix.
- beta (float, optional, default=1) – The value to \(\beta\).
- alpha (float, optional, default=1) – The value to \(\alpha\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
argmax¶
argmin¶
argsort¶
Tensor.
argsort
(
dim=- 1,
descending=False
)[source]¶Return the index of sorted elements.
- Parameters:
- dim (int, optional, default=-1) – The dimension to sort elements.
- descending (bool, optional, default=False) – Sort in the descending order or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
atan2¶
Tensor.
atan2
(other)[source]¶Compute the element-wise arc-tangent of two arguments.
\[\text{out} = \text{arctan}(\frac{\text{self}}{\text{other}}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to divide.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
backward¶
Tensor.
backward
(
gradient=None,
retain_graph=False
)[source]¶Compute the derivatives of this tensor w.r.t. graph leaves.
- Parameters:
- gradient (dragon.vm.torch.Tensor, optional) – The optional gradient of this tensor.
- retain_graph (bool, optional, default=False) –
False
to free the graph used to compute grad.
baddbmm¶
Tensor.
baddbmm
(
batch1,
batch2,
beta=1,
alpha=1
)[source]¶Add the result of batched matrix-matrix multiplication.
\[\text{out}_{i} = \alpha (\text{batch1}_{i} \times \text{batch2}_{i}) + \beta \text{self}_{i} \]- Parameters:
- batch1 (dragon.vm.torch.Tensor) – The first batch of matrices.
- batch2 (dragon.vm.torch.Tensor) – The second batch of matrices.
- beta (float, optional, default=1) – The value to \(\beta\).
- alpha (float, optional, default=1) – The value to \(\alpha\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
baddbmm_¶
Tensor.
baddbmm_
(
batch1,
batch2,
beta=1,
alpha=1
)[source]¶Add the result of batched matrix-matrix multiplication.
\[\text{self}_{i} = \alpha (\text{batch1}_{i} \times \text{batch2}_{i}) + \beta \text{self}_{i} \]- Parameters:
- batch1 (dragon.vm.torch.Tensor) – The first batch of matrices.
- batch2 (dragon.vm.torch.Tensor) – The second batch of matrices.
- beta (float, optional, default=1) – The value to \(\beta\).
- alpha (float, optional, default=1) – The value to \(\alpha\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_and¶
Tensor.
bitwise_and
(other)[source]¶Compute the element-wise AND bitwise operation.
\[\text{out} = \text{self} \mathbin{\&} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_and_¶
Tensor.
bitwise_and_
(other)[source]¶Compute the element-wise AND bitwise operation.
\[\text{self} = \text{self} \mathbin{\&} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_not¶
bitwise_not_¶
bitwise_or¶
Tensor.
bitwise_or
(other)[source]¶Compute the element-wise OR bitwise operation.
\[\text{out} = \text{self} \mathbin{|} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_or_¶
Tensor.
bitwise_or_
(other)[source]¶Compute the element-wise OR bitwise operation.
\[\text{self} = \text{self} \mathbin{|} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_xor¶
Tensor.
bitwise_xor
(other)[source]¶Compute the element-wise XOR bitwise operation.
\[\text{out} = \text{self} \oplus \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bitwise_xor_¶
Tensor.
bitwise_xor_
(other)[source]¶Compute the element-wise XOR bitwise operation.
\[\text{self} = \text{self} \oplus \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bmm¶
Tensor.
bmm
(batch2)[source]¶Compute the batched matrix multiplication.
\[\text{out}_{i} = \text{self}_{i} \times \text{batch2}_{i} \]- Parameters:
- batch2 (dragon.vm.torch.Tensor) – The second batch of matrices.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
bool¶
bool_¶
byte¶
byte_¶
ceil¶
ceil_¶
char¶
char_¶
chunk¶
Tensor.
chunk
(
chunks,
dim=0,
copy=True
)[source]¶Split self into several parts along the given dim.
- Parameters:
- chunks (int) – The number of chunks to split.
- dim (int, optional, default=0) – The dimension to split.
- copy (bool, optional, default=True) – Copy or create the views of input.
- Returns:
Sequence[dragon.vm.torch.Tensor] – The output chunks.
clamp¶
clamp_¶
contiguous¶
copy_¶
Tensor.
copy_
(src)[source]¶Copy the elements into this tensor.
- Parameters:
- src (dragon.vm.torch.Tensor) – The tensor to copy from.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
cos¶
cpu¶
cuda¶
Tensor.
cuda
(device=None)[source]¶Copy memory to the specified cuda device.
- Parameters:
- device (Union[int, dragon.vm.torch.device], optional) – The device to copy to.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
cumsum¶
detach¶
div¶
Tensor.
div
(other)[source]¶Compute the element-wise division.
\[\text{out} = \text{self} \div \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to divide.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
div_¶
Tensor.
div_
(other)[source]¶Compute the element-wise division.
\[\text{self} \mathrel{\div}= \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to be divided.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
double¶
double_¶
eq¶
Tensor.
eq
(other)[source]¶Compute the element-wise equal comparison.
\[\text{out} = (\text{self} = \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
exp¶
exp_¶
expand¶
expand_as¶
Tensor.
expand_as
(other)[source]¶Return a tensor with elements broadcast like the other.
- Parameters:
- other (dragon.vm.torch.Tensor) – The tensor provided the output dimensions.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
fill_¶
flatten¶
Tensor.
flatten
(
start_dim=0,
end_dim=- 1
)[source]¶Return a tensor with dimensions flattened.
- Parameters:
- start_dim (int, optional, default=0) – The start dimension to flatten.
- end_dim (int, optional, default=-1) – The end dimension to flatten.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
flatten_¶
flip¶
fliplr¶
flipud¶
float¶
float_¶
floor¶
floor_¶
gather¶
Tensor.
gather
(
dim,
index
)[source]¶Gather elements along the given dimension of index.
- Parameters:
- dim (int) – The dimension of index values.
- index (dragon.vm.torch.Tensor) – The index tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
ge¶
Tensor.
ge
(other)[source]¶Compute the element-wise greater-equal comparison.
\[\text{out} = (\text{self} \geq \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
gt¶
Tensor.
gt
(other)[source]¶Compute the element-wise greater comparison.
\[\text{out} = (\text{self} > \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
half¶
half_¶
index_select¶
Tensor.
index_select
(
dim,
index
)[source]¶Select the elements along the dim using index.
- Parameters:
- dim (Union[int, Sequence[int]]) – The dim(s) to select.
- index (dragon.vm.torch.Tensor) – The index.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
int¶
int_¶
isfinite¶
isinf¶
isnan¶
is_contiguous¶
is_floating_point¶
le¶
Tensor.
le
(other)[source]¶Compute the element-wise less-equal comparison.
\[\text{out} = (\text{self} \leq \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
log¶
log_¶
logical_and¶
Tensor.
logical_and
(other)[source]¶Compute the element-wise AND logical operation.
\[\text{out} = \text{self} \mathbin{\&} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
logical_not¶
logical_or¶
Tensor.
logical_or
(other)[source]¶Compute the element-wise OR logical operation.
\[\text{out} = \text{self} \mathbin{|} \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
logical_xor¶
Tensor.
logical_xor
(other)[source]¶Compute the element-wise XOR logical operation.
\[\text{out} = \text{self} \oplus \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compute with.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
logsumexp¶
Tensor.
logsumexp
(
dim,
keepdim=False
)[source]¶Apply the composite of log, sum, and exp.
\[\text{out}_{i} = \log\sum_{j}\exp(\text{self}_{ij}) \]- Parameters:
- dim (Union[int, Sequence[int]]) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Whether the output tensor has dim retained or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
long¶
long_¶
lt¶
Tensor.
lt
(other)[source]¶Compute the element-wise less comparison.
\[\text{out} = (\text{self} < \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
masked_fill_¶
Tensor.
masked_fill_
(
mask,
value
)[source]¶Fill self with the value where mask is 1.
\[\text{self}_{i} = \begin{cases} \text{value}_{i}, & \text{ if } \text{mask}_{i} = 1 \\ \text{self}_{i}, & \text{ otherwise } \end{cases} \]- Parameters:
- mask (dragon.vm.torch.Tensor) – The boolean mask.
- value (number) – The value to fill.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
masked_select¶
Tensor.
masked_select
(mask)[source]¶Select the elements where mask is 1.
- Parameters:
- mask (dragon.vm.torch.Tensor) – The mask for selecting.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
matmul¶
Tensor.
matmul
(tensor2)[source]¶Compute the matrix multiplication.
\[\text{out} = \text{self} \times \text{tensor2} \]- Parameters:
- tensor2 (dragon.vm.torch.Tensor) – The tensor to multiply.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
max¶
Tensor.
max
(
dim=None,
keepdim=False
)[source]¶Compute the max value of elements along the given dimension.
- Parameters:
- dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
maximum¶
Tensor.
maximum
(other)[source]¶Compute the maximum value of inputs.
\[\text{out} = \max(\text{self}, \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The second input tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
mean¶
Tensor.
mean
(
dim=None,
keepdim=False
)[source]¶Compute the mean value of elements along the given dimension.
- Parameters:
- dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
min¶
Tensor.
min
(
dim=None,
keepdim=False
)[source]¶Compute the min value of elements along the given dimension.
- Parameters:
- dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
minimum¶
Tensor.
minimum
(other)[source]¶Compute the minimum value of inputs.
\[\text{out} = \min(\text{self}, \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The second input tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
mm¶
Tensor.
mm
(mat2)[source]¶Compute the matrix-matrix multiplication.
\[\text{out} = \text{self} \times \text{mat2} \]- Parameters:
- mat2 (dragon.vm.torch.Tensor) – The second matrix.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
mul¶
Tensor.
mul
(other)[source]¶Compute the element-wise multiplication.
\[\text{out} = \text{self} \times \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to multiply.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
mul_¶
Tensor.
mul_
(other)[source]¶Compute the element-wise multiplication.
\[\text{self} \mathrel{\times}= \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to multiply.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
multinomial¶
narrow¶
ndimension¶
ne¶
Tensor.
ne
(other)[source]¶Compute the element-wise not-equal comparison.
\[\text{out} = (\text{self} \neq \text{other}) \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to compare.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
neg¶
neg_¶
new_empty¶
Tensor.
new_empty
(
*size,
dtype=None,
device=None,
requires_grad=False
)[source]¶Return a tensor filled with uninitialized data.
Refer this tensor if
dtype
anddevice
not provided.- Parameters:
- size (int...) – The size of output tensor.
- dtype (str, optional) – The optional data type.
- device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
- requires_grad (bool, optional, default=False) –
True
to record gradient for returned tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
new_full¶
Tensor.
new_full
(
size,
fill_value,
dtype=None,
device=None,
requires_grad=False
)[source]¶Return a tensor filled with a scalar.
Refer this tensor if
dtype
anddevice
not provided.- Parameters:
- size (Sequence[int]) – The size of output tensor.
- fill_value (number) – The scalar to fill.
- dtype (str, optional) – The optional data type.
- device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
- requires_grad (bool, optional, default=False) –
True
to record gradient for returned tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
new_ones¶
Tensor.
new_ones
(
*size,
dtype=None,
device=None,
requires_grad=False
)[source]¶Return a tensor filled with ones.
Refer this tensor if
dtype
anddevice
not provided.- Parameters:
- size (int...) – The size of output tensor.
- dtype (str, optional) – The optional data type.
- device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
- requires_grad (bool, optional, default=False) –
True
to record gradient for returned tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
new_tensor¶
Tensor.
new_tensor
(
data,
dtype=None,
device=None,
requires_grad=False
)[source]¶Return a tensor initializing from the given data.
Refer this tensor if
dtype
anddevice
not provided.- Parameters:
- data (array_like) – The data to initialize from.
- dtype (str, optional) – The optional data type.
- device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
- requires_grad (bool, optional, default=False) –
True
to record gradient for returned tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
new_zeros¶
Tensor.
new_zeros
(
*size,
dtype=None,
device=None,
requires_grad=False
)[source]¶Return a tensor filled with zeros.
Refer this tensor if
dtype
anddevice
not provided.- Parameters:
- size (int...) – The size of output tensor.
- dtype (str, optional) – The optional data type.
- device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
- requires_grad (bool, optional, default=False) –
True
to record gradient for returned tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
nonzero¶
norm¶
Tensor.
norm
(
p='fro',
dim=None,
keepdim=False,
out=None,
dtype=None
)[source]¶Compute the norm value of elements along the given dimension.
- Parameters:
- p ({'fro', 1, 2}, optional) – The norm order.
- dim (Union[int, Sequence[int]], optional) – The dimension to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimension or not.
- dtype (str, optional) – The data type to cast to.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
normal_¶
Tensor.
normal_
(
mean=0,
std=1
)[source]¶Fill self from a normal distribution.
\[\text{self} \sim \mathcal{N}(\mu, \sigma^{2}) \]- Parameters:
- mean (number, optional, default=0) – The value to \(\mu\).
- std (number, optional, default=1) – The value to \(\sigma\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
numpy¶
one_¶
permute¶
permute_¶
pow¶
Tensor.
pow
(exponent)[source]¶Compute the power.
- Parameters:
- exponent (Union[dragon.vm.torch.Tensor, number]) – The exponent value.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
reciprocal¶
reciprocal_¶
repeat¶
reshape¶
reshape_¶
roll¶
round¶
round_¶
rsqrt¶
rsqrt_¶
scatter¶
Tensor.
scatter
(
dim,
index,
src
)[source]¶Return a tensor with elements updated from the source.
- Parameters:
- dim (int) – The dimension of index values.
- index (dragon.vm.torch.Tensor) – The index tensor.
- src (Union[dragon.vm.torch.Tensor, number]) – The tensor to update from.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
scatter_¶
Tensor.
scatter_
(
dim,
index,
src,
reduce=None
)[source]¶Update elements from the source.
- Parameters:
- dim (int) – The dimension of index values.
- index (dragon.vm.torch.Tensor) – The index tensor.
- src (Union[dragon.vm.torch.Tensor, number]) – The tensor to update from.
- reduce (str, optional) –
'add'
or'multiply'
.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
scatter_add¶
Tensor.
scatter_add
(
dim,
index,
src
)[source]¶Return a tensor with elements added from the source.
- Parameters:
- dim (int) – The dimension of index values.
- index (dragon.vm.torch.Tensor) – The index tensor.
- src (Union[dragon.vm.torch.Tensor, number]) – The tensor to add from.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
scatter_add_¶
Tensor.
scatter_add_
(
dim,
index,
src
)[source]¶Add elements from the source.
- Parameters:
- dim (int) – The dimension of index values.
- index (dragon.vm.torch.Tensor) – The index tensor.
- src (Union[dragon.vm.torch.Tensor, number]) – The tensor to add from.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
sign¶
Tensor.
sign
()[source]¶Return a tensor taken the sign indication of elements.
\[\text{out}_{i} = \begin{cases} -1, & \text{ if } \text{self}_{i} < 0 \\ 0, & \text{ if } \text{self}_{i} = 0 \\ 1, & \text{ if } \text{self}_{i} > 0 \end{cases} \]- Returns:
- dragon.vm.torch.Tensor – The output tensor.
See also
sign_¶
sin¶
size¶
sort¶
Tensor.
sort
(
dim=- 1,
descending=False
)[source]¶Return the sorted elements.
- Parameters:
- dim (int, optional, default=-1) – The dimension to sort elements.
- descending (bool, optional, default=False) – Sort in the descending order or not.
- Returns:
Sequence[dragon.vm.torch.Tensor] – The value and index tensor.
See also
split¶
Tensor.
split
(
split_size_or_sections,
dim=0,
copy=True
)[source]¶Return the split chunks along the given dimension.
- Parameters:
- split_size_or_sections (Union[int, Sequence[int]) – The number or size of chunks.
- dim (int, optional, default=0) – The dimension to split.
- copy (bool, optional, default=True) – Copy or create the views of input.
- Returns:
Sequence[dragon.vm.torch.Tensor] – The output tensors.
See also
sqrt¶
sqrt_¶
square¶
squeeze¶
squeeze_¶
sum¶
Tensor.
sum
(
dim=None,
keepdim=False
)[source]¶Compute the sum value of elements along the given dimension.
- Parameters:
- dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
sub¶
Tensor.
sub
(other)[source]¶Compute the element-wise subtraction.
\[\text{out} = \text{self} - \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to subtract.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
sub_¶
Tensor.
sub_
(other)[source]¶Compute the element-wise subtraction.
\[\text{self} \mathrel{-}= \text{other} \]- Parameters:
- other (Union[dragon.vm.torch.Tensor, number]) – The value to be subtracted.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
to¶
Tensor.
to
(
*args,
**kwargs
)[source]¶Convert to the specified data type or device.
The arguments could be
torch.dtype
ortorch.device
:x = torch.FloatTensor(1) x.to(torch.int32) # Equivalent to ``x.int()`` x.to(torch.device('cpu')) # Equivalent to ``x.cpu()`` x.to(torch.device('cuda'), torch.float32) # Convert both
Or
torch.Tensor
to provide bothdtype
anddevice
:a, b = torch.tensor(1.), torch.tensor(2) print(a.to(b)) # 1
- Returns:
- dragon.vm.torch.Tensor – The output tensor.
topk¶
Tensor.
topk
(
k,
dim=- 1,
largest=True,
sorted=True
)[source]¶Return the top k-largest or smallest elements.
- Parameters:
- k (int) – The number of top elements to select.
- dim (int, optional, default=-1) – The dimension to select elements.
- largest (bool, optional, default=True) – Return largest or smallest elements.
- sorted (bool, optional, default=True) – Whether to return elements in the sorted order.
- Returns:
Sequence[dragon.vm.torch.Tensor] – The value and index tensor.
See also
transpose¶
transpose_¶
tril¶
Tensor.
tril
(k=0)[source]¶Return the lower triangular part.
\[\text{out}_{ij} = \begin{cases} 0, & \text{ if } j > i + k \\ \text{self}_{ij}, & \text{ otherwise } \end{cases} \]- Parameters:
- k (int, optional, default=0) – Diagonal above which to zero elements.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
tril_¶
Tensor.
tril_
(k=0)[source]¶Set to the lower triangular part.
\[\text{self}_{ij} = \begin{cases} 0, & \text{ if } j > i + k \\ \text{self}_{ij}, & \text{ otherwise } \end{cases} \]- Parameters:
- k (int, optional, default=0) – Diagonal above which to zero elements.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
triu¶
Tensor.
triu
(k=0)[source]¶Return the upper triangular part.
\[\text{out}_{ij} = \begin{cases} 0, & \text{ if } j < i + k \\ \text{self}_{ij}, & \text{ otherwise } \end{cases} \]- Parameters:
- k (int, optional, default=0) – Diagonal below which to zero elements.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
triu_¶
Tensor.
triu_
(k=0)[source]¶Set to the upper triangular part.
\[\text{self}_{ij} = \begin{cases} 0, & \text{ if } j < i + k \\ \text{self}_{ij}, & \text{ otherwise } \end{cases} \]- Parameters:
- k (int, optional, default=0) – Diagonal below which to zero elements.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
type¶
unbind¶
Tensor.
unbind
(
dim=0,
copy=True
)[source]¶Unpack to chunks along the given dimension.
- Parameters:
- dim (int, optional, default=0) – The dimension to unpack.
- copy (bool, optional, default=True) – Copy or create the views of input.
- Returns:
Sequence[dragon.vm.torch.Tensor] – The output tensors.
See also
uniform_¶
Tensor.
uniform_
(
low=0,
high=1
)[source]¶Fill self from a uniform distribution.
\[\text{self} \sim \mathcal{U}(\alpha, \beta) \]- Parameters:
- low (number, optional, default=0) – The value to \(\alpha\).
- high (number, optional, default=1) – The value to \(\beta\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
unique¶
Tensor.
unique
(
return_inverse=False,
return_counts=False,
**kwargs
)[source]¶Return the unique elements.
- Parameters:
- return_inverse (bool, optional, default=False) – Return the inverse index or not.
- return_counts (bool, optional, default=False) – Return the counts or not.
- Returns:
- dragon.vm.torch.Tensor – The output tensor.
- dragon.vm.torch.Tensor, optional – The inverse index tensor.
- dragon.vm.torch.Tensor, optional – The counting tensor.
See also
unsqueeze¶
unsqueeze_¶
view¶
view_¶
view_as¶
Tensor.
view_as
(other)[source]¶Return a tensor with the same data but a different size.
- Parameters:
- other (dragon.vm.torch.Tensor) – The tensor to guide the new size.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
where¶
Tensor.
where
(
condition,
y
)[source]¶Select the elements from two branches under the condition.
\[\text{out}_{i} = \begin{cases} \text{self}_{i} & \text{ if } \text{condition}_{i} \\ y_{i}, & \text{ otherwise } \end{cases} \]- Parameters:
- condition (dragon.vm.torch.Tensor) – The condition tensor.
- y (dragon.vm.torch.Tensor) – The tensor \(y\).
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also
var¶
Tensor.
var
(
dim=None,
keepdim=False
)[source]¶Compute the variance value of elements along the given dimension.
- Parameters:
- dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
- keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
- Returns:
dragon.vm.torch.Tensor – The output tensor.
See also