torch The torch package contains data structures for multi-dimensional tensors and defines mathematical operations over these tensors. Additionally, it provides many utilities for efficient serializing of Tensors and arbitrary types, and other useful utilities. It has a CUDA counterpart, that enables you to run your tensor computations on an NVIDIA GPU with compute capability >= 3.0 Tensors

is_tensor
 Returns True if obj is a PyTorch tensor.

is_storage
 Returns True if obj is a PyTorch storage object.

is_complex
 Returns True if the data type of input is a complex data type i.e., one of torch.complex64, and torch.complex128.

is_floating_point
 Returns True if the data type of input is a floating point data type i.e., one of torch.float64, torch.float32, torch.float16, and torch.bfloat16.

is_nonzero
 Returns True if the input is a single element tensor which is not equal to zero after type conversions.

set_default_dtype
 Sets the default floating point dtype to d.

get_default_dtype
 Get the current default floating point torch.dtype.

set_default_tensor_type
 Sets the default torch.Tensor type to floating point tensor type t.

numel
 Returns the total number of elements in the input tensor.

set_printoptions
 Set options for printing.

set_flush_denormal
 Disables denormal floating numbers on CPU.   Creation Ops  Note Random sampling creation ops are listed under Random sampling and include: torch.rand() torch.rand_like() torch.randn() torch.randn_like() torch.randint() torch.randint_like() torch.randperm() You may also use torch.empty() with the In-place random sampling methods to create torch.Tensor s with values sampled from a broader range of distributions.

tensor
 Constructs a tensor with data.

sparse_coo_tensor
 Constructs a sparse tensor in COO(rdinate) format with specified values at the given indices.

as_tensor
 Convert the data into a torch.Tensor.

as_strided
 Create a view of an existing torch.Tensor input with specified size, stride and storage_offset.

from_numpy
 Creates a Tensor from a numpy.ndarray.

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

zeros_like
 Returns a tensor filled with the scalar value 0, with the same size as input.

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

ones_like
 Returns a tensor filled with the scalar value 1, with the same size as input.

arange
 Returns a 1-D tensor of size ⌈end−startstep⌉\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil  with values from the interval [start, end) taken with common difference step beginning from start.

range
 Returns a 1-D tensor of size ⌊end−startstep⌋+1\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1  with values from start to end with step step.

linspace
 Creates a one-dimensional tensor of size steps whose values are evenly spaced from start to end, inclusive.

logspace
 Creates a one-dimensional tensor of size steps whose values are evenly spaced from basestart{{\text{{base}}}}^{{\text{{start}}}}  to baseend{{\text{{base}}}}^{{\text{{end}}}} , inclusive, on a logarithmic scale with base base.

eye
 Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.

empty
 Returns a tensor filled with uninitialized data.

empty_like
 Returns an uninitialized tensor with the same size as input.

empty_strided
 Returns a tensor filled with uninitialized data.

full
 Creates a tensor of size size filled with fill_value.

full_like
 Returns a tensor with the same size as input filled with fill_value.

quantize_per_tensor
 Converts a float tensor to a quantized tensor with given scale and zero point.

quantize_per_channel
 Converts a float tensor to a per-channel quantized tensor with given scales and zero points.

dequantize
 Returns an fp32 Tensor by dequantizing a quantized Tensor

complex
 Constructs a complex tensor with its real part equal to real and its imaginary part equal to imag.

polar
 Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value abs and angle angle.

heaviside
 Computes the Heaviside step function for each element in input.   Indexing, Slicing, Joining, Mutating Ops

cat
 Concatenates the given sequence of seq tensors in the given dimension.

chunk
 Splits a tensor into a specific number of chunks.

column_stack
 Creates a new tensor by horizontally stacking the tensors in tensors.

dstack
 Stack tensors in sequence depthwise (along third axis).

gather
 Gathers values along an axis specified by dim.

hstack
 Stack tensors in sequence horizontally (column wise).

index_select
 Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor.

masked_select
 Returns a new 1-D tensor which indexes the input tensor according to the boolean mask mask which is a BoolTensor.

movedim
 Moves the dimension(s) of input at the position(s) in source to the position(s) in destination.

moveaxis
 Alias for torch.movedim().

narrow
 Returns a new tensor that is a narrowed version of input tensor.

nonzero

reshape
 Returns a tensor with the same data and number of elements as input, but with the specified shape.

row_stack
 Alias of torch.vstack().

scatter
 Out-of-place version of torch.Tensor.scatter_()

scatter_add
 Out-of-place version of torch.Tensor.scatter_add_()

split
 Splits the tensor into chunks.

squeeze
 Returns a tensor with all the dimensions of input of size 1 removed.

stack
 Concatenates a sequence of tensors along a new dimension.

swapaxes
 Alias for torch.transpose().

swapdims
 Alias for torch.transpose().

t
 Expects input to be <= 2-D tensor and transposes dimensions 0 and 1.

take
 Returns a new tensor with the elements of input at the given indices.

tensor_split
 Splits a tensor into multiple sub-tensors, all of which are views of input, along dimension dim according to the indices or number of sections specified by indices_or_sections.

tile
 Constructs a tensor by repeating the elements of input.

transpose
 Returns a tensor that is a transposed version of input.

unbind
 Removes a tensor dimension.

unsqueeze
 Returns a new tensor with a dimension of size one inserted at the specified position.

vstack
 Stack tensors in sequence vertically (row wise).

where
 Return a tensor of elements selected from either x or y, depending on condition.   Generators

Generator
 Creates and returns a generator object that manages the state of the algorithm which produces pseudo random numbers.   Random sampling

seed
 Sets the seed for generating random numbers to a non-deterministic random number.

manual_seed
 Sets the seed for generating random numbers.

initial_seed
 Returns the initial seed for generating random numbers as a Python long.

get_rng_state
 Returns the random number generator state as a torch.ByteTensor.

set_rng_state
 Sets the random number generator state.
torch.default_generator Returns the default CPU torch.Generator

bernoulli
 Draws binary random numbers (0 or 1) from a Bernoulli distribution.

multinomial
 Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.

normal
 Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.

poisson
 Returns a tensor of the same size as input with each element sampled from a Poisson distribution with rate parameter given by the corresponding element in input i.e.,

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

rand_like
 Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval [0,1)[0, 1) .

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

randint_like
 Returns a tensor with the same shape as Tensor input filled with random integers generated uniformly between low (inclusive) and high (exclusive).

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

randn_like
 Returns a tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1.

randperm
 Returns a random permutation of integers from 0 to n - 1.   In-place random sampling There are a few more in-place random sampling functions defined on Tensors as well. Click through to refer to their documentation:
torch.Tensor.bernoulli_() - in-place version of torch.bernoulli()

