latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional API
Functions 605
abs_
functionFull reference ↗- tensorplay.functional.abs_(input)[source]
abs
functionFull reference ↗- tensorplay.functional.abs(input: Tensor, *, out: Tensor | None) Tensor[source]
Computes the absolute value of each element in
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.abs(tensorplay.tensor([-1, -2, 3])) tensor([ 1, 2, 3])
absolute
functionFull reference ↗acos_
functionFull reference ↗- tensorplay.functional.acos_(input)[source]
acos
functionFull reference ↗- tensorplay.functional.acos(input: Tensor, *, out: Tensor | None) Tensor[source]
Computes the inverse cosine of each element in
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.3348, -0.5889, 0.2005, -0.1584]) >>> tensorplay.acos(a) tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
acosh_
functionFull reference ↗- tensorplay.functional.acosh_(input)[source]
acosh
functionFull reference ↗- tensorplay.functional.acosh(input: Tensor, *, out: Tensor | None) Tensor[source]
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.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4).uniform_(1, 2) >>> a tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ]) >>> tensorplay.acosh(a) tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
adaptive_avg_pool1d
functionFull reference ↗- tensorplay.functional.adaptive_avg_pool1d(input, output_size)[source]
adaptive_max_pool1d
functionFull reference ↗- tensorplay.functional.adaptive_max_pool1d(input, output_size)[source]
add
functionFull reference ↗- tensorplay.functional.add(input, other, *, alpha=1, out=None) Tensor[source]
Adds
other, scaled byalpha, toinput.Supports broadcasting to a common shape, type promotion, and integer, float, and complex inputs.
- Parameters:
- Keyword Arguments:
alpha (Number) – the multiplier for
other.out (Tensor, optional) – the output tensor.
Examples:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.0202, 1.0985, 1.3506, -0.6056]) >>> tensorplay.add(a, 20) tensor([ 20.0202, 21.0985, 21.3506, 19.3944]) >>> b = tensorplay.randn(4) >>> b tensor([-0.9732, -0.3497, 0.6245, 0.4022]) >>> c = tensorplay.randn(4, 1) >>> c tensor([[ 0.3743], [-1.7724], [-0.5811], [-0.8017]]) >>> tensorplay.add(b, c, 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]])
addbmm
functionFull reference ↗- tensorplay.functional.addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) Tensor[source]
Performs a batch matrix-matrix product of matrices stored in
batch1andbatch2, with a reduced add step (all matrix multiplications get accumulated along the first dimension).inputis added to the final result.batch1andbatch2must be 3-D tensors each containing the same number of matrices.If
out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)batch1is a tensor,batch2is a tensor,inputmust be broadcastable with a tensor andoutwill be a tensor.If
betais 0, then the content ofinputwill be ignored, and nan and inf in it will not be propagated.For inputs of type FloatTensor or DoubleTensor, arguments
betaandalphamust be real numbers, otherwise they should be integers.This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
- Parameters:
- Keyword Arguments:
beta (Number, optional) – multiplier for
input()alpha (Number, optional) – multiplier for batch1 @ batch2 ()
out (Tensor, optional) – the output tensor.
Example:
>>> M = tensorplay.randn(3, 5) >>> batch1 = tensorplay.randn(10, 3, 4) >>> batch2 = tensorplay.randn(10, 4, 5) >>> tensorplay.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]])
addcdiv
functionFull reference ↗- tensorplay.functional.addcdiv(input, tensor1, tensor2, *, value=1, out=None) Tensor[source]
Performs the element-wise division of
tensor1bytensor2, multiplies the result by the scalarvalueand adds it toinput.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 * tensorplay.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.
The shapes of
input,tensor1, andtensor2must be broadcastable.For inputs of type FloatTensor or DoubleTensor,
valuemust be a real number, otherwise an integer.- Parameters:
- Keyword Arguments:
value (Number, optional) – multiplier for
out (Tensor, optional) – the output tensor.
Example:
>>> t = tensorplay.randn(1, 3) >>> t1 = tensorplay.randn(3, 1) >>> t2 = tensorplay.randn(1, 3) >>> tensorplay.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]])
addcmul
functionFull reference ↗- tensorplay.functional.addcmul(input, tensor1, tensor2, *, value=1, out=None) Tensor[source]
Performs the element-wise multiplication of
tensor1bytensor2, multiplies the result by the scalarvalueand adds it toinput.The shapes of
tensor,tensor1, andtensor2must be broadcastable.For inputs of type FloatTensor or DoubleTensor,
valuemust be a real number, otherwise an integer.- Parameters:
- Keyword Arguments:
value (Number, optional) – multiplier for
out (Tensor, optional) – the output tensor.
Example:
>>> t = tensorplay.randn(1, 3) >>> t1 = tensorplay.randn(3, 1) >>> t2 = tensorplay.randn(1, 3) >>> tensorplay.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]])
addmm
functionFull reference ↗- tensorplay.functional.addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) Tensor[source]
Performs a matrix multiplication of the matrices
mat1andmat2. The matrixinputis added to the final result.If
mat1is a tensor,mat2is a tensor, theninputmust be broadcastable with a tensor andoutwill be a tensor.
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)alphaandbetaare scaling factors on matrix-vector product betweenmat1andmat2and the added matrixinputrespectively.If
betais 0, then the content ofinputwill be ignored, and nan and inf in it will not be propagated.For inputs of type FloatTensor or DoubleTensor, arguments
betaandalphamust be real numbers, otherwise they should be integers.This operation has support for arguments with sparse layouts. If
inputis sparse the result will have the same layout and ifoutis provided it must have the same layout asinput.Warning
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported, or may not have autograd support. If you notice missing functionality please open a feature request.
This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
- 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
out_dtype (dtype, optional) – the dtype of the output tensor, Supported only on CUDA and for tensorplay.float32 given tensorplay.float16/tensorplay.bfloat16 input dtypes
- Keyword Arguments:
beta (Number, optional) – multiplier for
input()alpha (Number, optional) – multiplier for mat1 @ mat2 ()
out (Tensor, optional) – the output tensor.
Example:
>>> M = tensorplay.randn(2, 3) >>> mat1 = tensorplay.randn(2, 3) >>> mat2 = tensorplay.randn(3, 3) >>> tensorplay.addmm(M, mat1, mat2) tensor([[-4.8716, 1.4671, -1.3746], [ 0.7573, -3.9555, -2.8681]])
addmv_
functionFull reference ↗- tensorplay.functional.addmv_(input, mat, vec, beta=1, alpha=1)[source]
addmv
functionFull reference ↗- tensorplay.functional.addmv(input, mat, vec, *, beta=1, alpha=1, out=None) Tensor[source]
Performs a matrix-vector product of the matrix
matand the vectorvec. The vectorinputis added to the final result.If
matis a tensor,vecis a 1-D tensor of size m, theninputmust be broadcastable with a 1-D tensor of size n andoutwill be 1-D tensor of size n.
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})alphaandbetaare scaling factors on matrix-vector product betweenmatandvecand the added tensorinputrespectively.If
betais 0, then the content ofinputwill be ignored, and nan and inf in it will not be propagated.For inputs of type FloatTensor or DoubleTensor, arguments
betaandalphamust be real numbers, otherwise they should be integers.- Parameters:
- Keyword Arguments:
beta (Number, optional) – multiplier for
input()alpha (Number, optional) – multiplier for mat @ vec ()
out (Tensor, optional) – the output tensor.
Example:
>>> M = tensorplay.randn(2) >>> mat = tensorplay.randn(2, 3) >>> vec = tensorplay.randn(3) >>> tensorplay.addmv(M, mat, vec) tensor([-0.3768, -5.5565])
addr
functionFull reference ↗- tensorplay.functional.addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) Tensor[source]
Performs the outer-product of vectors
vec1andvec2and adds it to the matrixinput.Optional values
betaandalphaare scaling factors on the outer product betweenvec1andvec2and the added matrixinputrespectively.If
betais 0, then the content ofinputwill be ignored, and nan and inf in it will not be propagated.If
vec1is a vector of size n andvec2is a vector of size m, theninputmust be broadcastable with a matrix of size andoutwill be a matrix of size .- Parameters:
- Keyword Arguments:
beta (Number, optional) – multiplier for
input()alpha (Number, optional) – multiplier for ()
out (Tensor, optional) – the output tensor.
Example:
>>> vec1 = tensorplay.arange(1., 4.) >>> vec2 = tensorplay.arange(1., 3.) >>> M = tensorplay.zeros(3, 2) >>> tensorplay.addr(M, vec1, vec2) tensor([[ 1., 2.], [ 2., 4.], [ 3., 6.]])
adjoint
functionFull reference ↗- tensorplay.functional.adjoint(input: Tensor) Tensor[source]
Returns a view of the tensor conjugated and with the last two dimensions transposed.
x.adjoint()is equivalent tox.transpose(-2, -1).conj()for complex tensors and tox.transpose(-2, -1)for real tensors.- Parameters:
{input}
Example:
>>> x = tensorplay.arange(4, dtype=tensorplay.float) >>> A = tensorplay.complex(x, x).reshape(2, 2) >>> A tensor([[0.+0.j, 1.+1.j], [2.+2.j, 3.+3.j]]) >>> A.adjoint() tensor([[0.-0.j, 2.-2.j], [1.-1.j, 3.-3.j]]) >>> (A.adjoint() == A.mH).all() tensor(True)
affine_grid_generator
functionFull reference ↗- tensorplay.functional.affine_grid_generator(theta, size, align_corners)[source]
airy_ai
functionFull reference ↗- tensorplay.functional.airy_ai(input)[source]
alias_copy
functionFull reference ↗- tensorplay.functional.alias_copy(input)[source]
Performs the same operation as
tensorplay.alias(), but all output tensors are freshly created instead of aliasing the input.
all
functionFull reference ↗- tensorplay.functional.all(input: Tensor, *, out=None) Tensor[source]
Tests if all elements in
inputevaluate 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.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=tensorplay.bool) >>> tensorplay.all(a) tensor(False, dtype=tensorplay.bool) >>> a = tensorplay.arange(0, 3) >>> a tensor([0, 1, 2]) >>> tensorplay.all(a) tensor(False)For each row of
inputin the given dimensiondim, returns True if all elements in the row evaluate to True and False otherwise.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(4, 2).bool() >>> a tensor([[True, True], [True, False], [True, True], [True, True]], dtype=tensorplay.bool) >>> tensorplay.all(a, dim=1) tensor([ True, False, True, True], dtype=tensorplay.bool) >>> tensorplay.all(a, dim=0) tensor([ True, False], dtype=tensorplay.bool)
allclose
functionFull reference ↗- tensorplay.functional.allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) bool[source]
This function checks if
inputandothersatisfy the condition:elementwise, for all elements of
inputandother. The behaviour of this function is analogous to numpy.allclose- Parameters:
Example:
>>> tensorplay.allclose(tensorplay.tensor([10000., 1e-07]), tensorplay.tensor([10000.1, 1e-08])) False >>> tensorplay.allclose(tensorplay.tensor([10000., 1e-08]), tensorplay.tensor([10000.1, 1e-09])) True >>> tensorplay.allclose(tensorplay.tensor([1.0, float('nan')]), tensorplay.tensor([1.0, float('nan')])) False >>> tensorplay.allclose(tensorplay.tensor([1.0, float('nan')]), tensorplay.tensor([1.0, float('nan')]), equal_nan=True) True
alpha_dropout_
functionFull reference ↗- tensorplay.functional.alpha_dropout_(input, p=0.5, train=True)[source]
alpha_dropout
functionFull reference ↗- tensorplay.functional.alpha_dropout(input, p=0.5, train=True)[source]
amax
functionFull reference ↗- tensorplay.functional.amax(input, dim, keepdim=False, *, out=None) Tensor[source]
Returns the maximum value of each slice of the
inputtensor in the given dimension(s)dim.Note
- The difference between
max/minandamax/aminis: amax/aminsupports reducing on multiple dimensions,amax/amindoes not return indices.
Both
amax/aminevenly distribute gradients between equal values when there are multiple input elements with the same minimum or maximum value.- For
max/min: If reduce over all dimensions(no dim specified), gradients evenly distribute between equally
max/minvalues.If reduce over one specified axis, only propagate to the indexed element.
If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.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]]) >>> tensorplay.amax(a, 1) tensor([1.4878, 2.0992, 0.0164, 1.9700])- The difference between
amin
functionFull reference ↗- tensorplay.functional.amin(input, dim, keepdim=False, *, out=None) Tensor[source]
Returns the minimum value of each slice of the
inputtensor in the given dimension(s)dim.Note
- The difference between
max/minandamax/aminis: amax/aminsupports reducing on multiple dimensions,amax/amindoes not return indices.
Both
amax/aminevenly distribute gradients between equal values when there are multiple input elements with the same minimum or maximum value.- For
max/min: If reduce over all dimensions(no dim specified), gradients evenly distribute between equally
max/minvalues.If reduce over one specified axis, only propagate to the indexed element.
If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.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]]) >>> tensorplay.amin(a, 1) tensor([-1.3312, -0.5744, -1.7268, -1.6165])- The difference between
aminmax
functionFull reference ↗- tensorplay.functional.aminmax(input, dim=[], keepdim=False, *, out=None)[source]
angle
functionFull reference ↗- tensorplay.functional.angle(input: Tensor, *, out: Tensor | None) Tensor[source]
Computes the element-wise angle (in radians) of the given
inputtensor.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) –
the output tensor.
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:
>>> tensorplay.angle(tensorplay.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159 tensor([ 135., 135, -45])
any
functionFull reference ↗- tensorplay.functional.any(input: Tensor, *, out: Tensor | None) Tensor[source]
Tests if any element in
inputevaluates 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.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=tensorplay.bool) >>> tensorplay.any(a) tensor(True, dtype=tensorplay.bool) >>> a = tensorplay.arange(0, 3) >>> a tensor([0, 1, 2]) >>> tensorplay.any(a) tensor(True)For each row of
inputin the given dimensiondim, returns True if any element in the row evaluate to True and False otherwise.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4, 2) < 0 >>> a tensor([[ True, True], [False, True], [ True, True], [False, False]]) >>> tensorplay.any(a, 1) tensor([ True, True, True, False]) >>> tensorplay.any(a, 0) tensor([True, True])
arange
functionFull reference ↗- tensorplay.functional.arange(start=0, end, step=1, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Returns a 1-D tensor of size with values from the interval
[start, end)taken with common differencestepbeginning from start.Note: When using floating-point dtypes (especially reduced precision types like
bfloat16), the results may be affected by floating-point rounding behavior. Some values in the sequence might not be exactly representable in certain floating-point formats, which can lead to repeated values or unexpected rounding. For precise sequences, it is recommended to use integer dtypes instead of floating-point dtypes.Note that non-integer
stepis subject to floating point rounding errors when comparing againstend; to avoid inconsistency, we advise subtracting a small epsilon fromendin such cases.- Parameters:
start (Number, optional) – the starting value for the set of points. Default:
0.end (Number) – the ending value for the set of points
step (Number, optional) – the gap between each pair of adjacent points. Default:
1.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). 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, seeget_default_dtype(). Otherwise, the dtype is inferred to be tensorplay.int64.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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:
>>> tensorplay.arange(5) tensor([ 0, 1, 2, 3, 4]) >>> tensorplay.arange(1, 4) tensor([ 1, 2, 3]) >>> tensorplay.arange(1, 2.5, 0.5) tensor([ 1.0000, 1.5000, 2.0000])
arccos_
functionFull reference ↗- tensorplay.functional.arccos_(input)[source]
arccos
functionFull reference ↗arccosh_
functionFull reference ↗- tensorplay.functional.arccosh_(input)[source]
arccosh
functionFull reference ↗arcsin_
functionFull reference ↗- tensorplay.functional.arcsin_(input)[source]
arcsin
functionFull reference ↗arcsinh_
functionFull reference ↗- tensorplay.functional.arcsinh_(input)[source]
arcsinh
functionFull reference ↗arctan_
functionFull reference ↗- tensorplay.functional.arctan_(input)[source]
arctan
functionFull reference ↗arctan2
functionFull reference ↗arctanh_
functionFull reference ↗- tensorplay.functional.arctanh_(input)[source]
arctanh
functionFull reference ↗argmax
functionFull reference ↗- tensorplay.functional.argmax(input) LongTensor[source]
Returns the indices of the maximum value of all elements in the
inputtensor.This is the second value returned by
tensorplay.max(). See its documentation for the exact semantics of this method.Note
If there are multiple maximal values then the indices of the first maximal value are returned.
- Parameters:
input (Tensor) – the input tensor.
Example:
>>> a = tensorplay.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]]) >>> tensorplay.argmax(a) tensor(0)- tensorplay.functional.argmax(input, dim, keepdim=False) LongTensor[source]
Returns the indices of the maximum values of a tensor across a dimension.
This is the second value returned by
tensorplay.max(). See its documentation for the exact semantics of this method.- Parameters:
input (Tensor) – the input tensor.
dim – the dimension to reduce.
Example:
>>> a = tensorplay.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]]) >>> tensorplay.argmax(a, dim=1) tensor([ 0, 2, 0, 1])
argmin
functionFull reference ↗- tensorplay.functional.argmin(input, dim=None, keepdim=False) LongTensor[source]
Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
This is the second value returned by
tensorplay.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 – the dimension to reduce.
Example:
>>> a = tensorplay.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]]) >>> tensorplay.argmin(a) tensor(13) >>> tensorplay.argmin(a, dim=1) tensor([ 2, 1, 3, 1]) >>> tensorplay.argmin(a, dim=1, keepdim=True) tensor([[2], [1], [3], [1]])
argsort
functionFull reference ↗- tensorplay.functional.argsort(input, dim=-1, descending=False, *, stable=False) Tensor[source]
Returns the indices that sort a tensor along a given dimension in ascending order by value.
This is the second value returned by
tensorplay.sort(). See its documentation for the exact semantics of this method.If
stableisTruethen the sorting routine becomes stable, preserving the order of equivalent elements. IfFalse, the relative order of values which compare equal is not guaranteed.Trueis slower.- Parameters:
- Keyword Arguments:
stable (bool, optional) – controls the relative order of equivalent elements
Example:
>>> a = tensorplay.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]]) >>> tensorplay.argsort(a, dim=1) tensor([[2, 0, 3, 1], [3, 2, 1, 0], [2, 1, 0, 3], [3, 2, 1, 0]])
argwhere
functionFull reference ↗- tensorplay.functional.argwhere(input) Tensor[source]
Returns a tensor containing the indices of all non-zero elements of
input. Each row in the result contains the indices of a non-zero element ininput. The result is sorted lexicographically, with the last index changing the fastest (C-style).If
inputhas dimensions, then the resulting indices tensoroutis of size , where is the total number of non-zero elements in theinputtensor.Note
This function is similar to NumPy’s argwhere.
When
inputis on CUDA, this function causes host-device synchronization.- Parameters:
{input}
Example:
>>> t = tensorplay.tensor([1, 0, 1]) >>> tensorplay.argwhere(t) tensor([[0], [2]]) >>> t = tensorplay.tensor([[1, 0, 1], [0, 1, 1]]) >>> tensorplay.argwhere(t) tensor([[0, 0], [0, 2], [1, 1], [1, 2]])
as_strided_
functionFull reference ↗- tensorplay.functional.as_strided_(input, size, stride, storage_offset=None)[source]
as_strided_copy
functionFull reference ↗- tensorplay.functional.as_strided_copy(input, size, stride, storage_offset=None)[source]
Performs the same operation as
tensorplay.as_strided(), but all output tensors are freshly created instead of aliasing the input.
as_strided_scatter
functionFull reference ↗- tensorplay.functional.as_strided_scatter(input, src, size, stride, storage_offset=None) Tensor[source]
Embeds the values of the
srctensor intoinputalong the elements corresponding to the result of calling input.as_strided(size, stride, storage_offset).This function returns a tensor with fresh storage; it does not return a view.
- Parameters:
Note
srcmust be of the proper size in order to be embedded intoinput. Specifically, it should have the same shape as tensorplay.as_strided(input, size, stride, storage_offset)Example:
>>> a = tensorplay.arange(4).reshape(2, 2) + 1 >>> a tensor([[1, 2], [3, 4]]) >>> b = tensorplay.zeros(3, 3) >>> b tensor([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]) >>> tensorplay.as_strided_scatter(b, a, (2, 2), (1, 2)) tensor([[1., 3., 2.], [4., 0., 0.], [0., 0., 0.]])
as_strided
functionFull reference ↗- tensorplay.functional.as_strided(input, size, stride, storage_offset=None) Tensor[source]
Create a view of an existing tensorplay.Tensor
inputwith specifiedsize,strideandstorage_offset.Warning
Prefer using other view functions, like
tensorplay.Tensor.view()ortensorplay.Tensor.expand(), to setting a view’s strides manually with as_strided, as this function will throw an error on non-standard Pytensorplay backends (that do not have a concept of stride) and the result will depend on the current layout in memory. The constructed view must only refer to elements within the Tensor’s storage or a runtime error will be thrown. If the generated view is “overlapped” (with multiple indices referring to the same element in memory), the behavior of inplace operations on this view is undefined (and might not throw runtime errors).- 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. If
None, the storage_offset of the output tensor will match the input tensor.
Example:
>>> x = tensorplay.randn(3, 3) >>> x tensor([[ 0.9039, 0.6291, 1.0795], [ 0.1586, 2.1939, -0.4900], [-0.1909, -0.7503, 1.9355]]) >>> t = tensorplay.as_strided(x, (2, 2), (1, 2)) >>> t tensor([[0.9039, 1.0795], [0.6291, 0.1586]]) >>> t = tensorplay.as_strided(x, (2, 2), (1, 2), 1) tensor([[0.6291, 0.1586], [1.0795, 2.1939]])
asin_
functionFull reference ↗- tensorplay.functional.asin_(input)[source]
asin
functionFull reference ↗- tensorplay.functional.asin(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the arcsine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.5962, 1.4985, -0.4396, 1.4525]) >>> tensorplay.asin(a) tensor([-0.6387, nan, -0.4552, nan])
asinh_
functionFull reference ↗- tensorplay.functional.asinh_(input)[source]
asinh
functionFull reference ↗- tensorplay.functional.asinh(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the inverse hyperbolic sine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ]) >>> tensorplay.asinh(a) tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
atan_
functionFull reference ↗- tensorplay.functional.atan_(input)[source]
atan
functionFull reference ↗- tensorplay.functional.atan(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the arctangent of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.2341, 0.2539, -0.6256, -0.6448]) >>> tensorplay.atan(a) tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
atan2
functionFull reference ↗- tensorplay.functional.atan2(input: Tensor, other: Tensor, *, out: Tensor | None) Tensor[source]
Element-wise arctangent of with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector and vector . (Note that , the second parameter, is the x-coordinate, while , the first parameter, is the y-coordinate.)
The shapes of
inputandothermust be broadcastable.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.9041, 0.0196, -0.3108, -2.4423]) >>> tensorplay.atan2(a, tensorplay.randn(4)) tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
atanh_
functionFull reference ↗- tensorplay.functional.atanh_(input)[source]
atanh
functionFull reference ↗- tensorplay.functional.atanh(input: Tensor, *, out: Tensor | None) Tensor[source]
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.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4).uniform_(-1, 1) >>> a tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ]) >>> tensorplay.atanh(a) tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
atleast_1d
functionFull reference ↗- tensorplay.functional.atleast_1d(*args)[source]
atleast_2d
functionFull reference ↗- tensorplay.functional.atleast_2d(*args)[source]
atleast_3d
functionFull reference ↗- tensorplay.functional.atleast_3d(*args)[source]
avg_pool1d
functionFull reference ↗- tensorplay.functional.avg_pool1d(input, kernel_size, stride=[], padding=0, ceil_mode=False, count_include_pad=True)[source]
baddbmm
functionFull reference ↗- tensorplay.functional.baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) Tensor[source]
Performs a batch matrix-matrix product of matrices in
batch1andbatch2.inputis added to the final result.batch1andbatch2must be 3-D tensors each containing the same number of matrices.If
\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)batch1is a tensor,batch2is a tensor, theninputmust be broadcastable with a tensor andoutwill be a tensor. Bothalphaandbetamean the same as the scaling factors used intensorplay.addbmm().If
betais 0, then the content ofinputwill be ignored, and nan and inf in it will not be propagated.For inputs of type FloatTensor or DoubleTensor, arguments
betaandalphamust be real numbers, otherwise they should be integers.This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
- Parameters:
input (Tensor) – the tensor to be added
batch1 (Tensor) – the first batch of matrices to be multiplied
batch2 (Tensor) – the second batch of matrices to be multiplied
out_dtype (dtype, optional) – the dtype of the output tensor, Supported only on CUDA and for tensorplay.float32 given tensorplay.float16/tensorplay.bfloat16 input dtypes
- Keyword Arguments:
beta (Number, optional) – multiplier for
input()alpha (Number, optional) – multiplier for \text{batch1} \mathbin{@} \text{batch2} ()
out (Tensor, optional) – the output tensor.
Example:
>>> M = tensorplay.randn(10, 3, 5) >>> batch1 = tensorplay.randn(10, 3, 4) >>> batch2 = tensorplay.randn(10, 4, 5) >>> tensorplay.baddbmm(M, batch1, batch2).size() tensorplay.Size([10, 3, 5])
bartlett_window
functionFull reference ↗- tensorplay.functional.bartlett_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Bartlett window function.
where is the full window size.
The input
window_lengthis a positive integer controlling the returned window size.periodicflag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions liketensorplay.stft(). Therefore, ifperiodicis true, the in above formula is in fact . Also, we always havetensorplay.bartlett_window(L, periodic=True)equal totensorplay.bartlett_window(L + 1, periodic=False)[:-1]).Note
If
window_length, the returned window contains a single value 1.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
- Returns:
A 1-D tensor of size containing the window
- Return type:
batch_norm_backward_elemt
functionFull reference ↗- tensorplay.functional.batch_norm_backward_elemt(grad_out, input, mean, invstd, weight, sum_dy, sum_dy_xmu, count)[source]
batch_norm_backward_reduce
functionFull reference ↗- tensorplay.functional.batch_norm_backward_reduce(grad_out, input, mean, invstd, weight, input_g, weight_g, bias_g)[source]
batch_norm_elemt
functionFull reference ↗- tensorplay.functional.batch_norm_elemt(input, weight, bias, mean, invstd, eps, *, out=None)[source]
batch_norm_gather_stats_with_counts
functionFull reference ↗- tensorplay.functional.batch_norm_gather_stats_with_counts(input, mean, invstd, running_mean, running_var, momentum, eps, counts)[source]
batch_norm_gather_stats
functionFull reference ↗- tensorplay.functional.batch_norm_gather_stats(input, mean, invstd, running_mean, running_var, momentum, eps, count)[source]
batch_norm_stats
functionFull reference ↗- tensorplay.functional.batch_norm_stats(input, eps)[source]
batch_norm_update_stats
functionFull reference ↗- tensorplay.functional.batch_norm_update_stats(input, running_mean, running_var, momentum)[source]
bernoulli
functionFull reference ↗- tensorplay.functional.bernoulli(input: Tensor, *, generator: Generator | None, out: Tensor | None) Tensor[source]
Draws binary random numbers (0 or 1) from a Bernoulli distribution.
The
inputtensor should be a tensor containing probabilities to be used for drawing the binary random number. Hence, all values ininputhave to be in the range: .The element of the output tensor will draw a value according to the probability value given in
input.The returned
outtensor only has values 0 or 1 and is of the same shape asinput.outcan have integraldtype, butinputmust have floating pointdtype.- Parameters:
input (Tensor) – the input tensor of probability values for the Bernoulli distribution
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for samplingout (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1] >>> a tensor([[ 0.1737, 0.0950, 0.3609], [ 0.7148, 0.0289, 0.2676], [ 0.9456, 0.8937, 0.7202]]) >>> tensorplay.bernoulli(a) tensor([[ 1., 0., 0.], [ 0., 0., 0.], [ 1., 1., 1.]]) >>> a = tensorplay.ones(3, 3) # probability of drawing "1" is 1 >>> tensorplay.bernoulli(a) tensor([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.]]) >>> a = tensorplay.zeros(3, 3) # probability of drawing "1" is 0 >>> tensorplay.bernoulli(a) tensor([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])
bessel_j0
functionFull reference ↗- tensorplay.functional.bessel_j0(input)[source]
bessel_j1
functionFull reference ↗- tensorplay.functional.bessel_j1(input)[source]
bessel_y0
functionFull reference ↗- tensorplay.functional.bessel_y0(input)[source]
bessel_y1
functionFull reference ↗- tensorplay.functional.bessel_y1(input)[source]
bilinear
functionFull reference ↗- tensorplay.functional.bilinear(input1, input2, weight, bias=None)[source]
bincount
functionFull reference ↗- tensorplay.functional.bincount(input, weights=None, minlength=0) Tensor[source]
Count the frequency of each value in an array of non-negative ints.
The number of bins (size 1) is one larger than the largest value in
inputunlessinputis empty, in which case the result is a tensor of size 0. Ifminlengthis specified, the number of bins is at leastminlengthand ifinputis empty, then the result is tensor of sizeminlengthfilled with zeros. Ifnis the value at positioni,out[n] += weights[i]ifweightsis specified elseout[n] += 1.Note
This operation may produce nondeterministic gradients when given tensors on a CUDA device. See Reproducibility for more information.
- Parameters:
- Returns:
a tensor of shape
Size([max(input) + 1])ifinputis non-empty, elseSize(0)- Return type:
output (Tensor)
Example:
>>> input = tensorplay.randint(0, 8, (5,), dtype=tensorplay.int64) >>> weights = tensorplay.linspace(0, 1, steps=5) >>> input, weights (tensor([4, 3, 6, 3, 4]), tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000]) >>> tensorplay.bincount(input) tensor([0, 0, 0, 2, 2, 0, 1]) >>> input.bincount(weights) tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
binomial
functionFull reference ↗- tensorplay.functional.binomial(count, prob, generator=None)[source]
bitwise_and
functionFull reference ↗- tensorplay.functional.bitwise_and(input, other, *, out=None) Tensor[source]
Computes the bitwise AND of
inputandother. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical AND.- Parameters:
input – the first input tensor
other – the second input tensor
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_and(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8), tensorplay.tensor([1, 0, 3], dtype=tensorplay.int8)) tensor([1, 0, 3], dtype=tensorplay.int8) >>> tensorplay.bitwise_and(tensorplay.tensor([True, True, False]), tensorplay.tensor([False, True, False])) tensor([ False, True, False])
bitwise_left_shift
functionFull reference ↗- tensorplay.functional.bitwise_left_shift(input, other, *, out=None) Tensor[source]
Computes the left arithmetic shift of
inputbyotherbits. The input tensor must be of integral type. This operator supports broadcasting to a common shape and type promotion.The operation applied is:
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_left_shift(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8), tensorplay.tensor([1, 0, 3], dtype=tensorplay.int8)) tensor([-2, -2, 24], dtype=tensorplay.int8)
bitwise_not
functionFull reference ↗- tensorplay.functional.bitwise_not(input, *, out=None) Tensor[source]
Computes the bitwise NOT of the given input tensor. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical NOT.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_not(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8)) tensor([ 0, 1, -4], dtype=tensorplay.int8)
bitwise_or
functionFull reference ↗- tensorplay.functional.bitwise_or(input: Tensor, other: Tensor, *, out: Tensor | None) Tensor[source]
Computes the bitwise OR of
inputandother. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical OR.- Parameters:
input – the first input tensor
other – the second input tensor
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_or(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8), tensorplay.tensor([1, 0, 3], dtype=tensorplay.int8)) tensor([-1, -2, 3], dtype=tensorplay.int8) >>> tensorplay.bitwise_or(tensorplay.tensor([True, True, False]), tensorplay.tensor([False, True, False])) tensor([ True, True, False])
bitwise_right_shift
functionFull reference ↗- tensorplay.functional.bitwise_right_shift(input, other, *, out=None) Tensor[source]
Computes the right arithmetic shift of
inputbyotherbits. The input tensor must be of integral type. This operator supports broadcasting to a common shape and type promotion. In any case, if the value of the right operand is negative or is greater or equal to the number of bits in the promoted left operand, the behavior is undefined.The operation applied is:
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_right_shift(tensorplay.tensor([-2, -7, 31], dtype=tensorplay.int8), tensorplay.tensor([1, 0, 3], dtype=tensorplay.int8)) tensor([-1, -7, 3], dtype=tensorplay.int8)
bitwise_xor
functionFull reference ↗- tensorplay.functional.bitwise_xor(input, other, *, out=None) Tensor[source]
Computes the bitwise XOR of
inputandother. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical XOR.- Parameters:
input – the first input tensor
other – the second input tensor
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.bitwise_xor(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8), tensorplay.tensor([1, 0, 3], dtype=tensorplay.int8)) tensor([-2, -2, 0], dtype=tensorplay.int8) >>> tensorplay.bitwise_xor(tensorplay.tensor([True, True, False]), tensorplay.tensor([False, True, False])) tensor([ True, False, False])
blackman_window
functionFull reference ↗- tensorplay.functional.blackman_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Blackman window function.
where is the full window size.
The input
window_lengthis a positive integer controlling the returned window size.periodicflag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions liketensorplay.stft(). Therefore, ifperiodicis true, the in above formula is in fact . Also, we always havetensorplay.blackman_window(L, periodic=True)equal totensorplay.blackman_window(L + 1, periodic=False)[:-1].Note
If
window_length, the returned window contains a single value 1.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
- Returns:
A 1-D tensor of size containing the window
- Return type:
bmm
functionFull reference ↗- tensorplay.functional.bmm(input, mat2, out_dtype=None, *, out=None) Tensor[source]
Performs a batch matrix-matrix product of matrices stored in
inputandmat2.inputandmat2must be 3-D tensors each containing the same number of matrices.If
\text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_iinputis a tensor,mat2is a tensor,outwill be a tensor.This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
Note
This function does not broadcast. For broadcasting matrix products, see
tensorplay.matmul().- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> input = tensorplay.randn(10, 3, 4) >>> mat2 = tensorplay.randn(10, 4, 5) >>> res = tensorplay.bmm(input, mat2) >>> res.size() tensorplay.Size([10, 3, 5])
broadcast_to
functionFull reference ↗- tensorplay.functional.broadcast_to(input, shape) Tensor[source]
Broadcasts
inputto the shapeshape. Equivalent to callinginput.expand(shape). Seeexpand()for details.- Parameters:
input (Tensor) – the input tensor.
shape (list, tuple, or
tensorplay.Size) – the new shape.
Example:
>>> x = tensorplay.tensor([1, 2, 3]) >>> tensorplay.broadcast_to(x, (3, 3)) tensor([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
bucketize
functionFull reference ↗- tensorplay.functional.bucketize(input, boundaries, *, out_int32=False, right=False, out=None) Tensor[source]
Returns the indices of the buckets to which each value in the
inputbelongs, where the boundaries of the buckets are set byboundaries. Return a new tensor with the same size asinput. Ifrightis False (default), then the left boundary is open. Note that this behavior is opposite the behavior of numpy.digitize. More formally, the returned index satisfies the following rules:rightreturned index satisfies
False
boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]True
boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]- Parameters:
- Keyword Arguments:
out_int32 (bool, optional) – indicate the output data type. tensorplay.int32 if True, tensorplay.int64 otherwise. Default value is False, i.e. default output data type is tensorplay.int64.
right (bool, optional) – determines the behavior for values in
boundaries. See the table above.out (Tensor, optional) – the output tensor, must be the same size as
inputif provided.
Example:
>>> boundaries = tensorplay.tensor([1, 3, 5, 7, 9]) >>> boundaries tensor([1, 3, 5, 7, 9]) >>> v = tensorplay.tensor([[3, 6, 9], [3, 6, 9]]) >>> v tensor([[3, 6, 9], [3, 6, 9]]) >>> tensorplay.bucketize(v, boundaries) tensor([[1, 3, 4], [1, 3, 4]]) >>> tensorplay.bucketize(v, boundaries, right=True) tensor([[2, 3, 5], [2, 3, 5]])
can_cast
functionFull reference ↗- tensorplay.functional.can_cast(from_, to) bool[source]
described in the type promotion documentation.
- Parameters:
from_ (dtype) – The original
tensorplay.dtype.to (dtype) – The target
tensorplay.dtype.
Example:
>>> tensorplay.can_cast(tensorplay.double, tensorplay.float) True >>> tensorplay.can_cast(tensorplay.float, tensorplay.int) False
cartesian_prod
functionFull reference ↗- tensorplay.functional.cartesian_prod(*args)[source]
cat
functionFull reference ↗- tensorplay.functional.cat(tensors, dim=0, *, out=None) Tensor[source]
Concatenates the given sequence of tensors in
tensorsin the given dimension. All tensors must either have the same shape (except in the concatenating dimension) or be a 1-D empty tensor with size(0,).tensorplay.cat()can be seen as an inverse operation fortensorplay.split()andtensorplay.chunk().tensorplay.cat()can be best understood via examples.See also
tensorplay.stack()concatenates the given sequence along a new dimension.- Parameters:
tensors (sequence of Tensors) – Non-empty tensors provided must have the same shape, except in the cat dimension.
dim (int, optional) – the dimension over which the tensors are concatenated
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.randn(2, 3) >>> x tensor([[ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497]]) >>> tensorplay.cat((x, x, x), 0) tensor([[ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497], [ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497], [ 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497]]) >>> tensorplay.cat((x, x, x), 1) tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614], [-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497]])
ccol_indices_copy
functionFull reference ↗- tensorplay.functional.ccol_indices_copy(input)[source]
cdist
functionFull reference ↗- tensorplay.functional.cdist(x1, x2, p=2, compute_mode=None)[source]
ceil_
functionFull reference ↗- tensorplay.functional.ceil_(input)[source]
ceil
functionFull reference ↗- tensorplay.functional.ceil(input, *, out=None) Tensor[source]
Returns a new tensor with the ceil of the elements of
input, the smallest integer greater than or equal to each element.For integer inputs, follows the array-api convention of returning a copy of the input tensor.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.6341, -1.4208, -1.0900, 0.5826]) >>> tensorplay.ceil(a) tensor([-0., -1., -1., 1.])
celu_
functionFull reference ↗- tensorplay.functional.celu_(input, alpha=1.0)[source]
chain_matmul
functionFull reference ↗- tensorplay.functional.chain_matmul(*args, out=None)[source]
channel_shuffle
functionFull reference ↗- tensorplay.functional.channel_shuffle(input, groups)[source]
chebyshev_polynomial_t
functionFull reference ↗- tensorplay.functional.chebyshev_polynomial_t(x, n)[source]
chebyshev_polynomial_u
functionFull reference ↗- tensorplay.functional.chebyshev_polynomial_u(x, n)[source]
chebyshev_polynomial_v
functionFull reference ↗- tensorplay.functional.chebyshev_polynomial_v(x, n)[source]
chebyshev_polynomial_w
functionFull reference ↗- tensorplay.functional.chebyshev_polynomial_w(x, n)[source]
cholesky_inverse
functionFull reference ↗- tensorplay.functional.cholesky_inverse(L, upper=False, *, out=None) Tensor[source]
Computes the inverse of a complex Hermitian or real symmetric positive-definite matrix given its Cholesky decomposition.
Let be a complex Hermitian or real symmetric positive-definite matrix, and its Cholesky decomposition such that:
where is the conjugate transpose when is complex, and the transpose when is real-valued.
Computes the inverse matrix .
Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if is a batch of matrices then the output has the same batch dimensions.
- Parameters:
L (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of lower or upper triangular Cholesky decompositions of symmetric or Hermitian positive-definite matrices.
upper (bool, optional) – flag that indicates whether is lower triangular or upper triangular. Default:
False
- Keyword Arguments:
out (Tensor, optional) – output tensor. Ignored if None. Default: None.
Example:
>>> A = tensorplay.randn(3, 3) >>> A = A @ A.T + tensorplay.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix >>> L = tensorplay.linalg.cholesky(A) # Extract Cholesky decomposition >>> tensorplay.cholesky_inverse(L) tensor([[ 1.9314, 1.2251, -0.0889], [ 1.2251, 2.4439, 0.2122], [-0.0889, 0.2122, 0.1412]]) >>> A.inverse() tensor([[ 1.9314, 1.2251, -0.0889], [ 1.2251, 2.4439, 0.2122], [-0.0889, 0.2122, 0.1412]]) >>> A = tensorplay.randn(3, 2, 2, dtype=tensorplay.complex64) >>> A = A @ A.mH + tensorplay.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices >>> L = tensorplay.linalg.cholesky(A) >>> tensorplay.dist(tensorplay.inverse(A), tensorplay.cholesky_inverse(L)) tensor(5.6358e-7)
cholesky_solve
functionFull reference ↗- tensorplay.functional.cholesky_solve(B, L, upper=False, *, out=None) Tensor[source]
Computes the solution of a system of linear equations with complex Hermitian or real symmetric positive-definite lhs given its Cholesky decomposition.
Let be a complex Hermitian or real symmetric positive-definite matrix, and its Cholesky decomposition such that:
where is the conjugate transpose when is complex, and the transpose when is real-valued.
Returns the solution of the following linear system:
Supports inputs of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if or is a batch of matrices then the output has the same batch dimensions.
- Parameters:
B (Tensor) – right-hand side tensor of shape (*, n, k) where is zero or more batch dimensions
L (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of lower or upper triangular Cholesky decompositions of symmetric or Hermitian positive-definite matrices.
upper (bool, optional) – flag that indicates whether is lower triangular or upper triangular. Default:
False.
- Keyword Arguments:
out (Tensor, optional) – output tensor. Ignored if None. Default: None.
Example:
>>> A = tensorplay.randn(3, 3) >>> A = A @ A.T + tensorplay.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix >>> L = tensorplay.linalg.cholesky(A) # Extract Cholesky decomposition >>> B = tensorplay.randn(3, 2) >>> tensorplay.cholesky_solve(B, L) tensor([[ -8.1625, 19.6097], [ -5.8398, 14.2387], [ -4.3771, 10.4173]]) >>> A.inverse() @ B tensor([[ -8.1626, 19.6097], [ -5.8398, 14.2387], [ -4.3771, 10.4173]]) >>> A = tensorplay.randn(3, 2, 2, dtype=tensorplay.complex64) >>> A = A @ A.mH + tensorplay.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices >>> L = tensorplay.linalg.cholesky(A) >>> B = tensorplay.randn(2, 1, dtype=tensorplay.complex64) >>> X = tensorplay.cholesky_solve(B, L) >>> tensorplay.dist(X, A.inverse() @ B) tensor(1.6881e-5)
choose_qparams_optimized
functionFull reference ↗- tensorplay.functional.choose_qparams_optimized(input, numel, n_bins, ratio, bit_width)[source]
chunk
functionFull reference ↗- tensorplay.functional.chunk(input: Tensor, chunks: int, dim: int = 0) Tuple[Tensor, ...][source]
Attempts to split a tensor into the specified number of chunks. Each chunk is a view of the input tensor.
Note
This function may return fewer than the specified number of chunks!
See also
tensorplay.tensor_split()a function that always returns exactly the specified number of chunksIf the tensor size along the given dimension
dimis divisible bychunks, all returned chunks will be the same size. If the tensor size along the given dimensiondimis not divisible bychunks, all returned chunks will be the same size, except the last one. If such division is not possible, this function may return fewer than the specified number of chunks.- Parameters:
Example
>>> tensorplay.arange(11).chunk(6) (tensor([0, 1]), tensor([2, 3]), tensor([4, 5]), tensor([6, 7]), tensor([8, 9]), tensor([10])) >>> tensorplay.arange(12).chunk(6) (tensor([0, 1]), tensor([2, 3]), tensor([4, 5]), tensor([6, 7]), tensor([8, 9]), tensor([10, 11])) >>> tensorplay.arange(13).chunk(6) (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7, 8]), tensor([ 9, 10, 11]), tensor([12]))
clamp_
functionFull reference ↗- tensorplay.functional.clamp_(input, min=None, max=None)[source]
clamp_max_
functionFull reference ↗- tensorplay.functional.clamp_max_(input, max)[source]
clamp_min_
functionFull reference ↗- tensorplay.functional.clamp_min_(input, min)[source]
clamp
functionFull reference ↗- tensorplay.functional.clamp(input, min=None, max=None, *, out=None) Tensor[source]
Clamps all elements in
inputinto the range [min,max]. Letting min_value and max_value beminandmax, respectively, this returns:If
minisNone, there is no lower bound. Or, ifmaxisNonethere is no upper bound.Note
If
minis greater thanmaxtensorplay.clamp(..., min, max)sets all elements ininputto the value ofmax.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-1.7120, 0.1734, -0.0478, -0.0922]) >>> tensorplay.clamp(a, min=-0.5, max=0.5) tensor([-0.5000, 0.1734, -0.0478, -0.0922]) >>> min = tensorplay.linspace(-1, 1, steps=4) >>> tensorplay.clamp(a, min=min) tensor([-1.0000, 0.1734, 0.3333, 1.0000])
clip_
functionFull reference ↗- tensorplay.functional.clip_(input, min=None, max=None)[source]
clip
functionFull reference ↗clone
functionFull reference ↗- tensorplay.functional.clone(input, *, memory_format=tensorplay.preserve_format) Tensor[source]
Returns a copy of
input.Note
This function is differentiable, so gradients will flow back from the result of this operation to
input. To create a tensor without an autograd relationship toinputseedetach().In addition, when
tensorplay.preserve_formatis used: If the input tensor is dense (i.e., non-overlapping strided), its memory format (including strides) is retained. Otherwise (e.g., a non-dense view like a stepped slice), the output is converted to the dense (contiguous) format.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned tensor. Default:tensorplay.preserve_format.
col_indices_copy
functionFull reference ↗- tensorplay.functional.col_indices_copy(input)[source]
Performs the same operation as
tensorplay.col_indices(), but all output tensors are freshly created instead of aliasing the input.
column_stack
functionFull reference ↗- tensorplay.functional.column_stack(tensors, *, out=None) Tensor[source]
Creates a new tensor by horizontally stacking the tensors in
tensors.Equivalent to
tensorplay.hstack(tensors), except each zero or one dimensional tensortintensorsis first reshaped into a(t.numel(), 1)column before being stacked horizontally.- Parameters:
tensors (sequence of Tensors) – sequence of tensors to concatenate
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([1, 2, 3]) >>> b = tensorplay.tensor([4, 5, 6]) >>> tensorplay.column_stack((a, b)) tensor([[1, 4], [2, 5], [3, 6]]) >>> a = tensorplay.arange(5) >>> b = tensorplay.arange(10).reshape(5, 2) >>> tensorplay.column_stack((a, b, b)) tensor([[0, 0, 1, 0, 1], [1, 2, 3, 2, 3], [2, 4, 5, 4, 5], [3, 6, 7, 6, 7], [4, 8, 9, 8, 9]])
combinations
functionFull reference ↗- tensorplay.functional.combinations(input: Tensor, r: int = 2, with_replacement: bool = False) seq[source]
Compute combinations of length of the given tensor. The behavior is similar to python’s itertools.combinations when with_replacement is set to False, and itertools.combinations_with_replacement when with_replacement is set to True.
- Parameters:
- Returns:
A tensor equivalent to converting all the input tensors into lists, do itertools.combinations or itertools.combinations_with_replacement on these lists, and finally convert the resulting list into tensor.
- Return type:
Example:
>>> a = [1, 2, 3] >>> list(itertools.combinations(a, r=2)) [(1, 2), (1, 3), (2, 3)] >>> list(itertools.combinations(a, r=3)) [(1, 2, 3)] >>> list(itertools.combinations_with_replacement(a, r=2)) [(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)] >>> tensor_a = tensorplay.tensor(a) >>> tensorplay.combinations(tensor_a) tensor([[1, 2], [1, 3], [2, 3]]) >>> tensorplay.combinations(tensor_a, r=3) tensor([[1, 2, 3]]) >>> tensorplay.combinations(tensor_a, with_replacement=True) tensor([[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]])
complex
functionFull reference ↗- tensorplay.functional.complex(real, imag, *, out=None) Tensor[source]
Constructs a complex tensor with its real part equal to
realand its imaginary part equal toimag.- Parameters:
- Keyword Arguments:
out (Tensor) – If the inputs are
tensorplay.float32, must betensorplay.complex64. If the inputs aretensorplay.float64, must betensorplay.complex128.
Example:
>>> real = tensorplay.tensor([1, 2], dtype=tensorplay.float32) >>> imag = tensorplay.tensor([3, 4], dtype=tensorplay.float32) >>> z = tensorplay.complex(real, imag) >>> z tensor([(1.+3.j), (2.+4.j)]) >>> z.dtype tensorplay.complex64
concat
functionFull reference ↗concatenate
functionFull reference ↗conj_physical_
functionFull reference ↗- tensorplay.functional.conj_physical_(input)[source]
conj_physical
functionFull reference ↗- tensorplay.functional.conj_physical(input, *, out=None) Tensor[source]
Computes the element-wise conjugate of the given
inputtensor. Ifinputhas a non-complex dtype, this function just returnsinput.Note
This performs the conjugate operation regardless of the fact conjugate bit is set or not.
Warning
In the future,
tensorplay.conj_physical()may return a non-writeable view for aninputof non-complex dtype. It’s recommended that programs not modify the tensor returned bytensorplay.conj_physical()wheninputis of non-complex dtype to be compatible with this change.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.conj_physical(tensorplay.tensor([-1 + 1j, -2 + 2j, 3 - 3j])) tensor([-1 - 1j, -2 - 2j, 3 + 3j])
conj
functionFull reference ↗- tensorplay.functional.conj(input) Tensor[source]
Returns a view of
inputwith a flipped conjugate bit. Ifinputhas a non-complex dtype, this function just returnsinput.Note
tensorplay.conj()performs a lazy conjugation, but the actual conjugated tensor can be materialized at any time usingtensorplay.resolve_conj().Warning
In the future,
tensorplay.conj()may return a non-writeable view for aninputof non-complex dtype. It’s recommended that programs not modify the tensor returned bytensorplay.conj_physical()wheninputis of non-complex dtype to be compatible with this change.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x = tensorplay.tensor([-1 + 1j, -2 + 2j, 3 - 3j]) >>> x.is_conj() False >>> y = tensorplay.conj(x) >>> y.is_conj() True
conv_tbc
functionFull reference ↗- tensorplay.functional.conv_tbc(input, weight, bias, pad=0)[source]
conv_transpose1d
functionFull reference ↗- tensorplay.functional.conv_transpose1d(input, weight, bias=None, stride=[], padding=[], output_padding=[], groups=1, dilation=[])[source]
conv_transpose2d
functionFull reference ↗- tensorplay.functional.conv_transpose2d(input, weight, bias=None, stride=[1, 1], padding=[0, 0], output_padding=[0, 0], groups=1, dilation=[1, 1])[source]
conv_transpose3d
functionFull reference ↗- tensorplay.functional.conv_transpose3d(input, weight, bias=None, stride=[1, 1, 1], padding=[0, 0, 0], output_padding=[0, 0, 0], groups=1, dilation=[1, 1, 1])[source]
conv1d
functionFull reference ↗- tensorplay.functional.conv1d(input, weight, bias=None, stride=[1], padding=[0], dilation=[1], groups=1)[source]
conv3d
functionFull reference ↗- tensorplay.functional.conv3d(input, weight, bias=None, stride=[1, 1, 1], padding=[0, 0, 0], dilation=[1, 1, 1], groups=1)[source]
convolution
functionFull reference ↗- tensorplay.functional.convolution(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups)[source]
copysign
functionFull reference ↗- tensorplay.functional.copysign(input, other, *, out=None) Tensor[source]
Create a new floating-point tensor with the magnitude of
inputand the sign ofother, elementwise.Supports broadcasting to a common shape, and integer and float inputs.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(5) >>> a tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244]) >>> tensorplay.copysign(a, 1) tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244]) >>> a = tensorplay.randn(4, 4) >>> a tensor([[ 0.7079, 0.2778, -1.0249, 0.5719], [-0.0059, -0.2600, -0.4475, -1.3948], [ 0.3667, -0.9567, -2.5757, -0.1751], [ 0.2046, -0.0742, 0.2998, -0.1054]]) >>> b = tensorplay.randn(4) tensor([ 0.2373, 0.3120, 0.3190, -1.1128]) >>> tensorplay.copysign(a, b) tensor([[ 0.7079, 0.2778, 1.0249, -0.5719], [ 0.0059, 0.2600, 0.4475, -1.3948], [ 0.3667, 0.9567, 2.5757, -0.1751], [ 0.2046, 0.0742, 0.2998, -0.1054]]) >>> a = tensorplay.tensor([1.]) >>> b = tensorplay.tensor([-0.]) >>> tensorplay.copysign(a, b) tensor([-1.])Note
copysign handles signed zeros. If the other argument has a negative zero (-0), the corresponding output value will be negative.
corrcoef
functionFull reference ↗- tensorplay.functional.corrcoef(input) Tensor[source]
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the
inputmatrix, where rows are the variables and columns are the observations.Note
The correlation coefficient matrix R is computed using the covariance matrix C as given by
Note
Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1. The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
- Parameters:
input (Tensor) – A 2D matrix containing multiple variables and observations, or a Scalar or 1D vector representing a single variable.
- Returns:
(Tensor) The correlation coefficient matrix of the variables.
See also
tensorplay.cov()covariance matrix.Example:
>>> x = tensorplay.tensor([[0, 1, 2], [2, 1, 0]]) >>> tensorplay.corrcoef(x) tensor([[ 1., -1.], [-1., 1.]]) >>> x = tensorplay.randn(2, 4) >>> x tensor([[-0.2678, -0.0908, -0.3766, 0.2780], [-0.5812, 0.1535, 0.2387, 0.2350]]) >>> tensorplay.corrcoef(x) tensor([[1.0000, 0.3582], [0.3582, 1.0000]]) >>> tensorplay.corrcoef(x[0]) tensor(1.)
cos_
functionFull reference ↗- tensorplay.functional.cos_(input)[source]
cos
functionFull reference ↗- tensorplay.functional.cos(input, *, out=None) Tensor[source]
Returns a new tensor with the cosine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 1.4309, 1.2706, -0.8562, 0.9796]) >>> tensorplay.cos(a) tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
cosh_
functionFull reference ↗- tensorplay.functional.cosh_(input)[source]
cosh
functionFull reference ↗- tensorplay.functional.cosh(input, *, out=None) Tensor[source]
Returns a new tensor with the hyperbolic cosine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.1632, 1.1835, -0.6979, -0.7325]) >>> tensorplay.cosh(a) tensor([ 1.0133, 1.7860, 1.2536, 1.2805])Note
When
inputis on the CPU, the implementation of tensorplay.cosh may use the Sleef library, which rounds very large results to infinity or negative infinity. See here for details.
cosine_embedding_loss
functionFull reference ↗- tensorplay.functional.cosine_embedding_loss(x1, x2, target, margin=0)[source]
cosine_similarity
functionFull reference ↗- tensorplay.functional.cosine_similarity(x1, x2, dim=1, eps=1e-08)[source]
count_nonzero
functionFull reference ↗- tensorplay.functional.count_nonzero(input, dim=None) Tensor[source]
Counts the number of non-zero values in the tensor
inputalong the givendim. If no dim is specified then all non-zeros in the tensor are counted.- Parameters:
Example:
>>> x = tensorplay.zeros(3,3) >>> x[tensorplay.randn(3,3) > 0.5] = 1 >>> x tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 1.]]) >>> tensorplay.count_nonzero(x) tensor(3) >>> tensorplay.count_nonzero(x, dim=0) tensor([0, 1, 2])
cov
functionFull reference ↗- tensorplay.functional.cov(input, *, correction=1, fweights=None, aweights=None) Tensor[source]
Estimates the covariance matrix of the variables given by the
inputmatrix, where rows are the variables and columns are the observations.A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains the variance of each variable (covariance of a variable with itself). By definition, if
inputrepresents a single variable (Scalar or 1D) then its variance is returned.The sample covariance of the variables and is given by:
where and are the simple means of the and respectively, and is the
correction.If
fweightsand/oraweightsare provided, the weighted covariance is calculated, which is given by:where denotes
fweightsoraweights(fandafor brevity) based on whichever is provided, or if both are provided, and is the weighted mean of the variable. If not provided,fand/oracan be seen as a vector of appropriate size.- Parameters:
input (Tensor) – A 2D matrix containing multiple variables and observations, or a Scalar or 1D vector representing a single variable.
- Keyword Arguments:
correction (int, optional) – difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
correction = 1which returns the unbiased estimate, even if bothfweightsandaweightsare specified.correction = 0will return the simple average. Defaults to1.fweights (tensor, optional) – A Scalar or 1D tensor of observation vector frequencies representing the number of times each observation should be repeated. Its numel must equal the number of columns of
input. Must have integral dtype. Ignored ifNone. Defaults toNone.aweights (tensor, optional) – A Scalar or 1D array of observation vector weights. These relative weights are typically large for observations considered “important” and smaller for observations considered less “important”. Its numel must equal the number of columns of
input. Must have floating point dtype. Ignored ifNone. Defaults toNone.
- Returns:
(Tensor) The covariance matrix of the variables.
See also
tensorplay.corrcoef()normalized covariance matrix.Example:
>>> x = tensorplay.tensor([[0, 2], [1, 1], [2, 0]]).T >>> x tensor([[0, 1, 2], [2, 1, 0]]) >>> tensorplay.cov(x) tensor([[ 1., -1.], [-1., 1.]]) >>> tensorplay.cov(x, correction=0) tensor([[ 0.6667, -0.6667], [-0.6667, 0.6667]]) >>> fw = tensorplay.randint(1, 10, (3,)) >>> fw tensor([1, 6, 9]) >>> aw = tensorplay.rand(3) >>> aw tensor([0.4282, 0.0255, 0.4144]) >>> tensorplay.cov(x, fweights=fw, aweights=aw) tensor([[ 0.4169, -0.4169], [-0.4169, 0.4169]])
cross
functionFull reference ↗- tensorplay.functional.cross(input, other, dim=None, *, out=None) Tensor[source]
Returns the cross product of vectors in dimension
dimofinputandother.Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of vectors, for which it computes the product along the dimension
dim. In this case, the output has the same batch dimensions as the inputs.Warning
If
dimis not given, it defaults to the first dimension found with the size 3. Note that this might be unexpected.This behavior is deprecated and will be changed to match that of
tensorplay.linalg.cross()in a future release.See also
tensorplay.linalg.cross()which has dim=-1 as default.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4, 3) >>> a tensor([[-0.3956, 1.1455, 1.6895], [-0.5849, 1.3672, 0.3599], [-1.1626, 0.7180, -0.0521], [-0.1339, 0.9902, -2.0225]]) >>> b = tensorplay.randn(4, 3) >>> b tensor([[-0.0257, -1.4725, -1.2251], [-1.1479, -0.7005, -1.9757], [-1.3904, 0.3726, -1.1836], [-0.9688, -0.7153, 0.2159]]) >>> tensorplay.cross(a, b, dim=1) tensor([[ 1.0844, -0.5281, 0.6120], [-2.4490, -1.5687, 1.9792], [-0.8304, -1.3037, 0.5650], [-1.2329, 1.9883, 1.0551]]) >>> tensorplay.cross(a, b) tensor([[ 1.0844, -0.5281, 0.6120], [-2.4490, -1.5687, 1.9792], [-0.8304, -1.3037, 0.5650], [-1.2329, 1.9883, 1.0551]])
crow_indices_copy
functionFull reference ↗- tensorplay.functional.crow_indices_copy(input)[source]
Performs the same operation as
tensorplay.crow_indices(), but all output tensors are freshly created instead of aliasing the input.
ctc_loss
functionFull reference ↗- tensorplay.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reduction=1, zero_infinity=False)[source]
cudnn_affine_grid_generator
functionFull reference ↗- tensorplay.functional.cudnn_affine_grid_generator(theta, N, C, H, W)[source]
cudnn_batch_norm
functionFull reference ↗- tensorplay.functional.cudnn_batch_norm(input, weight, bias, running_mean, running_var, training, exponential_average_factor, epsilon, *, out=None)[source]
cudnn_convolution_add_relu
functionFull reference ↗- tensorplay.functional.cudnn_convolution_add_relu(input, weight, z, alpha, bias, stride, padding, dilation, groups)[source]
cudnn_convolution_relu
functionFull reference ↗- tensorplay.functional.cudnn_convolution_relu(input, weight, bias, stride, padding, dilation, groups)[source]
cudnn_convolution_transpose
functionFull reference ↗- tensorplay.functional.cudnn_convolution_transpose(input, weight, padding, output_padding, stride, dilation, groups, benchmark, deterministic, allow_tf32)[source]
cudnn_convolution
functionFull reference ↗- tensorplay.functional.cudnn_convolution(input, weight, padding, stride, dilation, groups, benchmark, deterministic, allow_tf32, *, out=None)[source]
cudnn_grid_sampler
functionFull reference ↗- tensorplay.functional.cudnn_grid_sampler(input, grid)[source]
cudnn_is_acceptable
functionFull reference ↗- tensorplay.functional.cudnn_is_acceptable(input)[source]
cummax
functionFull reference ↗- tensorplay.functional.cummax(input, dim, *, out=None)[source]
cummin
functionFull reference ↗- tensorplay.functional.cummin(input, dim, *, out=None)[source]
cumprod
functionFull reference ↗- tensorplay.functional.cumprod(input, dim, *, dtype=None, out=None) Tensor[source]
Returns the cumulative product of elements of
inputin the dimensiondim.For example, if
inputis a vector of size N, the result will also be a vector of size N, with elements.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(10) >>> a tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126, -0.2129, -0.4206, 0.1968]) >>> tensorplay.cumprod(a, dim=0) tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065, 0.0014, -0.0006, -0.0001]) >>> a[5] = 0.0 >>> tensorplay.cumprod(a, dim=0) tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000, 0.0000, -0.0000, -0.0000])
cumsum
functionFull reference ↗- tensorplay.functional.cumsum(input, dim, *, dtype=None, out=None) Tensor[source]
Returns the cumulative sum of elements of
inputin the dimensiondim.For example, if
inputis a vector of size N, the result will also be a vector of size N, with elements.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randint(1, 20, (10,)) >>> a tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10]) >>> tensorplay.cumsum(a, dim=0) tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
cumulative_trapezoid
functionFull reference ↗- tensorplay.functional.cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) Tensor[source]
Cumulatively computes the trapezoidal rule along
dim. By default the spacing between elements is assumed to be 1, butdxcan be used to specify a different constant spacing, andxcan be used to specify arbitrary spacing alongdim.For more details, please read
tensorplay.trapezoid(). The difference betweentensorplay.trapezoid()and this function is that,tensorplay.trapezoid()returns a value for each integration, where as this function returns a cumulative value for every spacing within the integration. This is analogous to how .sum returns a value and .cumsum returns a cumulative sum.- Parameters:
- Keyword Arguments:
Examples:
>>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1. >>> y = tensorplay.tensor([1, 5, 10]) >>> tensorplay.cumulative_trapezoid(y) tensor([3., 10.5]) >>> # Computes the same trapezoidal rule directly up to each element to verify >>> (1 + 5) / 2 3.0 >>> (1 + 10 + 10) / 2 10.5 >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2 >>> # NOTE: the result is the same as before, but multiplied by 2 >>> tensorplay.cumulative_trapezoid(y, dx=2) tensor([6., 21.]) >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing >>> x = tensorplay.tensor([1, 3, 6]) >>> tensorplay.cumulative_trapezoid(y, x) tensor([6., 28.5]) >>> # Computes the same trapezoidal rule directly up to each element to verify >>> ((3 - 1) * (1 + 5)) / 2 6.0 >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2 28.5 >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix >>> y = tensorplay.arange(9).reshape(3, 3) tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> tensorplay.cumulative_trapezoid(y) tensor([[ 0.5, 2.], [ 3.5, 8.], [ 6.5, 14.]]) >>> # Cumulatively computes the trapezoidal rule for each column of the matrix >>> tensorplay.cumulative_trapezoid(y, dim=0) tensor([[ 1.5, 2.5, 3.5], [ 6.0, 8.0, 10.0]]) >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with the same arbitrary spacing >>> y = tensorplay.ones(3, 3) >>> x = tensorplay.tensor([1, 3, 6]) >>> tensorplay.cumulative_trapezoid(y, x) tensor([[2., 5.], [2., 5.], [2., 5.]]) >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with different arbitrary spacing per row >>> y = tensorplay.ones(3, 3) >>> x = tensorplay.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]]) >>> tensorplay.cumulative_trapezoid(y, x) tensor([[1., 2.], [2., 4.], [3., 6.]])
deg2rad_
functionFull reference ↗- tensorplay.functional.deg2rad_(input)[source]
deg2rad
functionFull reference ↗- tensorplay.functional.deg2rad(input, *, out=None) Tensor[source]
Returns a new tensor with each of the elements of
inputconverted from angles in degrees to radians.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]]) >>> tensorplay.deg2rad(a) tensor([[ 3.1416, -3.1416], [ 6.2832, -6.2832], [ 1.5708, -1.5708]])
dequantize
functionFull reference ↗- tensorplay.functional.dequantize(tensor) Tensor[source]
Returns an fp32 Tensor by dequantizing a quantized Tensor
- Parameters:
tensor (Tensor) – A quantized Tensor
- tensorplay.functional.dequantize(tensors) sequence of Tensors[source]
Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
- Parameters:
tensors (sequence of Tensors) – A list of quantized Tensors
det
functionFull reference ↗- tensorplay.functional.det(input) Tensor[source]
Alias for
tensorplay.linalg.det()
detach_
functionFull reference ↗- tensorplay.functional.detach_(input)[source]
detach_copy
functionFull reference ↗- tensorplay.functional.detach_copy(input)[source]
Performs the same operation as
tensorplay.detach(), but all output tensors are freshly created instead of aliasing the input.
detach
functionFull reference ↗- tensorplay.functional.detach(input)[source]
diag_embed
functionFull reference ↗- tensorplay.functional.diag_embed(input, offset=0, dim1=-2, dim2=-1) Tensor[source]
Creates a tensor whose diagonals of certain 2D planes (specified by
dim1anddim2) are filled byinput. To facilitate creating batched diagonal matrices, the 2D planes formed by the last two dimensions of the returned tensor are chosen by default.The argument
offsetcontrols which diagonal to consider:If
offset= 0, it is the main diagonal.If
offset> 0, it is above the main diagonal.If
offset< 0, it is below the main diagonal.
The size of the new matrix will be calculated to make the specified diagonal of the size of the last input dimension. Note that for
offsetother than , the order ofdim1anddim2matters. Exchanging them is equivalent to changing the sign ofoffset.Applying
tensorplay.diagonal()to the output of this function with the same arguments yields a matrix identical to input. However,tensorplay.diagonal()has different default dimensions, so those need to be explicitly specified.- Parameters:
input (Tensor) – the input tensor. Must be at least 1-dimensional.
offset (int, optional) – which diagonal to consider. Default: 0 (main diagonal).
dim1 (int, optional) – first dimension with respect to which to take diagonal. Default: -2.
dim2 (int, optional) – second dimension with respect to which to take diagonal. Default: -1.
Example:
>>> a = tensorplay.randn(2, 3) >>> tensorplay.diag_embed(a) tensor([[[ 1.5410, 0.0000, 0.0000], [ 0.0000, -0.2934, 0.0000], [ 0.0000, 0.0000, -2.1788]], [[ 0.5684, 0.0000, 0.0000], [ 0.0000, -1.0845, 0.0000], [ 0.0000, 0.0000, -1.3986]]]) >>> tensorplay.diag_embed(a, offset=1, dim1=0, dim2=2) tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000], [ 0.0000, 0.5684, 0.0000, 0.0000]], [[ 0.0000, 0.0000, -0.2934, 0.0000], [ 0.0000, 0.0000, -1.0845, 0.0000]], [[ 0.0000, 0.0000, 0.0000, -2.1788], [ 0.0000, 0.0000, 0.0000, -1.3986]], [[ 0.0000, 0.0000, 0.0000, 0.0000], [ 0.0000, 0.0000, 0.0000, 0.0000]]])
diag
functionFull reference ↗- tensorplay.functional.diag(input, diagonal=0, *, out=None) Tensor[source]
If
inputis a vector (1-D tensor), then returns a 2-D square tensor with the elements ofinputas the diagonal.If
inputis a matrix (2-D tensor), then returns a 1-D tensor with the diagonal elements ofinput.
The argument
diagonalcontrols which diagonal to consider:If
diagonal= 0, it is the main diagonal.If
diagonal> 0, it is above the main diagonal.If
diagonal< 0, it is below the main diagonal.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
See also
tensorplay.diagonal()always returns the diagonal of its input.tensorplay.diagflat()always constructs a tensor with diagonal elements specified by the input.Examples:
Get the square matrix where the input vector is the diagonal:
>>> a = tensorplay.randn(3) >>> a tensor([ 0.5950,-0.0872, 2.3298]) >>> tensorplay.diag(a) tensor([[ 0.5950, 0.0000, 0.0000], [ 0.0000,-0.0872, 0.0000], [ 0.0000, 0.0000, 2.3298]]) >>> tensorplay.diag(a, 1) tensor([[ 0.0000, 0.5950, 0.0000, 0.0000], [ 0.0000, 0.0000,-0.0872, 0.0000], [ 0.0000, 0.0000, 0.0000, 2.3298], [ 0.0000, 0.0000, 0.0000, 0.0000]])Get the k-th diagonal of a given matrix:
>>> a = tensorplay.randn(3, 3) >>> a tensor([[-0.4264, 0.0255,-0.1064], [ 0.8795,-0.2429, 0.1374], [ 0.1029,-0.6482,-1.6300]]) >>> tensorplay.diag(a, 0) tensor([-0.4264,-0.2429,-1.6300]) >>> tensorplay.diag(a, 1) tensor([ 0.0255, 0.1374])
diagflat
functionFull reference ↗- tensorplay.functional.diagflat(input, offset=0) Tensor[source]
If
inputis a vector (1-D tensor), then returns a 2-D square tensor with the elements ofinputas the diagonal.If
inputis a tensor with more than one dimension, then returns a 2-D tensor with diagonal elements equal to a flattenedinput.
The argument
offsetcontrols which diagonal to consider:If
offset= 0, it is the main diagonal.If
offset> 0, it is above the main diagonal.If
offset< 0, it is below the main diagonal.
- Parameters:
Examples:
>>> a = tensorplay.randn(3) >>> a tensor([-0.2956, -0.9068, 0.1695]) >>> tensorplay.diagflat(a) tensor([[-0.2956, 0.0000, 0.0000], [ 0.0000, -0.9068, 0.0000], [ 0.0000, 0.0000, 0.1695]]) >>> tensorplay.diagflat(a, 1) tensor([[ 0.0000, -0.2956, 0.0000, 0.0000], [ 0.0000, 0.0000, -0.9068, 0.0000], [ 0.0000, 0.0000, 0.0000, 0.1695], [ 0.0000, 0.0000, 0.0000, 0.0000]]) >>> a = tensorplay.randn(2, 2) >>> a tensor([[ 0.2094, -0.3018], [-0.1516, 1.9342]]) >>> tensorplay.diagflat(a) tensor([[ 0.2094, 0.0000, 0.0000, 0.0000], [ 0.0000, -0.3018, 0.0000, 0.0000], [ 0.0000, 0.0000, -0.1516, 0.0000], [ 0.0000, 0.0000, 0.0000, 1.9342]])
diagonal_copy
functionFull reference ↗- tensorplay.functional.diagonal_copy(input, offset=0, dim1=0, dim2=1)[source]
Performs the same operation as
tensorplay.diagonal(), but all output tensors are freshly created instead of aliasing the input.
diagonal_scatter
functionFull reference ↗- tensorplay.functional.diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) Tensor[source]
Embeds the values of the
srctensor intoinputalong the diagonal elements ofinput, with respect todim1anddim2.This function returns a tensor with fresh storage; it does not return a view.
The argument
offsetcontrols which diagonal to consider:If
offset= 0, it is the main diagonal.If
offset> 0, it is above the main diagonal.If
offset< 0, it is below the main diagonal.
- Parameters:
input (Tensor) – the input tensor. Must be at least 2-dimensional.
src (Tensor) – the tensor to embed into
input.offset (int, optional) – which diagonal to consider. Default: 0 (main diagonal).
dim1 (int, optional) – first dimension with respect to which to take diagonal. Default: 0.
dim2 (int, optional) – second dimension with respect to which to take diagonal. Default: 1.
Note
srcmust be of the proper size in order to be embedded intoinput. Specifically, it should have the same shape astensorplay.diagonal(input, offset, dim1, dim2)Examples:
>>> a = tensorplay.zeros(3, 3) >>> a tensor([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]) >>> tensorplay.diagonal_scatter(a, tensorplay.ones(3), 0) tensor([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) >>> tensorplay.diagonal_scatter(a, tensorplay.ones(2), 1) tensor([[0., 1., 0.], [0., 0., 1.], [0., 0., 0.]])
diagonal
functionFull reference ↗- tensorplay.functional.diagonal(input, offset=0, dim1=0, dim2=1) Tensor[source]
Returns a partial view of
inputwith the its diagonal elements with respect todim1anddim2appended as a dimension at the end of the shape.The argument
offsetcontrols which diagonal to consider:If
offset= 0, it is the main diagonal.If
offset> 0, it is above the main diagonal.If
offset< 0, it is below the main diagonal.
Applying
tensorplay.diag_embed()to the output of this function with the same arguments yields a diagonal matrix with the diagonal entries of the input. However,tensorplay.diag_embed()has different default dimensions, so those need to be explicitly specified.- Parameters:
input (Tensor) – the input tensor. Must be at least 2-dimensional.
offset (int, optional) – which diagonal to consider. Default: 0 (main diagonal).
dim1 (int, optional) – first dimension with respect to which to take diagonal. Default: 0.
dim2 (int, optional) – second dimension with respect to which to take diagonal. Default: 1.
Note
To take a batch diagonal, pass in dim1=-2, dim2=-1.
Examples:
>>> a = tensorplay.randn(3, 3) >>> a tensor([[-1.0854, 1.1431, -0.1752], [ 0.8536, -0.0905, 0.0360], [ 0.6927, -0.3735, -0.4945]]) >>> tensorplay.diagonal(a) tensor([-1.0854, -0.0905, -0.4945]) >>> tensorplay.diagonal(a, 1) tensor([ 1.1431, 0.0360]) >>> b = tensorplay.randn(2, 5) >>> b tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745], [ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]]) >>> tensorplay.diagonal(b, 1, 1, 0) tensor([1.8262]) >>> x = tensorplay.randn(2, 5, 4, 2) >>> tensorplay.diagonal(x, offset=-1, dim1=1, dim2=2) tensor([[[-1.2631, 0.3755, -1.5977, -1.8172], [-1.1065, 1.0401, -0.2235, -0.7938]], [[-1.7325, -0.3081, 0.6166, 0.2335], [ 1.0500, 0.7336, -0.3836, -1.1015]]])
diff
functionFull reference ↗- tensorplay.functional.diff(input, n=1, dim=-1, prepend=None, append=None) Tensor[source]
Computes the n-th forward difference along the given dimension.
The first-order differences are given by out[i] = input[i + 1] - input[i]. Higher-order differences are calculated by using
tensorplay.diff()recursively.- Parameters:
input (Tensor) – the tensor to compute the differences on
n (int, optional) – the number of times to recursively compute the difference
dim (int, optional) – the dimension to compute the difference along. Default is the last dimension.
prepend (Tensor, optional) – values to prepend or append to
inputalongdimbefore computing the difference. Their dimensions must be equivalent to that of input, and their shapes must match input’s shape except ondim.append (Tensor, optional) – values to prepend or append to
inputalongdimbefore computing the difference. Their dimensions must be equivalent to that of input, and their shapes must match input’s shape except ondim.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([1, 3, 2]) >>> tensorplay.diff(a) tensor([ 2, -1]) >>> b = tensorplay.tensor([4, 5]) >>> tensorplay.diff(a, append=b) tensor([ 2, -1, 2, 1]) >>> c = tensorplay.tensor([[1, 2, 3], [3, 4, 5]]) >>> tensorplay.diff(c, dim=0) tensor([[2, 2, 2]]) >>> tensorplay.diff(c, dim=1) tensor([[1, 1], [1, 1]])
digamma
functionFull reference ↗dist
functionFull reference ↗- tensorplay.functional.dist(input, other, p=2) Tensor[source]
Returns the p-norm of (
input-other)The shapes of
inputandothermust be broadcastable.- Parameters:
Example:
>>> x = tensorplay.randn(4) >>> x tensor([-1.5393, -0.8675, 0.5916, 1.6321]) >>> y = tensorplay.randn(4) >>> y tensor([ 0.0967, -1.0511, 0.6295, 0.8360]) >>> tensorplay.dist(x, y, 3.5) tensor(1.6727) >>> tensorplay.dist(x, y, 3) tensor(1.6973) >>> tensorplay.dist(x, y, 0) tensor(4.) >>> tensorplay.dist(x, y, 1) tensor(2.6537)
div
functionFull reference ↗- tensorplay.functional.div(input, other, *, rounding_mode=None, out=None) Tensor[source]
Divides each element of the input
inputby the corresponding element ofother.Note
By default, this performs a “true” division like Python 3. See the
rounding_modeargument for floor division.Supports broadcasting to a common shape, type promotion, and integer, float, and complex inputs. Always promotes integer types to the default scalar type.
- Parameters:
- Keyword Arguments:
rounding_mode (str, optional) –
Type of rounding applied to the result:
None - default behavior. Performs no rounding and, if both
inputandotherare integer types, promotes the inputs to the default scalar type. Equivalent to true division in Python (the/operator) and NumPy’snp.true_divide."trunc"- rounds the results of the division towards zero. Equivalent to C-style integer division."floor"- rounds the results of the division down. Equivalent to floor division in Python (the//operator) and NumPy’snp.floor_divide.
out (Tensor, optional) – the output tensor.
Examples:
>>> x = tensorplay.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637]) >>> tensorplay.div(x, 0.5) tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274]) >>> a = tensorplay.tensor([[-0.3711, -1.9353, -0.4605, -0.2917], ... [ 0.1815, -1.0111, 0.9805, -1.5923], ... [ 0.1062, 1.4581, 0.7759, -1.2344], ... [-0.1830, -0.0313, 1.1908, -1.4757]]) >>> b = tensorplay.tensor([ 0.8032, 0.2930, -0.8113, -0.2308]) >>> tensorplay.div(a, b) tensor([[-0.4620, -6.6051, 0.5676, 1.2639], [ 0.2260, -3.4509, -1.2086, 6.8990], [ 0.1322, 4.9764, -0.9564, 5.3484], [-0.2278, -0.1068, -1.4678, 6.3938]]) >>> tensorplay.div(a, b, rounding_mode='trunc') tensor([[-0., -6., 0., 1.], [ 0., -3., -1., 6.], [ 0., 4., -0., 5.], [-0., -0., -1., 6.]]) >>> tensorplay.div(a, b, rounding_mode='floor') tensor([[-1., -7., 0., 1.], [ 0., -4., -2., 6.], [ 0., 4., -1., 5.], [-1., -1., -2., 6.]])
divide
functionFull reference ↗dot
functionFull reference ↗- tensorplay.functional.dot(input, tensor, *, out=None) Tensor[source]
Computes the dot product of two 1D tensors.
Note
Unlike NumPy’s dot, tensorplay.dot intentionally only supports computing the dot product of two 1D tensors with the same number of elements.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.dot(tensorplay.tensor([2, 3]), tensorplay.tensor([2, 1])) tensor(7) >>> t1, t2 = tensorplay.tensor([0, 1]), tensorplay.tensor([2, 3]) >>> tensorplay.dot(t1, t2) tensor(3)
dropout_
functionFull reference ↗- tensorplay.functional.dropout_(input, p=0.5, train=True)[source]
dsplit
functionFull reference ↗- tensorplay.functional.dsplit(input, indices_or_sections) List of Tensors[source]
Splits
input, a tensor with three or more dimensions, into multiple tensors depthwise according toindices_or_sections. Each split is a view ofinput.This is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=2) (the split dimension is 2), except that if
indices_or_sectionsis an integer it must evenly divide the split dimension or a runtime error will be thrown.This function is based on NumPy’s
numpy.dsplit().- Parameters:
Example:
>>> t = tensorplay.arange(16.0).reshape(2, 2, 4) >>> t tensor([[[ 0., 1., 2., 3.], [ 4., 5., 6., 7.]], [[ 8., 9., 10., 11.], [12., 13., 14., 15.]]]) >>> tensorplay.dsplit(t, 2) (tensor([[[ 0., 1.], [ 4., 5.]], [[ 8., 9.], [12., 13.]]]), tensor([[[ 2., 3.], [ 6., 7.]], [[10., 11.], [14., 15.]]])) >>> tensorplay.dsplit(t, [3, 6]) (tensor([[[ 0., 1., 2.], [ 4., 5., 6.]], [[ 8., 9., 10.], [12., 13., 14.]]]), tensor([[[ 3.], [ 7.]], [[11.], [15.]]]), tensor([], size=(2, 2, 0)))
dstack
functionFull reference ↗- tensorplay.functional.dstack(tensors, *, out=None) Tensor[source]
Stack tensors in sequence depthwise (along third axis).
This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by
tensorplay.atleast_3d().- Parameters:
tensors (sequence of Tensors) – sequence of tensors to concatenate
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([1, 2, 3]) >>> b = tensorplay.tensor([4, 5, 6]) >>> tensorplay.dstack((a,b)) tensor([[[1, 4], [2, 5], [3, 6]]]) >>> a = tensorplay.tensor([[1],[2],[3]]) >>> b = tensorplay.tensor([[4],[5],[6]]) >>> tensorplay.dstack((a,b)) tensor([[[1, 4]], [[2, 5]], [[3, 6]]])
embedding_renorm_
functionFull reference ↗- tensorplay.functional.embedding_renorm_(input, indices, max_norm, norm_type)[source]
embedding
functionFull reference ↗- tensorplay.functional.embedding(weight, indices, padding_idx=-1, scale_grad_by_freq=False, sparse=False)[source]
empty_like
functionFull reference ↗- tensorplay.functional.empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor
Returns an uninitialized tensor with the same size as
input.tensorplay.empty_like(input)is equivalent totensorplay.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).Note
The returned storage is uninitialized, and
tensorplay.use_deterministic_algorithms()does not change that. If the contents matter, allocate withtensorplay.zeros()or fill the tensor before reading it, otherwise the output becomes a source of nondeterminism. Floating point and complex tensors are filled with NaN, and integer tensors are filled with the maximum value.When
tensorplay.preserve_formatis used: If the input tensor is dense (i.e., non-overlapping strided), its memory format (including strides) is retained. Otherwise (e.g., a non-dense view like a stepped slice), the output is converted to the dense format.- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
Example:
>>> a=tensorplay.empty((2,3), dtype=tensorplay.int32, device = 'cuda') >>> tensorplay.empty_like(a) tensor([[0, 0, 0], [0, 0, 0]], device='cuda:0', dtype=tensorplay.int32)
empty_permuted
functionFull reference ↗- tensorplay.functional.empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) Tensor[source]
Creates an uninitialized, non-overlapping and dense tensor with the specified
size, withphysical_layoutspecifying how the dimensions are physically laid out in memory (each logical dimension is listed from outermost to innermost).physical_layoutis a generalization of NCHW/NHWC notation: if each dimension is assigned a number according to what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is(0, 1, 2, 3)while NHWC is(0, 2, 3, 1). Equivalently, the strides of the output tensortare such thatt.stride(physical_layout[i]) == contiguous_strides[i](notably, this function is not equivalent totensorplay.empty(size).permute(physical_layout)).Unlike
tensorplay.empty_strided(), this is guaranteed to produce a dense tensor with no overlaps. If possible, prefer using this function overtensorplay.empty_strided()or manual use oftensorplay.as_strided().Note
The returned storage is uninitialized, and
tensorplay.use_deterministic_algorithms()does not change that. If the contents matter, allocate withtensorplay.zeros()or fill the tensor before reading it, otherwise the output becomes a source of nondeterminism. Floating point and complex tensors are filled with NaN, and integer tensors are filled with the maximum value.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.
Examples
>>> tensorplay.empty((2, 3, 5, 7)).stride() (105, 35, 7, 1) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride() (105, 35, 7, 1) >>> tensorplay.empty((2, 3, 5, 7), memory_format=tensorplay.channels_last).stride() (105, 1, 21, 3) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride() (105, 1, 21, 3) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order() (0, 2, 3, 1)
empty_quantized
functionFull reference ↗- tensorplay.functional.empty_quantized(size, qtensor, dtype=None, layout=None, device=None, pin_memory=None, memory_format=None)[source]
empty_strided
functionFull reference ↗- tensorplay.functional.empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) Tensor[source]
Creates a tensor with the specified
sizeandstrideand filled with undefined data.Warning
If the constructed tensor is “overlapped” (with multiple indices referring to the same element in memory) its behavior is undefined.
Note
The returned storage is uninitialized, and
tensorplay.use_deterministic_algorithms()does not change that. If the contents matter, allocate withtensorplay.zeros()or fill the tensor before reading it, otherwise the output becomes a source of nondeterminism. Floating point and complex tensors are filled with NaN, and integer tensors are filled with the maximum value.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.
Example:
>>> a = tensorplay.empty_strided((2, 3), (1, 2)) >>> a tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07], [0.0000e+00, 0.0000e+00, 3.0705e-41]]) >>> a.stride() (1, 2) >>> a.size() tensorplay.Size([2, 3])
entr
functionFull reference ↗- tensorplay.functional.entr(input)[source]
eq
functionFull reference ↗- tensorplay.functional.eq(input, other, *, out=None) Tensor[source]
Computes element-wise equality
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis equal tootherand False elsewhere
Example:
>>> tensorplay.eq(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[ True, False], [False, True]])
equal
functionFull reference ↗- tensorplay.functional.equal(input, other) bool[source]
Trueif two tensors have the same size and elements,Falseotherwise.Note
Tensors containing NaNs are never equal to each other. Additionally, this function does not differentiate between the data types of the tensors during comparison. For more thorough tensor checks, use
tensorplay.testing.assert_close().Example:
>>> tensorplay.equal(tensorplay.tensor([1, 2]), tensorplay.tensor([1, 2])) True >>> tensorplay.equal(tensorplay.tensor([3, tensorplay.nan]), tensorplay.tensor([3, tensorplay.nan])) False >>> tensorplay.equal(tensorplay.tensor([1, 2, 3], dtype=tensorplay.int32), tensorplay.tensor([1, 2, 3], dtype=tensorplay.float32)) True
erf_
functionFull reference ↗- tensorplay.functional.erf_(input)[source]
erf
functionFull reference ↗erfc_
functionFull reference ↗- tensorplay.functional.erfc_(input)[source]
erfc
functionFull reference ↗erfcx
functionFull reference ↗- tensorplay.functional.erfcx(input)[source]
erfinv
functionFull reference ↗exp_
functionFull reference ↗- tensorplay.functional.exp_(input)[source]
exp
functionFull reference ↗- tensorplay.functional.exp(input, *, out=None) Tensor[source]
Returns a new tensor with the exponential of the elements of the input tensor
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.exp(tensorplay.tensor([0, math.log(2.)])) tensor([ 1., 2.])
exp2_
functionFull reference ↗- tensorplay.functional.exp2_(input)[source]
exp2
functionFull reference ↗expand_copy
functionFull reference ↗- tensorplay.functional.expand_copy(input, size, implicit=False)[source]
Performs the same operation as
tensorplay.Tensor.expand(), but all output tensors are freshly created instead of aliasing the input.
expm1_
functionFull reference ↗- tensorplay.functional.expm1_(input)[source]
expm1
functionFull reference ↗eye
functionFull reference ↗- tensorplay.functional.eye(n, m=None, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor
Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
- Returns:
A 2-D tensor with ones on the diagonal and zeros elsewhere
- Return type:
Example:
>>> tensorplay.eye(3) tensor([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]])
fake_quantize_per_channel_affine
functionFull reference ↗- tensorplay.functional.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) Tensor[source]
Returns a new tensor with the data in
inputfake quantized per channel usingscale,zero_point,quant_minandquant_max, across the channel specified byaxis.- Parameters:
input (Tensor) – the input value(s), in
tensorplay.float32scale (Tensor) – quantization scale, per channel in
tensorplay.float32zero_point (Tensor) – quantization zero_point, per channel in
tensorplay.int32ortensorplay.halfortensorplay.float32axis (int32) – channel axis
quant_min (int64) – lower bound of the quantized domain
quant_max (int64) – upper bound of the quantized domain
- Returns:
A newly fake_quantized per channel
tensorplay.float32tensor- Return type:
Example:
>>> x = tensorplay.randn(2, 2, 2) >>> x tensor([[[-0.2525, -0.0466], [ 0.3491, -0.2168]], [[-0.5906, 1.6258], [ 0.6444, -0.0542]]]) >>> scales = (tensorplay.randn(2) + 1) * 0.05 >>> scales tensor([0.0475, 0.0486]) >>> zero_points = tensorplay.zeros(2).to(tensorplay.int32) >>> zero_points tensor([0, 0]) >>> tensorplay.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255) tensor([[[0.0000, 0.0000], [0.3405, 0.0000]], [[0.0000, 1.6134], [0.6323, 0.0000]]])
fake_quantize_per_tensor_affine
functionFull reference ↗- tensorplay.functional.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) Tensor[source]
Returns a new tensor with the data in
inputfake quantized usingscale,zero_point,quant_minandquant_max.- Parameters:
input (Tensor) – the input value(s),
tensorplay.float32tensorscale (double scalar or
float32Tensor) – quantization scalezero_point (int64 scalar or
int32Tensor) – quantization zero_pointquant_min (int64) – lower bound of the quantized domain
quant_max (int64) – upper bound of the quantized domain
- Returns:
A newly fake_quantized
tensorplay.float32tensor- Return type:
Example:
>>> x = tensorplay.randn(4) >>> x tensor([ 0.0552, 0.9730, 0.3973, -1.0780]) >>> tensorplay.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255) tensor([0.1000, 1.0000, 0.4000, 0.0000]) >>> tensorplay.fake_quantize_per_tensor_affine(x, tensorplay.tensor(0.1), tensorplay.tensor(0), 0, 255) tensor([0.1000, 1.0000, 0.4000, 0.0000])
fbgemm_linear_fp16_weight_fp32_activation
functionFull reference ↗- tensorplay.functional.fbgemm_linear_fp16_weight_fp32_activation(input, packed_weight, bias, *, out=None)[source]
fbgemm_linear_fp16_weight
functionFull reference ↗- tensorplay.functional.fbgemm_linear_fp16_weight(input, packed_weight, bias, *, out=None)[source]
fbgemm_linear_int8_weight_fp32_activation
functionFull reference ↗- tensorplay.functional.fbgemm_linear_int8_weight_fp32_activation(input, weight, packed, col_offsets, weight_scale, weight_zero_point, bias)[source]
fbgemm_linear_int8_weight
functionFull reference ↗- tensorplay.functional.fbgemm_linear_int8_weight(input, weight, packed, col_offsets, weight_scale, weight_zero_point, bias)[source]
fbgemm_linear_quantize_weight
functionFull reference ↗- tensorplay.functional.fbgemm_linear_quantize_weight(input)[source]
fbgemm_pack_gemm_matrix_fp16
functionFull reference ↗- tensorplay.functional.fbgemm_pack_gemm_matrix_fp16(input)[source]
fbgemm_pack_quantized_matrix
functionFull reference ↗- tensorplay.functional.fbgemm_pack_quantized_matrix(input, K=None, N=None)[source]
feature_alpha_dropout_
functionFull reference ↗- tensorplay.functional.feature_alpha_dropout_(input, p=0.5, train=True)[source]
feature_alpha_dropout
functionFull reference ↗- tensorplay.functional.feature_alpha_dropout(input, p=0.5, train=True)[source]
feature_dropout_
functionFull reference ↗- tensorplay.functional.feature_dropout_(input, p=0.5, train=True)[source]
feature_dropout
functionFull reference ↗- tensorplay.functional.feature_dropout(input, p=0.5, train=True)[source]
fill_
functionFull reference ↗- tensorplay.functional.fill_(input, value)[source]
fill
functionFull reference ↗- tensorplay.functional.fill(input, value)[source]
fix_
functionFull reference ↗- tensorplay.functional.fix_(input)[source]
fix
functionFull reference ↗flatten
functionFull reference ↗- tensorplay.functional.flatten(input, start_dim=0, end_dim=-1) Tensor[source]
Flattens
inputby reshaping it into a one-dimensional tensor. Ifstart_dimorend_dimare passed, only dimensions starting withstart_dimand ending withend_dimare flattened. The order of elements ininputis unchanged.Unlike NumPy’s flatten, which always copies input’s data, this function may return the original object, a view, or copy. If no dimensions are flattened, then the original object
inputis returned. Otherwise, if input can be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the flattened shape is input’s data copied. Seetensorplay.Tensor.view()for details on when a view will be returned.Note
Flattening a zero-dimensional tensor will return a one-dimensional view.
- Parameters:
Example:
>>> t = tensorplay.tensor([[[1, 2], ... [3, 4]], ... [[5, 6], ... [7, 8]]]) >>> tensorplay.flatten(t) tensor([1, 2, 3, 4, 5, 6, 7, 8]) >>> tensorplay.flatten(t, start_dim=1) tensor([[1, 2, 3, 4], [5, 6, 7, 8]])
flip
functionFull reference ↗- tensorplay.functional.flip(input, dims) Tensor[source]
Reverse the order of an n-D tensor along given axis in dims.
Note
tensorplay.flip makes a copy of
input’s data. This is different from NumPy’s np.flip, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, tensorplay.flip is expected to be slower than np.flip.Example:
>>> x = tensorplay.arange(8).view(2, 2, 2) >>> x tensor([[[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]]]) >>> tensorplay.flip(x, [0, 1]) tensor([[[ 6, 7], [ 4, 5]], [[ 2, 3], [ 0, 1]]])
fliplr
functionFull reference ↗- tensorplay.functional.fliplr(input) Tensor[source]
Flip tensor in the left/right direction, returning a new tensor.
Flip the entries in each row in the left/right direction. Columns are preserved, but appear in a different order than before.
Note
Requires the tensor to be at least 2-D.
Note
tensorplay.fliplr makes a copy of
input’s data. This is different from NumPy’s np.fliplr, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, tensorplay.fliplr is expected to be slower than np.fliplr.- Parameters:
input (Tensor) – Must be at least 2-dimensional.
Example:
>>> x = tensorplay.arange(4).view(2, 2) >>> x tensor([[0, 1], [2, 3]]) >>> tensorplay.fliplr(x) tensor([[1, 0], [3, 2]])
flipud
functionFull reference ↗- tensorplay.functional.flipud(input) Tensor[source]
Flip tensor in the up/down direction, returning a new tensor.
Flip the entries in each column in the up/down direction. Rows are preserved, but appear in a different order than before.
Note
Requires the tensor to be at least 1-D.
Note
tensorplay.flipud makes a copy of
input’s data. This is different from NumPy’s np.flipud, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, tensorplay.flipud is expected to be slower than np.flipud.- Parameters:
input (Tensor) – Must be at least 1-dimensional.
Example:
>>> x = tensorplay.arange(4).view(2, 2) >>> x tensor([[0, 1], [2, 3]]) >>> tensorplay.flipud(x) tensor([[2, 3], [0, 1]])
float_power
functionFull reference ↗- tensorplay.functional.float_power(input, exponent, *, out=None) Tensor[source]
Raises
inputto the power ofexponent, elementwise, in double precision. If neither input is complex returns atensorplay.float64tensor, and if one or more inputs is complex returns atensorplay.complex128tensor.Note
This function always computes in double precision, unlike
tensorplay.pow(), which implements more typical type promotion. This is useful when the computation needs to be performed in a wider or more precise dtype, or the results of the computation may contain fractional values not representable in the input dtypes, like when an integer base is raised to a negative integer exponent.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randint(10, (4,)) >>> a tensor([6, 4, 7, 1]) >>> tensorplay.float_power(a, 2) tensor([36., 16., 49., 1.], dtype=tensorplay.float64) >>> a = tensorplay.arange(1, 5) >>> a tensor([ 1, 2, 3, 4]) >>> exp = tensorplay.tensor([2, -3, 4, -5]) >>> exp tensor([ 2, -3, 4, -5]) >>> tensorplay.float_power(a, exp) tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=tensorplay.float64)
floor_
functionFull reference ↗- tensorplay.functional.floor_(input)[source]
floor_divide
functionFull reference ↗- tensorplay.functional.floor_divide(input, other, *, out=None) Tensor[source]
Note
truncation division. To restore the previous behavior use
tensorplay.div()withrounding_mode='trunc'.Computes
inputdivided byother, elementwise, and floors the result.Supports broadcasting to a common shape, type promotion, and integer and float inputs.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([4.0, 3.0]) >>> b = tensorplay.tensor([2.0, 2.0]) >>> tensorplay.floor_divide(a, b) tensor([2.0, 1.0]) >>> tensorplay.floor_divide(a, 1.4) tensor([2.0, 2.0])
floor
functionFull reference ↗- tensorplay.functional.floor(input, *, out=None) Tensor[source]
Returns a new tensor with the floor of the elements of
input, the largest integer less than or equal to each element.For integer inputs, follows the array-api convention of returning a copy of the input tensor.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.8166, 1.5308, -0.2530, -0.2091]) >>> tensorplay.floor(a) tensor([-1., 1., -1., -1.])
fmax
functionFull reference ↗- tensorplay.functional.fmax(input, other, *, out=None) Tensor[source]
Computes the element-wise maximum of
inputandother.This is like
tensorplay.maximum()except it handles NaNs differently: if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum. Only if both elements are NaN is NaN propagated.This function is a wrapper around C++’s
std::fmaxand is similar to NumPy’sfmaxfunction.Supports broadcasting to a common shape, type promotion, and integer and floating-point inputs.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([9.7, float('nan'), 3.1, float('nan')]) >>> b = tensorplay.tensor([-2.2, 0.5, float('nan'), float('nan')]) >>> tensorplay.fmax(a, b) tensor([9.7000, 0.5000, 3.1000, nan])
fmin
functionFull reference ↗- tensorplay.functional.fmin(input, other, *, out=None) Tensor[source]
Computes the element-wise minimum of
inputandother.This is like
tensorplay.minimum()except it handles NaNs differently: if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum. Only if both elements are NaN is NaN propagated.This function is a wrapper around C++’s
std::fminand is similar to NumPy’sfminfunction.Supports broadcasting to a common shape, type promotion, and integer and floating-point inputs.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([2.2, float('nan'), 2.1, float('nan')]) >>> b = tensorplay.tensor([-9.3, 0.1, float('nan'), float('nan')]) >>> tensorplay.fmin(a, b) tensor([-9.3000, 0.1000, 2.1000, nan])
fmod
functionFull reference ↗- tensorplay.functional.fmod(input, other, *, out=None) Tensor[source]
Applies C++’s std::fmod entrywise. The result has the same sign as the dividend
inputand its absolute value is less than that ofother.This function may be defined in terms of
tensorplay.div()astensorplay.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * bSupports broadcasting to a common shape, type promotion, and integer and float inputs.
Note
When the divisor is zero, returns
NaNfor floating point dtypes on both CPU and GPU; raisesRuntimeErrorfor integer division by zero on CPU; Integer division by zero on GPU may return any value.Note
Complex inputs are not supported. In some cases, it is not mathematically possible to satisfy the definition of a modulo operation with complex numbers.
See also
tensorplay.remainder()which implements Python’s modulus operator. This one is defined using division rounding down the result.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.fmod(tensorplay.tensor([-3., -2, -1, 1, 2, 3]), 2) tensor([-1., -0., -1., 1., 0., 1.]) >>> tensorplay.fmod(tensorplay.tensor([1, 2, 3, 4, 5]), -1.5) tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
frac_
functionFull reference ↗- tensorplay.functional.frac_(input)[source]
frac
functionFull reference ↗frexp
functionFull reference ↗- tensorplay.functional.frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)[source]
Decomposes
inputinto mantissa and exponent tensors such that .The range of mantissa is the open interval (-1, 1).
Supports float inputs.
- Parameters:
input (Tensor) – the input tensor
- Keyword Arguments:
out (tuple, optional) – the output tensors
Example:
>>> x = tensorplay.arange(9.) >>> mantissa, exponent = tensorplay.frexp(x) >>> mantissa tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000]) >>> exponent tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=tensorplay.int32) >>> tensorplay.ldexp(mantissa, exponent) tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
from_file
functionFull reference ↗- tensorplay.functional.from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)[source]
Creates a CPU tensor with a storage backed by a memory-mapped file.
If
sharedis True, then memory is shared between processes. All changes are written to the file. Ifsharedis False, then changes to the tensor do not affect the file.sizeis the number of elements in the Tensor. IfsharedisFalse, then the file must contain at leastsize * sizeof(dtype)bytes. IfsharedisTruethe file will be created if needed.Note
Only CPU tensors can be mapped to files.
Note
For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
- Parameters:
filename (str) – file name to map
shared (bool) – whether to share memory (whether
MAP_SHAREDorMAP_PRIVATEis passed to the underlying mmap(2) call)size (int) – number of elements in the tensor
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.
Example:
>>> t = tensorplay.randn(2, 5, dtype=tensorplay.float64) >>> t.numpy().tofile('storage.pt') >>> t_mapped = tensorplay.from_file('storage.pt', shared=False, size=10, dtype=tensorplay.float64)
full_like
functionFull reference ↗- tensorplay.functional.full_like(input, fill_value, \*, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor
Returns a tensor with the same size as
inputfilled withfill_value.tensorplay.full_like(input, fill_value)is equivalent totensorplay.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device).- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.fill_value – the number to fill the output tensor with.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
Example:
>>> x = tensorplay.ones(2, 3) >>> tensorplay.full_like(x, 3.141592) tensor([[ 3.1416, 3.1416, 3.1416], [ 3.1416, 3.1416, 3.1416]]) >>> tensorplay.full_like(x, 7) tensor([[7., 7., 7.], [7., 7., 7.]]) >>> tensorplay.full_like(x, 0.5, dtype=tensorplay.int32) tensor([[0, 0, 0], [0, 0, 0]], dtype=tensorplay.int32) >>> y = tensorplay.randn(3, 4, dtype=tensorplay.float64) >>> tensorplay.full_like(y, -1.0) tensor([[-1., -1., -1., -1.], [-1., -1., -1., -1.], [-1., -1., -1., -1.]], dtype=tensorplay.float64)
fused_moving_avg_obs_fake_quant
functionFull reference ↗- tensorplay.functional.fused_moving_avg_obs_fake_quant(input, observer_on, fake_quant_on, running_min, running_max, scale, zero_point, averaging_const, quant_min, quant_max, ch_axis, per_row_fake_quant=False, symmetric_quant=False)[source]
gammainc
functionFull reference ↗- tensorplay.functional.gammainc(a, x)[source]
gammaincc
functionFull reference ↗- tensorplay.functional.gammaincc(a, x)[source]
gather
functionFull reference ↗- tensorplay.functional.gather(input, dim, index, *, sparse_grad=False, out=None) Tensor[source]
Gathers values along an axis specified by dim.
For a 3-D tensor the output is specified by:
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0 out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1 out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2inputandindexmust have the same number of dimensions. It is also required thatindex.size(d) <= input.size(d)for all dimensionsd != dim.outwill have the same shape asindex. Note thatinputandindexdo not broadcast against each other. Whenindexis empty, we always return an empty output with the same shape without further error checking.- Parameters:
- Keyword Arguments:
Example:
>>> t = tensorplay.tensor([[1, 2], [3, 4]]) >>> tensorplay.gather(t, 1, tensorplay.tensor([[0, 0], [1, 0]])) tensor([[ 1, 1], [ 4, 3]])
gcd_
functionFull reference ↗- tensorplay.functional.gcd_(input, other)[source]
gcd
functionFull reference ↗- tensorplay.functional.gcd(input, other, *, out=None) Tensor[source]
Computes the element-wise greatest common divisor (GCD) of
inputandother.Both
inputandothermust have integer types.Note
This defines .
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([5, 10, 15]) >>> b = tensorplay.tensor([3, 4, 5]) >>> tensorplay.gcd(a, b) tensor([1, 2, 5]) >>> c = tensorplay.tensor([3]) >>> tensorplay.gcd(a, c) tensor([1, 1, 3])
ge
functionFull reference ↗- tensorplay.functional.ge(input, other, *, out=None) Tensor[source]
Computes element-wise.
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis greater than or equal tootherand False elsewhere
Example:
>>> tensorplay.ge(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[True, True], [False, True]])
geqrf
functionFull reference ↗- tensorplay.functional.geqrf(input, *, out=None)[source]
This is a low-level function for calling LAPACK’s geqrf directly. This function returns a namedtuple (a, tau) as defined in LAPACK documentation for geqrf .
Computes a QR decomposition of
input. Both Q and R matrices are stored in the same output tensor a. The elements of R are stored on and above the diagonal. Elementary reflectors (or Householder vectors) implicitly defining matrix Q are stored below the diagonal. The results of this function can be used together withtensorplay.linalg.householder_product()to obtain the Q matrix or withtensorplay.ormqr(), which uses an implicit representation of the Q matrix, for an efficient matrix-matrix multiplication.See LAPACK documentation for geqrf for further details.
Note
See also
tensorplay.linalg.qr(), which computes Q and R matrices, andtensorplay.linalg.lstsq()with thedriver="gels"option for a function that can solve matrix equations using a QR decomposition.
ger
functionFull reference ↗get_device
functionFull reference ↗- tensorplay.functional.get_device(input)[source]
greater_equal
functionFull reference ↗greater
functionFull reference ↗grid_sampler_2d
functionFull reference ↗- tensorplay.functional.grid_sampler_2d(input, grid, interpolation_mode, padding_mode, align_corners)[source]
grid_sampler_3d
functionFull reference ↗- tensorplay.functional.grid_sampler_3d(input, grid, interpolation_mode, padding_mode, align_corners)[source]
group_norm
functionFull reference ↗- tensorplay.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-05)[source]
gru_cell
functionFull reference ↗- tensorplay.functional.gru_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None)[source]
gru
functionFull reference ↗- tensorplay.functional.gru(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False)[source]
gt
functionFull reference ↗- tensorplay.functional.gt(input, other, *, out=None) Tensor[source]
Computes element-wise.
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis greater thanotherand False elsewhere
Example:
>>> tensorplay.gt(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, True], [False, False]])
hamming_window
functionFull reference ↗- tensorplay.functional.hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) Tensor[source]
Hamming window function.
where is the full window size.
The input
window_lengthis a positive integer controlling the returned window size.periodicflag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions liketensorplay.stft(). Therefore, ifperiodicis true, the in above formula is in fact . Also, we always havetensorplay.hamming_window(L, periodic=True)equal totensorplay.hamming_window(L + 1, periodic=False)[:-1]).Note
If
window_length, the returned window contains a single value 1.Note
This is a generalized version of
tensorplay.hann_window().- Parameters:
window_length (int) – the size of returned window
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.
- Returns:
A 1-D tensor of size containing the window.
- Return type:
- tensorplay.functional.hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) Tensor[source]
Hamming window function with periodic specified.
- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.
- Returns:
A 1-D tensor of size containing the window.
- Return type:
- tensorplay.functional.hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) Tensor[source]
Hamming window function with periodic and alpha specified.
- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.
- Returns:
A 1-D tensor of size containing the window.
- Return type:
- tensorplay.functional.hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) Tensor[source]
Hamming window function with periodic, alpha and beta specified.
- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.
- Returns:
A 1-D tensor of size containing the window.
- Return type:
hann_window
functionFull reference ↗- tensorplay.functional.hann_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Hann window function.
where is the full window size.
The input
window_lengthis a positive integer controlling the returned window size.periodicflag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions liketensorplay.stft(). Therefore, ifperiodicis true, the in above formula is in fact . Also, we always havetensorplay.hann_window(L, periodic=True)equal totensorplay.hann_window(L + 1, periodic=False)[:-1]).Note
If
window_length, the returned window contains a single value 1.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). Only floating point types are supported.layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
- Returns:
A 1-D tensor of size containing the window
- Return type:
hardshrink
functionFull reference ↗- tensorplay.functional.hardshrink(input, lambd=0.5, *, out=None)[source]
hash_tensor
functionFull reference ↗- tensorplay.functional.hash_tensor(input, *, mode=0) Tensor[source]
Returns a hash of all elements in the
inputtensor.Currently only mode=0 (reduction via xor) is supported. The output will always be of type
tensorplay.uint64. The elements ofinputare upcasted to their 64 bit float / integer equivalent and bitcasted totensorplay.uint64before reduction via xor.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
mode (int) – The hash to use. Default: 0 (xor_reduction)
Example:
>>> a = tensorplay.randn(1, 3) >>> a tensor([[ 1.1918, -1.1813, 0.3373]]) >>> tensorplay.hash_tensor(a) tensor(13822780554648485888, dtype=tensorplay.uint64)Returns the hash of each row of the
inputtensor in the given dimensiondimgiven by mode. Ifdimis a list of dimensions, reduce over all of them.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
mode (int) – The hash to use. Default: 0 (xor_reduction)
Example:
>>> a = tensorplay.randn(2, 4) >>> a tensor([[ 0.1317, -0.5554, -1.4724, -1.1391], [ 0.0778, -0.6070, 0.6375, 0.1798]]) >>> tensorplay.hash_tensor(a, 1) tensor([9233691267014066176, 9255993250844508160], dtype=tensorplay.uint64)
heaviside
functionFull reference ↗- tensorplay.functional.heaviside(input, values, *, out=None) Tensor[source]
Computes the Heaviside step function for each element in
input. The Heaviside step function is defined as:- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> input = tensorplay.tensor([-1.5, 0, 2.0]) >>> values = tensorplay.tensor([0.5]) >>> tensorplay.heaviside(input, values) tensor([0.0000, 0.5000, 1.0000]) >>> values = tensorplay.tensor([1.2, -2.0, 3.5]) >>> tensorplay.heaviside(input, values) tensor([0., -2., 1.])
hermite_polynomial_h
functionFull reference ↗- tensorplay.functional.hermite_polynomial_h(x, n)[source]
hermite_polynomial_he
functionFull reference ↗- tensorplay.functional.hermite_polynomial_he(x, n)[source]
hinge_embedding_loss
functionFull reference ↗- tensorplay.functional.hinge_embedding_loss(input, target, margin=1.0)[source]
histc
functionFull reference ↗- tensorplay.functional.histc(input, bins=100, min=0, max=0, *, out=None) Tensor[source]
Computes the histogram of a tensor.
The elements are sorted into equal width bins between
minandmax. Ifminandmaxare both zero, the minimum and maximum values of the data are used.Elements lower than min and higher than max and
NaNelements are ignored.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
Histogram represented as a tensor
- Return type:
Example:
>>> tensorplay.histc(tensorplay.tensor([1., 2, 1]), bins=4, min=0, max=3) tensor([ 0., 2., 1., 0.])
histogramdd
functionFull reference ↗- tensorplay.functional.histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
Computes a multi-dimensional histogram of the values in a tensor.
Interprets the elements of an input tensor whose innermost dimension has size N as a collection of N-dimensional points. Maps each of the points into a set of N-dimensional bins and returns the number of points (or total weight) in each bin.
inputmust be a tensor with at least 2 dimensions. If input has shape (M, N), each of its M rows defines a point in N-dimensional space. If input has three or more dimensions, all but the last dimension are flattened.Each dimension is independently associated with its own strictly increasing sequence of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D tensors. Alternatively, bin edges may be constructed automatically by passing a sequence of integers specifying the number of equal-width bins in each dimension.
- For each N-dimensional point in input:
- Each of its coordinates is binned independently among the bin edges
corresponding to its dimension
- Binning results are combined to identify the N-dimensional bin (if any)
into which the point falls
If the point falls into a bin, the bin’s count (or total weight) is incremented
Points which do not fall into any bin do not contribute to the output
binscan be a sequence of N 1D tensors, a sequence of N ints, or a single int.If
binsis a sequence of N 1D tensors, it explicitly specifies the N sequences of bin edges. Each 1D tensor should contain a strictly increasing sequence with at least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying the left and right edges of all bins. Every bin is inclusive of its left edge. Only the rightmost bin is inclusive of its right edge.If
binsis a sequence of N ints, it specifies the number of equal-width bins in each dimension. By default, the leftmost and rightmost bin edges in each dimension are determined by the minimum and maximum elements of the input tensor in the corresponding dimension. Therangeargument can be provided to manually specify the leftmost and rightmost bin edges in each dimension.If
binsis an int, it specifies the number of equal-width bins for all dimensions.Note
See also
tensorplay.histogram(), which specifically computes 1D histograms. Whiletensorplay.histogramdd()infers the dimensionality of its bins and binned values from the shape ofinput,tensorplay.histogram()accepts and flattensinputof any shape.- Parameters:
input (Tensor) – the input tensor.
bins – Tensor[], int[], or int. If Tensor[], defines the sequences of bin edges. If int[], defines the number of equal-width bins in each dimension. If int, defines the number of equal-width bins for all dimensions.
- Keyword Arguments:
range (sequence of float) – Defines the leftmost and rightmost bin edges in each dimension.
weight (Tensor) – By default, each value in the input has weight 1. If a weight tensor is passed, each N-dimensional coordinate in input contributes its associated weight towards its bin’s result. The weight tensor should have the same shape as the
inputtensor excluding its innermost dimension N.density (bool) – If False (default), the result will contain the count (or total weight) in each bin. If True, each count (weight) is divided by the total count (total weight), then divided by the volume of its associated bin.
- Returns:
N-dimensional Tensor containing the values of the histogram. bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
- Return type:
hist (Tensor)
Example:
>>> tensorplay.histogramdd(tensorplay.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3], ... weight=tensorplay.tensor([1., 2., 4., 8.])) tensorplay.return_types.histogramdd( hist=tensor([[0., 1., 0.], [2., 0., 0.], [4., 0., 8.]]), bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]), tensor([0.0000, 0.6667, 1.3333, 2.0000]))) >>> tensorplay.histogramdd(tensorplay.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2], ... range=[0., 1., 0., 1.], density=True) tensorplay.return_types.histogramdd( hist=tensor([[2., 0.], [0., 2.]]), bin_edges=(tensor([0.0000, 0.5000, 1.0000]), tensor([0.0000, 0.5000, 1.0000])))
hsplit
functionFull reference ↗- tensorplay.functional.hsplit(input, indices_or_sections) List of Tensors[source]
Splits
input, a tensor with one or more dimensions, into multiple tensors horizontally according toindices_or_sections. Each split is a view ofinput.If
inputis one dimensional this is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=0) (the split dimension is zero), and ifinputhas two or more dimensions it’s equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1), except that ifindices_or_sectionsis an integer it must evenly divide the split dimension or a runtime error will be thrown.This function is based on NumPy’s
numpy.hsplit().- Parameters:
Example:
>>> t = tensorplay.arange(16.0).reshape(4,4) >>> t tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) >>> tensorplay.hsplit(t, 2) (tensor([[ 0., 1.], [ 4., 5.], [ 8., 9.], [12., 13.]]), tensor([[ 2., 3.], [ 6., 7.], [10., 11.], [14., 15.]])) >>> tensorplay.hsplit(t, [3, 6]) (tensor([[ 0., 1., 2.], [ 4., 5., 6.], [ 8., 9., 10.], [12., 13., 14.]]), tensor([[ 3.], [ 7.], [11.], [15.]]), tensor([], size=(4, 0)))
hstack
functionFull reference ↗- tensorplay.functional.hstack(tensors, *, out=None) Tensor[source]
Stack tensors in sequence horizontally (column wise).
This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
- Parameters:
tensors (sequence of Tensors) – sequence of tensors to concatenate
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([1, 2, 3]) >>> b = tensorplay.tensor([4, 5, 6]) >>> tensorplay.hstack((a,b)) tensor([1, 2, 3, 4, 5, 6]) >>> a = tensorplay.tensor([[1],[2],[3]]) >>> b = tensorplay.tensor([[4],[5],[6]]) >>> tensorplay.hstack((a,b)) tensor([[1, 4], [2, 5], [3, 6]])
hypot
functionFull reference ↗- tensorplay.functional.hypot(input, other, *, out=None) Tensor[source]
Given the legs of a right triangle, return its hypotenuse.
The shapes of
inputandothermust be broadcastable.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.hypot(tensorplay.tensor([4.0]), tensorplay.tensor([3.0, 4.0, 5.0])) tensor([5.0000, 5.6569, 6.4031])
i0_
functionFull reference ↗- tensorplay.functional.i0_(input)[source]
i0
functionFull reference ↗i0e
functionFull reference ↗- tensorplay.functional.i0e(input)[source]
i1
functionFull reference ↗- tensorplay.functional.i1(input)[source]
i1e
functionFull reference ↗- tensorplay.functional.i1e(input)[source]
igamma
functionFull reference ↗igammac
functionFull reference ↗imag
functionFull reference ↗- tensorplay.functional.imag(input) Tensor[source]
Returns a new tensor containing imaginary values of the
selftensor. The returned tensor andselfshare the same underlying storage.Warning
imag()is only supported for tensors with complex dtypes.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x=tensorplay.randn(4, dtype=tensorplay.cfloat) >>> x tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)]) >>> x.imag tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
index_add
functionFull reference ↗index_copy
functionFull reference ↗index_put_
functionFull reference ↗- tensorplay.functional.index_put_(input, indices, values, accumulate=False)[source]
index_reduce
functionFull reference ↗index_select
functionFull reference ↗- tensorplay.functional.index_select(input, dim, index, *, out=None) Tensor[source]
Returns a new tensor which indexes the
inputtensor along dimensiondimusing the entries inindexwhich is a LongTensor.The returned tensor has the same number of dimensions as the original tensor (
input). Thedimth dimension has the same size as the length ofindex; other dimensions have the same size as in the original tensor.Note
The returned tensor does not use the same storage as the original tensor. If
outhas a different shape than expected, we silently change it to the correct shape, reallocating the underlying storage if necessary.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.randn(3, 4) >>> x tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-0.4664, 0.2647, -0.1228, -1.1068], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> indices = tensorplay.tensor([0, 2]) >>> tensorplay.index_select(x, 0, indices) tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> tensorplay.index_select(x, 1, indices) tensor([[ 0.1427, -0.5414], [-0.4664, -0.1228], [-1.1734, 0.7230]])
indices_copy
functionFull reference ↗- tensorplay.functional.indices_copy(input)[source]
Performs the same operation as
tensorplay.indices(), but all output tensors are freshly created instead of aliasing the input.
inner
functionFull reference ↗- tensorplay.functional.inner(input, other, *, out=None) Tensor[source]
Computes the dot product for 1D tensors. For higher dimensions, sums the product of elements from
inputandotheralong their last dimension.Note
If either
inputorotheris a scalar, the result is equivalent to tensorplay.mul(input, other).If both
inputandotherare non-scalars, the size of their last dimension must match and the result is equivalent to tensorplay.tensordot(input, other, dims=([-1], [-1]))- Parameters:
- Keyword Arguments:
out (Tensor, optional) – Optional output tensor to write result into. The output shape is input.shape[:-1] + other.shape[:-1].
Example:
# Dot product >>> tensorplay.inner(tensorplay.tensor([1, 2, 3]), tensorplay.tensor([0, 2, 1])) tensor(7) # Multidimensional input tensors >>> a = tensorplay.randn(2, 3) >>> a tensor([[0.8173, 1.0874, 1.1784], [0.3279, 0.1234, 2.7894]]) >>> b = tensorplay.randn(2, 4, 3) >>> b tensor([[[-0.4682, -0.7159, 0.1506], [ 0.4034, -0.3657, 1.0387], [ 0.9892, -0.6684, 0.1774], [ 0.9482, 1.3261, 0.3917]], [[ 0.4537, 0.7493, 1.1724], [ 0.2291, 0.5749, -0.2267], [-0.7920, 0.3607, -0.3701], [ 1.3666, -0.5850, -1.7242]]]) >>> tensorplay.inner(a, b) tensor([[[-0.9837, 1.1560, 0.2907, 2.6785], [ 2.5671, 0.5452, -0.6912, -1.5509]], [[ 0.1782, 2.9843, 0.7366, 1.5672], [ 3.5115, -0.4864, -1.2476, -4.4337]]]) # Scalar input >>> tensorplay.inner(a, tensorplay.tensor(2)) tensor([[1.6347, 2.1748, 2.3567], [0.6558, 0.2469, 5.5787]])
instance_norm
functionFull reference ↗- tensorplay.functional.instance_norm(input, weight=None, bias=None, running_mean=None, running_var=None, use_input_stats=True, momentum=0.1, eps=1e-05)[source]
int_repr
functionFull reference ↗- tensorplay.functional.int_repr(input)[source]
inverse
functionFull reference ↗- tensorplay.functional.inverse(input, *, out=None) Tensor[source]
Alias for
tensorplay.linalg.inv()
is_complex
functionFull reference ↗- tensorplay.functional.is_complex(input: Tensor) bool[source]
Returns True if the data type of
inputis a complex data type i.e., one oftensorplay.complex64, andtensorplay.complex128.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> tensorplay.is_complex(tensorplay.tensor([1, 2, 3], dtype=tensorplay.complex64)) True >>> tensorplay.is_complex(tensorplay.tensor([1, 2, 3], dtype=tensorplay.complex128)) True >>> tensorplay.is_complex(tensorplay.tensor([1, 2, 3], dtype=tensorplay.int32)) False >>> tensorplay.is_complex(tensorplay.tensor([1.0, 2.0, 3.0], dtype=tensorplay.float16)) False
is_conj
functionFull reference ↗is_distributed
functionFull reference ↗- tensorplay.functional.is_distributed(input)[source]
is_floating_point
functionFull reference ↗- tensorplay.functional.is_floating_point(input: Tensor) bool[source]
Returns True if the data type of
inputis a floating point data type i.e., one oftensorplay.float64,tensorplay.float32,tensorplay.float16, andtensorplay.bfloat16.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> tensorplay.is_floating_point(tensorplay.tensor([1.0, 2.0, 3.0])) True >>> tensorplay.is_floating_point(tensorplay.tensor([1, 2, 3], dtype=tensorplay.int32)) False >>> tensorplay.is_floating_point(tensorplay.tensor([1.0, 2.0, 3.0], dtype=tensorplay.float16)) True >>> tensorplay.is_floating_point(tensorplay.tensor([1, 2, 3], dtype=tensorplay.complex64)) False
is_inference
functionFull reference ↗- tensorplay.functional.is_inference(input)[source]
Returns True if
inputis an inference tensor.A non-view tensor is an inference tensor if and only if it was allocated during inference mode. A view tensor is an inference tensor if and only if the tensor it is a view of is an inference tensor.
For details on inference mode please see Inference Mode.
- Parameters:
input (Tensor) – the input tensor.
is_neg
functionFull reference ↗- tensorplay.functional.is_neg(input)[source]
is_nonzero
functionFull reference ↗- tensorplay.functional.is_nonzero(input)[source]
Returns True if the
inputis a single element tensor which is not equal to zero after type conversions. i.e. not equal totensorplay.tensor([0.])ortensorplay.tensor([0])ortensorplay.tensor([False]). Throws aRuntimeErroriftensorplay.numel() != 1(even in case of sparse tensors).- Parameters:
input (Tensor) – the input tensor.
Examples:
>>> tensorplay.is_nonzero(tensorplay.tensor([0.])) False >>> tensorplay.is_nonzero(tensorplay.tensor([1.5])) True >>> tensorplay.is_nonzero(tensorplay.tensor([False])) False >>> tensorplay.is_nonzero(tensorplay.tensor([3])) True >>> tensorplay.is_nonzero(tensorplay.tensor([1, 3, 5])) Traceback (most recent call last): ... RuntimeError: Boolean value of Tensor with more than one value is ambiguous >>> tensorplay.is_nonzero(tensorplay.tensor([])) Traceback (most recent call last): ... RuntimeError: Boolean value of Tensor with no values is ambiguous
is_same_size
functionFull reference ↗- tensorplay.functional.is_same_size(input, other)[source]
is_signed
functionFull reference ↗- tensorplay.functional.is_signed(input)[source]
is_vulkan_available
functionFull reference ↗- tensorplay.functional.is_vulkan_available()[source]
isclose
functionFull reference ↗- tensorplay.functional.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) Tensor[source]
Returns a new tensor with boolean elements representing if each element of
inputis “close” to the corresponding element ofother. Closeness is defined as:where
inputandotherare finite. Whereinputand/orotherare nonfinite they are close if and only if they are equal, with NaNs being considered equal to each other whenequal_nanis True.- Parameters:
Examples:
>>> tensorplay.isclose(tensorplay.tensor((1., 2, 3)), tensorplay.tensor((1 + 1e-10, 3, 4))) tensor([ True, False, False]) >>> tensorplay.isclose(tensorplay.tensor((float('inf'), 4)), tensorplay.tensor((float('inf'), 6)), rtol=.5) tensor([True, True])
isfinite
functionFull reference ↗- tensorplay.functional.isfinite(input) Tensor[source]
Returns a new tensor with boolean elements representing if each element is finite or not.
Real values are finite when they are not NaN, negative infinity, or infinity. Complex values are finite when both their real and imaginary parts are finite.
- Parameters:
input (Tensor) – the input tensor.
- Returns:
A boolean tensor that is True where
inputis finite and False elsewhere
Example:
>>> tensorplay.isfinite(tensorplay.tensor([1, float('inf'), 2, float('-inf'), float('nan')])) tensor([True, False, True, False, False])
isin
functionFull reference ↗- tensorplay.functional.isin(elements, test_elements, *, assume_unique=False, invert=False) Tensor[source]
Tests if each element of
elementsis intest_elements. Returns a boolean tensor of the same shape aselementsthat is True for elements intest_elementsand False otherwise.Note
One of
elementsortest_elementscan be a scalar, but not both.- Parameters:
test_elements (Tensor or Scalar) – Values against which to test for each input element
assume_unique (bool, optional) – If True, assumes both
elementsandtest_elementscontain unique elements, which can speed up the calculation. Default: Falseinvert (bool, optional) – If True, inverts the boolean return tensor, resulting in True values for elements not in
test_elements. Default: False
- Returns:
A boolean tensor of the same shape as
elementsthat is True for elements intest_elementsand False otherwise
Example
>>> tensorplay.isin(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([2, 3])) tensor([[False, True], [ True, False]])
isinf
functionFull reference ↗- tensorplay.functional.isinf(input) Tensor[source]
Tests if each element of
inputis infinite (positive or negative infinity) or not.Note
Complex values are infinite when their real or imaginary part is infinite.
- Parameters:
input (Tensor) – the input tensor.
- Returns:
A boolean tensor that is True where
inputis infinite and False elsewhere
Example:
>>> tensorplay.isinf(tensorplay.tensor([1, float('inf'), 2, float('-inf'), float('nan')])) tensor([False, True, False, True, False])
isnan
functionFull reference ↗- tensorplay.functional.isnan(input) Tensor[source]
Returns a new tensor with boolean elements representing if each element of
inputis NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.- Parameters:
input (Tensor) – the input tensor.
- Returns:
A boolean tensor that is True where
inputis NaN and False elsewhere
Example:
>>> tensorplay.isnan(tensorplay.tensor([1, float('nan'), 2])) tensor([False, True, False])
isneginf
functionFull reference ↗- tensorplay.functional.isneginf(input, *, out=None) Tensor[source]
Tests if each element of
inputis negative infinity or not.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([-float('inf'), float('inf'), 1.2]) >>> tensorplay.isneginf(a) tensor([ True, False, False])
isposinf
functionFull reference ↗- tensorplay.functional.isposinf(input, *, out=None) Tensor[source]
Tests if each element of
inputis positive infinity or not.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([-float('inf'), float('inf'), 1.2]) >>> tensorplay.isposinf(a) tensor([False, True, False])
isreal
functionFull reference ↗- tensorplay.functional.isreal(input) Tensor[source]
Returns a new tensor with boolean elements representing if each element of
inputis real-valued or not. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.- Parameters:
input (Tensor) – the input tensor.
- Returns:
A boolean tensor that is True where
inputis real and False elsewhere
Example:
>>> tensorplay.isreal(tensorplay.tensor([1, 1+1j, 2+0j])) tensor([True, False, True])
istft
functionFull reference ↗- tensorplay.functional.istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=True, length=None, return_complex=False)[source]
kaiser_window
functionFull reference ↗- tensorplay.functional.kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Computes the Kaiser window with window length
window_lengthand shape parameterbeta.Let I_0 be the zeroth order modified Bessel function of the first kind (see
tensorplay.i0()) andN = L - 1ifperiodicis False andLifperiodicis True, whereLis thewindow_length. This function computes:Calling
tensorplay.kaiser_window(L, B, periodic=True)is equivalent to callingtensorplay.kaiser_window(L + 1, B, periodic=False)[:-1]). Theperiodicargument is intended as a helpful shorthand to produce a periodic window as input to functions liketensorplay.stft().Note
If
window_lengthis one, then the returned window is a single element tensor containing a one.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned window tensor. Onlytensorplay.strided(dense layout) is supported.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
kl_div
functionFull reference ↗- tensorplay.functional.kl_div(input, target)[source]
kron
functionFull reference ↗- tensorplay.functional.kron(input, other, *, out=None) Tensor[source]
Computes the Kronecker product, denoted by , of
inputandother.If
inputis a tensor andotheris a tensor, the result will be a tensor with the following entries:where for . If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
Supports real-valued and complex-valued inputs.
Note
This function generalizes the typical definition of the Kronecker product for two matrices to two tensors, as described above. When
inputis a matrix andotheris a matrix, the result will be a block matrix:where
inputis andotheris .- Parameters:
- Keyword Arguments:
out (Tensor, optional) – The output tensor. Ignored if
None. Default:None
Examples:
>>> mat1 = tensorplay.eye(2) >>> mat2 = tensorplay.ones(2, 2) >>> tensorplay.kron(mat1, mat2) tensor([[1., 1., 0., 0.], [1., 1., 0., 0.], [0., 0., 1., 1.], [0., 0., 1., 1.]]) >>> mat1 = tensorplay.eye(2) >>> mat2 = tensorplay.arange(1, 5).reshape(2, 2) >>> tensorplay.kron(mat1, mat2) tensor([[1., 2., 0., 0.], [3., 4., 0., 0.], [0., 0., 1., 2.], [0., 0., 3., 4.]])
kthvalue
functionFull reference ↗- tensorplay.functional.kthvalue(input, k, dim=-1, keepdim=False, *, out=None)[source]
laguerre_polynomial_l
functionFull reference ↗- tensorplay.functional.laguerre_polynomial_l(x, n)[source]
lcm_
functionFull reference ↗- tensorplay.functional.lcm_(input, other)[source]
lcm
functionFull reference ↗- tensorplay.functional.lcm(input, other, *, out=None) Tensor[source]
Computes the element-wise least common multiple (LCM) of
inputandother.Both
inputandothermust have integer types.Note
This defines and .
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([5, 10, 15]) >>> b = tensorplay.tensor([3, 4, 5]) >>> tensorplay.lcm(a, b) tensor([15, 20, 15]) >>> c = tensorplay.tensor([3]) >>> tensorplay.lcm(a, c) tensor([15, 30, 15])
ldexp_
functionFull reference ↗- tensorplay.functional.ldexp_(input, other)[source]
ldexp
functionFull reference ↗- tensorplay.functional.ldexp(input, other, *, out=None) Tensor[source]
Multiplies
inputby 2 **other.Typically this function is used to construct floating point numbers by multiplying mantissas in
inputwith integral powers of two created from the exponents inother.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.ldexp(tensorplay.tensor([1.]), tensorplay.tensor([1])) tensor([2.]) >>> tensorplay.ldexp(tensorplay.tensor([1.0]), tensorplay.tensor([1, 2, 3, 4])) tensor([ 2., 4., 8., 16.])
le
functionFull reference ↗- tensorplay.functional.le(input, other, *, out=None) Tensor[source]
Computes element-wise.
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis less than or equal tootherand False elsewhere
Example:
>>> tensorplay.le(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[True, False], [True, True]])
legendre_polynomial_p
functionFull reference ↗- tensorplay.functional.legendre_polynomial_p(x, n)[source]
lerp
functionFull reference ↗- tensorplay.functional.lerp(input, end, weight, *, out=None)[source]
Does a linear interpolation of two tensors
start(given byinput) andendbased on a scalar or tensorweightand returns the resultingouttensor.The shapes of
startandendmust be broadcastable. Ifweightis a tensor, then the shapes ofweight,start, andendmust be broadcastable.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> start = tensorplay.arange(1., 5.) >>> end = tensorplay.empty(4).fill_(10) >>> start tensor([ 1., 2., 3., 4.]) >>> end tensor([ 10., 10., 10., 10.]) >>> tensorplay.lerp(start, end, 0.5) tensor([ 5.5000, 6.0000, 6.5000, 7.0000]) >>> tensorplay.lerp(start, end, tensorplay.full_like(start, 0.5)) tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
less_equal
functionFull reference ↗less
functionFull reference ↗lgamma
functionFull reference ↗- tensorplay.functional.lgamma(input, *, out=None) Tensor[source]
Computes the natural logarithm of the absolute value of the gamma function on
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.arange(0.5, 2, 0.5) >>> tensorplay.lgamma(a) tensor([ 0.5724, 0.0000, -0.1208])
linspace
functionFull reference ↗- tensorplay.functional.linspace(start, end, steps, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Creates a one-dimensional tensor of size
stepswhose values are evenly spaced fromstarttoend, inclusive. That is, the value are:- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (tensorplay.dtype, optional) – the data type to perform the computation in. Default: if None, uses the global default dtype (see tensorplay.get_default_dtype()) when both
startandendare real, and corresponding complex dtype when either is complex.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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:
>>> tensorplay.linspace(3, 10, steps=5) tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000]) >>> tensorplay.linspace(-10, 10, steps=5) tensor([-10., -5., 0., 5., 10.]) >>> tensorplay.linspace(start=-10, end=10, steps=5) tensor([-10., -5., 0., 5., 10.]) >>> tensorplay.linspace(start=-10, end=10, steps=1) tensor([-10.])
log_
functionFull reference ↗- tensorplay.functional.log_(input)[source]
log_ndtr
functionFull reference ↗- tensorplay.functional.log_ndtr(input)[source]
log
functionFull reference ↗- tensorplay.functional.log(input, *, out=None) Tensor[source]
Returns a new tensor with the natural logarithm of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(5) * 5 >>> a tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]) >>> tensorplay.log(a) tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
log10_
functionFull reference ↗- tensorplay.functional.log10_(input)[source]
log10
functionFull reference ↗- tensorplay.functional.log10(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the logarithm to the base 10 of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(5) >>> a tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251]) >>> tensorplay.log10(a) tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
log1p_
functionFull reference ↗- tensorplay.functional.log1p_(input)[source]
log1p
functionFull reference ↗- tensorplay.functional.log1p(input, *, out=None) Tensor[source]
Returns a new tensor with the natural logarithm of (1 +
input).Note
This function is more accurate than
tensorplay.log()for small values ofinput- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(5) >>> a tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492]) >>> tensorplay.log1p(a) tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
log2_
functionFull reference ↗- tensorplay.functional.log2_(input)[source]
log2
functionFull reference ↗- tensorplay.functional.log2(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the logarithm to the base 2 of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.rand(5) >>> a tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490]) >>> tensorplay.log2(a) tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
logaddexp
functionFull reference ↗- tensorplay.functional.logaddexp(input, other, *, out=None) Tensor[source]
Logarithm of the sum of exponentiations of the inputs.
Calculates pointwise . This function is useful in statistics where the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the logarithm of the calculated probability is stored. This function allows adding probabilities stored in such a fashion.
This op should be disambiguated with
tensorplay.logsumexp()which performs a reduction on a single tensor.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.logaddexp(tensorplay.tensor([-1.0]), tensorplay.tensor([-1.0, -2, -3])) tensor([-0.3069, -0.6867, -0.8731]) >>> tensorplay.logaddexp(tensorplay.tensor([-100.0, -200, -300]), tensorplay.tensor([-1.0, -2, -3])) tensor([-1., -2., -3.]) >>> tensorplay.logaddexp(tensorplay.tensor([1.0, 2000, 30000]), tensorplay.tensor([-1.0, -2, -3])) tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
logaddexp2
functionFull reference ↗logcumsumexp
functionFull reference ↗- tensorplay.functional.logcumsumexp(input, dim, *, out=None) Tensor[source]
Returns the logarithm of the cumulative summation of the exponentiation of elements of
inputin the dimensiondim.For summation index given by dim and other indices , the result is
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(10) >>> tensorplay.logcumsumexp(a, dim=0) tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811, 1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
logdet
functionFull reference ↗- tensorplay.functional.logdet(input) Tensor[source]
Calculates log determinant of a square matrix or batches of square matrices.
It returns
-infif the input has a determinant of zero, andNaNif it has a negative determinant.Note
Backward through
logdet()internally uses SVD results wheninputis not invertible. In this case, double backward throughlogdet()will be unstable in wheninputdoesn’t have distinct singular values. Seetensorplay.linalg.svd()for details.See also
tensorplay.linalg.slogdet()computes the sign (resp. angle) and natural logarithm of the absolute value of the determinant of real-valued (resp. complex) square matrices.- Parameters:
input (Tensor) – the input tensor of size
(*, n, n)where*is zero or more batch dimensions.
Example:
>>> A = tensorplay.randn(3, 3) >>> tensorplay.det(A) tensor(0.2611) >>> tensorplay.logdet(A) tensor(-1.3430) >>> A tensor([[[ 0.9254, -0.6213], [-0.5787, 1.6843]], [[ 0.3242, -0.9665], [ 0.4539, -0.0887]], [[ 1.1336, -0.4025], [-0.7089, 0.9032]]]) >>> A.det() tensor([1.1990, 0.4099, 0.7386]) >>> A.det().log() tensor([ 0.1815, -0.8917, -0.3031])
logical_and
functionFull reference ↗- tensorplay.functional.logical_and(input, other, *, out=None) Tensor[source]
Computes the element-wise logical AND of the given input tensors. Zeros are treated as
Falseand nonzeros are treated asTrue.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.logical_and(tensorplay.tensor([True, False, True]), tensorplay.tensor([True, False, False])) tensor([ True, False, False]) >>> a = tensorplay.tensor([0, 1, 10, 0], dtype=tensorplay.int8) >>> b = tensorplay.tensor([4, 0, 1, 0], dtype=tensorplay.int8) >>> tensorplay.logical_and(a, b) tensor([False, False, True, False]) >>> tensorplay.logical_and(a.double(), b.double()) tensor([False, False, True, False]) >>> tensorplay.logical_and(a.double(), b) tensor([False, False, True, False]) >>> tensorplay.logical_and(a, b, out=tensorplay.empty(4, dtype=tensorplay.bool)) tensor([False, False, True, False])
logical_not
functionFull reference ↗- tensorplay.functional.logical_not(input, *, out=None) Tensor[source]
Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool dtype. If the input tensor is not a bool tensor, zeros are treated as
Falseand non-zeros are treated asTrue.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.logical_not(tensorplay.tensor([True, False])) tensor([False, True]) >>> tensorplay.logical_not(tensorplay.tensor([0, 1, -10], dtype=tensorplay.int8)) tensor([ True, False, False]) >>> tensorplay.logical_not(tensorplay.tensor([0., 1.5, -10.], dtype=tensorplay.double)) tensor([ True, False, False]) >>> tensorplay.logical_not(tensorplay.tensor([0., 1., -10.], dtype=tensorplay.double), out=tensorplay.empty(3, dtype=tensorplay.int16)) tensor([1, 0, 0], dtype=tensorplay.int16)
logical_or
functionFull reference ↗- tensorplay.functional.logical_or(input, other, *, out=None) Tensor[source]
Computes the element-wise logical OR of the given input tensors. Zeros are treated as
Falseand nonzeros are treated asTrue.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.logical_or(tensorplay.tensor([True, False, True]), tensorplay.tensor([True, False, False])) tensor([ True, False, True]) >>> a = tensorplay.tensor([0, 1, 10, 0], dtype=tensorplay.int8) >>> b = tensorplay.tensor([4, 0, 1, 0], dtype=tensorplay.int8) >>> tensorplay.logical_or(a, b) tensor([ True, True, True, False]) >>> tensorplay.logical_or(a.double(), b.double()) tensor([ True, True, True, False]) >>> tensorplay.logical_or(a.double(), b) tensor([ True, True, True, False]) >>> tensorplay.logical_or(a, b, out=tensorplay.empty(4, dtype=tensorplay.bool)) tensor([ True, True, True, False])
logical_xor
functionFull reference ↗- tensorplay.functional.logical_xor(input: Tensor, other: Tensor, *, out: Tensor | None) Tensor[source]
Computes the element-wise logical XOR of the given input tensors. Zeros are treated as
Falseand nonzeros are treated asTrue.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.logical_xor(tensorplay.tensor([True, False, True]), tensorplay.tensor([True, False, False])) tensor([False, False, True]) >>> a = tensorplay.tensor([0, 1, 10, 0], dtype=tensorplay.int8) >>> b = tensorplay.tensor([4, 0, 1, 0], dtype=tensorplay.int8) >>> tensorplay.logical_xor(a, b) tensor([ True, True, False, False]) >>> tensorplay.logical_xor(a.double(), b.double()) tensor([ True, True, False, False]) >>> tensorplay.logical_xor(a.double(), b) tensor([ True, True, False, False]) >>> tensorplay.logical_xor(a, b, out=tensorplay.empty(4, dtype=tensorplay.bool)) tensor([ True, True, False, False])
logit_
functionFull reference ↗- tensorplay.functional.logit_(input, eps=None)[source]
logit
functionFull reference ↗logspace
functionFull reference ↗- tensorplay.functional.logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Creates a one-dimensional tensor of size
stepswhose values are evenly spaced from to , inclusive, on a logarithmic scale with basebase. That is, the values are:- Parameters:
start (float or Tensor) – the starting value for the set of points. If Tensor, it must be 0-dimensional
end (float or Tensor) – the ending value for the set of points. If Tensor, it must be 0-dimensional
steps (int) – size of the constructed tensor
base (float, optional) – base of the logarithm function. Default:
10.0.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (tensorplay.dtype, optional) – the data type to perform the computation in. Default: if None, uses the global default dtype (see tensorplay.get_default_dtype()) when both
startandendare real, and corresponding complex dtype when either is complex.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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:
>>> tensorplay.logspace(start=-10, end=10, steps=5) tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10]) >>> tensorplay.logspace(start=0.1, end=1.0, steps=5) tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000]) >>> tensorplay.logspace(start=0.1, end=1.0, steps=1) tensor([1.2589]) >>> tensorplay.logspace(start=2, end=2, steps=1, base=2) tensor([4.0])
logsumexp
functionFull reference ↗- tensorplay.functional.logsumexp(input, dim, keepdim=False, *, out=None)[source]
Returns the log of summed exponentials of each row of the
inputtensor in the given dimensiondim. The computation is numerically stabilized.For summation index given by dim and other indices , the result is
If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(3, 3) >>> tensorplay.logsumexp(a, 1) tensor([1.4907, 1.0593, 1.5696]) >>> tensorplay.dist(tensorplay.logsumexp(a, 1), tensorplay.log(tensorplay.sum(tensorplay.exp(a), 1))) tensor(1.6859e-07)
lstm_cell
functionFull reference ↗- tensorplay.functional.lstm_cell(input, hx, cx, w_ih, w_hh, b_ih=None, b_hh=None)[source]
lstm
functionFull reference ↗- tensorplay.functional.lstm(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False)[source]
lt
functionFull reference ↗- tensorplay.functional.lt(input, other, *, out=None) Tensor[source]
Computes element-wise.
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis less thanotherand False elsewhere
Example:
>>> tensorplay.lt(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, False], [True, False]])
lu_solve
functionFull reference ↗- tensorplay.functional.lu_solve(b, LU_data, LU_pivots, *, out=None) Tensor[source]
Returns the LU solve of the linear system using the partially pivoted LU factorization of A from
lu_factor().This function supports
float,double,cfloatandcdoubledtypes forinput.Warning
tensorplay.lu_solve()is deprecated in favor oftensorplay.linalg.lu_solve().X = tensorplay.lu_solve(B, LU, pivots)should be replaced withX = linalg.lu_solve(LU, pivots, B)- Parameters:
b (Tensor) – the RHS tensor of size , where is zero or more batch dimensions.
LU_data (Tensor) – the pivoted LU factorization of A from
lu_factor()of size , where is zero or more batch dimensions.LU_pivots (IntTensor) – the pivots of the LU factorization from
lu_factor()of size , where is zero or more batch dimensions. The batch dimensions ofLU_pivotsmust be equal to the batch dimensions ofLU_data.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> A = tensorplay.randn(2, 3, 3) >>> b = tensorplay.randn(2, 3, 1) >>> LU, pivots = tensorplay.linalg.lu_factor(A) >>> x = tensorplay.lu_solve(b, LU, pivots) >>> tensorplay.dist(A @ x, b) tensor(1.00000e-07 * 2.8312)
lu_unpack
functionFull reference ↗- tensorplay.functional.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None)[source]
Unpacks the LU decomposition returned by
lu_factor()into the P, L, U matrices.See also
lu()returns the matrices from the LU decomposition. Its gradient formula is more efficient than that of doinglu_factor()followed bylu_unpack().- Parameters:
LU_data (Tensor) – the packed LU factorization data
LU_pivots (Tensor) – the packed LU factorization pivots
unpack_data (bool) – flag indicating if the data should be unpacked. If
False, then the returnedLandUare empty tensors. Default:Trueunpack_pivots (bool) – flag indicating if the pivots should be unpacked into a permutation matrix
P. IfFalse, then the returnedPis an empty tensor. Default:True
- Keyword Arguments:
out (tuple, optional) – output tuple of three tensors. Ignored if None.
- Returns:
A namedtuple
(P, L, U)
Examples:
>>> A = tensorplay.randn(2, 3, 3) >>> LU, pivots = tensorplay.linalg.lu_factor(A) >>> P, L, U = tensorplay.lu_unpack(LU, pivots) >>> # We can recover A from the factorization >>> A_ = P @ L @ U >>> tensorplay.allclose(A, A_) True >>> # LU factorization of a rectangular matrix: >>> A = tensorplay.randn(2, 3, 2) >>> LU, pivots = tensorplay.linalg.lu_factor(A) >>> P, L, U = tensorplay.lu_unpack(LU, pivots) >>> # P, L, U are the same as returned by linalg.lu >>> P_, L_, U_ = tensorplay.linalg.lu(A) >>> tensorplay.allclose(P, P_) and tensorplay.allclose(L, L_) and tensorplay.allclose(U, U_) True
margin_ranking_loss
functionFull reference ↗- tensorplay.functional.margin_ranking_loss(input1, input2, target, margin=0)[source]
masked_fill
functionFull reference ↗- tensorplay.functional.masked_fill(input, mask, value)[source]
masked_select
functionFull reference ↗- tensorplay.functional.masked_select(input, mask, *, out=None) Tensor[source]
Returns a new 1-D tensor which indexes the
inputtensor according to the boolean maskmaskwhich is a BoolTensor.The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable.Note
The returned tensor does not use the same storage as the original tensor
- Parameters:
input (Tensor) – the input tensor.
mask (BoolTensor) – the tensor containing the binary mask to index with
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.randn(3, 4) >>> x tensor([[ 0.3552, -2.3825, -0.8297, 0.3477], [-1.2035, 1.2252, 0.5002, 0.6248], [ 0.1307, -2.0608, 0.1244, 2.0139]]) >>> mask = x.ge(0.5) >>> mask tensor([[False, False, False, False], [False, True, True, True], [False, False, False, True]]) >>> tensorplay.masked_select(x, mask) tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
matmul
functionFull reference ↗- tensorplay.functional.matmul(input, other, *, out=None) Tensor[source]
Matrix product of two tensors.
The behavior depends on the dimensionality of the tensors as follows:
If both tensors are 1-dimensional, the dot product (scalar) is returned.
If both arguments are 2-dimensional, the matrix-matrix product is returned.
If the first argument is 1-dimensional and the second argument is 2-dimensional, a 1 is prepended to its dimension for the purpose of the matrix multiply. After the matrix multiply, the prepended dimension is removed.
If the first argument is 2-dimensional and the second argument is 1-dimensional, the matrix-vector product is returned.
If both arguments are at least 1-dimensional and at least one argument is N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the batched matrix multiply and removed after. If the second argument is 1-dimensional, a 1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
The first N-2 dimensions of each argument, the batch dimensions, are broadcast (and thus must be broadcastable). The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
For example, if
inputis a tensor andotheris a tensor, the batch dimensions are and , and the matrix dimensions are and .outwill be a tensor.
This operation has support for arguments with sparse layouts. In particular the matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions as
tensorplay.mm()Warning
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported, or may not have autograd support. If you notice missing functionality please open a feature request.
This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
Note
The 1-dimensional dot product version of this function does not support an
outparameter.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> # vector x vector >>> tensor1 = tensorplay.randn(3) >>> tensor2 = tensorplay.randn(3) >>> tensorplay.matmul(tensor1, tensor2).size() tensorplay.Size([]) >>> # matrix x vector >>> tensor1 = tensorplay.randn(3, 4) >>> tensor2 = tensorplay.randn(4) >>> tensorplay.matmul(tensor1, tensor2).size() tensorplay.Size([3]) >>> # batched matrix x broadcasted vector >>> tensor1 = tensorplay.randn(10, 3, 4) >>> tensor2 = tensorplay.randn(4) >>> tensorplay.matmul(tensor1, tensor2).size() tensorplay.Size([10, 3]) >>> # batched matrix x batched matrix >>> tensor1 = tensorplay.randn(10, 3, 4) >>> tensor2 = tensorplay.randn(10, 4, 5) >>> tensorplay.matmul(tensor1, tensor2).size() tensorplay.Size([10, 3, 5]) >>> # batched matrix x broadcasted matrix >>> tensor1 = tensorplay.randn(10, 3, 4) >>> tensor2 = tensorplay.randn(4, 5) >>> tensorplay.matmul(tensor1, tensor2).size() tensorplay.Size([10, 3, 5])
matrix_exp
functionFull reference ↗- tensorplay.functional.matrix_exp(A) Tensor[source]
Alias for
tensorplay.linalg.matrix_exp().
matrix_power
functionFull reference ↗- tensorplay.functional.matrix_power(input, n, *, out=None) Tensor[source]
Alias for
tensorplay.linalg.matrix_power()
max_pool1d
functionFull reference ↗- tensorplay.functional.max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False)[source]
max_pool3d
functionFull reference ↗- tensorplay.functional.max_pool3d(input, kernel_size, stride=[], padding=[0, 0, 0], dilation=[1, 1, 1], ceil_mode=False)[source]
maximum
functionFull reference ↗- tensorplay.functional.maximum(input, other, *, out=None) Tensor[source]
Computes the element-wise maximum of
inputandother.Note
If one of the elements being compared is a NaN, then that element is returned.
maximum()is not supported for tensors with complex dtypes.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor((1, 2, -1)) >>> b = tensorplay.tensor((3, 0, 4)) >>> tensorplay.maximum(a, b) tensor([3, 2, 4])
mean
functionFull reference ↗- tensorplay.functional.mean(input, *, dtype=None) Tensor[source]
Note
If the input tensor is empty,
tensorplay.mean()returnsnan. This behavior is consistent with NumPy and follows the definition that the mean over an empty set is undefined.Returns the mean value of all elements in the
inputtensor. Input must be floating point or complex.- Parameters:
input (Tensor) – the input tensor, either of floating point or complex dtype
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = tensorplay.randn(1, 3) >>> a tensor([[ 0.2294, -0.5481, 1.3288]]) >>> tensorplay.mean(a) tensor(0.3367)Returns the mean value of each row of the
inputtensor in the given dimensiondim. Ifdimis a list of dimensions, reduce over all of them.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.out (Tensor, optional) – the output tensor.
See also
tensorplay.nanmean()computes the mean value of non-NaN elements.Example:
>>> a = tensorplay.randn(4, 4) >>> a tensor([[-0.3841, 0.6320, 0.4254, -0.7384], [-0.9644, 1.0131, -0.6549, -1.4279], [-0.2951, -1.3350, -0.7694, 0.5600], [ 1.0842, -0.9580, 0.3623, 0.2343]]) >>> tensorplay.mean(a, 1) tensor([-0.0163, -0.5085, -0.4599, 0.1807]) >>> tensorplay.mean(a, 1, True) tensor([[-0.0163], [-0.5085], [-0.4599], [ 0.1807]])
median
functionFull reference ↗- tensorplay.functional.median(input, dim=None, keepdim=False)[source]
meshgrid
functionFull reference ↗- tensorplay.functional.meshgrid(tensors, indexing='ij')[source]
minimum
functionFull reference ↗- tensorplay.functional.minimum(input, other, *, out=None) Tensor[source]
Computes the element-wise minimum of
inputandother.Note
If one of the elements being compared is a NaN, then that element is returned.
minimum()is not supported for tensors with complex dtypes.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor((1, 2, -1)) >>> b = tensorplay.tensor((3, 0, 4)) >>> tensorplay.minimum(a, b) tensor([1, 0, -1])
miopen_batch_norm
functionFull reference ↗- tensorplay.functional.miopen_batch_norm(input, weight, bias, running_mean, running_var, training, exponential_average_factor, epsilon)[source]
miopen_convolution_add_relu
functionFull reference ↗- tensorplay.functional.miopen_convolution_add_relu(input, weight, z, alpha, bias, stride, padding, dilation, groups)[source]
miopen_convolution_relu
functionFull reference ↗- tensorplay.functional.miopen_convolution_relu(input, weight, bias, stride, padding, dilation, groups)[source]
miopen_convolution_transpose
functionFull reference ↗- tensorplay.functional.miopen_convolution_transpose(input, weight, bias, padding, output_padding, stride, dilation, groups, benchmark, deterministic)[source]
miopen_convolution
functionFull reference ↗- tensorplay.functional.miopen_convolution(input, weight, bias, padding, stride, dilation, groups, benchmark, deterministic)[source]
miopen_ctc_loss
functionFull reference ↗- tensorplay.functional.miopen_ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, deterministic, zero_infinity)[source]
miopen_depthwise_convolution
functionFull reference ↗- tensorplay.functional.miopen_depthwise_convolution(input, weight, bias, padding, stride, dilation, groups, benchmark, deterministic)[source]
miopen_rnn
functionFull reference ↗- tensorplay.functional.miopen_rnn(input, weight, weight_stride0, hx, cx, mode, hidden_size, num_layers, batch_first, dropout, train, bidirectional, batch_sizes, dropout_state)[source]
mkldnn_adaptive_avg_pool2d
functionFull reference ↗- tensorplay.functional.mkldnn_adaptive_avg_pool2d(input, output_size, *, out=None)[source]
mkldnn_convolution
functionFull reference ↗- tensorplay.functional.mkldnn_convolution(input, weight, bias, padding, stride, dilation, groups)[source]
mkldnn_linear_backward_weights
functionFull reference ↗- tensorplay.functional.mkldnn_linear_backward_weights(grad_output, input, weight, bias_defined)[source]
mkldnn_max_pool2d
functionFull reference ↗- tensorplay.functional.mkldnn_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False)[source]
mkldnn_max_pool3d
functionFull reference ↗- tensorplay.functional.mkldnn_max_pool3d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False)[source]
mkldnn_rnn_layer
functionFull reference ↗- tensorplay.functional.mkldnn_rnn_layer(input, weight0, weight1, weight2, weight3, hx_, cx_, reverse, batch_sizes, mode, hidden_size, num_layers, has_biases, bidirectional, batch_first, train)[source]
mm
functionFull reference ↗- tensorplay.functional.mm(input, mat2, out_dtype=None, *, out=None) Tensor[source]
Performs a matrix multiplication of the matrices
inputandmat2.If
inputis a tensor,mat2is a tensor,outwill be a tensor.Note
This function does not broadcast. For broadcasting matrix products, see
tensorplay.matmul().Supports strided and sparse 2-D tensors as inputs, autograd with respect to strided inputs.
This operation has support for arguments with sparse layouts. If
outis provided its layout will be used. Otherwise, the result layout will be deduced from that ofinput.Warning
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported, or may not have autograd support. If you notice missing functionality please open a feature request.
This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will use different precision for backward.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> mat1 = tensorplay.randn(2, 3) >>> mat2 = tensorplay.randn(3, 3) >>> tensorplay.mm(mat1, mat2) tensor([[ 0.4851, 0.5037, -0.3633], [-0.0760, -3.6705, 2.4784]])
mode
functionFull reference ↗- tensorplay.functional.mode(input, dim=-1, keepdim=False, *, out=None)[source]
modified_bessel_i0
functionFull reference ↗- tensorplay.functional.modified_bessel_i0(input)[source]
modified_bessel_i1
functionFull reference ↗- tensorplay.functional.modified_bessel_i1(input)[source]
modified_bessel_k0
functionFull reference ↗- tensorplay.functional.modified_bessel_k0(input)[source]
modified_bessel_k1
functionFull reference ↗- tensorplay.functional.modified_bessel_k1(input)[source]
moveaxis
functionFull reference ↗- tensorplay.functional.moveaxis(input, source, destination) Tensor[source]
Alias for
tensorplay.movedim().This function is equivalent to NumPy’s moveaxis function.
Examples:
>>> t = tensorplay.randn(3,2,1) >>> t tensor([[[-0.3362], [-0.8437]], [[-0.9627], [ 0.1727]], [[ 0.5173], [-0.1398]]]) >>> tensorplay.moveaxis(t, 1, 0).shape tensorplay.Size([2, 3, 1]) >>> tensorplay.moveaxis(t, 1, 0) tensor([[[-0.3362], [-0.9627], [ 0.5173]], [[-0.8437], [ 0.1727], [-0.1398]]]) >>> tensorplay.moveaxis(t, (1, 2), (0, 1)).shape tensorplay.Size([2, 1, 3]) >>> tensorplay.moveaxis(t, (1, 2), (0, 1)) tensor([[[-0.3362, -0.9627, 0.5173]], [[-0.8437, 0.1727, -0.1398]]])
movedim
functionFull reference ↗- tensorplay.functional.movedim(input, source, destination) Tensor[source]
Moves the dimension(s) of
inputat the position(s) insourceto the position(s) indestination.Other dimensions of
inputthat are not explicitly moved remain in their original order and appear at the positions not specified indestination.- Parameters:
Examples:
>>> t = tensorplay.randn(3,2,1) >>> t tensor([[[-0.3362], [-0.8437]], [[-0.9627], [ 0.1727]], [[ 0.5173], [-0.1398]]]) >>> tensorplay.movedim(t, 1, 0).shape tensorplay.Size([2, 3, 1]) >>> tensorplay.movedim(t, 1, 0) tensor([[[-0.3362], [-0.9627], [ 0.5173]], [[-0.8437], [ 0.1727], [-0.1398]]]) >>> tensorplay.movedim(t, (1, 2), (0, 1)).shape tensorplay.Size([2, 1, 3]) >>> tensorplay.movedim(t, (1, 2), (0, 1)) tensor([[[-0.3362, -0.9627, 0.5173]], [[-0.8437, 0.1727, -0.1398]]])
msort
functionFull reference ↗- tensorplay.functional.msort(input: Tensor, *, out: Tensor | None) Tensor[source]
Sorts the elements of the
inputtensor along its first dimension in ascending order by value.Note
tensorplay.msort(t) is equivalent to tensorplay.sort(t, dim=0)[0]. See also
tensorplay.sort().- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> t = tensorplay.randn(3, 4) >>> t tensor([[-0.1321, 0.4370, -1.2631, -1.1289], [-2.0527, -1.1250, 0.2275, 0.3077], [-0.0881, -0.1259, -0.5495, 1.0284]]) >>> tensorplay.msort(t) tensor([[-2.0527, -1.1250, -1.2631, -1.1289], [-0.1321, -0.1259, -0.5495, 0.3077], [-0.0881, 0.4370, 0.2275, 1.0284]])
mul
functionFull reference ↗- tensorplay.functional.mul(input, other, *, out=None) Tensor[source]
Multiplies
inputbyother.Supports broadcasting to a common shape, type promotion, and integer, float, and complex inputs.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Examples:
>>> a = tensorplay.randn(3) >>> a tensor([ 0.2015, -0.4255, 2.6087]) >>> tensorplay.mul(a, 100) tensor([ 20.1494, -42.5491, 260.8663]) >>> b = tensorplay.randn(4, 1) >>> b tensor([[ 1.1207], [-0.3137], [ 0.0700], [ 0.8378]]) >>> c = tensorplay.randn(1, 4) >>> c tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]]) >>> tensorplay.mul(b, c) tensor([[ 0.5767, 0.1363, -0.5877, 2.5083], [-0.1614, -0.0382, 0.1645, -0.7021], [ 0.0360, 0.0085, -0.0367, 0.1567], [ 0.4312, 0.1019, -0.4394, 1.8753]])
multinomial
functionFull reference ↗- tensorplay.functional.multinomial(input, num_samples, replacement=False, *, generator=None, out=None) LongTensor[source]
Returns a tensor where each row contains
num_samplesindices sampled from the multinomial (a stricter definition would be multivariate, refer totensorplay.distributions.multinomial.Multinomialfor more details) probability distribution located in the corresponding row of tensorinput.Note
The rows of
inputdo not need to sum to one (in which case we use the values as weights), but must be non-negative, finite and have a non-zero sum.Indices are ordered from left to right according to when each was sampled (first samples are placed in first column).
If
inputis a vector,outis a vector of sizenum_samples.If
inputis a matrix with m rows,outis an matrix of shape .If replacement is
True, samples are drawn with replacement.If not, they are drawn without replacement, which means that when a sample index is drawn for a row, it cannot be drawn again for that row.
Note
When drawn without replacement,
num_samplesmust be lower than number of non-zero elements ininput(or the min number of non-zero elements in each row ofinputif it is a matrix).- Parameters:
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for samplingout (Tensor, optional) – the output tensor.
Example:
>>> weights = tensorplay.tensor([0, 10, 3, 0], dtype=tensorplay.float) # create a tensor of weights >>> tensorplay.multinomial(weights, 2) tensor([1, 2]) >>> tensorplay.multinomial(weights, 5) # ERROR! RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement >>> tensorplay.multinomial(weights, 4, replacement=True) tensor([ 2, 1, 1, 1])
multiply
functionFull reference ↗- tensorplay.functional.multiply(input, other, *, out=None)[source]
Alias for
tensorplay.mul().
mv
functionFull reference ↗- tensorplay.functional.mv(input, vec, *, out=None) Tensor[source]
Performs a matrix-vector product of the matrix
inputand the vectorvec.If
inputis a tensor,vecis a 1-D tensor of size ,outwill be 1-D of size .Note
This function does not broadcast.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> mat = tensorplay.randn(2, 3) >>> vec = tensorplay.randn(3) >>> tensorplay.mv(mat, vec) tensor([ 1.0404, -0.6361])
mvlgamma
functionFull reference ↗nan_to_num_
functionFull reference ↗- tensorplay.functional.nan_to_num_(input, nan=0.0, posinf=None, neginf=None)[source]
nan_to_num
functionFull reference ↗- tensorplay.functional.nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) Tensor[source]
Replaces
NaN, positive infinity, and negative infinity values ininputwith the values specified bynan,posinf, andneginf, respectively. By default,NaNs are replaced with zero, positive infinity is replaced with the greatest finite value representable byinput’s dtype, and negative infinity is replaced with the least finite value representable byinput’s dtype.- Parameters:
input (Tensor) – the input tensor.
nan (Number, optional) – the value to replace
NaNs with. Default is zero.posinf (Number, optional) – if a Number, the value to replace positive infinity values with. If None, positive infinity values are replaced with the greatest finite value representable by
input’s dtype. Default is None.neginf (Number, optional) – if a Number, the value to replace negative infinity values with. If None, negative infinity values are replaced with the lowest finite value representable by
input’s dtype. Default is None.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.tensor([float('nan'), float('inf'), -float('inf'), 3.14]) >>> tensorplay.nan_to_num(x) tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00]) >>> tensorplay.nan_to_num(x, nan=2.0) tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00]) >>> tensorplay.nan_to_num(x, nan=2.0, posinf=1.0) tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
nanmean
functionFull reference ↗- tensorplay.functional.nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) Tensor[source]
Computes the mean of all non-NaN elements along the specified dimensions. Input must be floating point or complex.
This function is identical to
tensorplay.mean()when there are no NaN values in theinputtensor. In the presence of NaN,tensorplay.mean()will propagate the NaN to the output whereastensorplay.nanmean()will ignore the NaN values (tensorplay.nanmean(a) is equivalent to tensorplay.mean(a[~a.isnan()])).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.out (Tensor, optional) – the output tensor.
See also
tensorplay.mean()computes the mean value, propagating NaN.Example:
>>> x = tensorplay.tensor([[tensorplay.nan, 1, 2], [1, 2, 3]]) >>> x.mean() tensor(nan) >>> x.nanmean() tensor(1.8000) >>> x.mean(dim=0) tensor([ nan, 1.5000, 2.5000]) >>> x.nanmean(dim=0) tensor([1.0000, 1.5000, 2.5000]) # If all elements in the reduced dimensions are NaN then the result is NaN >>> tensorplay.tensor([tensorplay.nan]).nanmean() tensor(nan)
nanmedian
functionFull reference ↗- tensorplay.functional.nanmedian(input, dim=None, keepdim=False)[source]
nansum
functionFull reference ↗- tensorplay.functional.nansum(input, *, dtype=None) Tensor[source]
Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = tensorplay.tensor([1., 2., float('nan'), 4.]) >>> tensorplay.nansum(a) tensor(7.)Returns the sum of each row of the
inputtensor in the given dimensiondim, treating Not a Numbers (NaNs) as zero. Ifdimis a list of dimensions, reduce over all of them.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> tensorplay.nansum(tensorplay.tensor([1., float("nan")])) tensor(1.) >>> a = tensorplay.tensor([[1, 2], [3., float("nan")]]) >>> tensorplay.nansum(a) tensor(6.) >>> tensorplay.nansum(a, dim=0) tensor([4., 2.]) >>> tensorplay.nansum(a, dim=1) tensor([3., 3.])
narrow_copy
functionFull reference ↗- tensorplay.functional.narrow_copy(input, dim, start, length, *, out=None) Tensor[source]
Same as
Tensor.narrow()except this returns a copy rather than shared storage. This is primarily for sparse tensors, which do not have a shared-storage narrow method.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> tensorplay.narrow_copy(x, 0, 0, 2) tensor([[ 1, 2, 3], [ 4, 5, 6]]) >>> tensorplay.narrow_copy(x, 1, 1, 2) tensor([[ 2, 3], [ 5, 6], [ 8, 9]]) >>> s = tensorplay.arange(16).reshape(2, 2, 2, 2).to_sparse(2) >>> tensorplay.narrow_copy(s, 0, 0, 1) tensor(indices=tensor([[0, 0], [0, 1]]), values=tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]), size=(1, 2, 2, 2), nnz=2, layout=tensorplay.sparse_coo)See also
tensorplay.narrow()for a non copy variant
narrow
functionFull reference ↗- tensorplay.functional.narrow(input, dim, start, length) Tensor[source]
Returns a new tensor that is a narrowed version of
inputtensor. The dimensiondimis input fromstarttostart + length. The returned tensor andinputtensor share the same underlying storage.- Parameters:
input (Tensor) – the tensor to narrow
dim (int) – the dimension along which to narrow
start (int or Tensor) – index of the element to start the narrowed dimension from. Can be negative, which means indexing from the end of dim. If Tensor, it must be an 0-dim integral Tensor (bools not allowed)
length (int) – length of the narrowed dimension, must be weakly positive
Example:
>>> x = tensorplay.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> tensorplay.narrow(x, 0, 0, 2) tensor([[ 1, 2, 3], [ 4, 5, 6]]) >>> tensorplay.narrow(x, 1, 1, 2) tensor([[ 2, 3], [ 5, 6], [ 8, 9]]) >>> tensorplay.narrow(x, -1, tensorplay.tensor(-1), 1) tensor([[3], [6], [9]])
native_batch_norm
functionFull reference ↗- tensorplay.functional.native_batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps, *, out=None)[source]
native_channel_shuffle
functionFull reference ↗- tensorplay.functional.native_channel_shuffle(input, groups)[source]
native_group_norm
functionFull reference ↗- tensorplay.functional.native_group_norm(input, weight, bias, N, C, HxW, group, eps)[source]
native_layer_norm
functionFull reference ↗- tensorplay.functional.native_layer_norm(input, normalized_shape, weight, bias, eps)[source]
native_norm
functionFull reference ↗- tensorplay.functional.native_norm(input, p=2)[source]
ndtr
functionFull reference ↗- tensorplay.functional.ndtr(input)[source]
ndtri
functionFull reference ↗- tensorplay.functional.ndtri(input)[source]
ne
functionFull reference ↗- tensorplay.functional.ne(input, other, *, out=None) Tensor[source]
Computes element-wise.
The second argument can be a number or a tensor whose shape is broadcastable with the first argument.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A boolean tensor that is True where
inputis not equal tootherand False elsewhere
Example:
>>> tensorplay.ne(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, True], [True, False]])
neg_
functionFull reference ↗- tensorplay.functional.neg_(input)[source]
neg
functionFull reference ↗- tensorplay.functional.neg(input, *, out=None) Tensor[source]
Returns a new tensor with the negative of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(5) >>> a tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940]) >>> tensorplay.neg(a) tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
negative_
functionFull reference ↗- tensorplay.functional.negative_(input)[source]
negative
functionFull reference ↗nextafter
functionFull reference ↗- tensorplay.functional.nextafter(input, other, *, out=None) Tensor[source]
Return the next floating-point value after
inputtowardsother, elementwise.The shapes of
inputandothermust be broadcastable.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> eps = tensorplay.finfo(tensorplay.float32).eps >>> tensorplay.nextafter(tensorplay.tensor([1.0, 2.0]), tensorplay.tensor([2.0, 1.0])) == tensorplay.tensor([eps + 1, 2 - eps]) tensor([True, True])
nonzero_static
functionFull reference ↗- tensorplay.functional.nonzero_static(input, *, size, fill_value=-1, out=None)[source]
nonzero
functionFull reference ↗- tensorplay.functional.nonzero(input, *, out=None, as_tuple=False) LongTensor or tuple of LongTensors[source]
Note
tensorplay.nonzero(..., as_tuple=False)(default) returns a 2-D tensor where each row is the index for a nonzero value.tensorplay.nonzero(..., as_tuple=True)returns a tuple of 1-D index tensors, allowing for advanced indexing, sox[x.nonzero(as_tuple=True)]gives all nonzero values of tensorx. Of the returned tuple, each index tensor contains nonzero indices for a certain dimension.See below for more details on the two behaviors.
When
inputis on CUDA,tensorplay.nonzero()causes host-device synchronization.When
as_tupleisFalse(default):Returns a tensor containing the indices of all non-zero elements of
input. Each row in the result contains the indices of a non-zero element ininput. The result is sorted lexicographically, with the last index changing the fastest (C-style).If
inputhas dimensions, then the resulting indices tensoroutis of size , where is the total number of non-zero elements in theinputtensor.When
as_tupleisTrue:Returns a tuple of 1-D tensors, one for each dimension in
input, each containing the indices (in that dimension) of all non-zero elements ofinput.If
inputhas dimensions, then the resulting tuple contains tensors of size , where is the total number of non-zero elements in theinputtensor.As a special case, when
inputhas zero dimensions and a nonzero scalar value, it is treated as a one-dimensional tensor with one element.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (LongTensor, optional) – the output tensor containing indices
- Returns:
If
as_tupleisFalse, the output tensor containing indices. Ifas_tupleisTrue, one 1-D tensor for each dimension, containing the indices of each nonzero element along that dimension.- Return type:
LongTensor or tuple of LongTensor
Example:
>>> tensorplay.nonzero(tensorplay.tensor([1, 1, 1, 0, 1])) tensor([[ 0], [ 1], [ 2], [ 4]]) >>> tensorplay.nonzero(tensorplay.tensor([[0.6, 0.0, 0.0, 0.0], ... [0.0, 0.4, 0.0, 0.0], ... [0.0, 0.0, 1.2, 0.0], ... [0.0, 0.0, 0.0,-0.4]])) tensor([[ 0, 0], [ 1, 1], [ 2, 2], [ 3, 3]]) >>> tensorplay.nonzero(tensorplay.tensor([1, 1, 1, 0, 1]), as_tuple=True) (tensor([0, 1, 2, 4]),) >>> tensorplay.nonzero(tensorplay.tensor([[0.6, 0.0, 0.0, 0.0], ... [0.0, 0.4, 0.0, 0.0], ... [0.0, 0.0, 1.2, 0.0], ... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True) (tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3])) >>> tensorplay.nonzero(tensorplay.tensor(5), as_tuple=True) (tensor([0]),)
norm_except_dim
functionFull reference ↗- tensorplay.functional.norm_except_dim(v, pow=2, dim=0)[source]
norm
functionFull reference ↗- tensorplay.functional.norm(input, p=2.0, dim=None, keepdim=False)[source]
normal
functionFull reference ↗- tensorplay.functional.normal(mean, std, *, generator=None, out=None) Tensor[source]
Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.
The
meanis a tensor with the mean of each output element’s normal distributionThe
stdis a tensor with the standard deviation of each output element’s normal distributionThe shapes of
meanandstddon’t need to match, but the total number of elements in each tensor need to be the same.Note
When the shapes do not match, the shape of
meanis used as the shape for the returned output tensorNote
When
stdis a CUDA tensor, this function synchronizes its device with the CPU.- Parameters:
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for samplingout (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.normal(mean=tensorplay.arange(1., 11.), std=tensorplay.arange(1, 0, -0.1)) tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134, 8.0505, 8.1408, 9.0563, 10.0566])Similar to the function above, but the means are shared among all drawn elements.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.normal(mean=0.5, std=tensorplay.arange(1., 6.)) tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])Similar to the function above, but the standard deviations are shared among all drawn elements.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor
Example:
>>> tensorplay.normal(mean=tensorplay.arange(1., 6.)) tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])Similar to the function above, but the means and standard deviations are shared among all drawn elements. The resulting tensor has size given by
size.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.normal(2, 3, size=(1, 4)) tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
not_equal
functionFull reference ↗nuclear_norm
functionFull reference ↗- tensorplay.functional.nuclear_norm(input, keepdim=False, dim=None)[source]
numel
functionFull reference ↗ones_like
functionFull reference ↗- tensorplay.functional.ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor
Returns a tensor filled with the scalar value 1, with the same size as
input.tensorplay.ones_like(input)is equivalent totensorplay.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).Warning
As of 0.4, this function does not support an
outkeyword. As an alternative, the oldtensorplay.ones_like(input, out=output)is equivalent totensorplay.ones(input.size(), out=output).- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
Example:
>>> input = tensorplay.empty(2, 3) >>> tensorplay.ones_like(input) tensor([[ 1., 1., 1.], [ 1., 1., 1.]])
orgqr
functionFull reference ↗- tensorplay.functional.orgqr(input, tau) Tensor[source]
Alias for
tensorplay.linalg.householder_product().
ormqr
functionFull reference ↗- tensorplay.functional.ormqr(input, tau, other, left=True, transpose=False, *, out=None) Tensor[source]
Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
Multiplies a matrix C (given by
other) with a matrix Q, where Q is represented using Householder reflectors (input, tau). See Representation of Orthogonal or Unitary Matrices for further details.If
leftis True then op(Q) times C is computed, otherwise the result is C times op(Q). Whenleftis True, the implicit matrix Q has size . It has size otherwise. Iftransposeis True then op is the conjugate transpose operation, otherwise it’s a no-op.Supports inputs of float, double, cfloat and cdouble dtypes. Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
See also
tensorplay.geqrf()can be used to form the Householder representation (input, tau) of matrix Q from the QR decomposition.Note
This function supports backward but it is only fast when
(input, tau)do not require gradients and/ortau.size(-1)is very small. ``- Parameters:
input (Tensor) – tensor of shape (*, mn, k) where * is zero or more batch dimensions and mn equals to m or n depending on the
left.tau (Tensor) – tensor of shape (*, min(mn, k)) where * is zero or more batch dimensions.
other (Tensor) – tensor of shape (*, m, n) where * is zero or more batch dimensions.
left (bool) – controls the order of multiplication.
transpose (bool) – controls whether the matrix Q is conjugate transposed or not.
- Keyword Arguments:
out (Tensor, optional) – the output Tensor. Ignored if None. Default: None.
outer
functionFull reference ↗- tensorplay.functional.outer(input, vec2, *, out=None) Tensor[source]
Outer product of
inputandvec2. Ifinputis a vector of size andvec2is a vector of size , thenoutmust be a matrix of size .Note
This function does not broadcast.
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – optional output matrix
Example:
>>> v1 = tensorplay.arange(1., 5.) >>> v2 = tensorplay.arange(1., 4.) >>> tensorplay.outer(v1, v2) tensor([[ 1., 2., 3.], [ 2., 4., 6.], [ 3., 6., 9.], [ 4., 8., 12.]])
pairwise_distance
functionFull reference ↗- tensorplay.functional.pairwise_distance(x1, x2, p=2.0, eps=1e-06, keepdim=False)[source]
pdist
functionFull reference ↗- tensorplay.functional.pdist(input, p=2.0)[source]
permute_copy
functionFull reference ↗- tensorplay.functional.permute_copy(input, dims)[source]
Performs the same operation as
tensorplay.permute(), but all output tensors are freshly created instead of aliasing the input.
permute
functionFull reference ↗pinverse
functionFull reference ↗- tensorplay.functional.pinverse(input, rcond=1e-15) Tensor[source]
Alias for
tensorplay.linalg.pinv()
pixel_unshuffle
functionFull reference ↗- tensorplay.functional.pixel_unshuffle(input, downscale_factor)[source]
poisson_nll_loss
functionFull reference ↗- tensorplay.functional.poisson_nll_loss(input, target, log_input=True, full=False, eps=1e-08)[source]
poisson
functionFull reference ↗- tensorplay.functional.poisson(input, generator=None) Tensor[source]
Returns a tensor of the same size as
inputwith each element sampled from a Poisson distribution with rate parameter given by the corresponding element ininputi.e.,inputmust be non-negative.- Parameters:
input (Tensor) – the input tensor containing the rates of the Poisson distribution
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for sampling
Example:
>>> rates = tensorplay.rand(4, 4) * 5 # rate parameter between 0 and 5 >>> tensorplay.poisson(rates) tensor([[9., 1., 3., 5.], [8., 6., 6., 0.], [0., 4., 5., 3.], [2., 1., 4., 2.]])
polar
functionFull reference ↗- tensorplay.functional.polar(abs, angle, *, out=None) Tensor[source]
Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value
absand angleangle.Note
tensorplay.polar is similar to std::polar and does not compute the polar decomposition of a complex tensor like Python’s cmath.polar and SciPy’s linalg.polar do. The behavior of this function is undefined if abs is negative or NaN, or if angle is infinite.
- Parameters:
- Keyword Arguments:
out (Tensor) – If the inputs are
tensorplay.float32, must betensorplay.complex64. If the inputs aretensorplay.float64, must betensorplay.complex128.
Example:
>>> import numpy as np >>> abs = tensorplay.tensor([1, 2], dtype=tensorplay.float64) >>> angle = tensorplay.tensor([np.pi / 2, 5 * np.pi / 4], dtype=tensorplay.float64) >>> z = tensorplay.polar(abs, angle) >>> z tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=tensorplay.complex128)
polygamma
functionFull reference ↗positive
functionFull reference ↗- tensorplay.functional.positive(input) Tensor[source]
Returns
input. Throws a runtime error ifinputis a bool tensor.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> t = tensorplay.randn(5) >>> t tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940]) >>> tensorplay.positive(t) tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
pow
functionFull reference ↗- tensorplay.functional.pow(input, exponent, *, out=None) Tensor[source]
Takes the power of each element in
inputwithexponentand returns a tensor with the result.exponentcan be either a singlefloatnumber or a Tensor with the same number of elements asinput.When
exponentis a scalar value, the operation applied is:When
exponentis a tensor, the operation applied is:When
exponentis a tensor, the shapes ofinputandexponentmust be broadcastable.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.4331, 1.2475, 0.6834, -0.2791]) >>> tensorplay.pow(a, 2) tensor([ 0.1875, 1.5561, 0.4670, 0.0779]) >>> exp = tensorplay.arange(1., 5.) >>> a = tensorplay.arange(1., 5.) >>> a tensor([ 1., 2., 3., 4.]) >>> exp tensor([ 1., 2., 3., 4.]) >>> tensorplay.pow(a, exp) tensor([ 1., 4., 27., 256.])selfis a scalarfloatvalue, andexponentis a tensor. The returned tensoroutis of the same shape asexponentThe operation applied is:
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> exp = tensorplay.arange(1., 5.) >>> base = 2 >>> tensorplay.pow(base, exp) tensor([ 2., 4., 8., 16.])
prelu
functionFull reference ↗- tensorplay.functional.prelu(input, weight)[source]
prod
functionFull reference ↗- tensorplay.functional.prod(input: Tensor, *, dtype: _dtype | None) Tensor[source]
Returns the product of all elements in the
inputtensor.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = tensorplay.randn(1, 3) >>> a tensor([[-0.8020, 0.5428, -1.5854]]) >>> tensorplay.prod(a) tensor(0.6902)Returns the product of each row of the
inputtensor in the given dimensiondim.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimensiondimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 fewer dimension thaninput.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = tensorplay.randn(4, 2) >>> a tensor([[ 0.5261, -0.3837], [ 1.1857, -0.2498], [-1.1646, 0.0705], [ 1.1131, -1.0629]]) >>> tensorplay.prod(a, 1) tensor([-0.2018, -0.2962, -0.0821, -1.1831])
promote_types
functionFull reference ↗- tensorplay.functional.promote_types(type1, type2) dtype[source]
Returns the
tensorplay.dtypewith the smallest size and scalar kind that is not smaller nor of lower kind than either type1 or type2. See type promotion documentation for more information on the type promotion logic.- Parameters:
type1 (
tensorplay.dtype)type2 (
tensorplay.dtype)
Example:
>>> tensorplay.promote_types(tensorplay.int32, tensorplay.float32) tensorplay.float32 >>> tensorplay.promote_types(tensorplay.uint8, tensorplay.long) tensorplay.long
put
functionFull reference ↗- tensorplay.functional.put(input, index, source, accumulate=False)[source]
q_per_channel_axis
functionFull reference ↗- tensorplay.functional.q_per_channel_axis(input)[source]
q_per_channel_scales
functionFull reference ↗- tensorplay.functional.q_per_channel_scales(input)[source]
q_per_channel_zero_points
functionFull reference ↗- tensorplay.functional.q_per_channel_zero_points(input)[source]
q_scale
functionFull reference ↗- tensorplay.functional.q_scale(input)[source]
q_zero_point
functionFull reference ↗- tensorplay.functional.q_zero_point(input)[source]
quantize_per_channel
functionFull reference ↗- tensorplay.functional.quantize_per_channel(input, scales, zero_points, axis, dtype) Tensor[source]
Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
- Parameters:
input (Tensor) – float tensor to quantize
scales (Tensor) – float 1D tensor of scales to use, size should match
input.size(axis)zero_points (int) – integer 1D tensor of offset to use, size should match
input.size(axis)axis (int) – dimension on which apply per-channel quantization
dtype (
tensorplay.dtype) – the desired data type of returned tensor. Has to be one of the quantized dtypes:tensorplay.quint8,tensorplay.qint8,tensorplay.qint32
- Returns:
A newly quantized tensor
- Return type:
Example:
>>> x = tensorplay.tensor([[-1.0, 0.0], [1.0, 2.0]]) >>> tensorplay.quantize_per_channel(x, tensorplay.tensor([0.1, 0.01]), tensorplay.tensor([10, 0]), 0, tensorplay.quint8) tensor([[-1., 0.], [ 1., 2.]], size=(2, 2), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_channel_affine, scale=tensor([0.1000, 0.0100], dtype=tensorplay.float64), zero_point=tensor([10, 0]), axis=0) >>> tensorplay.quantize_per_channel(x, tensorplay.tensor([0.1, 0.01]), tensorplay.tensor([10, 0]), 0, tensorplay.quint8).int_repr() tensor([[ 0, 10], [100, 200]], dtype=tensorplay.uint8)
quantize_per_tensor_dynamic
functionFull reference ↗- tensorplay.functional.quantize_per_tensor_dynamic(input, dtype, reduce_range) Tensor[source]
Converts a float tensor to a quantized tensor with scale and zero_point calculated dynamically based on the input.
- Parameters:
input (Tensor) – float tensor or list of tensors to quantize
dtype (
tensorplay.dtype) – the desired data type of returned tensor. Has to be one of the quantized dtypes:tensorplay.quint8,tensorplay.qint8reduce_range (bool) – a flag to indicate whether to reduce the range of quantized
bit (data by 1)
hardwares (it's required to avoid instruction overflow for some)
- Returns:
A newly (dynamically) quantized tensor
- Return type:
Example:
>>> t = tensorplay.quantize_per_tensor_dynamic(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), tensorplay.quint8, False) >>> print(t) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.011764705882352941, zero_point=85) >>> t.int_repr() tensor([ 0, 85, 170, 255], dtype=tensorplay.uint8)
quantize_per_tensor
functionFull reference ↗- tensorplay.functional.quantize_per_tensor(input, scale, zero_point, dtype) Tensor[source]
Converts a float tensor to a quantized tensor with given scale and zero point.
- Parameters:
input (Tensor) – float tensor or list of tensors to quantize
scale (float or Tensor) – scale to apply in quantization formula
zero_point (int or Tensor) – offset in integer value that maps to float zero
dtype (
tensorplay.dtype) – the desired data type of returned tensor. Has to be one of the quantized dtypes:tensorplay.quint8,tensorplay.qint8,tensorplay.qint32
- Returns:
A newly quantized tensor or list of quantized tensors.
- Return type:
Example:
>>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8).int_repr() tensor([ 0, 10, 20, 30], dtype=tensorplay.uint8) >>> tensorplay.quantize_per_tensor([tensorplay.tensor([-1.0, 0.0]), tensorplay.tensor([-2.0, 2.0])], >>> tensorplay.tensor([0.1, 0.2]), tensorplay.tensor([10, 20]), tensorplay.quint8) (tensor([-1., 0.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10), tensor([-2., 2.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.2, zero_point=20)) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), tensorplay.tensor(0.1), tensorplay.tensor(10), tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.10, zero_point=10)
quantized_batch_norm
functionFull reference ↗- tensorplay.functional.quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) Tensor[source]
Applies batch normalization on a 4D (NCHW) quantized tensor.
- Parameters:
input (Tensor) – quantized tensor
weight (Tensor) – float tensor that corresponds to the gamma, size C
bias (Tensor) – float tensor that corresponds to the beta, size C
mean (Tensor) – float mean value in batch normalization, size C
var (Tensor) – float tensor for variance, size C
eps (float) – a value added to the denominator for numerical stability.
output_scale (float) – output quantized tensor scale
output_zero_point (int) – output quantized tensor zero_point
- Returns:
A quantized tensor with batch normalization applied.
- Return type:
Example:
>>> qx = tensorplay.quantize_per_tensor(tensorplay.rand(2, 2, 2, 2), 1.5, 3, tensorplay.quint8) >>> tensorplay.quantized_batch_norm(qx, tensorplay.ones(2), tensorplay.zeros(2), tensorplay.rand(2), tensorplay.rand(2), 0.00001, 0.2, 2) tensor([[[[-0.2000, -0.2000], [ 1.6000, -0.2000]], [[-0.4000, -0.4000], [-0.4000, 0.6000]]], [[[-0.2000, -0.2000], [-0.2000, -0.2000]], [[ 0.6000, -0.4000], [ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.2, zero_point=2)
quantized_gru_cell
functionFull reference ↗- tensorplay.functional.quantized_gru_cell(input, hx, w_ih, w_hh, b_ih, b_hh, packed_ih, packed_hh, col_offsets_ih, col_offsets_hh, scale_ih, scale_hh, zero_point_ih, zero_point_hh)[source]
quantized_lstm_cell
functionFull reference ↗- tensorplay.functional.quantized_lstm_cell(input, hx, w_ih, w_hh, b_ih, b_hh, packed_ih, packed_hh, col_offsets_ih, col_offsets_hh, scale_ih, scale_hh, zero_point_ih, zero_point_hh)[source]
quantized_max_pool1d
functionFull reference ↗- tensorplay.functional.quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) Tensor[source]
Applies a 1D max pooling over an input quantized tensor composed of several input planes.
- Parameters:
input (Tensor) – quantized tensor
stride (
list of int, optional) – the stride of the sliding windowpadding (
list of int, optional) – padding to be added on both sides, must be >= 0 and <= kernel_size / 2dilation (
list of int, optional) – The stride between elements within a sliding window, must be > 0. Default 1ceil_mode (bool, optional) – If True, will use ceil instead of floor to compute the output shape. Defaults to False.
- Returns:
A quantized tensor with max_pool1d applied.
- Return type:
Example:
>>> qx = tensorplay.quantize_per_tensor(tensorplay.rand(2, 2), 1.5, 3, tensorplay.quint8) >>> tensorplay.quantized_max_pool1d(qx, [2]) tensor([[0.0000], [1.5000]], size=(2, 1), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=1.5, zero_point=3)
quantized_max_pool2d
functionFull reference ↗- tensorplay.functional.quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) Tensor[source]
Applies a 2D max pooling over an input quantized tensor composed of several input planes.
- Parameters:
input (Tensor) – quantized tensor
kernel_size (
list of int) – the size of the sliding windowstride (
list of int, optional) – the stride of the sliding windowpadding (
list of int, optional) – padding to be added on both sides, must be >= 0 and <= kernel_size / 2dilation (
list of int, optional) – The stride between elements within a sliding window, must be > 0. Default 1ceil_mode (bool, optional) – If True, will use ceil instead of floor to compute the output shape. Defaults to False.
- Returns:
A quantized tensor with max_pool2d applied.
- Return type:
Example:
>>> qx = tensorplay.quantize_per_tensor(tensorplay.rand(2, 2, 2, 2), 1.5, 3, tensorplay.quint8) >>> tensorplay.quantized_max_pool2d(qx, [2,2]) tensor([[[[1.5000]], [[1.5000]]], [[[0.0000]], [[0.0000]]]], size=(2, 2, 1, 1), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=1.5, zero_point=3)
quantized_max_pool3d
functionFull reference ↗- tensorplay.functional.quantized_max_pool3d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False)[source]
quantized_rnn_relu_cell
functionFull reference ↗- tensorplay.functional.quantized_rnn_relu_cell(input, hx, w_ih, w_hh, b_ih, b_hh, packed_ih, packed_hh, col_offsets_ih, col_offsets_hh, scale_ih, scale_hh, zero_point_ih, zero_point_hh)[source]
quantized_rnn_tanh_cell
functionFull reference ↗- tensorplay.functional.quantized_rnn_tanh_cell(input, hx, w_ih, w_hh, b_ih, b_hh, packed_ih, packed_hh, col_offsets_ih, col_offsets_hh, scale_ih, scale_hh, zero_point_ih, zero_point_hh)[source]
rad2deg_
functionFull reference ↗- tensorplay.functional.rad2deg_(input)[source]
rad2deg
functionFull reference ↗- tensorplay.functional.rad2deg(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with each of the elements of
inputconverted from angles in radians to degrees.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]]) >>> tensorplay.rad2deg(a) tensor([[ 180.0233, -180.0233], [ 359.9894, -359.9894], [ 89.9544, -89.9544]])
rand_like
functionFull reference ↗- tensorplay.functional.rand_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor[source]
Returns a tensor with the same size as
inputthat is filled with random numbers from a uniform distribution on the interval .tensorplay.rand_like(input)is equivalent totensorplay.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
randint_like
functionFull reference ↗- tensorplay.functional.randint_like(input, low=0, high, \*, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor[source]
Returns a tensor with the same shape as Tensor
inputfilled with random integers generated uniformly betweenlow(inclusive) andhigh(exclusive).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
randint
functionFull reference ↗- tensorplay.functional.randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Returns a tensor filled with random integers generated uniformly between
low(inclusive) andhigh(exclusive).The shape of the tensor is defined by the variable argument
size.Note
With the global dtype default (
tensorplay.float32), this function returns a tensor with dtypetensorplay.int64.- Parameters:
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for samplingout (Tensor, optional) – the output tensor.
dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if
None, this function returns a tensor with dtypetensorplay.int64.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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:
>>> tensorplay.randint(3, 5, (3,)) tensor([4, 3, 4]) >>> tensorplay.randint(10, (2, 2)) tensor([[0, 2], [5, 5]]) >>> tensorplay.randint(3, 10, (2, 2)) tensor([[4, 5], [6, 7]])
randn_like
functionFull reference ↗- tensorplay.functional.randn_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor[source]
Returns a tensor with the same size as
inputthat is filled with random numbers from a normal distribution with mean 0 and variance 1. Please refer totensorplay.randn()for the sampling process of complex dtypes.tensorplay.randn_like(input)is equivalent totensorplay.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
randperm
functionFull reference ↗- tensorplay.functional.randperm(n, *, generator=None, out=None, dtype=tensorplay.int64, layout=tensorplay.strided, device=None, requires_grad=False, pin_memory=False) Tensor[source]
Returns a random permutation of integers from
0ton - 1.- Parameters:
n (int) – the upper bound (exclusive)
- Keyword Arguments:
generator (
tensorplay.Generator, optional) – a pseudorandom number generator for samplingout (Tensor, optional) – the output tensor.
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default:tensorplay.int64.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.
Example:
>>> tensorplay.randperm(4) tensor([2, 1, 0, 3])
range
functionFull reference ↗- tensorplay.functional.range(start=0, end, step=1, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) Tensor[source]
Returns a 1-D tensor of size with values from
starttoendwith stepstep. Step is the gap between two values in the tensor.Warning
This function is deprecated and will be removed in a future release because its behavior is inconsistent with Python’s range builtin. Instead, use
tensorplay.arange(), which produces values in [start, end).- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()). If dtype is not given, infer the data type from the other input arguments. If any of start, end, or step are floating-point, the dtype is inferred to be the default dtype, seeget_default_dtype(). Otherwise, the dtype is inferred to be tensorplay.int64.layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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:
>>> tensorplay.range(1, 4) tensor([ 1., 2., 3., 4.]) >>> tensorplay.range(1, 4, 0.5) tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
ravel
functionFull reference ↗- tensorplay.functional.ravel(input) Tensor[source]
Return a contiguous flattened tensor. A copy is made only if needed.
- Parameters:
input (Tensor) – the input tensor.
Example:
>>> t = tensorplay.tensor([[[1, 2], ... [3, 4]], ... [[5, 6], ... [7, 8]]]) >>> tensorplay.ravel(t) tensor([1, 2, 3, 4, 5, 6, 7, 8])
real
functionFull reference ↗- tensorplay.functional.real(input) Tensor[source]
Returns a new tensor containing real values of the
selftensor. The returned tensor andselfshare the same underlying storage.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x=tensorplay.randn(4, dtype=tensorplay.cfloat) >>> x tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)]) >>> x.real tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
reciprocal_
functionFull reference ↗- tensorplay.functional.reciprocal_(input)[source]
reciprocal
functionFull reference ↗- tensorplay.functional.reciprocal(input, *, out=None) Tensor[source]
Returns a new tensor with the reciprocal of the elements of
inputNote
Unlike NumPy’s reciprocal, tensorplay.reciprocal supports integral inputs. Integral inputs to reciprocal are automatically promoted to the default scalar type.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.4595, -2.1219, -1.4314, 0.7298]) >>> tensorplay.reciprocal(a) tensor([-2.1763, -0.4713, -0.6986, 1.3702])
relu_
functionFull reference ↗- tensorplay.functional.relu_(input)[source]
remainder
functionFull reference ↗- tensorplay.functional.remainder(input, other, *, out=None) Tensor[source]
Computes Python’s modulus operation entrywise. The result has the same sign as the divisor
otherand its absolute value is less than that ofother.It may also be defined in terms of
tensorplay.div()astensorplay.remainder(a, b) == a - a.div(b, rounding_mode="floor") * bSupports broadcasting to a common shape, type promotion, and integer and float inputs.
Note
Complex inputs are not supported. In some cases, it is not mathematically possible to satisfy the definition of a modulo operation with complex numbers. See
tensorplay.fmod()for how division by zero is handled.See also
tensorplay.fmod()which implements C++’s std::fmod. This one is defined in terms of division rounding towards zero.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.remainder(tensorplay.tensor([-3., -2, -1, 1, 2, 3]), 2) tensor([ 1., 0., 1., 1., 0., 1.]) >>> tensorplay.remainder(tensorplay.tensor([1, 2, 3, 4, 5]), -1.5) tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
renorm
functionFull reference ↗- tensorplay.functional.renorm(input, p, dim, maxnorm, *, out=None) Tensor[source]
Returns a tensor where each sub-tensor of
inputalong dimensiondimis normalized such that the p-norm of the sub-tensor is lower than the valuemaxnormNote
If the norm of a row is lower than maxnorm, the row is unchanged
- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.ones(3, 3) >>> x[1].fill_(2) tensor([ 2., 2., 2.]) >>> x[2].fill_(3) tensor([ 3., 3., 3.]) >>> x tensor([[ 1., 1., 1.], [ 2., 2., 2.], [ 3., 3., 3.]]) >>> tensorplay.renorm(x, 1, 0, 5) tensor([[ 1.0000, 1.0000, 1.0000], [ 1.6667, 1.6667, 1.6667], [ 1.6667, 1.6667, 1.6667]])
repeat_interleave
functionFull reference ↗- tensorplay.functional.repeat_interleave(input, repeats, dim=None, *, output_size=None) Tensor[source]
Repeat elements of a tensor.
Warning
This is different from
tensorplay.Tensor.repeat()but similar tonumpy.repeat.- Parameters:
input (Tensor) – the input tensor.
repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
dim (int, optional) – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array.
- Keyword Arguments:
output_size (int, optional) – Total output size for the given axis ( e.g. sum of repeats). If given, it will avoid stream synchronization needed to calculate output shape of the tensor.
- Returns:
Repeated tensor which has the same shape as input, except along the given axis.
- Return type:
Example:
>>> x = tensorplay.tensor([1, 2, 3]) >>> x.repeat_interleave(2) tensor([1, 1, 2, 2, 3, 3]) >>> y = tensorplay.tensor([[1, 2], [3, 4]]) >>> tensorplay.repeat_interleave(y, 2) tensor([1, 1, 2, 2, 3, 3, 4, 4]) >>> tensorplay.repeat_interleave(y, 3, dim=1) tensor([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> tensorplay.repeat_interleave(y, tensorplay.tensor([1, 2]), dim=0) tensor([[1, 2], [3, 4], [3, 4]]) >>> tensorplay.repeat_interleave(y, tensorplay.tensor([1, 2]), dim=0, output_size=3) tensor([[1, 2], [3, 4], [3, 4]])If the repeats is tensor([n1, n2, n3, …]), then the output will be tensor([0, 0, …, 1, 1, …, 2, 2, …, …]) where 0 appears n1 times, 1 appears n2 times, 2 appears n3 times, etc.
Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
- Parameters:
repeats (Tensor) – The number of repetitions for each element.
- Returns:
Repeated tensor of size sum(repeats).
- Return type:
Example:
>>> tensorplay.repeat_interleave(tensorplay.tensor([1, 2, 3])) tensor([0, 1, 1, 2, 2, 2])
reshape
functionFull reference ↗- tensorplay.functional.reshape(input, shape) Tensor[source]
Returns a tensor with the same data and number of elements as
input, but with the specified shape. When possible, the returned tensor will be a view ofinput. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.See
tensorplay.Tensor.view()on when it is possible to return a view.A single dimension may be -1, in which case it’s inferred from the remaining dimensions and the number of elements in
input.Example:
>>> a = tensorplay.arange(4.) >>> tensorplay.reshape(a, (2, 2)) tensor([[ 0., 1.], [ 2., 3.]]) >>> b = tensorplay.tensor([[0, 1], [2, 3]]) >>> tensorplay.reshape(b, (-1,)) tensor([ 0, 1, 2, 3])
resize_as_
functionFull reference ↗- tensorplay.functional.resize_as_(input, other, memory_format=None)[source]
resize_as_sparse_
functionFull reference ↗- tensorplay.functional.resize_as_sparse_(input, the_template)[source]
resolve_conj
functionFull reference ↗- tensorplay.functional.resolve_conj(input) Tensor[source]
Returns a new tensor with materialized conjugation if
input’s conjugate bit is set to True, else returnsinput. The output tensor will always have its conjugate bit set to False.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x = tensorplay.tensor([-1 + 1j, -2 + 2j, 3 - 3j]) >>> y = x.conj() >>> y.is_conj() True >>> z = y.resolve_conj() >>> z tensor([-1 - 1j, -2 - 2j, 3 + 3j]) >>> z.is_conj() False
resolve_neg
functionFull reference ↗- tensorplay.functional.resolve_neg(input) Tensor[source]
Returns a new tensor with materialized negation if
input’s negative bit is set to True, else returnsinput. The output tensor will always have its negative bit set to False.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x = tensorplay.tensor([-1 + 1j, -2 + 2j, 3 - 3j]) >>> y = x.conj() >>> z = y.imag >>> z.is_neg() True >>> out = z.resolve_neg() >>> out tensor([-1., -2., 3.]) >>> out.is_neg() False
result_type
functionFull reference ↗- tensorplay.functional.result_type(tensor1, tensor2) dtype[source]
Returns the
tensorplay.dtypethat would result from performing an arithmetic operation on the provided input tensors. See type promotion documentation for more information on the type promotion logic.- Parameters:
Example:
>>> tensorplay.result_type(tensorplay.tensor([1, 2], dtype=tensorplay.int), 1.0) tensorplay.float32 >>> tensorplay.result_type(tensorplay.tensor([1, 2], dtype=tensorplay.uint8), tensorplay.tensor(1)) tensorplay.uint8
rms_norm
functionFull reference ↗- tensorplay.functional.rms_norm(input, normalized_shape, weight=None, eps=None)[source]
rnn_relu_cell
functionFull reference ↗- tensorplay.functional.rnn_relu_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None)[source]
rnn_relu
functionFull reference ↗- tensorplay.functional.rnn_relu(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False)[source]
rnn_tanh_cell
functionFull reference ↗- tensorplay.functional.rnn_tanh_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None)[source]
rnn_tanh
functionFull reference ↗- tensorplay.functional.rnn_tanh(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False)[source]
roll
functionFull reference ↗- tensorplay.functional.roll(input, shifts, dims=None) Tensor[source]
Roll the tensor
inputalong the given dimension(s). Elements that are shifted beyond the last position are re-introduced at the first position. Ifdimsis None, the tensor will be flattened before rolling and then restored to the original shape.- Parameters:
Example:
>>> x = tensorplay.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2) >>> x tensor([[1, 2], [3, 4], [5, 6], [7, 8]]) >>> tensorplay.roll(x, 1) tensor([[8, 1], [2, 3], [4, 5], [6, 7]]) >>> tensorplay.roll(x, 1, 0) tensor([[7, 8], [1, 2], [3, 4], [5, 6]]) >>> tensorplay.roll(x, -1, 0) tensor([[3, 4], [5, 6], [7, 8], [1, 2]]) >>> tensorplay.roll(x, shifts=(2, 1), dims=(0, 1)) tensor([[6, 5], [8, 7], [2, 1], [4, 3]])
rot90
functionFull reference ↗- tensorplay.functional.rot90(input, k=1, dims=(0, 1)) Tensor[source]
Rotate an n-D tensor by 90 degrees in the plane specified by dims axis. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
- Parameters:
Example:
>>> x = tensorplay.arange(4).view(2, 2) >>> x tensor([[0, 1], [2, 3]]) >>> tensorplay.rot90(x, 1, [0, 1]) tensor([[1, 3], [0, 2]]) >>> x = tensorplay.arange(8).view(2, 2, 2) >>> x tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> tensorplay.rot90(x, 1, [1, 2]) tensor([[[1, 3], [0, 2]], [[5, 7], [4, 6]]])
round_
functionFull reference ↗- tensorplay.functional.round_(input)[source]
round
functionFull reference ↗- tensorplay.functional.round(input, *, decimals=0, out=None) Tensor[source]
Rounds elements of
inputto the nearest integer.For integer inputs, follows the array-api convention of returning a copy of the input tensor. The return type of output is same as that of input’s dtype.
Note
This function implements the “round half to even” to break ties when a number is equidistant from two integers (e.g. round(2.5) is 2).
When the :attr:`decimals` argument is specified the algorithm used is similar to NumPy’s around. This algorithm is fast but inexact and it can easily overflow for low precision dtypes. Eg. round(tensor([10000], dtype=tensorplay.float16), decimals=3) is inf.
See also
tensorplay.ceil(), which rounds up.tensorplay.floor(), which rounds down.tensorplay.trunc(), which rounds towards zero.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.round(tensorplay.tensor((4.7, -2.3, 9.1, -7.7))) tensor([ 5., -2., 9., -8.]) >>> # Values equidistant from two integers are rounded towards the >>> # the nearest even value (zero is treated as even) >>> tensorplay.round(tensorplay.tensor([-0.5, 0.5, 1.5, 2.5])) tensor([-0., 0., 2., 2.]) >>> # A positive decimals argument rounds to the to that decimal place >>> tensorplay.round(tensorplay.tensor([0.1234567]), decimals=3) tensor([0.1230]) >>> # A negative decimals argument rounds to the left of the decimal >>> tensorplay.round(tensorplay.tensor([1200.1234567]), decimals=-3) tensor([1000.])
row_indices_copy
functionFull reference ↗- tensorplay.functional.row_indices_copy(input)[source]
row_stack
functionFull reference ↗rrelu_
functionFull reference ↗- tensorplay.functional.rrelu_(input, lower=0.125, upper=0.3333333333333333, training=False, generator=None)[source]
rrelu
functionFull reference ↗- tensorplay.functional.rrelu(input, lower=0.125, upper=0.3333333333333333, training=False, generator=None)[source]
rsqrt_
functionFull reference ↗- tensorplay.functional.rsqrt_(input)[source]
rsqrt
functionFull reference ↗- tensorplay.functional.rsqrt(input, *, out=None) Tensor[source]
Returns a new tensor with the reciprocal of the square-root of each of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.0370, 0.2970, 1.5420, -0.9105]) >>> tensorplay.rsqrt(a) tensor([ nan, 1.8351, 0.8053, nan])
rsub
functionFull reference ↗- tensorplay.functional.rsub(input, other, alpha=1)[source]
scalar_tensor
functionFull reference ↗- tensorplay.functional.scalar_tensor(s, dtype=None, device=None, pin_memory=False)[source]
scaled_modified_bessel_k0
functionFull reference ↗- tensorplay.functional.scaled_modified_bessel_k0(input)[source]
scaled_modified_bessel_k1
functionFull reference ↗- tensorplay.functional.scaled_modified_bessel_k1(input)[source]
scatter_add
functionFull reference ↗scatter_reduce
functionFull reference ↗scatter
functionFull reference ↗searchsorted
functionFull reference ↗- tensorplay.functional.searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) Tensor[source]
Find the indices from the innermost dimension of
sorted_sequencesuch that, if the corresponding values invalueswere inserted before the indices, when sorted, the order of the corresponding innermost dimension withinsorted_sequencewould be preserved. Return a new tensor with the same size asvalues. More formally, the returned index satisfies the following rules:sorted_sequencerightreturned index satisfies
1-D
False
sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]1-D
True
sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]N-D
False
sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]N-D
True
sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]- Parameters:
- Keyword Arguments:
out_int32 (bool, optional) – indicate the output data type. tensorplay.int32 if True, tensorplay.int64 otherwise. Default value is False, i.e. default output data type is tensorplay.int64.
right (bool, optional) – if False, return the first suitable location that is found. If True, return the last such index. If no suitable index found, return 0 for non-numerical value (eg. nan, inf) or the size of innermost dimension within
sorted_sequence(one pass the last index of the innermost dimension). In other words, if False, gets the lower bound index for each value invalueson the corresponding innermost dimension of thesorted_sequence. If True, gets the upper bound index instead. Default value is False.sidedoes the same and is preferred. It will error ifsideis set to “left” while this is True.side (str, optional) – the same as
rightbut preferred. “left” corresponds to False forrightand “right” corresponds to True forright. It will error if this is set to “left” whilerightis True. Default value is None.out (Tensor, optional) – the output tensor, must be the same size as
valuesif provided.sorter (LongTensor, optional) – if provided, a tensor matching the shape of the unsorted
sorted_sequencecontaining a sequence of indices that sort it in the ascending order on the innermost dimension
Example:
>>> sorted_sequence = tensorplay.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]) >>> sorted_sequence tensor([[ 1, 3, 5, 7, 9], [ 2, 4, 6, 8, 10]]) >>> values = tensorplay.tensor([[3, 6, 9], [3, 6, 9]]) >>> values tensor([[3, 6, 9], [3, 6, 9]]) >>> tensorplay.searchsorted(sorted_sequence, values) tensor([[1, 3, 4], [1, 2, 4]]) >>> tensorplay.searchsorted(sorted_sequence, values, side='right') tensor([[2, 3, 5], [1, 3, 4]]) >>> sorted_sequence_1d = tensorplay.tensor([1, 3, 5, 7, 9]) >>> sorted_sequence_1d tensor([1, 3, 5, 7, 9]) >>> tensorplay.searchsorted(sorted_sequence_1d, values) tensor([[1, 3, 4], [1, 3, 4]])
segment_reduce
functionFull reference ↗- tensorplay.functional.segment_reduce(data: Tensor, reduce: str, *, lengths: Tensor | None = None, indices: Tensor | None = None, offsets: Tensor | None = None, axis: _int = 0, unsafe: _bool = False, initial: Number | _complex | None = None) Tensor[source]
Perform a segment reduction operation on the input tensor along the specified axis.
- Parameters:
- Keyword Arguments:
lengths (Tensor, optional) – Length of each segment. Default:
None.offsets (Tensor, optional) – Offset of each segment. Default:
None.axis (int, optional) – The axis perform reduction. Default:
0.unsafe (bool, optional) – Skip validation If True. Default:
False.initial (Number, optional) – The initial value for the reduction operation. Default:
None.
Example:
>>> data = tensorplay.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=tensorplay.float32, device='cuda') >>> lengths = tensorplay.tensor([2, 1], device='cuda') >>> tensorplay.segment_reduce(data, 'max', lengths=lengths) tensor([[ 5., 6., 7., 8.], [ 9., 10., 11., 12.]], device='cuda:0')
select_copy
functionFull reference ↗- tensorplay.functional.select_copy(input, dim, index)[source]
Performs the same operation as
tensorplay.select(), but all output tensors are freshly created instead of aliasing the input.
select_scatter
functionFull reference ↗- tensorplay.functional.select_scatter(input, src, dim, index) Tensor[source]
Embeds the values of the
srctensor intoinputat the given index. This function returns a tensor with fresh storage; it does not create a view.- Parameters:
Note
srcmust be of the proper size in order to be embedded intoinput. Specifically, it should have the same shape astensorplay.select(input, dim, index)Example:
>>> a = tensorplay.zeros(2, 2) >>> b = tensorplay.ones(2) >>> a.select_scatter(b, 0, 0) tensor([[1., 1.], [0., 0.]])
select
functionFull reference ↗- tensorplay.functional.select(input, dim, index) Tensor[source]
Slices the
inputtensor along the selected dimension at the given index. This function returns a view of the original tensor with the given dimension removed.Note
If
inputis a sparse tensor and returning a view of the tensor is not possible, a RuntimeError exception is raised. In this is the case, consider usingtensorplay.select_copy()function.- Parameters:
Note
select()is equivalent to slicing. For example,tensor.select(0, index)is equivalent totensor[index]andtensor.select(2, index)is equivalent totensor[:,:,index].
selu_
functionFull reference ↗- tensorplay.functional.selu_(input)[source]
selu
functionFull reference ↗- tensorplay.functional.selu(input)[source]
sgn
functionFull reference ↗- tensorplay.functional.sgn(input, *, out=None) Tensor[source]
This function is an extension of tensorplay.sign() to complex tensors. It computes a new tensor whose elements have the same angles as the corresponding elements of
inputand absolute values (i.e. magnitudes) of one for complex tensors and is equivalent to tensorplay.sign() for non-complex tensors.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> t = tensorplay.tensor([3+4j, 7-24j, 0, 1+2j]) >>> t.sgn() tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
shifted_chebyshev_polynomial_t
functionFull reference ↗- tensorplay.functional.shifted_chebyshev_polynomial_t(x, n)[source]
shifted_chebyshev_polynomial_u
functionFull reference ↗- tensorplay.functional.shifted_chebyshev_polynomial_u(x, n)[source]
shifted_chebyshev_polynomial_v
functionFull reference ↗- tensorplay.functional.shifted_chebyshev_polynomial_v(x, n)[source]
shifted_chebyshev_polynomial_w
functionFull reference ↗- tensorplay.functional.shifted_chebyshev_polynomial_w(x, n)[source]
sigmoid_
functionFull reference ↗- tensorplay.functional.sigmoid_(input)[source]
sigmoid
functionFull reference ↗sign
functionFull reference ↗- tensorplay.functional.sign(input, *, out=None) Tensor[source]
Returns a new tensor with the signs of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([0.7, -1.2, 0., 2.3]) >>> a tensor([ 0.7000, -1.2000, 0.0000, 2.3000]) >>> tensorplay.sign(a) tensor([ 1., -1., 0., 1.])
signbit
functionFull reference ↗- tensorplay.functional.signbit(input, *, out=None) Tensor[source]
Tests if each element of
inputhas its sign bit set or not.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([0.7, -1.2, 0., 2.3]) >>> tensorplay.signbit(a) tensor([ False, True, False, False]) >>> a = tensorplay.tensor([-0.0, 0.0]) >>> tensorplay.signbit(a) tensor([ True, False])Note
signbit handles signed zeros, so negative zero (-0) returns True.
sin_
functionFull reference ↗- tensorplay.functional.sin_(input)[source]
sin
functionFull reference ↗- tensorplay.functional.sin(input, *, out=None) Tensor[source]
Returns a new tensor with the sine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-0.5461, 0.1347, -2.7266, -0.2746]) >>> tensorplay.sin(a) tensor([-0.5194, 0.1343, -0.4032, -0.2711])
sinc_
functionFull reference ↗- tensorplay.functional.sinc_(input)[source]
sinc
functionFull reference ↗sinh_
functionFull reference ↗- tensorplay.functional.sinh_(input)[source]
sinh
functionFull reference ↗- tensorplay.functional.sinh(input, *, out=None) Tensor[source]
Returns a new tensor with the hyperbolic sine of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.5380, -0.8632, -0.1265, 0.9399]) >>> tensorplay.sinh(a) tensor([ 0.5644, -0.9744, -0.1268, 1.0845])Note
When
inputis on the CPU, the implementation of tensorplay.sinh may use the Sleef library, which rounds very large results to infinity or negative infinity. See here for details.
slice_copy
functionFull reference ↗- tensorplay.functional.slice_copy(input, dim=0, start=None, end=None, step=1)[source]
Performs the same operation as
tensorplay.slice(), but all output tensors are freshly created instead of aliasing the input.
slice_inverse
functionFull reference ↗- tensorplay.functional.slice_inverse(input, src, dim=0, start=None, end=None, step=1)[source]
slice_scatter
functionFull reference ↗- tensorplay.functional.slice_scatter(input, src, dim=0, start=None, end=None, step=1) Tensor[source]
Embeds the values of the
srctensor intoinputat the given dimension. This function returns a tensor with fresh storage; it does not create a view.- Parameters:
input (Tensor) – the input tensor.
src (Tensor) – The tensor to embed into
inputdim (int) – the dimension to insert the slice into
start (Optional[int]) – the start index of where to insert the slice
end (Optional[int]) – the end index of where to insert the slice
step (int) – the how many elements to skip in
Example:
>>> a = tensorplay.zeros(8, 8) >>> b = tensorplay.ones(2, 8) >>> a.slice_scatter(b, start=6) tensor([[0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [1., 1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1., 1.]]) >>> b = tensorplay.ones(8, 2) >>> a.slice_scatter(b, dim=1, start=2, end=6, step=2) tensor([[0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0.]])
slogdet
functionFull reference ↗- tensorplay.functional.slogdet(input)[source]
Alias for
tensorplay.linalg.slogdet()
softmax
functionFull reference ↗- tensorplay.functional.softmax(input, dim, *, dtype=None) Tensor[source]
Alias for
tensorplay.nn.functional.softmax().
sort
functionFull reference ↗- tensorplay.functional.sort(input, dim=-1, descending=False, *, stable=<object object>, out=None)[source]
sparse_bsc_tensor
functionFull reference ↗- tensorplay.functional.sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) Tensor[source]
Constructs a sparse tensor in BSC (Block Compressed Sparse Column)) with specified 2-dimensional blocks at the given
ccol_indicesandrow_indices. Sparse matrix multiplication operations in BSC format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.Note
If the
deviceargument is not specified the device of the givenvaluesand indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.- Parameters:
ccol_indices (array_like) – (B+1)-dimensional array of size
(*batchsize, ncolblocks + 1). The last element of each batch is the number of non-zeros. This tensor encodes the index in values and row_indices depending on where the given column starts. Each successive number in the tensor subtracted by the number before it denotes the number of elements in a given column.row_indices (array_like) – Row block coordinates of each block in values. (B+1)-dimensional tensor with the same length as values.
values (array_list) – Initial blocks for the tensor. Can be a list, tuple, NumPy
ndarray, and other types that represents a (1 + 2 + K)-dimensional tensor whereKis the number of dense dimensions.size (list, tuple,
tensorplay.Size, optional) – Size of the sparse tensor:(*batchsize, nrows * blocksize[0], ncols * blocksize[1], *densesize)If not provided, the size will be inferred as the minimum size big enough to hold all non-zero blocks.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type fromvalues.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by
tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.
Example:
>>> ccol_indices = [0, 1, 2] >>> row_indices = [0, 1] >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] >>> tensorplay.sparse_bsc_tensor(tensorplay.tensor(ccol_indices, dtype=tensorplay.int64), ... tensorplay.tensor(row_indices, dtype=tensorplay.int64), ... tensorplay.tensor(values), dtype=tensorplay.double) tensor(ccol_indices=tensor([0, 1, 2]), row_indices=tensor([0, 1]), values=tensor([[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]), size=(2, 2), nnz=2, dtype=tensorplay.float64, layout=tensorplay.sparse_bsc)
sparse_bsr_tensor
functionFull reference ↗- tensorplay.functional.sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) Tensor[source]
Constructs a sparse tensor in BSR (Block Compressed Sparse Row)) with specified 2-dimensional blocks at the given
crow_indicesandcol_indices. Sparse matrix multiplication operations in BSR format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.Note
If the
deviceargument is not specified the device of the givenvaluesand indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.- Parameters:
crow_indices (array_like) – (B+1)-dimensional array of size
(*batchsize, nrowblocks + 1). The last element of each batch is the number of non-zeros. This tensor encodes the block index in values and col_indices depending on where the given row block starts. Each successive number in the tensor subtracted by the number before it denotes the number of blocks in a given row.col_indices (array_like) – Column block coordinates of each block in values. (B+1)-dimensional tensor with the same length as values.
values (array_list) – Initial values for the tensor. Can be a list, tuple, NumPy
ndarray, scalar, and other types that represents a (1 + 2 + K)-dimensional tensor whereKis the number of dense dimensions.size (list, tuple,
tensorplay.Size, optional) – Size of the sparse tensor:(*batchsize, nrows * blocksize[0], ncols * blocksize[1], *densesize)whereblocksize == values.shape[1:3]. If not provided, the size will be inferred as the minimum size big enough to hold all non-zero blocks.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type fromvalues.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by
tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.
Example:
>>> crow_indices = [0, 1, 2] >>> col_indices = [0, 1] >>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] >>> tensorplay.sparse_bsr_tensor(tensorplay.tensor(crow_indices, dtype=tensorplay.int64), ... tensorplay.tensor(col_indices, dtype=tensorplay.int64), ... tensorplay.tensor(values), dtype=tensorplay.double) tensor(crow_indices=tensor([0, 1, 2]), col_indices=tensor([0, 1]), values=tensor([[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]), size=(2, 2), nnz=2, dtype=tensorplay.float64, layout=tensorplay.sparse_bsr)
sparse_coo_tensor
functionFull reference ↗- tensorplay.functional.sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) Tensor[source]
Constructs a sparse tensor in COO(rdinate) format with specified values at the given
indices.Note
This function returns an uncoalesced tensor when
is_coalescedis unspecified orNone.Note
If the
deviceargument is not specified the device of the givenvaluesand indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.- Parameters:
indices (array_like) – Initial data for the tensor. Can be a list, tuple, NumPy
ndarray, scalar, and other types. Will be cast to atensorplay.LongTensorinternally. The indices are the coordinates of the non-zero values in the matrix, and thus should be two-dimensional where the first dimension is the number of tensor dimensions and the second dimension is the number of non-zero values.values (array_like) – Initial values for the tensor. Can be a list, tuple, NumPy
ndarray, scalar, and other types.size (list, tuple, or
tensorplay.Size, optional) – Size of the sparse tensor. If not provided the size will be inferred as the minimum size big enough to hold all non-zero elements.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type fromvalues.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by
tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.is_coalesced (bool, optional) – When``True``, the caller is responsible for providing tensor indices that correspond to a coalesced tensor. If the
check_invariantsflag is False, no error will be raised if the prerequisites are not met and this will lead to silently incorrect results. To force coalescion please usecoalesce()on the resulting Tensor. Default: None: except for trivial cases (e.g. nnz < 2) the resulting Tensor has is_coalesced set toFalse`.
Example:
>>> i = tensorplay.tensor([[0, 1, 1], ... [2, 0, 2]]) >>> v = tensorplay.tensor([3, 4, 5], dtype=tensorplay.float32) >>> tensorplay.sparse_coo_tensor(i, v, [2, 4]) tensor(indices=tensor([[0, 1, 1], [2, 0, 2]]), values=tensor([3., 4., 5.]), size=(2, 4), nnz=3, layout=tensorplay.sparse_coo) >>> tensorplay.sparse_coo_tensor(i, v) # Shape inference tensor(indices=tensor([[0, 1, 1], [2, 0, 2]]), values=tensor([3., 4., 5.]), size=(2, 3), nnz=3, layout=tensorplay.sparse_coo) >>> tensorplay.sparse_coo_tensor(i, v, [2, 4], ... dtype=tensorplay.float64, ... device=tensorplay.device('cuda:0')) tensor(indices=tensor([[0, 1, 1], [2, 0, 2]]), values=tensor([3., 4., 5.]), device='cuda:0', size=(2, 4), nnz=3, dtype=tensorplay.float64, layout=tensorplay.sparse_coo) # Create an empty sparse tensor with the following invariants: # 1. sparse_dim + dense_dim = len(SparseTensor.shape) # 2. SparseTensor._indices().shape = (sparse_dim, nnz) # 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:]) # # For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and # sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0)) >>> S = tensorplay.sparse_coo_tensor(tensorplay.empty([1, 0]), [], [1]) tensor(indices=tensor([], size=(1, 0)), values=tensor([], size=(0,)), size=(1,), nnz=0, layout=tensorplay.sparse_coo) # and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and # sparse_dim = 1 >>> S = tensorplay.sparse_coo_tensor(tensorplay.empty([1, 0]), tensorplay.empty([0, 2]), [1, 2]) tensor(indices=tensor([], size=(1, 0)), values=tensor([], size=(0, 2)), size=(1, 2), nnz=0, layout=tensorplay.sparse_coo)
sparse_csc_tensor
functionFull reference ↗- tensorplay.functional.sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) Tensor[source]
Constructs a sparse tensor in CSC (Compressed Sparse Column) with specified values at the given
ccol_indicesandrow_indices. Sparse matrix multiplication operations in CSC format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.Note
If the
deviceargument is not specified the device of the givenvaluesand indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.- Parameters:
ccol_indices (array_like) – (B+1)-dimensional array of size
(*batchsize, ncols + 1). The last element of each batch is the number of non-zeros. This tensor encodes the index in values and row_indices depending on where the given column starts. Each successive number in the tensor subtracted by the number before it denotes the number of elements in a given column.row_indices (array_like) – Row coordinates of each element in values. (B+1)-dimensional tensor with the same length as values.
values (array_list) – Initial values for the tensor. Can be a list, tuple, NumPy
ndarray, scalar, and other types that represents a (1+K)-dimensional tensor whereKis the number of dense dimensions.size (list, tuple,
tensorplay.Size, optional) – Size of the sparse tensor:(*batchsize, nrows, ncols, *densesize). If not provided, the size will be inferred as the minimum size big enough to hold all non-zero elements.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type fromvalues.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by
tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.
Example:
>>> ccol_indices = [0, 2, 4] >>> row_indices = [0, 1, 0, 1] >>> values = [1, 2, 3, 4] >>> tensorplay.sparse_csc_tensor(tensorplay.tensor(ccol_indices, dtype=tensorplay.int64), ... tensorplay.tensor(row_indices, dtype=tensorplay.int64), ... tensorplay.tensor(values), dtype=tensorplay.double) tensor(ccol_indices=tensor([0, 2, 4]), row_indices=tensor([0, 1, 0, 1]), values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4, dtype=tensorplay.float64, layout=tensorplay.sparse_csc)
sparse_csr_tensor
functionFull reference ↗- tensorplay.functional.sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) Tensor[source]
Constructs a sparse tensor in CSR (Compressed Sparse Row) with specified values at the given
crow_indicesandcol_indices. Sparse matrix multiplication operations in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.Note
If the
deviceargument is not specified the device of the givenvaluesand indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.- Parameters:
crow_indices (array_like) – (B+1)-dimensional array of size
(*batchsize, nrows + 1). The last element of each batch is the number of non-zeros. This tensor encodes the index in values and col_indices depending on where the given row starts. Each successive number in the tensor subtracted by the number before it denotes the number of elements in a given row.col_indices (array_like) – Column coordinates of each element in values. (B+1)-dimensional tensor with the same length as values.
values (array_list) – Initial values for the tensor. Can be a list, tuple, NumPy
ndarray, scalar, and other types that represents a (1+K)-dimensional tensor whereKis the number of dense dimensions.size (list, tuple,
tensorplay.Size, optional) – Size of the sparse tensor:(*batchsize, nrows, ncols, *densesize). If not provided, the size will be inferred as the minimum size big enough to hold all non-zero elements.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type fromvalues.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by
tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.
Example:
>>> crow_indices = [0, 2, 4] >>> col_indices = [0, 1, 0, 1] >>> values = [1, 2, 3, 4] >>> tensorplay.sparse_csr_tensor(tensorplay.tensor(crow_indices, dtype=tensorplay.int64), ... tensorplay.tensor(col_indices, dtype=tensorplay.int64), ... tensorplay.tensor(values), dtype=tensorplay.double) tensor(crow_indices=tensor([0, 2, 4]), col_indices=tensor([0, 1, 0, 1]), values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4, dtype=tensorplay.float64, layout=tensorplay.sparse_csr)
spherical_bessel_j0
functionFull reference ↗- tensorplay.functional.spherical_bessel_j0(input)[source]
split_copy
functionFull reference ↗- tensorplay.functional.split_copy(input, split_size, dim=0, *, out=None)[source]
Performs the same operation as
tensorplay.split(), but all output tensors are freshly created instead of aliasing the input.
split_with_sizes_copy
functionFull reference ↗- tensorplay.functional.split_with_sizes_copy(input, split_sizes, dim=0, *, out=None)[source]
Performs the same operation as
tensorplay.split_with_sizes(), but all output tensors are freshly created instead of aliasing the input.
split
functionFull reference ↗- tensorplay.functional.split(input, split_size, dim=0)[source]
sqrt_
functionFull reference ↗- tensorplay.functional.sqrt_(input)[source]
sqrt
functionFull reference ↗- tensorplay.functional.sqrt(input, *, out=None) Tensor[source]
Returns a new tensor with the square-root of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-2.0755, 1.0226, 0.0831, 0.4806]) >>> tensorplay.sqrt(a) tensor([ nan, 1.0112, 0.2883, 0.6933])
square_
functionFull reference ↗- tensorplay.functional.square_(input)[source]
square
functionFull reference ↗- tensorplay.functional.square(input: Tensor, *, out: Tensor | None) Tensor[source]
Returns a new tensor with the square of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-2.0755, 1.0226, 0.0831, 0.4806]) >>> tensorplay.square(a) tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
squeeze_copy
functionFull reference ↗- tensorplay.functional.squeeze_copy(input, dim=None)[source]
Performs the same operation as
tensorplay.squeeze(), but all output tensors are freshly created instead of aliasing the input.
squeeze
functionFull reference ↗- tensorplay.functional.squeeze(input: Tensor, dim: int | List[int] | None) Tensor[source]
Returns a tensor with all specified dimensions of
inputof size 1 removed.For example, if input is of shape: then the input.squeeze() will be of shape: .
When
dimis given, a squeeze operation is done only in the given dimension(s). If input is of shape: ,squeeze(input, 0)leaves the tensor unchanged, butsqueeze(input, 1)will squeeze the tensor to the shape .Note
The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other.
Warning
If the tensor has a batch dimension of size 1, then squeeze(input) will also remove the batch dimension, which can lead to unexpected errors. Consider specifying only the dims you wish to be squeezed.
- Parameters:
Example:
>>> x = tensorplay.zeros(2, 1, 2, 1, 2) >>> x.size() tensorplay.Size([2, 1, 2, 1, 2]) >>> y = tensorplay.squeeze(x) >>> y.size() tensorplay.Size([2, 2, 2]) >>> y = tensorplay.squeeze(x, 0) >>> y.size() tensorplay.Size([2, 1, 2, 1, 2]) >>> y = tensorplay.squeeze(x, 1) >>> y.size() tensorplay.Size([2, 2, 1, 2]) >>> y = tensorplay.squeeze(x, (1, 2, 3)) tensorplay.Size([2, 2, 2])
stack
functionFull reference ↗- tensorplay.functional.stack(tensors, dim=0, *, out=None) Tensor[source]
Concatenates a sequence of tensors along a new dimension.
All tensors need to be of the same size.
See also
tensorplay.cat()concatenates the given sequence along an existing dimension.- Parameters:
tensors (sequence of Tensors) – sequence of tensors to concatenate
dim (int, optional) – dimension to insert. Has to be between 0 and the number of dimensions of concatenated tensors (inclusive). Default: 0
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.randn(2, 3) >>> x tensor([[ 0.3367, 0.1288, 0.2345], [ 0.2303, -1.1229, -0.1863]]) >>> tensorplay.stack((x, x)) # same as tensorplay.stack((x, x), dim=0) tensor([[[ 0.3367, 0.1288, 0.2345], [ 0.2303, -1.1229, -0.1863]], [[ 0.3367, 0.1288, 0.2345], [ 0.2303, -1.1229, -0.1863]]]) >>> tensorplay.stack((x, x)).size() tensorplay.Size([2, 2, 3]) >>> tensorplay.stack((x, x), dim=1) tensor([[[ 0.3367, 0.1288, 0.2345], [ 0.3367, 0.1288, 0.2345]], [[ 0.2303, -1.1229, -0.1863], [ 0.2303, -1.1229, -0.1863]]]) >>> tensorplay.stack((x, x), dim=2) tensor([[[ 0.3367, 0.3367], [ 0.1288, 0.1288], [ 0.2345, 0.2345]], [[ 0.2303, 0.2303], [-1.1229, -1.1229], [-0.1863, -0.1863]]]) >>> tensorplay.stack((x, x), dim=-1) tensor([[[ 0.3367, 0.3367], [ 0.1288, 0.1288], [ 0.2345, 0.2345]], [[ 0.2303, 0.2303], [-1.1229, -1.1229], [-0.1863, -0.1863]]])
std_mean
functionFull reference ↗- tensorplay.functional.std_mean(input, dim=None, *, correction=1, keepdim=False, out=None)[source]
Calculates the standard deviation and mean over the dimensions specified by
dim.dimcan be a single dimension, list of dimensions, orNoneto reduce over all dimensions.The standard deviation () is calculated as
where is the sample set of elements, is the sample mean, is the number of samples and is the
correction.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
correction=1.Changed in version 2.0: Previously this argument was called
unbiasedand was a boolean withTruecorresponding tocorrection=1andFalsebeingcorrection=0.keepdim (bool, optional): whether the output tensor has
dimretained or not. Default:False.out (Tensor, optional) – the output tensor.
- Returns:
A tuple (std, mean) containing the standard deviation and mean.
Example
>>> a = tensorplay.tensor( ... [[ 0.2035, 1.2959, 1.8101, -0.4644], ... [ 1.5027, -0.3270, 0.5905, 0.6538], ... [-1.5745, 1.3330, -0.5596, -0.6548], ... [ 0.1264, -0.5080, 1.6420, 0.1992]] ... ) # fmt: skip >>> tensorplay.std_mean(a, dim=0, keepdim=True) (tensor([[1.2620, 1.0028, 1.0957, 0.6038]]), tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
std
functionFull reference ↗- tensorplay.functional.std(input, dim=None, *, correction=1, keepdim=False, out=None) Tensor[source]
Calculates the standard deviation over the dimensions specified by
dim.dimcan be a single dimension, list of dimensions, orNoneto reduce over all dimensions.The standard deviation () is calculated as
where is the sample set of elements, is the sample mean, is the number of samples and is the
correction.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
correction=1.Changed in version 2.0: Previously this argument was called
unbiasedand was a boolean withTruecorresponding tocorrection=1andFalsebeingcorrection=0.keepdim (bool, optional): whether the output tensor has
dimretained or not. Default:False.out (Tensor, optional) – the output tensor.
Example
>>> a = tensorplay.tensor( ... [[ 0.2035, 1.2959, 1.8101, -0.4644], ... [ 1.5027, -0.3270, 0.5905, 0.6538], ... [-1.5745, 1.3330, -0.5596, -0.6548], ... [ 0.1264, -0.5080, 1.6420, 0.1992]] ... ) # fmt: skip >>> tensorplay.std(a, dim=1, keepdim=True) tensor([[1.0311], [0.7477], [1.2204], [0.9087]])
stft
functionFull reference ↗- tensorplay.functional.stft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, return_complex=True)[source]
sub
functionFull reference ↗- tensorplay.functional.sub(input, other, *, alpha=1, out=None) Tensor[source]
Subtracts
other, scaled byalpha, frominput.Supports broadcasting to a common shape, type promotion, and integer, float, and complex inputs.
- Parameters:
- Keyword Arguments:
alpha (Number) – the multiplier for
other.out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor((1, 2)) >>> b = tensorplay.tensor((0, 1)) >>> tensorplay.sub(a, b, alpha=2) tensor([1, 0])
subtract
functionFull reference ↗sum
functionFull reference ↗- tensorplay.functional.sum(input, *, dtype=None) Tensor[source]
Returns the sum of all elements in the
inputtensor.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Note
Use the dtype argument if you need the result in a specific tensor type. Otherwise, the result type may be automatically promoted (e.g., from tensorplay.int32 to tensorplay.int64).
Example:
>>> a = tensorplay.randn(1, 3) >>> a tensor([[ 0.1133, -0.9567, 0.2958]]) >>> tensorplay.sum(a) tensor(-0.5475)Returns the sum of each row of the
inputtensor in the given dimensiondim. Ifdimis a list of dimensions, reduce over all of them.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted todtypebefore the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> a = tensorplay.randn(4, 4) >>> a tensor([[ 0.0569, -0.2475, 0.0737, -0.3429], [-0.2993, 0.9138, 0.9337, -1.6864], [ 0.1132, 0.7892, -0.1003, 0.5688], [ 0.3637, -0.9906, -0.4752, -1.5197]]) >>> tensorplay.sum(a, 1) tensor([-0.4598, -0.1381, 1.3708, -2.6217]) >>> b = tensorplay.arange(4 * 5 * 6).view(4, 5, 6) >>> tensorplay.sum(b, (2, 1)) tensor([ 435., 1335., 2235., 3135.])
svd
functionFull reference ↗- tensorplay.functional.svd(input, some=True, compute_uv=True, *, out=None)[source]
Computes the singular value decomposition of either a matrix or batch of matrices
input. The singular value decomposition is represented as a namedtuple (U, S, V), such thatinput. where is the transpose of V for real inputs, and the conjugate transpose of V for complex inputs. Ifinputis a batch of matrices, then U, S, and V are also batched with the same batch dimensions asinput.If
someis True (default), the method returns the reduced singular value decomposition. In this case, if the last two dimensions ofinputare m and n, then the returned U and V matrices will contain only min(n, m) orthonormal columns.If
compute_uvis False, the returned U and V will be zero-filled matrices of shape (m, m) and (n, n) respectively, and the same device asinput. The argumentsomehas no effect whencompute_uvis False.Supports
inputof float, double, cfloat and cdouble data types. The dtypes of U and V are the same asinput’s. S will always be real-valued, even ifinputis complex.Warning
tensorplay.svd()is deprecated in favor oftensorplay.linalg.svd()U, S, V = tensorplay.svd(A, some=some, compute_uv=True)(default) should be replaced withU, S, Vh = tensorplay.linalg.svd(A, full_matrices=not some) V = Vh.mH_, S, _ = tensorplay.svd(A, some=some, compute_uv=False)should be replaced withS = tensorplay.linalg.svdvals(A)Note
Differences with
tensorplay.linalg.svd():someis the opposite oftensorplay.linalg.svd()’sfull_matrices. Note that default value for both is True, so the default behavior is effectively the opposite.tensorplay.svd()returns V, whereastensorplay.linalg.svd()returns Vh, that is, .If
compute_uvis False,tensorplay.svd()returns zero-filled tensors for U and Vh, whereastensorplay.linalg.svd()returns empty tensors.
Note
The singular values are returned in descending order. If
inputis a batch of matrices, then the singular values of each matrix in the batch are returned in descending order.Note
The S tensor can only be used to compute gradients if
compute_uvis True.Note
When
someis False, the gradients on U[…, :, min(m, n):] and V[…, :, min(m, n):] will be ignored in the backward pass, as those vectors can be arbitrary bases of the corresponding subspaces.Note
The implementation of
tensorplay.linalg.svd()on CPU uses LAPACK’s routine ?gesdd (a divide-and-conquer algorithm) instead of ?gesvd for speed. Analogously, on GPU, it uses cuSOLVER’s routines gesvdj and gesvdjBatched on CUDA 10.1.243 and later, and MAGMA’s routine gesdd on earlier versions of CUDA.Note
The returned U will not be contiguous. The matrix (or batch of matrices) will be represented as a column-major matrix (i.e. Fortran-contiguous).
Warning
The gradients with respect to U and V will only be finite when the input does not have zero nor repeated singular values.
Warning
If the distance between any two singular values is close to zero, the gradients with respect to U and V will be numerically unstable, as they depends on . The same happens when the matrix has small singular values, as these gradients also depend on S^{-1}.
Warning
For complex-valued
inputthe singular value decomposition is not unique, as U and V may be multiplied by an arbitrary phase factor on every column. The same happens wheninputhas repeated singular values, where one may multiply the columns of the spanning subspace in U and V by a rotation matrix and the resulting vectors will span the same subspace. Different platforms, like NumPy, or inputs on different device types, may produce different U and V tensors.- Parameters:
input (Tensor) – the input tensor of size (*, m, n) where * is zero or more batch dimensions consisting of (m, n) matrices.
some (bool, optional) – controls whether to compute the reduced or full decomposition, and consequently, the shape of returned U and V. Default: True.
compute_uv (bool, optional) – controls whether to compute U and V. Default: True.
- Keyword Arguments:
out (tuple, optional) – the output tuple of tensors
Example:
>>> a = tensorplay.randn(5, 3) >>> a tensor([[ 0.2364, -0.7752, 0.6372], [ 1.7201, 0.7394, -0.0504], [-0.3371, -1.0584, 0.5296], [ 0.3550, -0.4022, 1.5569], [ 0.2445, -0.0158, 1.1414]]) >>> u, s, v = tensorplay.svd(a) >>> u tensor([[ 0.4027, 0.0287, 0.5434], [-0.1946, 0.8833, 0.3679], [ 0.4296, -0.2890, 0.5261], [ 0.6604, 0.2717, -0.2618], [ 0.4234, 0.2481, -0.4733]]) >>> s tensor([2.3289, 2.0315, 0.7806]) >>> v tensor([[-0.0199, 0.8766, 0.4809], [-0.5080, 0.4054, -0.7600], [ 0.8611, 0.2594, -0.4373]]) >>> tensorplay.dist(a, tensorplay.mm(tensorplay.mm(u, tensorplay.diag(s)), v.t())) tensor(8.6531e-07) >>> a_big = tensorplay.randn(7, 5, 3) >>> u, s, v = tensorplay.svd(a_big) >>> tensorplay.dist(a_big, tensorplay.matmul(tensorplay.matmul(u, tensorplay.diag_embed(s)), v.mT)) tensor(2.6503e-06)
swapaxes
functionFull reference ↗- tensorplay.functional.swapaxes(input, axis0, axis1) Tensor[source]
Alias for
tensorplay.transpose().This function is equivalent to NumPy’s swapaxes function.
Examples:
>>> x = tensorplay.tensor([[[0,1],[2,3]],[[4,5],[6,7]]]) >>> x tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> tensorplay.swapaxes(x, 0, 1) tensor([[[0, 1], [4, 5]], [[2, 3], [6, 7]]]) >>> tensorplay.swapaxes(x, 0, 2) tensor([[[0, 4], [2, 6]], [[1, 5], [3, 7]]])
swapdims
functionFull reference ↗- tensorplay.functional.swapdims(input, dim0, dim1) Tensor[source]
Alias for
tensorplay.transpose().This function is equivalent to NumPy’s swapaxes function.
Examples:
>>> x = tensorplay.tensor([[[0,1],[2,3]],[[4,5],[6,7]]]) >>> x tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> tensorplay.swapdims(x, 0, 1) tensor([[[0, 1], [4, 5]], [[2, 3], [6, 7]]]) >>> tensorplay.swapdims(x, 0, 2) tensor([[[0, 4], [2, 6]], [[1, 5], [3, 7]]])
sym_constrain_range_for_size
functionFull reference ↗- tensorplay.functional.sym_constrain_range_for_size(size, min=None, max=None)[source]
sym_constrain_range
functionFull reference ↗- tensorplay.functional.sym_constrain_range(size, min=None, max=None)[source]
t_copy
functionFull reference ↗- tensorplay.functional.t_copy(input)[source]
Performs the same operation as
tensorplay.t(), but all output tensors are freshly created instead of aliasing the input.
t
functionFull reference ↗- tensorplay.functional.t(input) Tensor[source]
Expects
inputto be <= 2-D tensor and transposes dimensions 0 and 1.0-D and 1-D tensors are returned as is. When input is a 2-D tensor this is equivalent to
transpose(input, 0, 1).- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x = tensorplay.randn(()) >>> x tensor(0.1995) >>> tensorplay.t(x) tensor(0.1995) >>> x = tensorplay.randn(3) >>> x tensor([ 2.4320, -0.4608, 0.7702]) >>> tensorplay.t(x) tensor([ 2.4320, -0.4608, 0.7702]) >>> x = tensorplay.randn(2, 3) >>> x tensor([[ 0.4875, 0.9158, -0.5872], [ 0.3938, -0.6929, 0.6932]]) >>> tensorplay.t(x) tensor([[ 0.4875, 0.3938], [ 0.9158, -0.6929], [-0.5872, 0.6932]])See also
tensorplay.transpose().
take_along_dim
functionFull reference ↗- tensorplay.functional.take_along_dim(input, indices, dim=None, *, out=None) Tensor[source]
Selects values from
inputat the 1-dimensional indices fromindicesalong the givendim.If
dimis None, the input array is treated as if it has been flattened to 1d.Functions that return indices along a dimension, like
tensorplay.argmax()andtensorplay.argsort(), are designed to work with this function. See the examples below.Note
This function is similar to NumPy’s take_along_axis. See also
tensorplay.gather().- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> t = tensorplay.tensor([[10, 30, 20], [60, 40, 50]]) >>> max_idx = tensorplay.argmax(t) >>> tensorplay.take_along_dim(t, max_idx) tensor([60]) >>> sorted_idx = tensorplay.argsort(t, dim=1) >>> tensorplay.take_along_dim(t, sorted_idx, dim=1) tensor([[10, 20, 30], [40, 50, 60]])
take
functionFull reference ↗- tensorplay.functional.take(input, index) Tensor[source]
Returns a new tensor with the elements of
inputat the given indices. The input tensor is treated as if it were viewed as a 1-D tensor. The result takes the same shape as the indices.- Parameters:
input (Tensor) – the input tensor.
index (LongTensor) – the indices into tensor
Example:
>>> src = tensorplay.tensor([[4, 3, 5], ... [6, 7, 8]]) >>> tensorplay.take(src, tensorplay.tensor([0, 2, 5])) tensor([ 4, 5, 8])
tan_
functionFull reference ↗- tensorplay.functional.tan_(input)[source]
tan
functionFull reference ↗- tensorplay.functional.tan(input, *, out=None) Tensor[source]
Returns a new tensor with the tangent of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([-1.2027, -1.7687, 0.4412, -1.3856]) >>> tensorplay.tan(a) tensor([-2.5930, 4.9859, 0.4722, -5.3366])
tanh_
functionFull reference ↗- tensorplay.functional.tanh_(input)[source]
tanh
functionFull reference ↗- tensorplay.functional.tanh(input, *, out=None) Tensor[source]
Returns a new tensor with the hyperbolic tangent of the elements of
input.- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 0.8986, -0.7279, 1.1745, 0.2611]) >>> tensorplay.tanh(a) tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
tensor_split
functionFull reference ↗- tensorplay.functional.tensor_split(input, indices_or_sections, dim=0) List of Tensors[source]
Splits a tensor into multiple sub-tensors, all of which are views of
input, along dimensiondimaccording to the indices or number of sections specified byindices_or_sections. This function is based on NumPy’snumpy.array_split().- Parameters:
input (Tensor) – the tensor to split
indices_or_sections (Tensor, int or list or tuple of ints) –
If
indices_or_sectionsis an integernor a zero dimensional long tensor with valuen,inputis split intonsections along dimensiondim. Ifinputis divisible bynalong dimensiondim, each section will be of equal size,input.size(dim) / n. Ifinputis not divisible byn, the sizes of the firstint(input.size(dim) % n)sections will have sizeint(input.size(dim) / n) + 1, and the rest will have sizeint(input.size(dim) / n).If
indices_or_sectionsis a list or tuple of ints, or a one-dimensional long tensor, theninputis split along dimensiondimat each of the indices in the list, tuple or tensor. For instance,indices_or_sections=[2, 3]anddim=0would result in the tensorsinput[:2],input[2:3], andinput[3:].If
indices_or_sectionsis a tensor, it must be a zero-dimensional or one-dimensional long tensor on the CPU.dim (int, optional) – dimension along which to split the tensor. Default:
0
Example:
>>> x = tensorplay.arange(8) >>> tensorplay.tensor_split(x, 3) (tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7])) >>> x = tensorplay.arange(7) >>> tensorplay.tensor_split(x, 3) (tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6])) >>> tensorplay.tensor_split(x, (1, 6)) (tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6])) >>> x = tensorplay.arange(14).reshape(2, 7) >>> x tensor([[ 0, 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12, 13]]) >>> tensorplay.tensor_split(x, 3, dim=1) (tensor([[0, 1, 2], [7, 8, 9]]), tensor([[ 3, 4], [10, 11]]), tensor([[ 5, 6], [12, 13]])) >>> tensorplay.tensor_split(x, (1, 6), dim=1) (tensor([[0], [7]]), tensor([[ 1, 2, 3, 4, 5], [ 8, 9, 10, 11, 12]]), tensor([[ 6], [13]]))
threshold_
functionFull reference ↗- tensorplay.functional.threshold_(input, threshold, value)[source]
threshold
functionFull reference ↗- tensorplay.functional.threshold(input, threshold, value, *, out=None)[source]
tile
functionFull reference ↗- tensorplay.functional.tile(input, dims) Tensor[source]
Constructs a tensor by repeating the elements of
input. Thedimsargument specifies the number of repetitions in each dimension.If
dimsspecifies fewer dimensions thaninputhas, then ones are prepended todimsuntil all dimensions are specified. For example, ifinputhas shape (8, 6, 4, 2) anddimsis (2, 2), thendimsis treated as (1, 1, 2, 2).Analogously, if
inputhas fewer dimensions thandimsspecifies, theninputis treated as if it were unsqueezed at dimension zero until it has as many dimensions asdimsspecifies. For example, ifinputhas shape (4, 2) anddimsis (3, 3, 2, 2), theninputis treated as if it had the shape (1, 1, 4, 2).Note
This function is similar to NumPy’s tile function.
- Parameters:
Example:
>>> x = tensorplay.tensor([1, 2, 3]) >>> x.tile((2,)) tensor([1, 2, 3, 1, 2, 3]) >>> y = tensorplay.tensor([[1, 2], [3, 4]]) >>> tensorplay.tile(y, (2, 2)) tensor([[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]])
topk
functionFull reference ↗- tensorplay.functional.topk(input, k, dim=-1, largest=True, sorted=True, impl=0, *, out=None)[source]
trace
functionFull reference ↗transpose_copy
functionFull reference ↗- tensorplay.functional.transpose_copy(input, dim0, dim1)[source]
Performs the same operation as
tensorplay.transpose(), but all output tensors are freshly created instead of aliasing the input.
transpose
functionFull reference ↗- tensorplay.functional.transpose(input, dim0, dim1) Tensor[source]
Returns a tensor that is a transposed version of
input. The given dimensionsdim0anddim1are swapped.If
inputis a strided tensor then the resultingouttensor shares its underlying storage with theinputtensor, so changing the content of one would change the content of the other.If
inputis a the relevant documentation then the resultingouttensor does not share the underlying storage with theinputtensor.If
inputis a the relevant documentation with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the argumentsdim0anddim1must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.Note
Transpositions which interchange the sparse dimensions of a SparseCSR or SparseCSC layout tensor will result in the layout changing between the two options. Transposition of the sparse dimensions of a ` SparseBSR` or SparseBSC layout tensor will likewise generate a result with the opposite layout.
- Parameters:
Example:
>>> x = tensorplay.randn(2, 3) >>> x tensor([[ 1.0028, -0.9893, 0.5809], [-0.1669, 0.7299, 0.4942]]) >>> tensorplay.transpose(x, 0, 1) tensor([[ 1.0028, -0.1669], [-0.9893, 0.7299], [ 0.5809, 0.4942]])See also
tensorplay.t().
trapezoid
functionFull reference ↗- tensorplay.functional.trapezoid(y, x=None, *, dx=None, dim=-1) Tensor[source]
Computes the trapezoidal rule along
dim. By default the spacing between elements is assumed to be 1, butdxcan be used to specify a different constant spacing, andxcan be used to specify arbitrary spacing alongdim. Only one ofxordxshould be specified.Assuming
yis a one-dimensional tensor with elements , the default computation isWhen
dxis specified the computation becomeseffectively multiplying the result by
dx. Whenxis specified, assumingxis also a one-dimensional tensor with elements , the computation becomesWhen
xandyhave the same size, the computation is as described above and no broadcasting is needed. The broadcasting behavior of this function is as follows when their sizes are different. For bothxandy, the function computes the difference between consecutive elements along dimensiondim. This effectively creates two tensors, x_diff and y_diff, that have the same shape as the original tensors except their lengths along the dimensiondimis reduced by 1. After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule. See the examples below for details.Note
The trapezoidal rule is a technique for approximating the definite integral of a function by averaging its left and right Riemann sums. The approximation becomes more accurate as the resolution of the partition increases.
- Parameters:
- Keyword Arguments:
Examples:
>>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1 >>> y = tensorplay.tensor([1, 5, 10]) >>> tensorplay.trapezoid(y) tensor(10.5) >>> # Computes the same trapezoidal rule directly to verify >>> (1 + 10 + 10) / 2 10.5 >>> # Computes the trapezoidal rule in 1D with constant spacing of 2 >>> # NOTE: the result is the same as before, but multiplied by 2 >>> tensorplay.trapezoid(y, dx=2) 21.0 >>> # Computes the trapezoidal rule in 1D with arbitrary spacing >>> x = tensorplay.tensor([1, 3, 6]) >>> tensorplay.trapezoid(y, x) 28.5 >>> # Computes the same trapezoidal rule directly to verify >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2 28.5 >>> # Computes the trapezoidal rule for each row of a 3x3 matrix >>> y = tensorplay.arange(9).reshape(3, 3) tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> tensorplay.trapezoid(y) tensor([ 2., 8., 14.]) >>> # Computes the trapezoidal rule for each column of the matrix >>> tensorplay.trapezoid(y, dim=0) tensor([ 6., 8., 10.]) >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with the same arbitrary spacing >>> y = tensorplay.ones(3, 3) >>> x = tensorplay.tensor([1, 3, 6]) >>> tensorplay.trapezoid(y, x) array([5., 5., 5.]) >>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with different arbitrary spacing per row >>> y = tensorplay.ones(3, 3) >>> x = tensorplay.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]]) >>> tensorplay.trapezoid(y, x) array([2., 4., 6.])
trapz
functionFull reference ↗triangular_solve
functionFull reference ↗- tensorplay.functional.triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None)[source]
Solves a system of equations with a square upper or lower triangular invertible matrix and multiple right-hand sides .
In symbols, it solves and assumes is square upper-triangular (or lower-triangular if
upper= False) and does not have zeros on the diagonal.tensorplay.triangular_solve(b, A) can take in 2D inputs b, A or inputs that are batches of 2D matrices. If the inputs are batches, then returns batched outputs X
If the diagonal of
Acontains zeros or elements that are very close to zero andunitriangular= False (default) or if the input matrix is badly conditioned, the result may contain NaN s.Supports input of float, double, cfloat and cdouble data types.
Warning
tensorplay.triangular_solve()is deprecated in favor oftensorplay.linalg.solve_triangular()tensorplay.linalg.solve_triangular()has its arguments reversed and does not return a copy of one of the inputs.X = tensorplay.triangular_solve(B, A).solutionshould be replaced withX = tensorplay.linalg.solve_triangular(A, B)- Parameters:
b (Tensor) – multiple right-hand sides of size where is zero of more batch dimensions
A (Tensor) – the input triangular coefficient matrix of size where is zero or more batch dimensions
upper (bool, optional) – whether is upper or lower triangular. Default:
True.transpose (bool, optional) – solves op(A)X = b where op(A) = A^T if this flag is
True, and op(A) = A if it isFalse. Default:False.unitriangular (bool, optional) – whether is unit triangular. If True, the diagonal elements of are assumed to be 1 and not referenced from . Default:
False.
- Keyword Arguments:
out ((Tensor, Tensor), optional) – tuple of two tensors to write the output to. Ignored if None. Default: None.
- Returns:
A namedtuple (solution, cloned_coefficient) where cloned_coefficient is a clone of and solution is the solution to (or whatever variant of the system of equations, depending on the keyword arguments.)
Examples:
>>> A = tensorplay.randn(2, 2).triu() >>> A tensor([[ 1.1527, -1.0753], [ 0.0000, 0.7986]]) >>> b = tensorplay.randn(2, 3) >>> b tensor([[-0.0210, 2.3513, -1.5492], [ 1.5429, 0.7403, -1.0243]]) >>> tensorplay.triangular_solve(b, A) tensorplay.return_types.triangular_solve( solution=tensor([[ 1.7841, 2.9046, -2.5405], [ 1.9320, 0.9270, -1.2826]]), cloned_coefficient=tensor([[ 1.1527, -1.0753], [ 0.0000, 0.7986]]))
tril_indices
functionFull reference ↗- tensorplay.functional.tril_indices(row, col, offset=0, *, dtype=tensorplay.long, device='cpu', layout=tensorplay.strided) Tensor[source]
Returns the indices of the lower triangular part of a
row-by-colmatrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates. Indices are ordered based on rows and then columns.The lower triangular part of the matrix is defined as the elements on and below the diagonal.
The argument
offsetcontrols which diagonal to consider. Ifoffset= 0, all elements on and below the main diagonal are retained. A positive value includes just as many diagonals above the main diagonal, and similarly a negative value excludes just as many diagonals below the main diagonal. The main diagonal are the set of indices for where are the dimensions of the matrix.Note
When running on CUDA,
row * colmust be less than to prevent overflow during calculation.- Parameters:
row (
int) – number of rows in the 2-D matrix.col (
int) – number of columns in the 2-D matrix.offset (
int) – diagonal offset from the main diagonal. Default: if not provided, 0.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor, only supporttensorplay.int,tensorplay.long. Default: ifNone,tensorplay.long.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.layout (
tensorplay.layout, optional) – currently only supporttensorplay.strided.
Example:
>>> a = tensorplay.tril_indices(3, 3) >>> a tensor([[0, 1, 1, 2, 2, 2], [0, 0, 1, 0, 1, 2]]) >>> a = tensorplay.tril_indices(4, 3, -1) >>> a tensor([[1, 2, 2, 3, 3, 3], [0, 0, 1, 0, 1, 2]]) >>> a = tensorplay.tril_indices(4, 3, 1) >>> a tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3], [0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
tril
functionFull reference ↗- tensorplay.functional.tril(input, diagonal=0, *, out=None) Tensor[source]
Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
input, the other elements of the result tensoroutare set to 0.The lower triangular part of the matrix is defined as the elements on and below the diagonal.
The argument
diagonalcontrols which diagonal to consider. Ifdiagonal= 0, all elements on and below the main diagonal are retained. A positive value includes just as many diagonals above the main diagonal, and similarly a negative value excludes just as many diagonals below the main diagonal. The main diagonal are the set of indices for where are the dimensions of the matrix.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(3, 3) >>> a tensor([[-1.0813, -0.8619, 0.7105], [ 0.0935, 0.1380, 2.2112], [-0.3409, -0.9828, 0.0289]]) >>> tensorplay.tril(a) tensor([[-1.0813, 0.0000, 0.0000], [ 0.0935, 0.1380, 0.0000], [-0.3409, -0.9828, 0.0289]]) >>> b = tensorplay.randn(4, 6) >>> b tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461], [ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145], [ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864], [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]]) >>> tensorplay.tril(b, diagonal=1) tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000], [ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000], [ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000], [-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]]) >>> tensorplay.tril(b, diagonal=-1) tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], [ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], [ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000], [-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
triplet_margin_loss
functionFull reference ↗- tensorplay.functional.triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2.0)[source]
triu_indices
functionFull reference ↗- tensorplay.functional.triu_indices(row, col, offset=0, *, dtype=tensorplay.long, device='cpu', layout=tensorplay.strided) Tensor[source]
Returns the indices of the upper triangular part of a
rowbycolmatrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates. Indices are ordered based on rows and then columns.The upper triangular part of the matrix is defined as the elements on and above the diagonal.
The argument
offsetcontrols which diagonal to consider. Ifoffset= 0, all elements on and above the main diagonal are retained. A positive value excludes just as many diagonals above the main diagonal, and similarly a negative value includes just as many diagonals below the main diagonal. The main diagonal are the set of indices for where are the dimensions of the matrix.Note
When running on CUDA,
row * colmust be less than to prevent overflow during calculation.- Parameters:
row (
int) – number of rows in the 2-D matrix.col (
int) – number of columns in the 2-D matrix.offset (
int) – diagonal offset from the main diagonal. Default: if not provided, 0.
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor, only supporttensorplay.int,tensorplay.long. Default: ifNone,tensorplay.long.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.layout (
tensorplay.layout, optional) – currently only supporttensorplay.strided.
Example:
>>> a = tensorplay.triu_indices(3, 3) >>> a tensor([[0, 0, 0, 1, 1, 2], [0, 1, 2, 1, 2, 2]]) >>> a = tensorplay.triu_indices(4, 3, -1) >>> a tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3], [0, 1, 2, 0, 1, 2, 1, 2, 2]]) >>> a = tensorplay.triu_indices(4, 3, 1) >>> a tensor([[0, 0, 1], [1, 2, 2]])
triu
functionFull reference ↗- tensorplay.functional.triu(input, diagonal=0, *, out=None) Tensor[source]
Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
input, the other elements of the result tensoroutare set to 0.The upper triangular part of the matrix is defined as the elements on and above the diagonal.
The argument
diagonalcontrols which diagonal to consider. Ifdiagonal= 0, all elements on and above the main diagonal are retained. A positive value excludes just as many diagonals above the main diagonal, and similarly a negative value includes just as many diagonals below the main diagonal. The main diagonal are the set of indices for where are the dimensions of the matrix.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(3, 3) >>> a tensor([[ 0.2309, 0.5207, 2.0049], [ 0.2072, -1.0680, 0.6602], [ 0.3480, -0.5211, -0.4573]]) >>> tensorplay.triu(a) tensor([[ 0.2309, 0.5207, 2.0049], [ 0.0000, -1.0680, 0.6602], [ 0.0000, 0.0000, -0.4573]]) >>> tensorplay.triu(a, diagonal=1) tensor([[ 0.0000, 0.5207, 2.0049], [ 0.0000, 0.0000, 0.6602], [ 0.0000, 0.0000, 0.0000]]) >>> tensorplay.triu(a, diagonal=-1) tensor([[ 0.2309, 0.5207, 2.0049], [ 0.2072, -1.0680, 0.6602], [ 0.0000, -0.5211, -0.4573]]) >>> b = tensorplay.randn(4, 6) >>> b tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235], [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857], [ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410], [-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]]) >>> tensorplay.triu(b, diagonal=1) tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235], [ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857], [ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410], [ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]]) >>> tensorplay.triu(b, diagonal=-1) tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235], [-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857], [ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410], [ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
true_divide
functionFull reference ↗trunc_
functionFull reference ↗- tensorplay.functional.trunc_(input)[source]
trunc
functionFull reference ↗- tensorplay.functional.trunc(input, *, out=None) Tensor[source]
Returns a new tensor with the truncated integer values of the elements of
input.For integer inputs, follows the array-api convention of returning a copy of the input tensor.
- Parameters:
input (Tensor) – the input tensor.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.randn(4) >>> a tensor([ 3.4742, 0.5466, -0.8008, -0.9079]) >>> tensorplay.trunc(a) tensor([ 3., 0., -0., -0.])
unbind_copy
functionFull reference ↗- tensorplay.functional.unbind_copy(input, dim=0, *, out=None)[source]
Performs the same operation as
tensorplay.unbind(), but all output tensors are freshly created instead of aliasing the input.
unbind
functionFull reference ↗- tensorplay.functional.unbind(input, dim=0) seq[source]
Removes a tensor dimension.
Returns a tuple of all slices along a given dimension, already without it.
Example:
>>> tensorplay.unbind(tensorplay.tensor([[1, 2, 3], >>> [4, 5, 6], >>> [7, 8, 9]])) (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
unflatten
functionFull reference ↗- tensorplay.functional.unflatten(input, dim, sizes) Tensor[source]
Expands a dimension of the input tensor over multiple dimensions.
See also
tensorplay.flatten()the inverse of this function. It coalesces several dimensions into one.- Parameters:
input (Tensor) – the input tensor.
dim (int) – Dimension to be unflattened, specified as an index into
input.shape.sizes (Tuple[int]) – New shape of the unflattened dimension. One of its elements can be -1 in which case the corresponding output dimension is inferred. Otherwise, the product of
sizesmust equalinput.shape[dim].
- Returns:
A View of input with the specified dimension unflattened.
- Examples::
>>> tensorplay.unflatten(tensorplay.randn(3, 4, 1), 1, (2, 2)).shape tensorplay.Size([3, 2, 2, 1]) >>> tensorplay.unflatten(tensorplay.randn(3, 4, 1), 1, (-1, 2)).shape tensorplay.Size([3, 2, 2, 1]) >>> tensorplay.unflatten(tensorplay.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape tensorplay.Size([5, 2, 2, 3, 1, 1, 3])
unfold_copy
functionFull reference ↗- tensorplay.functional.unfold_copy(input, dimension, size, step)[source]
Performs the same operation as
tensorplay.unfold(), but all output tensors are freshly created instead of aliasing the input.
unique_consecutive
functionFull reference ↗- tensorplay.functional.unique_consecutive(input, return_inverse=False, return_counts=False, dim=None)[source]
unique
functionFull reference ↗- tensorplay.functional.unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None)[source]
unsqueeze_copy
functionFull reference ↗- tensorplay.functional.unsqueeze_copy(input, dim)[source]
Performs the same operation as
tensorplay.unsqueeze(), but all output tensors are freshly created instead of aliasing the input.
unsqueeze
functionFull reference ↗- tensorplay.functional.unsqueeze(input, dim) Tensor[source]
Returns a new tensor with a dimension of size one inserted at the specified position.
The returned tensor shares the same underlying data with this tensor.
A
dimvalue within the range[-input.dim() - 1, input.dim() + 1)can be used. Negativedimwill correspond tounsqueeze()applied atdim=dim + input.dim() + 1.- Parameters:
Example:
>>> x = tensorplay.tensor([1, 2, 3, 4]) >>> tensorplay.unsqueeze(x, 0) tensor([[ 1, 2, 3, 4]]) >>> tensorplay.unsqueeze(x, 1) tensor([[ 1], [ 2], [ 3], [ 4]])
values_copy
functionFull reference ↗- tensorplay.functional.values_copy(input)[source]
Performs the same operation as
tensorplay.values(), but all output tensors are freshly created instead of aliasing the input.
vander
functionFull reference ↗- tensorplay.functional.vander(x, N=None, increasing=False) Tensor[source]
Generates a Vandermonde matrix.
The columns of the output matrix are elementwise powers of the input vector . If increasing is True, the order of the columns is reversed . Such a matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
- Parameters:
- Returns:
Vandermonde matrix. If increasing is False, the first column is , the second and so forth. If increasing is True, the columns are .
- Return type:
Example:
>>> x = tensorplay.tensor([1, 2, 3, 5]) >>> tensorplay.vander(x) tensor([[ 1, 1, 1, 1], [ 8, 4, 2, 1], [ 27, 9, 3, 1], [125, 25, 5, 1]]) >>> tensorplay.vander(x, N=3) tensor([[ 1, 1, 1], [ 4, 2, 1], [ 9, 3, 1], [25, 5, 1]]) >>> tensorplay.vander(x, N=3, increasing=True) tensor([[ 1, 1, 1], [ 1, 2, 4], [ 1, 3, 9], [ 1, 5, 25]])
var_mean
functionFull reference ↗- tensorplay.functional.var_mean(input, dim=None, *, correction=1, keepdim=False, out=None)[source]
Calculates the variance and mean over the dimensions specified by
dim.dimcan be a single dimension, list of dimensions, orNoneto reduce over all dimensions.The variance () is calculated as
where is the sample set of elements, is the sample mean, is the number of samples and is the
correction.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
correction=1.Changed in version 2.0: Previously this argument was called
unbiasedand was a boolean withTruecorresponding tocorrection=1andFalsebeingcorrection=0.keepdim (bool, optional): whether the output tensor has
dimretained or not. Default:False.out (Tensor, optional) – the output tensor.
- Returns:
A tuple (var, mean) containing the variance and mean.
Example
>>> a = tensorplay.tensor( ... [[ 0.2035, 1.2959, 1.8101, -0.4644], ... [ 1.5027, -0.3270, 0.5905, 0.6538], ... [-1.5745, 1.3330, -0.5596, -0.6548], ... [ 0.1264, -0.5080, 1.6420, 0.1992]] ... ) # fmt: skip >>> tensorplay.var_mean(a, dim=0, keepdim=True) (tensor([[1.5926, 1.0056, 1.2005, 0.3646]]), tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
var
functionFull reference ↗- tensorplay.functional.var(input, dim=None, *, correction=1, keepdim=False, out=None) Tensor[source]
Calculates the variance over the dimensions specified by
dim.dimcan be a single dimension, list of dimensions, orNoneto reduce over all dimensions.The variance () is calculated as
where is the sample set of elements, is the sample mean, is the number of samples and is the
correction.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters:
- Keyword Arguments:
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
correction=1.Changed in version 2.0: Previously this argument was called
unbiasedand was a boolean withTruecorresponding tocorrection=1andFalsebeingcorrection=0.keepdim (bool, optional): whether the output tensor has
dimretained or not. Default:False.out (Tensor, optional) – the output tensor.
Example
>>> a = tensorplay.tensor( ... [[ 0.2035, 1.2959, 1.8101, -0.4644], ... [ 1.5027, -0.3270, 0.5905, 0.6538], ... [-1.5745, 1.3330, -0.5596, -0.6548], ... [ 0.1264, -0.5080, 1.6420, 0.1992]] ... ) # fmt: skip >>> tensorplay.var(a, dim=1, keepdim=True) tensor([[1.0631], [0.5590], [1.4893], [0.8258]])
vdot
functionFull reference ↗- tensorplay.functional.vdot(input, other, *, out=None) Tensor[source]
Computes the dot product of two 1D vectors along a dimension.
In symbols, this function computes
where denotes the conjugate for complex vectors, and it is the identity for real vectors.
Note
Unlike NumPy’s vdot, tensorplay.vdot intentionally only supports computing the dot product of two 1D tensors with the same number of elements.
See also
tensorplay.linalg.vecdot()computes the dot product of two batches of vectors along a dimension.- Parameters:
Keyword args:
Note
out (Tensor, optional): the output tensor.
Example:
>>> tensorplay.vdot(tensorplay.tensor([2, 3]), tensorplay.tensor([2, 1])) tensor(7) >>> a = tensorplay.tensor((1 +2j, 3 - 1j)) >>> b = tensorplay.tensor((2 +1j, 4 - 0j)) >>> tensorplay.vdot(a, b) tensor([16.+1.j]) >>> tensorplay.vdot(b, a) tensor([16.-1.j])
view_as_complex_copy
functionFull reference ↗- tensorplay.functional.view_as_complex_copy(input)[source]
Performs the same operation as
tensorplay.view_as_complex(), but all output tensors are freshly created instead of aliasing the input.
view_as_complex
functionFull reference ↗- tensorplay.functional.view_as_complex(input) Tensor[source]
Returns a view of
inputas a complex tensor. For an input complex tensor ofsize, this function returns a new complex tensor ofsizewhere the last dimension of the input tensor is expected to represent the real and imaginary components of complex numbers.Warning
view_as_complex()is only supported for tensors withtensorplay.dtypetensorplay.float64andtensorplay.float32. The input is expected to have the last dimension ofsize2. In addition, the tensor must have a stride of 1 for its last dimension. The strides of all other dimensions must be even numbers.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x=tensorplay.randn(4, 2) >>> x tensor([[ 1.6116, -0.5772], [-1.4606, -0.9120], [ 0.0786, -1.7497], [-0.6561, -1.6623]]) >>> tensorplay.view_as_complex(x) tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
view_as_real_copy
functionFull reference ↗- tensorplay.functional.view_as_real_copy(input)[source]
Performs the same operation as
tensorplay.view_as_real(), but all output tensors are freshly created instead of aliasing the input.
view_as_real
functionFull reference ↗- tensorplay.functional.view_as_real(input) Tensor[source]
Returns a view of
inputas a real tensor. For an input complex tensor ofsize, this function returns a new real tensor of size , where the last dimension of size 2 represents the real and imaginary components of complex numbers.Warning
view_as_real()is only supported for tensors withcomplex dtypes.- Parameters:
input (Tensor) – the input tensor.
Example:
>>> x=tensorplay.randn(4, dtype=tensorplay.cfloat) >>> x tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)]) >>> tensorplay.view_as_real(x) tensor([[ 0.4737, -0.3839], [-0.2098, -0.6699], [ 0.3470, -0.9451], [-0.5174, -1.3136]])
view_copy
functionFull reference ↗- tensorplay.functional.view_copy(input, size)[source]
Performs the same operation as
tensorplay.view(), but all output tensors are freshly created instead of aliasing the input.
vsplit
functionFull reference ↗- tensorplay.functional.vsplit(input, indices_or_sections) List of Tensors[source]
Splits
input, a tensor with two or more dimensions, into multiple tensors vertically according toindices_or_sections. Each split is a view ofinput.This is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=0) (the split dimension is 0), except that if
indices_or_sectionsis an integer it must evenly divide the split dimension or a runtime error will be thrown.This function is based on NumPy’s
numpy.vsplit().- Parameters:
Example:
>>> t = tensorplay.arange(16.0).reshape(4,4) >>> t tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) >>> tensorplay.vsplit(t, 2) (tensor([[0., 1., 2., 3.], [4., 5., 6., 7.]]), tensor([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])) >>> tensorplay.vsplit(t, [3, 6]) (tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]]), tensor([[12., 13., 14., 15.]]), tensor([], size=(0, 4)))
vstack
functionFull reference ↗- tensorplay.functional.vstack(tensors, *, out=None) Tensor[source]
Stack tensors in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by
tensorplay.atleast_2d().- Parameters:
tensors (sequence of Tensors) – sequence of tensors to concatenate
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> a = tensorplay.tensor([1, 2, 3]) >>> b = tensorplay.tensor([4, 5, 6]) >>> tensorplay.vstack((a,b)) tensor([[1, 2, 3], [4, 5, 6]]) >>> a = tensorplay.tensor([[1],[2],[3]]) >>> b = tensorplay.tensor([[4],[5],[6]]) >>> tensorplay.vstack((a,b)) tensor([[1], [2], [3], [4], [5], [6]])
where
functionFull reference ↗- tensorplay.functional.where(condition, input, other, *, out=None) Tensor[source]
Return a tensor of elements selected from either
inputorother, depending oncondition.The operation is defined as:
Note
The tensors
condition,input,othermust be broadcastable.- Parameters:
condition (BoolTensor) – When True (nonzero), yield input, otherwise yield other
input (Tensor or Scalar) – value (if
inputis a scalar) or values selected at indices whereconditionisTrueother (Tensor or Scalar) – value (if
otheris a scalar) or values selected at indices whereconditionisFalse
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
- Returns:
A tensor of shape equal to the broadcasted shape of
condition,input,other- Return type:
Example:
>>> x = tensorplay.randn(3, 2) >>> y = tensorplay.ones(3, 2) >>> x tensor([[-0.4620, 0.3139], [ 0.3898, -0.7197], [ 0.0478, -0.1657]]) >>> tensorplay.where(x > 0, 1.0, 0.0) tensor([[0., 1.], [1., 0.], [1., 0.]]) >>> tensorplay.where(x > 0, x, y) tensor([[ 1.0000, 0.3139], [ 0.3898, 1.0000], [ 0.0478, 1.0000]]) >>> x = tensorplay.randn(2, 2, dtype=tensorplay.double) >>> x tensor([[ 1.0779, 0.0383], [-0.8785, -1.1089]], dtype=tensorplay.float64) >>> tensorplay.where(x > 0, x, 0.) tensor([[1.0779, 0.0383], [0.0000, 0.0000]], dtype=tensorplay.float64)- tensorplay.functional.where(condition) tuple of LongTensor[source]
tensorplay.where(condition)is identical totensorplay.nonzero(condition, as_tuple=True).Note
See also
tensorplay.nonzero().
xlog1py
functionFull reference ↗- tensorplay.functional.xlog1py(input, other)[source]
xlogy_
functionFull reference ↗- tensorplay.functional.xlogy_(input, other)[source]
xlogy
functionFull reference ↗zero_
functionFull reference ↗- tensorplay.functional.zero_(input)[source]
zeros_like
functionFull reference ↗- tensorplay.functional.zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) Tensor
Returns a tensor filled with the scalar value 0, with the same size as
input.tensorplay.zeros_like(input)is equivalent totensorplay.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).Warning
As of 0.4, this function does not support an
outkeyword. As an alternative, the oldtensorplay.zeros_like(input, out=output)is equivalent totensorplay.zeros(input.size(), out=output).- Parameters:
input (Tensor) – the size of
inputwill determine size of the output tensor.- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned Tensor. Default: ifNone, defaults to the dtype ofinput.layout (
tensorplay.layout, optional) – the desired layout of returned tensor. Default: ifNone, defaults to the layout ofinput.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, defaults to the device ofinput.requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default:
False.memory_format (
tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default:tensorplay.preserve_format.
Example:
>>> input = tensorplay.empty(2, 3) >>> tensorplay.zeros_like(input) tensor([[ 0., 0., 0.], [ 0., 0., 0.]])
zeta
functionFull reference ↗- tensorplay.functional.zeta(input, other)[source]
Help improve this page
Found an error, an unclear step, or a missing example?