torch.Tensor.cauchy_() - numbers drawn from the Cauchy distribution
torch.Tensor.exponential_() - numbers drawn from the exponential distribution
torch.Tensor.geometric_() - elements drawn from the geometric distribution
torch.Tensor.log_normal_() - samples from the log-normal distribution
torch.Tensor.normal_() - in-place version of torch.normal()

torch.Tensor.random_() - numbers sampled from the discrete uniform distribution
torch.Tensor.uniform_() - numbers sampled from the continuous uniform distribution  Quasi-random sampling
quasirandom.SobolEngine The torch.quasirandom.SobolEngine is an engine for generating (scrambled) Sobol sequences.   Serialization

save
 Saves an object to a disk file.

load
 Loads an object saved with torch.save() from a file.   Parallelism

get_num_threads
 Returns the number of threads used for parallelizing CPU operations

set_num_threads
 Sets the number of threads used for intraop parallelism on CPU.

get_num_interop_threads
 Returns the number of threads used for inter-op parallelism on CPU (e.g.

set_num_interop_threads
 Sets the number of threads used for interop parallelism (e.g.   Locally disabling gradient computation The context managers torch.no_grad(), torch.enable_grad(), and torch.set_grad_enabled() are helpful for locally disabling and enabling gradient computation. See Locally disabling gradient computation for more details on their usage. These context managers are thread local, so they won’t work if you send work to another thread using the threading module, etc. Examples: >>> x = torch.zeros(1, requires_grad=True)
>>> with torch.no_grad():
...     y = x * 2
>>> y.requires_grad
False

>>> is_train = False
>>> with torch.set_grad_enabled(is_train):
...     y = x * 2
>>> y.requires_grad
False

>>> torch.set_grad_enabled(True)  # this can also be used as a function
>>> y = x * 2
>>> y.requires_grad
True

>>> torch.set_grad_enabled(False)
>>> y = x * 2
>>> y.requires_grad
False

no_grad
 Context-manager that disabled gradient calculation.

enable_grad
 Context-manager that enables gradient calculation.

set_grad_enabled
 Context-manager that sets gradient calculation to on or off.   Math operations Pointwise Ops

abs
 Computes the absolute value of each element in input.

absolute
 Alias for torch.abs()

acos
 Computes the inverse cosine of each element in input.

arccos
 Alias for torch.acos().

acosh
 Returns a new tensor with the inverse hyperbolic cosine of the elements of input.

arccosh
 Alias for torch.acosh().

add
 Adds the scalar other to each element of the input input and returns a new resulting tensor.

addcdiv
 Performs the element-wise division of tensor1 by tensor2, multiply the result by the scalar value and add it to input.

addcmul
 Performs the element-wise multiplication of tensor1 by tensor2, multiply the result by the scalar value and add it to input.

angle
 Computes the element-wise angle (in radians) of the given input tensor.

asin
 Returns a new tensor with the arcsine of the elements of input.

arcsin
 Alias for torch.asin().

asinh
 Returns a new tensor with the inverse hyperbolic sine of the elements of input.

arcsinh
 Alias for torch.asinh().

atan
 Returns a new tensor with the arctangent of the elements of input.

arctan
 Alias for torch.atan().

atanh
 Returns a new tensor with the inverse hyperbolic tangent of the elements of input.

arctanh
 Alias for torch.atanh().

atan2
 Element-wise arctangent of inputi/otheri\text{input}_{i} / \text{other}_{i}  with consideration of the quadrant.

bitwise_not
 Computes the bitwise NOT of the given input tensor.

bitwise_and
 Computes the bitwise AND of input and other.

bitwise_or
 Computes the bitwise OR of input and other.

bitwise_xor
 Computes the bitwise XOR of input and other.

ceil
 Returns a new tensor with the ceil of the elements of input, the smallest integer greater than or equal to each element.

clamp
 Clamp all elements in input into the range [ min, max ].

clip
 Alias for torch.clamp().

conj
 Computes the element-wise conjugate of the given input tensor.

copysign
 Create a new floating-point tensor with the magnitude of input and the sign of other, elementwise.

cos
 Returns a new tensor with the cosine of the elements of input.

cosh
 Returns a new tensor with the hyperbolic cosine of the elements of input.

deg2rad
 Returns a new tensor with each of the elements of input converted from angles in degrees to radians.

div
 Divides each element of the input input by the corresponding element of other.

divide
 Alias for torch.div().

digamma
 Computes the logarithmic derivative of the gamma function on input.

erf
 Computes the error function of each element.

erfc
 Computes the complementary error function of each element of input.

erfinv
 Computes the inverse error function of each element of input.

exp
 Returns a new tensor with the exponential of the elements of the input tensor input.

exp2
 Computes the base two exponential function of input.

expm1
 Returns a new tensor with the exponential of the elements minus 1 of input.

fake_quantize_per_channel_affine
 Returns a new tensor with the data in input fake quantized per channel using scale, zero_point, quant_min and quant_max, across the channel specified by axis.

fake_quantize_per_tensor_affine
 Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min and quant_max.

fix
 Alias for torch.trunc()

float_power
 Raises input to the power of exponent, elementwise, in double precision.

floor
 Returns a new tensor with the floor of the elements of input, the largest integer less than or equal to each element.

floor_divide

fmod
 Computes the element-wise remainder of division.

frac
 Computes the fractional portion of each element in input.

imag
 Returns a new tensor containing imaginary values of the self tensor.

ldexp
 Multiplies input by 2**:attr:other.

lerp
 Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor.

lgamma
 Computes the logarithm of the gamma function on input.

log
 Returns a new tensor with the natural logarithm of the elements of input.

log10
 Returns a new tensor with the logarithm to the base 10 of the elements of input.

log1p
 Returns a new tensor with the natural logarithm of (1 + input).

log2
 Returns a new tensor with the logarithm to the base 2 of the elements of input.

logaddexp
 Logarithm of the sum of exponentiations of the inputs.

logaddexp2
 Logarithm of the sum of exponentiations of the inputs in base-2.

logical_and
 Computes the element-wise logical AND of the given input tensors.

logical_not
 Computes the element-wise logical NOT of the given input tensor.

logical_or
 Computes the element-wise logical OR of the given input tensors.

logical_xor
 Computes the element-wise logical XOR of the given input tensors.

logit
 Returns a new tensor with the logit of the elements of input.

hypot
 Given the legs of a right triangle, return its hypotenuse.

i0
 Computes the zeroth order modified Bessel function of the first kind for each element of input.

igamma
 Computes the regularized lower incomplete gamma function:

igammac
 Computes the regularized upper incomplete gamma function:

mul
 Multiplies each element of the input input with the scalar other and returns a new resulting tensor.

multiply
 Alias for torch.mul().

mvlgamma
 Computes the multivariate log-gamma function) with dimension pp  element-wise, given by

nan_to_num
 Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively.

neg
 Returns a new tensor with the negative of the elements of input.

negative
 Alias for torch.neg()

nextafter
 Return the next floating-point value after input towards other, elementwise.

polygamma
 Computes the nthn^{th}  derivative of the digamma function on input.

pow
 Takes the power of each element in input with exponent and returns a tensor with the result.

rad2deg
 Returns a new tensor with each of the elements of input converted from angles in radians to degrees.

real
 Returns a new tensor containing real values of the self tensor.

reciprocal
 Returns a new tensor with the reciprocal of the elements of input

remainder
 Computes the element-wise remainder of division.

round
 Returns a new tensor with each of the elements of input rounded to the closest integer.

rsqrt
 Returns a new tensor with the reciprocal of the square-root of each of the elements of input.

sigmoid
 Returns a new tensor with the sigmoid of the elements of input.

sign
 Returns a new tensor with the signs of the elements of input.

sgn
 For complex tensors, this function returns a new tensor whose elemants have the same angle as that of the elements of input and absolute value 1.

signbit
 Tests if each element of input has its sign bit set (is less than zero) or not.

sin
 Returns a new tensor with the sine of the elements of input.

sinc
 Computes the normalized sinc of input.

sinh
 Returns a new tensor with the hyperbolic sine of the elements of input.

sqrt
 Returns a new tensor with the square-root of the elements of input.

square
 Returns a new tensor with the square of the elements of input.

sub
 Subtracts other, scaled by alpha, from input.

subtract
 Alias for torch.sub().

tan
 Returns a new tensor with the tangent of the elements of input.

tanh
 Returns a new tensor with the hyperbolic tangent of the elements of input.

true_divide
 Alias for torch.div() with rounding_mode=None.

trunc
 Returns a new tensor with the truncated integer values of the elements of input.

xlogy
 Computes input * log(other) with the following cases.   Reduction Ops

argmax
 Returns the indices of the maximum value of all elements in the input tensor.

argmin
 Returns the indices of the minimum value(s) of the flattened tensor or along a dimension

amax
 Returns the maximum value of each slice of the input tensor in the given dimension(s) dim.

amin
 Returns the minimum value of each slice of the input tensor in the given dimension(s) dim.

all
 Tests if all elements in input evaluate to True.

any

 param input
the input tensor.

max
 Returns the maximum value of all elements in the input tensor.

min
 Returns the minimum value of all elements in the input tensor.

dist
 Returns the p-norm of (input - other)

logsumexp
 Returns the log of summed exponentials of each row of the input tensor in the given dimension dim.

mean
 Returns the mean value of all elements in the input tensor.

median
 Returns the median of the values in input.

nanmedian
 Returns the median of the values in input, ignoring NaN values.

mode
 Returns a namedtuple (values, indices) where values is the mode value of each row of the input tensor in the given dimension dim, i.e.

norm
 Returns the matrix norm or vector norm of a given tensor.

nansum
 Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.

prod
 Returns the product of all elements in the input tensor.

quantile
 Returns the q-th quantiles of all elements in the input tensor, doing a linear interpolation when the q-th quantile lies between two data points.

nanquantile
 This is a variant of torch.quantile() that “ignores” NaN values, computing the quantiles q as if NaN values in input did not exist.

std
 Returns the standard-deviation of all elements in the input tensor.

std_mean
 Returns the standard-deviation and mean of all elements in the input tensor.

sum
 Returns the sum of all elements in the input tensor.

unique
 Returns the unique elements of the input tensor.

unique_consecutive
 Eliminates all but the first element from every consecutive group of equivalent elements.

var
 Returns the variance of all elements in the input tensor.

var_mean
 Returns the variance and mean of all elements in the input tensor.

count_nonzero
 Counts the number of non-zero values in the tensor input along the given dim.   Comparison Ops

allclose
 This function checks if all input and other satisfy the condition:

argsort
 Returns the indices that sort a tensor along a given dimension in ascending order by value.

eq
 Computes element-wise equality

equal
 True if two tensors have the same size and elements, False otherwise.

ge
 Computes input≥other\text{input} \geq \text{other}  element-wise.

greater_equal
 Alias for torch.ge().

gt
 Computes input>other\text{input} > \text{other}  element-wise.

greater
 Alias for torch.gt().

isclose
 Returns a new tensor with boolean elements representing if each element of input is “close” to the corresponding element of other.

isfinite
 Returns a new tensor with boolean elements representing if each element is finite or not.

isinf
 Tests if each element of input is infinite (positive or negative infinity) or not.

isposinf
 Tests if each element of input is positive infinity or not.

isneginf
 Tests if each element of input is negative infinity or not.

isnan
 Returns a new tensor with boolean elements representing if each element of input is NaN or not.

isreal
 Returns a new tensor with boolean elements representing if each element of input is real-valued or not.

kthvalue
 Returns a namedtuple (values, indices) where values is the k th smallest element of each row of the input tensor in the given dimension dim.

le
 Computes input≤other\text{input} \leq \text{other}  element-wise.

less_equal
 Alias for torch.le().

lt
 Computes input<other\text{input} < \text{other}  element-wise.

less
 Alias for torch.lt().

maximum
 Computes the element-wise maximum of input and other.

minimum
 Computes the element-wise minimum of input and other.

fmax
 Computes the element-wise maximum of input and other.

fmin
 Computes the element-wise minimum of input and other.

ne
 Computes input≠other\text{input} \neq \text{other}  element-wise.

not_equal
 Alias for torch.ne().

sort
 Sorts the elements of the input tensor along a given dimension in ascending order by value.

topk
 Returns the k largest elements of the given input tensor along a given dimension.

msort
 Sorts the elements of the input tensor along its first dimension in ascending order by value.   Spectral Ops

stft
 Short-time Fourier transform (STFT).

istft
 Inverse short time Fourier Transform.

bartlett_window
 Bartlett window function.

blackman_window
 Blackman window function.

hamming_window
 Hamming window function.

hann_window
 Hann window function.

kaiser_window
 Computes the Kaiser window with window length window_length and shape parameter beta.   Other Operations

atleast_1d
 Returns a 1-dimensional view of each input tensor with zero dimensions.

atleast_2d
 Returns a 2-dimensional view of each input tensor with zero dimensions.

atleast_3d
 Returns a 3-dimensional view of each input tensor with zero dimensions.

bincount
 Count the frequency of each value in an array of non-negative ints.

block_diag
 Create a block diagonal matrix from provided tensors.

broadcast_tensors
 Broadcasts the given tensors according to Broadcasting semantics.

broadcast_to
 Broadcasts input to the shape shape.

broadcast_shapes
 Similar to broadcast_tensors() but for shapes.

bucketize
 Returns the indices of the buckets to which each value in the input belongs, where the boundaries of the buckets are set by boundaries.

cartesian_prod
 Do cartesian product of the given sequence of tensors.

cdist
 Computes batched the p-norm distance between each pair of the two collections of row vectors.

clone
 Returns a copy of input.

combinations
 Compute combinations of length rr  of the given tensor.

cross
 Returns the cross product of vectors in dimension dim of input and other.

cummax
 Returns a namedtuple (values, indices) where values is the cumulative maximum of elements of input in the dimension dim.

cummin
 Returns a namedtuple (values, indices) where values is the cumulative minimum of elements of input in the dimension dim.

cumprod
 Returns the cumulative product of elements of input in the dimension dim.

cumsum
 Returns the cumulative sum of elements of input in the dimension dim.

diag

 If input is a vector (1-D tensor), then returns a 2-D square tensor

diag_embed
 Creates a tensor whose diagonals of certain 2D planes (specified by dim1 and dim2) are filled by input.

diagflat

 If input is a vector (1-D tensor), then returns a 2-D square tensor

diagonal
 Returns a partial view of input with the its diagonal elements with respect to dim1 and dim2 appended as a dimension at the end of the shape.

diff
 Computes the n-th forward difference along the given dimension.

einsum
 Sums the product of the elements of the input operands along dimensions specified using a notation based on the Einstein summation convention.

flatten
 Flattens input by reshaping it into a one-dimensional tensor.

flip
 Reverse the order of a n-D tensor along given axis in dims.

fliplr
 Flip tensor in the left/right direction, returning a new tensor.

flipud
 Flip tensor in the up/down direction, returning a new tensor.

kron
 Computes the Kronecker product, denoted by ⊗\otimes , of input and other.

rot90
 Rotate a n-D tensor by 90 degrees in the plane specified by dims axis.

gcd
 Computes the element-wise greatest common divisor (GCD) of input and other.

histc
 Computes the histogram of a tensor.

meshgrid
 Take NN  tensors, each of which can be either scalar or 1-dimensional vector, and create NN  N-dimensional grids, where the ii  th grid is defined by expanding the ii  th input over dimensions defined by other inputs.

lcm
 Computes the element-wise least common multiple (LCM) of input and other.

logcumsumexp
 Returns the logarithm of the cumulative summation of the exponentiation of elements of input in the dimension dim.

ravel
 Return a contiguous flattened tensor.

renorm
 Returns a tensor where each sub-tensor of input along dimension dim is normalized such that the p-norm of the sub-tensor is lower than the value maxnorm

repeat_interleave
 Repeat elements of a tensor.

roll
 Roll the tensor along the given dimension(s).

searchsorted
 Find the indices from the innermost dimension of sorted_sequence such that, if the corresponding values in values were inserted before the indices, the order of the corresponding innermost dimension within sorted_sequence would be preserved.

tensordot
 Returns a contraction of a and b over multiple dimensions.

trace
 Returns the sum of the elements of the diagonal of the input 2-D matrix.

tril
 Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.

tril_indices
 Returns the indices of the lower triangular part of a row-by- col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates.

triu
 Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.

triu_indices
 Returns the indices of the upper triangular part of a row by col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates.

vander
 Generates a Vandermonde matrix.

view_as_real
 Returns a view of input as a real tensor.

view_as_complex
 Returns a view of input as a complex tensor.   BLAS and LAPACK Operations

addbmm
 Performs a batch matrix-matrix product of matrices stored in batch1 and batch2, with a reduced add step (all matrix multiplications get accumulated along the first dimension).

addmm
 Performs a matrix multiplication of the matrices mat1 and mat2.

addmv
 Performs a matrix-vector product of the matrix mat and the vector vec.

addr
 Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input.

baddbmm
 Performs a batch matrix-matrix product of matrices in batch1 and batch2.

bmm
 Performs a batch matrix-matrix product of matrices stored in input and mat2.

chain_matmul
 Returns the matrix product of the NN  2-D tensors.

cholesky
 Computes the Cholesky decomposition of a symmetric positive-definite matrix AA  or for batches of symmetric positive-definite matrices.

cholesky_inverse
 Computes the inverse of a symmetric positive-definite matrix AA  using its Cholesky factor uu : returns matrix inv.

cholesky_solve
 Solves a linear system of equations with a positive semidefinite matrix to be inverted given its Cholesky factor matrix uu .

dot
 Computes the dot product of two 1D tensors.

eig
 Computes the eigenvalues and eigenvectors of a real square matrix.

geqrf
 This is a low-level function for calling LAPACK directly.

ger
 Alias of torch.outer().

inner
 Computes the dot product for 1D tensors.

inverse
 Takes the inverse of the square matrix input.

det
 Calculates determinant of a square matrix or batches of square matrices.

logdet
 Calculates log determinant of a square matrix or batches of square matrices.

slogdet
 Calculates the sign and log absolute value of the determinant(s) of a square matrix or batches of square matrices.

lstsq
 Computes the solution to the least squares and least norm problems for a full rank matrix AA  of size (m×n)(m \times n)  and a matrix BB  of size (m×k)(m \times k) .

lu
 Computes the LU factorization of a matrix or batches of matrices A.

lu_solve
 Returns the LU solve of the linear system Ax=bAx = b  using the partially pivoted LU factorization of A from torch.lu().

lu_unpack
 Unpacks the data and pivots from a LU factorization of a tensor.

matmul
 Matrix product of two tensors.

matrix_power
 Returns the matrix raised to the power n for square matrices.

matrix_rank
 Returns the numerical rank of a 2-D tensor.

matrix_exp
 Returns the matrix exponential.

mm
 Performs a matrix multiplication of the matrices input and mat2.

mv
 Performs a matrix-vector product of the matrix input and the vector vec.

orgqr
 Computes the orthogonal matrix Q of a QR factorization, from the (input, input2) tuple returned by torch.geqrf().

ormqr
 Multiplies mat (given by input3) by the orthogonal Q matrix of the QR factorization formed by torch.geqrf() that is represented by (a, tau) (given by (input, input2)).

outer
 Outer product of input and vec2.

pinverse
 Calculates the pseudo-inverse (also known as the Moore-Penrose inverse) of a 2D tensor.

qr
 Computes the QR decomposition of a matrix or a batch of matrices input, and returns a namedtuple (Q, R) of tensors such that input=QR\text{input} = Q R  with QQ  being an orthogonal matrix or batch of orthogonal matrices and RR  being an upper triangular matrix or batch of upper triangular matrices.

solve
 This function returns the solution to the system of linear equations represented by AX=BAX = B  and the LU factorization of A, in order as a namedtuple solution, LU.

svd
 Computes the singular value decomposition of either a matrix or batch of matrices input.

svd_lowrank
 Return the singular value decomposition (U, S, V) of a matrix, batches of matrices, or a sparse matrix AA  such that A≈Udiag(S)VTA \approx U diag(S) V^T .

pca_lowrank
 Performs linear Principal Component Analysis (PCA) on a low-rank matrix, batches of such matrices, or sparse matrix.

symeig
 This function returns eigenvalues and eigenvectors of a real symmetric matrix input or a batch of real symmetric matrices, represented by a namedtuple (eigenvalues, eigenvectors).

lobpcg
 Find the k largest (or smallest) eigenvalues and the corresponding eigenvectors of a symmetric positive defined generalized eigenvalue problem using matrix-free LOBPCG methods.

trapz
 Estimate ∫ydx\int y\,dx  along dim, using the trapezoid rule.

triangular_solve
 Solves a system of equations with a triangular coefficient matrix AA  and multiple right-hand sides bb .

vdot
 Computes the dot product of two 1D tensors.   Utilities

compiled_with_cxx11_abi
 Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1

result_type
 Returns the torch.dtype that would result from performing an arithmetic operation on the provided input tensors.

can_cast
 Determines if a type conversion is allowed under PyTorch casting rules described in the type promotion documentation.

promote_types
 Returns the torch.dtype with the smallest size and scalar kind that is not smaller nor of lower kind than either type1 or type2.

use_deterministic_algorithms
 Sets whether PyTorch operations must use “deterministic” algorithms.

are_deterministic_algorithms_enabled
 Returns True if the global deterministic flag is turned on.

_assert
 A wrapper around Python’s assert which is symbolically traceable.


torch.abs(input, *, out=None) → Tensor
Computes the absolute value of each element in input.  outi=∣inputi∣\text{out}_{i} = |\text{input}_{i}|
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> torch.abs(torch.tensor([-1, -2, 3]))
tensor([ 1,  2,  3])


torch.absolute(input, *, out=None) → Tensor
Alias for torch.abs()


torch.acos(input, *, out=None) → Tensor
Computes the inverse cosine of each element in input.  outi=cos−1(inputi)\text{out}_{i} = \cos^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.3348, -0.5889,  0.2005, -0.1584])
>>> torch.acos(a)
tensor([ 1.2294,  2.2004,  1.3690,  1.7298])


torch.acosh(input, *, out=None) → Tensor
Returns a new tensor with the inverse hyperbolic cosine of the elements of input.  Note The domain of the inverse hyperbolic cosine is [1, inf) and values outside this range will be mapped to NaN, except for + INF for which the output is mapped to + INF.   outi=cosh−1(inputi)\text{out}_{i} = \cosh^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4).uniform_(1, 2)
>>> a
tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
>>> torch.acosh(a)
tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])


torch.add(input, other, *, out=None)
Adds the scalar other to each element of the input input and returns a new resulting tensor.  out=input+other\text{out} = \text{input} + \text{other}
If input is of type FloatTensor or DoubleTensor, other must be a real number, otherwise it should be an integer.  Parameters

input (Tensor) – the input tensor.
value (Number) – the number to be added to each element of input
   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.0202,  1.0985,  1.3506, -0.6056])
>>> torch.add(a, 20)
tensor([ 20.0202,  21.0985,  21.3506,  19.3944])

torch.add(input, other, *, alpha=1, out=None)
 Each element of the tensor other is multiplied by the scalar alpha and added to each element of the tensor input. The resulting tensor is returned. The shapes of input and other must be broadcastable.  out=input+alpha×other\text{out} = \text{input} + \text{alpha} \times \text{other}
If other is of type FloatTensor or DoubleTensor, alpha must be a real number, otherwise it should be an integer.  Parameters

input (Tensor) – the first input tensor
other (Tensor) – the second input tensor   Keyword Arguments

alpha (Number) – the scalar multiplier for other

out (Tensor, optional) – the output tensor.    Example: >>> a = torch.randn(4)
>>> a
tensor([-0.9732, -0.3497,  0.6245,  0.4022])
>>> b = torch.randn(4, 1)
>>> b
tensor([[ 0.3743],
        [-1.7724],
        [-0.5811],
        [-0.8017]])
>>> torch.add(a, b, alpha=10)
tensor([[  2.7695,   3.3930,   4.3672,   4.1450],
        [-18.6971, -18.0736, -17.0994, -17.3216],
        [ -6.7845,  -6.1610,  -5.1868,  -5.4090],
        [ -8.9902,  -8.3667,  -7.3925,  -7.6147]])


torch.addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) → Tensor
Performs a batch matrix-matrix product of matrices stored in batch1 and batch2, with a reduced add step (all matrix multiplications get accumulated along the first dimension). input is added to the final result. batch1 and batch2 must be 3-D tensors each containing the same number of matrices. If batch1 is a (b×n×m)(b \times n \times m)  tensor, batch2 is a (b×m×p)(b \times m \times p)  tensor, input must be broadcastable with a (n×p)(n \times p)  tensor and out will be a (n×p)(n \times p)  tensor.  out=β input+α(∑i=0b−1batch1i@batch2i)out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
If beta is 0, then input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operator supports TensorFloat32.  Parameters

batch1 (Tensor) – the first batch of matrices to be multiplied
batch2 (Tensor) – the second batch of matrices to be multiplied   Keyword Arguments

beta (Number, optional) – multiplier for input (β\beta )
input (Tensor) – matrix to be added
alpha (Number, optional) – multiplier for batch1 @ batch2 (α\alpha )
out (Tensor, optional) – the output tensor.    Example: >>> M = torch.randn(3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.addbmm(M, batch1, batch2)
tensor([[  6.6311,   0.0503,   6.9768, -12.0362,  -2.1653],
        [ -4.8185,  -1.4255,  -6.6760,   8.9453,   2.5743],
        [ -3.8202,   4.3691,   1.0943,  -1.1109,   5.4730]])


torch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) → Tensor
Performs the element-wise division of tensor1 by tensor2, multiply the result by the scalar value and add it to input.  Warning Integer division with addcdiv is no longer supported, and in a future release addcdiv will perform a true division of tensor1 and tensor2. The historic addcdiv behavior can be implemented as (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype) for integer inputs and as (input + value * tensor1 / tensor2) for float inputs. The future addcdiv behavior is just the latter implementation: (input + value * tensor1 / tensor2), for all dtypes.   outi=inputi+value×tensor1itensor2i\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
The shapes of input, tensor1, and tensor2 must be broadcastable. For inputs of type FloatTensor or DoubleTensor, value must be a real number, otherwise an integer.  Parameters

input (Tensor) – the tensor to be added
tensor1 (Tensor) – the numerator tensor
tensor2 (Tensor) – the denominator tensor   Keyword Arguments

value (Number, optional) – multiplier for tensor1/tensor2\text{tensor1} / \text{tensor2}

out (Tensor, optional) – the output tensor.    Example: >>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcdiv(t, t1, t2, value=0.1)
tensor([[-0.2312, -3.6496,  0.1312],
        [-1.0428,  3.4292, -0.1030],
        [-0.5369, -0.9829,  0.0430]])


torch.addcmul(input, tensor1, tensor2, *, value=1, out=None) → Tensor
Performs the element-wise multiplication of tensor1 by tensor2, multiply the result by the scalar value and add it to input.  outi=inputi+value×tensor1i×tensor2i\text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
The shapes of tensor, tensor1, and tensor2 must be broadcastable. For inputs of type FloatTensor or DoubleTensor, value must be a real number, otherwise an integer.  Parameters

input (Tensor) – the tensor to be added
tensor1 (Tensor) – the tensor to be multiplied
tensor2 (Tensor) – the tensor to be multiplied   Keyword Arguments

value (Number, optional) – multiplier for tensor1.∗tensor2tensor1 .* tensor2

out (Tensor, optional) – the output tensor.    Example: >>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcmul(t, t1, t2, value=0.1)
tensor([[-0.8635, -0.6391,  1.6174],
        [-0.7617, -0.5879,  1.7388],
        [-0.8353, -0.6249,  1.6511]])


torch.addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) → Tensor
Performs a matrix multiplication of the matrices mat1 and mat2. The matrix input is added to the final result. If mat1 is a (n×m)(n \times m)  tensor, mat2 is a (m×p)(m \times p)  tensor, then input must be broadcastable with a (n×p)(n \times p)  tensor and out will be a (n×p)(n \times p)  tensor. alpha and beta are scaling factors on matrix-vector product between mat1 and mat2 and the added matrix input respectively.  out=β input+α(mat1i@mat2i)\text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
If beta is 0, then input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operator supports TensorFloat32.  Parameters

input (Tensor) – matrix to be added
mat1 (Tensor) – the first matrix to be matrix multiplied
mat2 (Tensor) – the second matrix to be matrix multiplied   Keyword Arguments

beta (Number, optional) – multiplier for input (β\beta )
alpha (Number, optional) – multiplier for mat1@mat2mat1 @ mat2  (α\alpha )
out (Tensor, optional) – the output tensor.    Example: >>> M = torch.randn(2, 3)
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.addmm(M, mat1, mat2)
tensor([[-4.8716,  1.4671, -1.3746],
        [ 0.7573, -3.9555, -2.8681]])


torch.addmv(input, mat, vec, *, beta=1, alpha=1, out=None) → Tensor
Performs a matrix-vector product of the matrix mat and the vector vec. The vector input is added to the final result. If mat is a (n×m)(n \times m)  tensor, vec is a 1-D tensor of size m, then input must be broadcastable with a 1-D tensor of size n and out will be 1-D tensor of size n. alpha and beta are scaling factors on matrix-vector product between mat and vec and the added tensor input respectively.  out=β input+α(mat@vec)\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
If beta is 0, then input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers  Parameters

input (Tensor) – vector to be added
mat (Tensor) – matrix to be matrix multiplied
vec (Tensor) – vector to be matrix multiplied   Keyword Arguments

beta (Number, optional) – multiplier for input (β\beta )
alpha (Number, optional) – multiplier for mat@vecmat @ vec  (α\alpha )
out (Tensor, optional) – the output tensor.    Example: >>> M = torch.randn(2)
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.addmv(M, mat, vec)
tensor([-0.3768, -5.5565])


torch.addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) → Tensor
Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input. Optional values beta and alpha are scaling factors on the outer product between vec1 and vec2 and the added matrix input respectively.  out=β input+α(vec1⊗vec2)\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
If beta is 0, then input will be ignored, and nan and inf in it will not be propagated. If vec1 is a vector of size n and vec2 is a vector of size m, then input must be broadcastable with a matrix of size (n×m)(n \times m)  and out will be a matrix of size (n×m)(n \times m) .  Parameters

input (Tensor) – matrix to be added
vec1 (Tensor) – the first vector of the outer product
vec2 (Tensor) – the second vector of the outer product   Keyword Arguments

beta (Number, optional) – multiplier for input (β\beta )
alpha (Number, optional) – multiplier for vec1⊗vec2\text{vec1} \otimes \text{vec2}  (α\alpha )
out (Tensor, optional) – the output tensor.    Example: >>> vec1 = torch.arange(1., 4.)
>>> vec2 = torch.arange(1., 3.)
>>> M = torch.zeros(3, 2)
>>> torch.addr(M, vec1, vec2)
tensor([[ 1.,  2.],
        [ 2.,  4.],
        [ 3.,  6.]])


torch.all(input) → Tensor
Tests if all elements in input evaluate to True.  Note This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself.  Example: >>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.all(a)
tensor(False, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.all(a)
tensor(False)

torch.all(input, dim, keepdim=False, *, out=None) → Tensor
 For each row of input in the given dimension dim, returns True if all elements in the row evaluate to True and False otherwise. If keepdim is True, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 fewer dimension than input.  Parameters

input (Tensor) – the input tensor.
dim (int) – the dimension to reduce.
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.rand(4, 2).bool()
>>> a
tensor([[True, True],
        [True, False],
        [True, True],
        [True, True]], dtype=torch.bool)
>>> torch.all(a, dim=1)
tensor([ True, False,  True,  True], dtype=torch.bool)
>>> torch.all(a, dim=0)
tensor([ True, False], dtype=torch.bool)


torch.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) → bool
This function checks if all input and other satisfy the condition:  ∣input−other∣≤atol+rtol×∣other∣\lvert \text{input} - \text{other} \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other} \rvert
elementwise, for all elements of input and other. The behaviour of this function is analogous to numpy.allclose  Parameters

input (Tensor) – first tensor to compare
other (Tensor) – second tensor to compare
atol (float, optional) – absolute tolerance. Default: 1e-08
rtol (float, optional) – relative tolerance. Default: 1e-05
equal_nan (bool, optional) – if True, then two NaN s will be considered equal. Default: False
    Example: >>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
False
>>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
True
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
False
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
True


torch.amax(input, dim, keepdim=False, *, out=None) → Tensor
Returns the maximum value of each slice of the input tensor in the given dimension(s) dim.  Note
The difference between max/min and amax/amin is:

amax/amin supports reducing on multiple dimensions,
amax/amin does not return indices,
amax/amin evenly distributes gradient between equal values, while max(dim)/min(dim) propagates gradient only to a single index in the source tensor.     If keepdim is ``True`, the output tensors are of the same size as input except in the dimension(s) dim where they are of size 1. Otherwise, dim`s are squeezed (see :func:`torch.squeeze), resulting in the output tensors having fewer dimension than input.  Parameters

input (Tensor) – the input tensor.
dim (int or tuple of python:ints) – the dimension or dimensions to reduce.
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.8177,  1.4878, -0.2491,  0.9130],
        [-0.7158,  1.1775,  2.0992,  0.4817],
        [-0.0053,  0.0164, -1.3738, -0.0507],
        [ 1.9700,  1.1106, -1.0318, -1.0816]])
>>> torch.amax(a, 1)
tensor([1.4878, 2.0992, 0.0164, 1.9700])


torch.amin(input, dim, keepdim=False, *, out=None) → Tensor
Returns the minimum value of each slice of the input tensor in the given dimension(s) dim.  Note
The difference between max/min and amax/amin is:

amax/amin supports reducing on multiple dimensions,
amax/amin does not return indices,
amax/amin evenly distributes gradient between equal values, while max(dim)/min(dim) propagates gradient only to a single index in the source tensor.     If keepdim is True, the output tensors are of the same size as input except in the dimension(s) dim where they are of size 1. Otherwise, dim`s are squeezed (see :func:`torch.squeeze), resulting in the output tensors having fewer dimensions than input.  Parameters

input (Tensor) – the input tensor.
dim (int or tuple of python:ints) – the dimension or dimensions to reduce.
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.6451, -0.4866,  0.2987, -1.3312],
        [-0.5744,  1.2980,  1.8397, -0.2713],
        [ 0.9128,  0.9214, -1.7268, -0.2995],
        [ 0.9023,  0.4853,  0.9075, -1.6165]])
>>> torch.amin(a, 1)
tensor([-1.3312, -0.5744, -1.7268, -1.6165])


torch.angle(input, *, out=None) → Tensor
Computes the element-wise angle (in radians) of the given input tensor.  outi=angle(inputi)\text{out}_{i} = angle(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.    Note Starting in PyTorch 1.8, angle returns pi for negative real numbers, zero for non-negative real numbers, and propagates NaNs. Previously the function would return zero for all real numbers and not propagate floating-point NaNs.  Example: >>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
tensor([ 135.,  135,  -45])


torch.any(input) → Tensor
 Parameters
input (Tensor) – the input tensor.   Tests if any element in input evaluates to True.  Note This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself.  Example: >>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.any(a)
tensor(True, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.any(a)
tensor(True)

torch.any(input, dim, keepdim=False, *, out=None) → Tensor
 For each row of input in the given dimension dim, returns True if any element in the row evaluate to True and False otherwise. If keepdim is True, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 fewer dimension than input.  Parameters

input (Tensor) – the input tensor.
dim (int) – the dimension to reduce.
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4, 2) < 0
>>> a
tensor([[ True,  True],
        [False,  True],
        [ True,  True],
        [False, False]])
>>> torch.any(a, 1)
tensor([ True,  True,  True, False])
>>> torch.any(a, 0)
tensor([True, True])


torch.arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
Returns a 1-D tensor of size ⌈end−startstep⌉\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil  with values from the interval [start, end) taken with common difference step beginning from start. Note that non-integer step is subject to floating point rounding errors when comparing against end; to avoid inconsistency, we advise adding a small epsilon to end in such cases.  outi+1=outi+step\text{out}_{{i+1}} = \text{out}_{i} + \text{step}
 Parameters

start (Number) – the starting value for the set of points. Default: 0.
end (Number) – the ending value for the set of points
step (Number) – the gap between each pair of adjacent points. Default: 1.   Keyword Arguments

out (Tensor, optional) – the output tensor.
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()). If dtype is not given, infer the data type from the other input arguments. If any of start, end, or stop are floating-point, the dtype is inferred to be the default dtype, see get_default_dtype(). Otherwise, the dtype is inferred to be torch.int64.
layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided.
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.    Example: >>> torch.arange(5)
tensor([ 0,  1,  2,  3,  4])
>>> torch.arange(1, 4)
tensor([ 1,  2,  3])
>>> torch.arange(1, 2.5, 0.5)
tensor([ 1.0000,  1.5000,  2.0000])


torch.arccos(input, *, out=None) → Tensor
Alias for torch.acos().


torch.arccosh(input, *, out=None) → Tensor
Alias for torch.acosh().


torch.arcsin(input, *, out=None) → Tensor
Alias for torch.asin().


torch.arcsinh(input, *, out=None) → Tensor
Alias for torch.asinh().


torch.arctan(input, *, out=None) → Tensor
Alias for torch.atan().


torch.arctanh(input, *, out=None) → Tensor
Alias for torch.atanh().


torch.are_deterministic_algorithms_enabled() [source]

Returns True if the global deterministic flag is turned on. Refer to torch.use_deterministic_algorithms() documentation for more details.


torch.argmax(input) → LongTensor
Returns the indices of the maximum value of all elements in the input tensor. This is the second value returned by torch.max(). See its documentation for the exact semantics of this method.  Note If there are multiple minimal values then the indices of the first minimal value are returned.   Parameters
input (Tensor) – the input tensor.   Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398,  0.2663, -0.2686,  0.2450],
        [-0.7401, -0.8805, -0.3402, -1.1936],
        [ 0.4907, -1.3948, -1.0691, -0.3132],
        [-1.6092,  0.5419, -0.2993,  0.3195]])
>>> torch.argmax(a)
tensor(0)

torch.argmax(input, dim, keepdim=False) → LongTensor
 Returns the indices of the maximum values of a tensor across a dimension. This is the second value returned by torch.max(). See its documentation for the exact semantics of this method.  Parameters

input (Tensor) – the input tensor.
dim (int) – the dimension to reduce. If None, the argmax of the flattened input is returned.
keepdim (bool) – whether the output tensor has dim retained or not. Ignored if dim=None.    Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398,  0.2663, -0.2686,  0.2450],
        [-0.7401, -0.8805, -0.3402, -1.1936],
        [ 0.4907, -1.3948, -1.0691, -0.3132],
        [-1.6092,  0.5419, -0.2993,  0.3195]])
>>> torch.argmax(a, dim=1)
tensor([ 0,  2,  0,  1])


torch.argmin(input, dim=None, keepdim=False) → LongTensor
Returns the indices of the minimum value(s) of the flattened tensor or along a dimension This is the second value returned by torch.min(). See its documentation for the exact semantics of this method.  Note If there are multiple minimal values then the indices of the first minimal value are returned.   Parameters

input (Tensor) – the input tensor.
dim (int) – the dimension to reduce. If None, the argmin of the flattened input is returned.
keepdim (bool) – whether the output tensor has dim retained or not. Ignored if dim=None.    Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.1139,  0.2254, -0.1381,  0.3687],
        [ 1.0100, -1.1975, -0.0102, -0.4732],
        [-0.9240,  0.1207, -0.7506, -1.0213],
        [ 1.7809, -1.2960,  0.9384,  0.1438]])
>>> torch.argmin(a)
tensor(13)
>>> torch.argmin(a, dim=1)
tensor([ 2,  1,  3,  1])
>>> torch.argmin(a, dim=1, keepdim=True)
tensor([[2],
        [1],
        [3],
        [1]])


torch.argsort(input, dim=-1, descending=False) → LongTensor
Returns the indices that sort a tensor along a given dimension in ascending order by value. This is the second value returned by torch.sort(). See its documentation for the exact semantics of this method.  Parameters

input (Tensor) – the input tensor.
dim (int, optional) – the dimension to sort along
descending (bool, optional) – controls the sorting order (ascending or descending)    Example: >>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0785,  1.5267, -0.8521,  0.4065],
        [ 0.1598,  0.0788, -0.0745, -1.2700],
        [ 1.2208,  1.0722, -0.7064,  1.2564],
        [ 0.0669, -0.2318, -0.8229, -0.9280]])

>>> torch.argsort(a, dim=1)
tensor([[2, 0, 3, 1],
        [3, 2, 1, 0],
        [2, 1, 0, 3],
        [3, 2, 1, 0]])


torch.asin(input, *, out=None) → Tensor
Returns a new tensor with the arcsine of the elements of input.  outi=sin−1(inputi)\text{out}_{i} = \sin^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([-0.5962,  1.4985, -0.4396,  1.4525])
>>> torch.asin(a)
tensor([-0.6387,     nan, -0.4552,     nan])


torch.asinh(input, *, out=None) → Tensor
Returns a new tensor with the inverse hyperbolic sine of the elements of input.  outi=sinh−1(inputi)\text{out}_{i} = \sinh^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
>>> torch.asinh(a)
tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])


torch.as_strided(input, size, stride, storage_offset=0) → Tensor
Create a view of an existing torch.Tensor input with specified size, stride and storage_offset.  Warning More than one element of a created tensor may refer to a single memory location. As a result, in-place operations (especially ones that are vectorized) may result in incorrect behavior. If you need to write to the tensors, please clone them first. Many PyTorch functions, which return a view of a tensor, are internally implemented with this function. Those functions, like torch.Tensor.expand(), are easier to read and are therefore more advisable to use.   Parameters

input (Tensor) – the input tensor.
size (tuple or ints) – the shape of the output tensor
stride (tuple or ints) – the stride of the output tensor
storage_offset (int, optional) – the offset in the underlying storage of the output tensor    Example: >>> x = torch.randn(3, 3)
>>> x
tensor([[ 0.9039,  0.6291,  1.0795],
        [ 0.1586,  2.1939, -0.4900],
        [-0.1909, -0.7503,  1.9355]])
>>> t = torch.as_strided(x, (2, 2), (1, 2))
>>> t
tensor([[0.9039, 1.0795],
        [0.6291, 0.1586]])
>>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
tensor([[0.6291, 0.1586],
        [1.0795, 2.1939]])


torch.as_tensor(data, dtype=None, device=None) → Tensor
Convert the data into a torch.Tensor. If the data is already a Tensor with the same dtype and device, no copy will be performed, otherwise a new Tensor will be returned with computational graph retained if data Tensor has requires_grad=True. Similarly, if the data is an ndarray of the corresponding dtype and the device is the cpu, no copy will be performed.  Parameters

data (array_like) – Initial data for the tensor. Can be a list, tuple, NumPy ndarray, scalar, and other types.
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type from data.
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.    Example: >>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a)
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([-1,  2,  3])

>>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a, device=torch.device('cuda'))
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([1,  2,  3])


torch.atan(input, *, out=None) → Tensor
Returns a new tensor with the arctangent of the elements of input.  outi=tan−1(inputi)\text{out}_{i} = \tan^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.2341,  0.2539, -0.6256, -0.6448])
>>> torch.atan(a)
tensor([ 0.2299,  0.2487, -0.5591, -0.5727])


torch.atan2(input, other, *, out=None) → Tensor
Element-wise arctangent of inputi/otheri\text{input}_{i} / \text{other}_{i}  with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector (otheri,inputi)(\text{other}_{i}, \text{input}_{i})  and vector (1,0)(1, 0) . (Note that otheri\text{other}_{i} , the second parameter, is the x-coordinate, while inputi\text{input}_{i} , the first parameter, is the y-coordinate.) The shapes of input and other must be broadcastable.  Parameters

input (Tensor) – the first input tensor
other (Tensor) – the second input tensor   Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.9041,  0.0196, -0.3108, -2.4423])
>>> torch.atan2(a, torch.randn(4))
tensor([ 0.9833,  0.0811, -1.9743, -1.4151])


torch.atanh(input, *, out=None) → Tensor
Returns a new tensor with the inverse hyperbolic tangent of the elements of input.  Note The domain of the inverse hyperbolic tangent is (-1, 1) and values outside this range will be mapped to NaN, except for the values 1 and -1 for which the output is mapped to +/-INF respectively.   outi=tanh−1(inputi)\text{out}_{i} = \tanh^{-1}(\text{input}_{i})
 Parameters
input (Tensor) – the input tensor.  Keyword Arguments
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4).uniform_(-1, 1)
>>> a
tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
>>> torch.atanh(a)
tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])


torch.atleast_1d(*tensors) [source]

Returns a 1-dimensional view of each input tensor with zero dimensions. Input tensors with one or more dimensions are returned as-is.  Parameters
input (Tensor or list of Tensors) –   Returns
output (Tensor or tuple of Tensors)    Example::

>>> x = torch.randn(2)
>>> x
tensor([1.4584, 0.7583])
>>> torch.atleast_1d(x)
tensor([1.4584, 0.7583])
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_1d(x)
tensor([1.])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_1d((x,y))
(tensor([0.5000]), tensor([1.]))


torch.atleast_2d(*tensors) [source]

Returns a 2-dimensional view of each input tensor with zero dimensions. Input tensors with two or more dimensions are returned as-is. :param input: :type input: Tensor or list of Tensors  Returns
output (Tensor or tuple of Tensors)    Example::

>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_2d(x)
tensor([[1.]])
>>> x = torch.randn(2,2)
>>> x
tensor([[2.2086, 2.5165],
        [0.1757, 0.5194]])
>>> torch.atleast_2d(x)
tensor([[2.2086, 2.5165],
        [0.1757, 0.5194]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_2d((x,y))
(tensor([[0.5000]]), tensor([[1.]]))


torch.atleast_3d(*tensors) [source]

Returns a 3-dimensional view of each input tensor with zero dimensions. Input tensors with three or more dimensions are returned as-is. :param input: :type input: Tensor or list of Tensors  Returns
output (Tensor or tuple of Tensors)   Example >>> x = torch.tensor(0.5)
>>> x
tensor(0.5000)
>>> torch.atleast_3d(x)
tensor([[[0.5000]]])
>>> y = torch.randn(2,2)
>>> y
tensor([[-0.8079,  0.7460],
        [-1.1647,  1.4734]])
>>> torch.atleast_3d(y)
tensor([[[-0.8079],
        [ 0.7460]],

        [[-1.1647],
        [ 1.4734]]])
>>> x = torch.randn(1,1,1)
>>> x
tensor([[[-1.5689]]])
>>> torch.atleast_3d(x)
tensor([[[-1.5689]]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_3d((x,y))
(tensor([[[0.5000]]]), tensor([[[1.]]]))