# tensorplay.functional API Source: https://www.tensorplay.cn/docs/api/tensorplay.functional.html ## Functions 605 [#](#api-tensorplay.functional.abs_) ### abs_ function[Full reference ↗](/docs/generated/tensorplay.functional.abs_.html) ```python tensorplay.functional.abs_(input) ``` [#](#api-tensorplay.functional.abs) ### abs function[Full reference ↗](/docs/generated/tensorplay.functional.abs.html) ```python tensorplay.functional.abs(input: Tensor, *, out: Tensor | None) → Tensor ``` Computes the absolute value of each element in input. $$\text{out}_{i} = |\text{input}_{i}|$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.abs(tensorplay.tensor([-1, -2, 3])) tensor([ 1, 2, 3]) ``` [#](#api-tensorplay.functional.absolute) ### absolute function[Full reference ↗](/docs/generated/tensorplay.functional.absolute.html) ```python tensorplay.functional.absolute(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.abs() [#](#api-tensorplay.functional.acos_) ### acos_ function[Full reference ↗](/docs/generated/tensorplay.functional.acos_.html) ```python tensorplay.functional.acos_(input) ``` [#](#api-tensorplay.functional.acos) ### acos function[Full reference ↗](/docs/generated/tensorplay.functional.acos.html) ```python tensorplay.functional.acos(input: Tensor, *, out: Tensor | None) → Tensor ``` Computes the inverse cosine of each element in input. $$\text{out}_{i} = \cos^{-1}(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.acosh_) ### acosh_ function[Full reference ↗](/docs/generated/tensorplay.functional.acosh_.html) ```python tensorplay.functional.acosh_(input) ``` [#](#api-tensorplay.functional.acosh) ### acosh function[Full reference ↗](/docs/generated/tensorplay.functional.acosh.html) ```python tensorplay.functional.acosh(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the inverse hyperbolic cosine of the elements of input. $$\text{out}_{i} = \cosh^{-1}(\text{input}_{i})$$ > **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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ]) ``` [#](#api-tensorplay.functional.adaptive_avg_pool1d) ### adaptive_avg_pool1d function[Full reference ↗](/docs/generated/tensorplay.functional.adaptive_avg_pool1d.html) ```python tensorplay.functional.adaptive_avg_pool1d(input, output_size) ``` [#](#api-tensorplay.functional.adaptive_max_pool1d) ### adaptive_max_pool1d function[Full reference ↗](/docs/generated/tensorplay.functional.adaptive_max_pool1d.html) ```python tensorplay.functional.adaptive_max_pool1d(input, output_size) ``` [#](#api-tensorplay.functional.add) ### add function[Full reference ↗](/docs/generated/tensorplay.functional.add.html) ```python tensorplay.functional.add(input, other, *, alpha=1, out=None) → Tensor ``` Adds other, scaled by alpha, to input. $$\text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i$$ Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer, float, and complex inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the tensor or number to add to input. Keyword Arguments: - alpha (Number) – the multiplier for other. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.addbmm) ### addbmm function[Full reference ↗](/docs/generated/tensorplay.functional.addbmm.html) ```python tensorplay.functional.addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) → Tensor ``` Performs a batch matrix-matrix product of matrices stored in batch1 and batch2, with a reduced add step (all matrix multiplications get accumulated along the first dimension). input is added to the final result. batch1 and batch2 must be 3-D tensors each containing the same number of matrices. If batch1 is a $(b \times n \times m)$ tensor, batch2 is a $(b \times m \times p)$ tensor, input must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with a $(n \times p)$ tensor and out will be a $(n \times p)$ tensor. $$out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)$$ If beta is 0, then the content of input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operator supports [TensorFloat32](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – matrix to be added - batch1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first batch of matrices to be multiplied - batch2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second batch of matrices to be multiplied Keyword Arguments: - beta (Number, optional) – multiplier for input ($\beta$) - alpha (Number, optional) – multiplier for batch1 @ batch2 ($\alpha$) - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.addcdiv) ### addcdiv function[Full reference ↗](/docs/generated/tensorplay.functional.addcdiv.html) ```python tensorplay.functional.addcdiv(input, tensor1, tensor2, *, value=1, out=None) → Tensor ``` Performs the element-wise division of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input. > **Warning** > > Integer division with addcdiv is no longer supported, and in a future release addcdiv will perform a true division of tensor1 and tensor2. The historic addcdiv behavior can be implemented as (input + value * 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. @@TPBLOCK_282@@ The shapes of input, tensor1, and tensor2 must be broadcastable. For inputs of type FloatTensor or DoubleTensor, value must be a real number, otherwise an integer. Parameters : input (Tensor) – the tensor to be added tensor1 (Tensor) – the numerator tensor tensor2 (Tensor) – the denominator tensor Keyword Arguments : value (Number, optional) – multiplier for $\text{tensor1} / \text{tensor2}$ out (Tensor, optional) – the output tensor. Example: @@TPBLOCK_5@@ [#](#api-tensorplay.functional.addcmul) ### addcmul function[Full reference ↗](/docs/generated/tensorplay.functional.addcmul.html) ```python tensorplay.functional.addcmul(input, tensor1, tensor2, *, value=1, out=None) → Tensor ``` Performs the element-wise multiplication of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input. $$\text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i$$ The shapes of tensor, tensor1, and tensor2 must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). For inputs of type FloatTensor or DoubleTensor, value must be a real number, otherwise an integer. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to be added - tensor1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to be multiplied - tensor2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to be multiplied Keyword Arguments: - value (Number, optional) – multiplier for $tensor1 .* tensor2$ - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.addmm) ### addmm function[Full reference ↗](/docs/generated/tensorplay.functional.addmm.html) ```python tensorplay.functional.addmm(input, mat1, mat2, out_dtype=None, *, beta=1, alpha=1, out=None) → Tensor ``` Performs a matrix multiplication of the matrices mat1 and mat2. The matrix input is added to the final result. If mat1 is a $(n \times m)$ tensor, mat2 is a $(m \times p)$ tensor, then input must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with a $(n \times p)$ tensor and out will be a $(n \times p)$ tensor. alpha and beta are scaling factors on matrix-vector product between mat1 and mat2 and the added matrix input respectively. $$\text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)$$ If beta is 0, then the content of input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operation has support for arguments with sparse layouts. If input is sparse the result will have the same layout and if out is provided it must have the same layout as input. > **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](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – matrix to be added - mat1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first matrix to be matrix multiplied - mat2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second matrix to be matrix multiplied - out_dtype ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.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 ($\beta$) - alpha (Number, optional) – multiplier for $mat1 @ mat2$ ($\alpha$) - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.addmv_) ### addmv_ function[Full reference ↗](/docs/generated/tensorplay.functional.addmv_.html) ```python tensorplay.functional.addmv_(input, mat, vec, beta=1, alpha=1) ``` [#](#api-tensorplay.functional.addmv) ### addmv function[Full reference ↗](/docs/generated/tensorplay.functional.addmv.html) ```python tensorplay.functional.addmv(input, mat, vec, *, beta=1, alpha=1, out=None) → Tensor ``` Performs a matrix-vector product of the matrix mat and the vector vec. The vector input is added to the final result. If mat is a $(n \times m)$ tensor, vec is a 1-D tensor of size m, then input must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with a 1-D tensor of size n and out will be 1-D tensor of size n. alpha and beta are scaling factors on matrix-vector product between mat and vec and the added tensor input respectively. $$\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})$$ If beta is 0, then the content of input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – vector to be added - mat ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – matrix to be matrix multiplied - vec ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – vector to be matrix multiplied Keyword Arguments: - beta (Number, optional) – multiplier for input ($\beta$) - alpha (Number, optional) – multiplier for $mat @ vec$ ($\alpha$) - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.addr) ### addr function[Full reference ↗](/docs/generated/tensorplay.functional.addr.html) ```python tensorplay.functional.addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) → Tensor ``` Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input. Optional values beta and alpha are scaling factors on the outer product between vec1 and vec2 and the added matrix input respectively. $$\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})$$ If beta is 0, then the content of input will be ignored, and nan and inf in it will not be propagated. If vec1 is a vector of size n and vec2 is a vector of size m, then input must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with a matrix of size $(n \times m)$ and out will be a matrix of size $(n \times m)$. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – matrix to be added - vec1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first vector of the outer product - vec2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second vector of the outer product Keyword Arguments: - beta (Number, optional) – multiplier for input ($\beta$) - alpha (Number, optional) – multiplier for $\text{vec1} \otimes \text{vec2}$ ($\alpha$) - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]]) ``` [#](#api-tensorplay.functional.adjoint) ### adjoint function[Full reference ↗](/docs/generated/tensorplay.functional.adjoint.html) ```python tensorplay.functional.adjoint(input: Tensor) → Tensor ``` Returns a view of the tensor conjugated and with the last two dimensions transposed. x.adjoint() is equivalent to x.transpose(-2, -1).conj() for complex tensors and to x.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) ``` [#](#api-tensorplay.functional.affine_grid_generator) ### affine_grid_generator function[Full reference ↗](/docs/generated/tensorplay.functional.affine_grid_generator.html) ```python tensorplay.functional.affine_grid_generator(theta, size, align_corners) ``` [#](#api-tensorplay.functional.airy_ai) ### airy_ai function[Full reference ↗](/docs/generated/tensorplay.functional.airy_ai.html) ```python tensorplay.functional.airy_ai(input) ``` [#](#api-tensorplay.functional.alias_copy) ### alias_copy function[Full reference ↗](/docs/generated/tensorplay.functional.alias_copy.html) ```python tensorplay.functional.alias_copy(input) ``` Performs the same operation as [tensorplay.alias()](/docs/generated/tensorplay.alias.html#tensorplay.alias), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.all) ### all function[Full reference ↗](/docs/generated/tensorplay.functional.all.html) ```python tensorplay.functional.all(input: Tensor, *, out=None) → Tensor ``` Tests if all elements in input evaluate to True. > **Note** > > This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` ```python tensorplay.functional.all(input, dim, keepdim=False, *, out=None) → Tensor ``` For each row of input in the given dimension dim, returns True if all elements in the row evaluate to True and False otherwise. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.allclose) ### allclose function[Full reference ↗](/docs/generated/tensorplay.functional.allclose.html) ```python tensorplay.functional.allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) → bool ``` This function checks if input and other satisfy the condition: $$\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert$$ elementwise, for all elements of input and other. The behaviour of this function is analogous to [numpy.allclose](https://numpy.org/doc/stable/reference/generated/numpy.allclose.html) Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – first tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – second tensor to compare - atol ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – absolute tolerance. Default: 1e-08 - rtol ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – relative tolerance. Default: 1e-05 - equal_nan ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – if True, then two NaN s will be considered equal. Default: False 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 ``` [#](#api-tensorplay.functional.alpha_dropout_) ### alpha_dropout_ function[Full reference ↗](/docs/generated/tensorplay.functional.alpha_dropout_.html) ```python tensorplay.functional.alpha_dropout_(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.alpha_dropout) ### alpha_dropout function[Full reference ↗](/docs/generated/tensorplay.functional.alpha_dropout.html) ```python tensorplay.functional.alpha_dropout(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.amax) ### amax function[Full reference ↗](/docs/generated/tensorplay.functional.amax.html) ```python tensorplay.functional.amax(input, dim, keepdim=False, *, out=None) → Tensor ``` Returns the maximum value of each slice of the input tensor in the given dimension(s) dim. > **Note** > > The difference between max / min and amax / amin is: amax/amin supports reducing on multiple dimensions, amax/amin does not return indices. Both amax/amin evenly 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/min values. If reduce over one specified axis, only propagate to the indexed element. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.amin) ### amin function[Full reference ↗](/docs/generated/tensorplay.functional.amin.html) ```python tensorplay.functional.amin(input, dim, keepdim=False, *, out=None) → Tensor ``` Returns the minimum value of each slice of the input tensor in the given dimension(s) dim. > **Note** > > The difference between max / min and amax / amin is: amax/amin supports reducing on multiple dimensions, amax/amin does not return indices. Both amax/amin evenly 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/min values. If reduce over one specified axis, only propagate to the indexed element. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.aminmax) ### aminmax function[Full reference ↗](/docs/generated/tensorplay.functional.aminmax.html) ```python tensorplay.functional.aminmax(input, dim=[], keepdim=False, *, out=None) ``` [#](#api-tensorplay.functional.angle) ### angle function[Full reference ↗](/docs/generated/tensorplay.functional.angle.html) ```python tensorplay.functional.angle(input: Tensor, *, out: Tensor | None) → Tensor ``` Computes the element-wise angle (in radians) of the given input tensor. $$\text{out}_{i} = angle(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.any) ### any function[Full reference ↗](/docs/generated/tensorplay.functional.any.html) ```python tensorplay.functional.any(input: Tensor, *, out: Tensor | None) → Tensor ``` Tests if any element in input evaluates to True. > **Note** > > This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` ```python tensorplay.functional.any(input, dim, keepdim=False, *, out=None) → Tensor ``` For each row of input in the given dimension dim, returns True if any element in the row evaluate to True and False otherwise. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.arange) ### arange function[Full reference ↗](/docs/generated/tensorplay.functional.arange.html) ```python tensorplay.functional.arange(start=0, end, step=1, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Returns a 1-D tensor of size $\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil$ with values from the interval [start, end) taken with common difference step beginning from start. Note: 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 step is subject to floating point rounding errors when comparing against end; to avoid inconsistency, we advise subtracting a small epsilon from end in such cases. $$\text{out}_{{i+1}} = \text{out}_{i} + \text{step}$$ 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.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, see [get_default_dtype()](/docs/generated/tensorplay.get_default_dtype.html#tensorplay.get_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](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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]) ``` [#](#api-tensorplay.functional.arccos_) ### arccos_ function[Full reference ↗](/docs/generated/tensorplay.functional.arccos_.html) ```python tensorplay.functional.arccos_(input) ``` [#](#api-tensorplay.functional.arccos) ### arccos function[Full reference ↗](/docs/generated/tensorplay.functional.arccos.html) ```python tensorplay.functional.arccos(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.acos(). [#](#api-tensorplay.functional.arccosh_) ### arccosh_ function[Full reference ↗](/docs/generated/tensorplay.functional.arccosh_.html) ```python tensorplay.functional.arccosh_(input) ``` [#](#api-tensorplay.functional.arccosh) ### arccosh function[Full reference ↗](/docs/generated/tensorplay.functional.arccosh.html) ```python tensorplay.functional.arccosh(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.acosh(). [#](#api-tensorplay.functional.arcsin_) ### arcsin_ function[Full reference ↗](/docs/generated/tensorplay.functional.arcsin_.html) ```python tensorplay.functional.arcsin_(input) ``` [#](#api-tensorplay.functional.arcsin) ### arcsin function[Full reference ↗](/docs/generated/tensorplay.functional.arcsin.html) ```python tensorplay.functional.arcsin(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.asin(). [#](#api-tensorplay.functional.arcsinh_) ### arcsinh_ function[Full reference ↗](/docs/generated/tensorplay.functional.arcsinh_.html) ```python tensorplay.functional.arcsinh_(input) ``` [#](#api-tensorplay.functional.arcsinh) ### arcsinh function[Full reference ↗](/docs/generated/tensorplay.functional.arcsinh.html) ```python tensorplay.functional.arcsinh(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.asinh(). [#](#api-tensorplay.functional.arctan_) ### arctan_ function[Full reference ↗](/docs/generated/tensorplay.functional.arctan_.html) ```python tensorplay.functional.arctan_(input) ``` [#](#api-tensorplay.functional.arctan) ### arctan function[Full reference ↗](/docs/generated/tensorplay.functional.arctan.html) ```python tensorplay.functional.arctan(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.atan(). [#](#api-tensorplay.functional.arctan2) ### arctan2 function[Full reference ↗](/docs/generated/tensorplay.functional.arctan2.html) ```python tensorplay.functional.arctan2(input: Tensor, other: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.atan2(). [#](#api-tensorplay.functional.arctanh_) ### arctanh_ function[Full reference ↗](/docs/generated/tensorplay.functional.arctanh_.html) ```python tensorplay.functional.arctanh_(input) ``` [#](#api-tensorplay.functional.arctanh) ### arctanh function[Full reference ↗](/docs/generated/tensorplay.functional.arctanh.html) ```python tensorplay.functional.arctanh(input: Tensor, *, out: Tensor | None) → Tensor ``` Alias for tensorplay.atanh(). [#](#api-tensorplay.functional.argmax) ### argmax function[Full reference ↗](/docs/generated/tensorplay.functional.argmax.html) ```python tensorplay.functional.argmax(input) → LongTensor ``` Returns the indices of the maximum value of all elements in the input tensor. This is the second value returned by [tensorplay.max()](/docs/generated/tensorplay.max.html#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](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` ```python tensorplay.functional.argmax(input, dim, keepdim=False) → LongTensor ``` Returns the indices of the maximum values of a tensor across a dimension. This is the second value returned by [tensorplay.max()](/docs/generated/tensorplay.max.html#tensorplay.max). See its documentation for the exact semantics of this method. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.argmin) ### argmin function[Full reference ↗](/docs/generated/tensorplay.functional.argmin.html) ```python tensorplay.functional.argmin(input, dim=None, keepdim=False) → LongTensor ``` Returns the indices of the minimum value(s) of the flattened tensor or along a dimension This is the second value returned by [tensorplay.min()](/docs/generated/tensorplay.min.html#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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.argsort) ### argsort function[Full reference ↗](/docs/generated/tensorplay.functional.argsort.html) ```python tensorplay.functional.argsort(input, dim=-1, descending=False, *, stable=False) → Tensor ``` 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 stable is True then the sorting routine becomes stable, preserving the order of equivalent elements. If False, the relative order of values which compare equal is not guaranteed. True is slower. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the dimension to sort along - descending ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – controls the sorting order (ascending or descending) Keyword Arguments: stable ([bool](https://docs.python.org/3/builtins/functions.html#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]]) ``` [#](#api-tensorplay.functional.argwhere) ### argwhere function[Full reference ↗](/docs/generated/tensorplay.functional.argwhere.html) ```python tensorplay.functional.argwhere(input) → Tensor ``` 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 in input. The result is sorted lexicographically, with the last index changing the fastest (C-style). If input has $n$ dimensions, then the resulting indices tensor out is of size $(z \times n)$, where $z$ is the total number of non-zero elements in the input tensor. > **Note** > > This function is similar to NumPy’s argwhere. When input is 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]]) ``` [#](#api-tensorplay.functional.as_strided_) ### as_strided_ function[Full reference ↗](/docs/generated/tensorplay.functional.as_strided_.html) ```python tensorplay.functional.as_strided_(input, size, stride, storage_offset=None) ``` [#](#api-tensorplay.functional.as_strided_copy) ### as_strided_copy function[Full reference ↗](/docs/generated/tensorplay.functional.as_strided_copy.html) ```python tensorplay.functional.as_strided_copy(input, size, stride, storage_offset=None) ``` Performs the same operation as tensorplay.as_strided(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.as_strided_scatter) ### as_strided_scatter function[Full reference ↗](/docs/generated/tensorplay.functional.as_strided_scatter.html) ```python tensorplay.functional.as_strided_scatter(input, src, size, stride, storage_offset=None) → Tensor ``` Embeds the values of the src tensor into input along 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - size ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) or ints) – the shape of the output tensor - stride ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) or ints) – the stride of the output tensor - storage_offset ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the offset in the underlying storage of the output tensor > **Note** > > src must be of the proper size in order to be embedded into input. 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.]]) ``` [#](#api-tensorplay.functional.as_strided) ### as_strided function[Full reference ↗](/docs/generated/tensorplay.functional.as_strided.html) ```python tensorplay.functional.as_strided(input, size, stride, storage_offset=None) → Tensor ``` Create a view of an existing tensorplay.Tensor input with specified size, stride and storage_offset. > **Warning** > > Prefer using other view functions, like tensorplay.Tensor.view() or tensorplay.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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - size ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) or ints) – the shape of the output tensor - stride ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) or ints) – the stride of the output tensor - storage_offset ([int](https://docs.python.org/3/builtins/functions.html#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]]) ``` [#](#api-tensorplay.functional.asin_) ### asin_ function[Full reference ↗](/docs/generated/tensorplay.functional.asin_.html) ```python tensorplay.functional.asin_(input) ``` [#](#api-tensorplay.functional.asin) ### asin function[Full reference ↗](/docs/generated/tensorplay.functional.asin.html) ```python tensorplay.functional.asin(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the arcsine of the elements of input. $$\text{out}_{i} = \sin^{-1}(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.asinh_) ### asinh_ function[Full reference ↗](/docs/generated/tensorplay.functional.asinh_.html) ```python tensorplay.functional.asinh_(input) ``` [#](#api-tensorplay.functional.asinh) ### asinh function[Full reference ↗](/docs/generated/tensorplay.functional.asinh.html) ```python tensorplay.functional.asinh(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the inverse hyperbolic sine of the elements of input. $$\text{out}_{i} = \sinh^{-1}(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ]) ``` [#](#api-tensorplay.functional.atan_) ### atan_ function[Full reference ↗](/docs/generated/tensorplay.functional.atan_.html) ```python tensorplay.functional.atan_(input) ``` [#](#api-tensorplay.functional.atan) ### atan function[Full reference ↗](/docs/generated/tensorplay.functional.atan.html) ```python tensorplay.functional.atan(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the arctangent of the elements of input. $$\text{out}_{i} = \tan^{-1}(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.atan2) ### atan2 function[Full reference ↗](/docs/generated/tensorplay.functional.atan2.html) ```python tensorplay.functional.atan2(input: Tensor, other: Tensor, *, out: Tensor | None) → Tensor ``` Element-wise arctangent of $\text{input}_{i} / \text{other}_{i}$ with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector $(\text{other}_{i}, \text{input}_{i})$ and vector $(1, 0)$. (Note that $\text{other}_{i}$, the second parameter, is the x-coordinate, while $\text{input}_{i}$, the first parameter, is the y-coordinate.) The shapes of input and other must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.atanh_) ### atanh_ function[Full reference ↗](/docs/generated/tensorplay.functional.atanh_.html) ```python tensorplay.functional.atanh_(input) ``` [#](#api-tensorplay.functional.atanh) ### atanh function[Full reference ↗](/docs/generated/tensorplay.functional.atanh.html) ```python tensorplay.functional.atanh(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the inverse hyperbolic tangent of the elements of input. > **Note** > > The domain of the inverse hyperbolic tangent is (-1, 1) and values outside this range will be mapped to NaN, except for the values 1 and -1 for which the output is mapped to +/-INF respectively. @@TPBLOCK_293@@ Parameters : input (Tensor) – the input tensor. Keyword Arguments : out (Tensor, optional) – the output tensor. Example: @@TPBLOCK_31@@ [#](#api-tensorplay.functional.atleast_1d) ### atleast_1d function[Full reference ↗](/docs/generated/tensorplay.functional.atleast_1d.html) ```python tensorplay.functional.atleast_1d(*args) ``` [#](#api-tensorplay.functional.atleast_2d) ### atleast_2d function[Full reference ↗](/docs/generated/tensorplay.functional.atleast_2d.html) ```python tensorplay.functional.atleast_2d(*args) ``` [#](#api-tensorplay.functional.atleast_3d) ### atleast_3d function[Full reference ↗](/docs/generated/tensorplay.functional.atleast_3d.html) ```python tensorplay.functional.atleast_3d(*args) ``` [#](#api-tensorplay.functional.avg_pool1d) ### avg_pool1d function[Full reference ↗](/docs/generated/tensorplay.functional.avg_pool1d.html) ```python tensorplay.functional.avg_pool1d(input, kernel_size, stride=[], padding=0, ceil_mode=False, count_include_pad=True) ``` [#](#api-tensorplay.functional.baddbmm) ### baddbmm function[Full reference ↗](/docs/generated/tensorplay.functional.baddbmm.html) ```python tensorplay.functional.baddbmm(input, batch1, batch2, out_dtype=None, *, beta=1, alpha=1, out=None) → Tensor ``` Performs a batch matrix-matrix product of matrices in batch1 and batch2. input is added to the final result. batch1 and batch2 must be 3-D tensors each containing the same number of matrices. If batch1 is a $(b \times n \times m)$ tensor, batch2 is a $(b \times m \times p)$ tensor, then input must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with a $(b \times n \times p)$ tensor and out will be a $(b \times n \times p)$ tensor. Both alpha and beta mean the same as the scaling factors used in tensorplay.addbmm(). $$\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)$$ If beta is 0, then the content of input will be ignored, and nan and inf in it will not be propagated. For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. This operator supports [TensorFloat32](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to be added - batch1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first batch of matrices to be multiplied - batch2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second batch of matrices to be multiplied - out_dtype ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.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 ($\beta$) - alpha (Number, optional) – multiplier for $\text{batch1} \mathbin{@} \text{batch2}$ ($\alpha$) - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.bartlett_window) ### bartlett_window function[Full reference ↗](/docs/generated/tensorplay.functional.bartlett_window.html) ```python tensorplay.functional.bartlett_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Bartlett window function. $$\begin{split}w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases} \frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\ 2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\ \end{cases},\end{split}$$ where $N$ is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag 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 like tensorplay.stft(). Therefore, if periodic is true, the $N$ in above formula is in fact $\text{window\_length} + 1$. Also, we always have tensorplay.bartlett_window(L, periodic=True) equal to tensorplay.bartlett_window(L + 1, periodic=False)[:-1]). > **Note** > > If window_length $=1$, the returned window contains a single value 1. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) [#](#api-tensorplay.functional.batch_norm_backward_elemt) ### batch_norm_backward_elemt function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_backward_elemt.html) ```python tensorplay.functional.batch_norm_backward_elemt(grad_out, input, mean, invstd, weight, sum_dy, sum_dy_xmu, count) ``` [#](#api-tensorplay.functional.batch_norm_backward_reduce) ### batch_norm_backward_reduce function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_backward_reduce.html) ```python tensorplay.functional.batch_norm_backward_reduce(grad_out, input, mean, invstd, weight, input_g, weight_g, bias_g) ``` [#](#api-tensorplay.functional.batch_norm_elemt) ### batch_norm_elemt function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_elemt.html) ```python tensorplay.functional.batch_norm_elemt(input, weight, bias, mean, invstd, eps, *, out=None) ``` [#](#api-tensorplay.functional.batch_norm_gather_stats_with_counts) ### batch_norm_gather_stats_with_counts function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_gather_stats_with_counts.html) ```python tensorplay.functional.batch_norm_gather_stats_with_counts(input, mean, invstd, running_mean, running_var, momentum, eps, counts) ``` [#](#api-tensorplay.functional.batch_norm_gather_stats) ### batch_norm_gather_stats function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_gather_stats.html) ```python tensorplay.functional.batch_norm_gather_stats(input, mean, invstd, running_mean, running_var, momentum, eps, count) ``` [#](#api-tensorplay.functional.batch_norm_stats) ### batch_norm_stats function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_stats.html) ```python tensorplay.functional.batch_norm_stats(input, eps) ``` [#](#api-tensorplay.functional.batch_norm_update_stats) ### batch_norm_update_stats function[Full reference ↗](/docs/generated/tensorplay.functional.batch_norm_update_stats.html) ```python tensorplay.functional.batch_norm_update_stats(input, running_mean, running_var, momentum) ``` [#](#api-tensorplay.functional.bernoulli) ### bernoulli function[Full reference ↗](/docs/generated/tensorplay.functional.bernoulli.html) ```python tensorplay.functional.bernoulli(input: Tensor, *, generator: Generator | None, out: Tensor | None) → Tensor ``` Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor containing probabilities to be used for drawing the binary random number. Hence, all values in input have to be in the range: $0 \leq \text{input}_i \leq 1$. The $\text{i}^{th}$ element of the output tensor will draw a value $1$ according to the $\text{i}^{th}$ probability value given in input. $$\text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})$$ The returned out tensor only has values 0 or 1 and is of the same shape as input. out can have integral dtype, but input must have floating point dtype. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor of probability values for the Bernoulli distribution Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]]) ``` [#](#api-tensorplay.functional.bessel_j0) ### bessel_j0 function[Full reference ↗](/docs/generated/tensorplay.functional.bessel_j0.html) ```python tensorplay.functional.bessel_j0(input) ``` [#](#api-tensorplay.functional.bessel_j1) ### bessel_j1 function[Full reference ↗](/docs/generated/tensorplay.functional.bessel_j1.html) ```python tensorplay.functional.bessel_j1(input) ``` [#](#api-tensorplay.functional.bessel_y0) ### bessel_y0 function[Full reference ↗](/docs/generated/tensorplay.functional.bessel_y0.html) ```python tensorplay.functional.bessel_y0(input) ``` [#](#api-tensorplay.functional.bessel_y1) ### bessel_y1 function[Full reference ↗](/docs/generated/tensorplay.functional.bessel_y1.html) ```python tensorplay.functional.bessel_y1(input) ``` [#](#api-tensorplay.functional.bilinear) ### bilinear function[Full reference ↗](/docs/generated/tensorplay.functional.bilinear.html) ```python tensorplay.functional.bilinear(input1, input2, weight, bias=None) ``` [#](#api-tensorplay.functional.bincount) ### bincount function[Full reference ↗](/docs/generated/tensorplay.functional.bincount.html) ```python tensorplay.functional.bincount(input, weights=None, minlength=0) → Tensor ``` 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 input unless input is empty, in which case the result is a tensor of size 0. If minlength is specified, the number of bins is at least minlength and if input is empty, then the result is tensor of size minlength filled with zeros. If n is the value at position i, out[n] += weights[i] if weights is specified else out[n] += 1. > **Note** > > This operation may produce nondeterministic gradients when given tensors on a CUDA device. See Reproducibility for more information. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1-d int tensor - weights ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – optional, weight for each value in the input tensor. Should be of same size as input tensor. - minlength ([int](https://docs.python.org/3/builtins/functions.html#int)) – optional, minimum number of bins. Should be non-negative. Returns: a tensor of shape Size([max(input) + 1]) if input is non-empty, else Size(0) Return type: output ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.binomial) ### binomial function[Full reference ↗](/docs/generated/tensorplay.functional.binomial.html) ```python tensorplay.functional.binomial(count, prob, generator=None) ``` [#](#api-tensorplay.functional.bitwise_and) ### bitwise_and function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_and.html) ```python tensorplay.functional.bitwise_and(input, other, *, out=None) → Tensor ``` Computes the bitwise AND of input and other. 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.bitwise_left_shift) ### bitwise_left_shift function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_left_shift.html) ```python tensorplay.functional.bitwise_left_shift(input, other, *, out=None) → Tensor ``` Computes the left arithmetic shift of input by other bits. The input tensor must be of integral type. This operator supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics) and type promotion. The operation applied is: $$\text{out}_i = \text{input}_i << \text{other}_i$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the first input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.bitwise_not) ### bitwise_not function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_not.html) ```python tensorplay.functional.bitwise_not(input, *, out=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.bitwise_not(tensorplay.tensor([-1, -2, 3], dtype=tensorplay.int8)) tensor([ 0, 1, -4], dtype=tensorplay.int8) ``` [#](#api-tensorplay.functional.bitwise_or) ### bitwise_or function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_or.html) ```python tensorplay.functional.bitwise_or(input: Tensor, other: Tensor, *, out: Tensor | None) → Tensor ``` Computes the bitwise OR of input and other. 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.bitwise_right_shift) ### bitwise_right_shift function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_right_shift.html) ```python tensorplay.functional.bitwise_right_shift(input, other, *, out=None) → Tensor ``` Computes the right arithmetic shift of input by other bits. The input tensor must be of integral type. This operator supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics) 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: $$\text{out}_i = \text{input}_i >> \text{other}_i$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the first input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.bitwise_xor) ### bitwise_xor function[Full reference ↗](/docs/generated/tensorplay.functional.bitwise_xor.html) ```python tensorplay.functional.bitwise_xor(input, other, *, out=None) → Tensor ``` Computes the bitwise XOR of input and other. 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.blackman_window) ### blackman_window function[Full reference ↗](/docs/generated/tensorplay.functional.blackman_window.html) ```python tensorplay.functional.blackman_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Blackman window function. $$w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)$$ where $N$ is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag 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 like tensorplay.stft(). Therefore, if periodic is true, the $N$ in above formula is in fact $\text{window\_length} + 1$. Also, we always have tensorplay.blackman_window(L, periodic=True) equal to tensorplay.blackman_window(L + 1, periodic=False)[:-1]. > **Note** > > If window_length $=1$, the returned window contains a single value 1. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) [#](#api-tensorplay.functional.bmm) ### bmm function[Full reference ↗](/docs/generated/tensorplay.functional.bmm.html) ```python tensorplay.functional.bmm(input, mat2, out_dtype=None, *, out=None) → Tensor ``` Performs a batch matrix-matrix product of matrices stored in input and mat2. input and mat2 must be 3-D tensors each containing the same number of matrices. If input is a $(b \times n \times m)$ tensor, mat2 is a $(b \times m \times p)$ tensor, out will be a $(b \times n \times p)$ tensor. $$\text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i$$ This operator supports [TensorFloat32](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. > **Note** > > This function does not broadcast. For broadcasting matrix products, see tensorplay.matmul(). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first batch of matrices to be multiplied - mat2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second batch of matrices to be multiplied - out_dtype ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.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: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.broadcast_to) ### broadcast_to function[Full reference ↗](/docs/generated/tensorplay.functional.broadcast_to.html) ```python tensorplay.functional.broadcast_to(input, shape) → Tensor ``` Broadcasts input to the shape shape. Equivalent to calling input.expand(shape). See expand() for details. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - shape (list, tuple, or [tensorplay.Size](/docs/generated/tensorplay.Size.html#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]]) ``` [#](#api-tensorplay.functional.bucketize) ### bucketize function[Full reference ↗](/docs/generated/tensorplay.functional.bucketize.html) ```python tensorplay.functional.bucketize(input, boundaries, *, out_int32=False, right=False, out=None) → Tensor ``` Returns the indices of the buckets to which each value in the input belongs, where the boundaries of the buckets are set by boundaries. Return a new tensor with the same size as input. If right is False (default), then the left boundary is open. Note that this behavior is opposite the behavior of [numpy.digitize](https://numpy.org/doc/stable/reference/generated/numpy.digitize.html). More formally, the returned index satisfies the following rules: | right |returned 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – N-D tensor or a Scalar containing the search value(s). - boundaries ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined. Keyword Arguments: - out_int32 ([bool](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#bool), optional) – determines the behavior for values in boundaries. See the table above. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor, must be the same size as input if 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]]) ``` [#](#api-tensorplay.functional.can_cast) ### can_cast function[Full reference ↗](/docs/generated/tensorplay.functional.can_cast.html) ```python tensorplay.functional.can_cast(from_, to) → bool ``` described in the type promotion documentation. Parameters: - from_ ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType)) – The original [tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType). - to ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType)) – The target [tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType). Example: ``` >>> tensorplay.can_cast(tensorplay.double, tensorplay.float) True >>> tensorplay.can_cast(tensorplay.float, tensorplay.int) False ``` [#](#api-tensorplay.functional.cartesian_prod) ### cartesian_prod function[Full reference ↗](/docs/generated/tensorplay.functional.cartesian_prod.html) ```python tensorplay.functional.cartesian_prod(*args) ``` [#](#api-tensorplay.functional.cat) ### cat function[Full reference ↗](/docs/generated/tensorplay.functional.cat.html) ```python tensorplay.functional.cat(tensors, dim=0, *, out=None) → Tensor ``` Concatenates the given sequence of tensors in tensors in 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 for tensorplay.split() and tensorplay.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](https://docs.python.org/3/builtins/functions.html#int), optional) – the dimension over which the tensors are concatenated Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.ccol_indices_copy) ### ccol_indices_copy function[Full reference ↗](/docs/generated/tensorplay.functional.ccol_indices_copy.html) ```python tensorplay.functional.ccol_indices_copy(input) ``` [#](#api-tensorplay.functional.cdist) ### cdist function[Full reference ↗](/docs/generated/tensorplay.functional.cdist.html) ```python tensorplay.functional.cdist(x1, x2, p=2, compute_mode=None) ``` [#](#api-tensorplay.functional.ceil_) ### ceil_ function[Full reference ↗](/docs/generated/tensorplay.functional.ceil_.html) ```python tensorplay.functional.ceil_(input) ``` [#](#api-tensorplay.functional.ceil) ### ceil function[Full reference ↗](/docs/generated/tensorplay.functional.ceil.html) ```python tensorplay.functional.ceil(input, *, out=None) → Tensor ``` 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. $$\text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.celu_) ### celu_ function[Full reference ↗](/docs/generated/tensorplay.functional.celu_.html) ```python tensorplay.functional.celu_(input, alpha=1.0) ``` [#](#api-tensorplay.functional.chain_matmul) ### chain_matmul function[Full reference ↗](/docs/generated/tensorplay.functional.chain_matmul.html) ```python tensorplay.functional.chain_matmul(*args, out=None) ``` [#](#api-tensorplay.functional.channel_shuffle) ### channel_shuffle function[Full reference ↗](/docs/generated/tensorplay.functional.channel_shuffle.html) ```python tensorplay.functional.channel_shuffle(input, groups) ``` [#](#api-tensorplay.functional.chebyshev_polynomial_t) ### chebyshev_polynomial_t function[Full reference ↗](/docs/generated/tensorplay.functional.chebyshev_polynomial_t.html) ```python tensorplay.functional.chebyshev_polynomial_t(x, n) ``` [#](#api-tensorplay.functional.chebyshev_polynomial_u) ### chebyshev_polynomial_u function[Full reference ↗](/docs/generated/tensorplay.functional.chebyshev_polynomial_u.html) ```python tensorplay.functional.chebyshev_polynomial_u(x, n) ``` [#](#api-tensorplay.functional.chebyshev_polynomial_v) ### chebyshev_polynomial_v function[Full reference ↗](/docs/generated/tensorplay.functional.chebyshev_polynomial_v.html) ```python tensorplay.functional.chebyshev_polynomial_v(x, n) ``` [#](#api-tensorplay.functional.chebyshev_polynomial_w) ### chebyshev_polynomial_w function[Full reference ↗](/docs/generated/tensorplay.functional.chebyshev_polynomial_w.html) ```python tensorplay.functional.chebyshev_polynomial_w(x, n) ``` [#](#api-tensorplay.functional.cholesky_inverse) ### cholesky_inverse function[Full reference ↗](/docs/generated/tensorplay.functional.cholesky_inverse.html) ```python tensorplay.functional.cholesky_inverse(L, upper=False, *, out=None) → Tensor ``` Computes the inverse of a complex Hermitian or real symmetric positive-definite matrix given its Cholesky decomposition. Let $A$ be a complex Hermitian or real symmetric positive-definite matrix, and $L$ its Cholesky decomposition such that: $$A = LL^{\text{H}}$$ where $L^{\text{H}}$ is the conjugate transpose when $L$ is complex, and the transpose when $L$ is real-valued. Computes the inverse matrix $A^{-1}$. Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if $A$ is a batch of matrices then the output has the same batch dimensions. Parameters: - L ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](https://docs.python.org/3/builtins/functions.html#bool), optional) – flag that indicates whether $L$ is lower triangular or upper triangular. Default: False Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.cholesky_solve) ### cholesky_solve function[Full reference ↗](/docs/generated/tensorplay.functional.cholesky_solve.html) ```python tensorplay.functional.cholesky_solve(B, L, upper=False, *, out=None) → Tensor ``` Computes the solution of a system of linear equations with complex Hermitian or real symmetric positive-definite lhs given its Cholesky decomposition. Let $A$ be a complex Hermitian or real symmetric positive-definite matrix, and $L$ its Cholesky decomposition such that: $$A = LL^{\text{H}}$$ where $L^{\text{H}}$ is the conjugate transpose when $L$ is complex, and the transpose when $L$ is real-valued. Returns the solution $X$ of the following linear system: $$AX = B$$ Supports inputs of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if $A$ or $B$ is a batch of matrices then the output has the same batch dimensions. Parameters: - B ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – right-hand side tensor of shape (*, n, k) where $*$ is zero or more batch dimensions - L ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](https://docs.python.org/3/builtins/functions.html#bool), optional) – flag that indicates whether $L$ is lower triangular or upper triangular. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.choose_qparams_optimized) ### choose_qparams_optimized function[Full reference ↗](/docs/generated/tensorplay.functional.choose_qparams_optimized.html) ```python tensorplay.functional.choose_qparams_optimized(input, numel, n_bins, ratio, bit_width) ``` [#](#api-tensorplay.functional.chunk) ### chunk function[Full reference ↗](/docs/generated/tensorplay.functional.chunk.html) ```python tensorplay.functional.chunk(input: Tensor, chunks: int, dim: int = 0) → Tuple[Tensor, ...] ``` 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 chunks If the tensor size along the given dimension dim is divisible by chunks, all returned chunks will be the same size. If the tensor size along the given dimension dim is not divisible by chunks, 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to split - chunks ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of chunks to return - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – dimension along which to split the tensor 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])) ``` [#](#api-tensorplay.functional.clamp_) ### clamp_ function[Full reference ↗](/docs/generated/tensorplay.functional.clamp_.html) ```python tensorplay.functional.clamp_(input, min=None, max=None) ``` [#](#api-tensorplay.functional.clamp_max_) ### clamp_max_ function[Full reference ↗](/docs/generated/tensorplay.functional.clamp_max_.html) ```python tensorplay.functional.clamp_max_(input, max) ``` [#](#api-tensorplay.functional.clamp_min_) ### clamp_min_ function[Full reference ↗](/docs/generated/tensorplay.functional.clamp_min_.html) ```python tensorplay.functional.clamp_min_(input, min) ``` [#](#api-tensorplay.functional.clamp) ### clamp function[Full reference ↗](/docs/generated/tensorplay.functional.clamp.html) ```python tensorplay.functional.clamp(input, min=None, max=None, *, out=None) → Tensor ``` Clamps all elements in input into the range [ min, max ]. Letting min_value and max_value be min and max, respectively, this returns: $$y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)$$ If min is None, there is no lower bound. Or, if max is None there is no upper bound. > **Note** > > If min is greater than max tensorplay.clamp(..., min, max) sets all elements in input to the value of max. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - min (Number or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – lower-bound of the range to be clamped to - max (Number or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – upper-bound of the range to be clamped to Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.clip_) ### clip_ function[Full reference ↗](/docs/generated/tensorplay.functional.clip_.html) ```python tensorplay.functional.clip_(input, min=None, max=None) ``` [#](#api-tensorplay.functional.clip) ### clip function[Full reference ↗](/docs/generated/tensorplay.functional.clip.html) ```python tensorplay.functional.clip(input, min=None, max=None, *, out=None) → Tensor ``` Alias for tensorplay.clamp(). [#](#api-tensorplay.functional.clone) ### clone function[Full reference ↗](/docs/generated/tensorplay.functional.clone.html) ```python tensorplay.functional.clone(input, *, memory_format=tensorplay.preserve_format) → Tensor ``` 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 to input see detach(). In addition, when tensorplay.preserve_format is 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), optional) – the desired memory format of returned tensor. Default: tensorplay.preserve_format. [#](#api-tensorplay.functional.col_indices_copy) ### col_indices_copy function[Full reference ↗](/docs/generated/tensorplay.functional.col_indices_copy.html) ```python tensorplay.functional.col_indices_copy(input) ``` Performs the same operation as [tensorplay.col_indices()](/docs/generated/tensorplay.col_indices.html#tensorplay.col_indices), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.column_stack) ### column_stack function[Full reference ↗](/docs/generated/tensorplay.functional.column_stack.html) ```python tensorplay.functional.column_stack(tensors, *, out=None) → Tensor ``` Creates a new tensor by horizontally stacking the tensors in tensors. Equivalent to tensorplay.hstack(tensors), except each zero or one dimensional tensor t in tensors is 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.combinations) ### combinations function[Full reference ↗](/docs/generated/tensorplay.functional.combinations.html) ```python tensorplay.functional.combinations(input: Tensor, r: int = 2, with_replacement: bool = False) → seq ``` Compute combinations of length $r$ 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1D vector. - r ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – number of elements to combine - with_replacement ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – whether to allow duplication in combination 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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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]]) ``` [#](#api-tensorplay.functional.complex) ### complex function[Full reference ↗](/docs/generated/tensorplay.functional.complex.html) ```python tensorplay.functional.complex(real, imag, *, out=None) → Tensor ``` Constructs a complex tensor with its real part equal to [real](/docs/generated/tensorplay.functional.real.html#tensorplay.functional.real) and its imaginary part equal to [imag](/docs/generated/tensorplay.functional.imag.html#tensorplay.functional.imag). Parameters: - real ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The real part of the complex tensor. Must be half, float or double. - imag ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The imaginary part of the complex tensor. Must be same dtype as [real](/docs/generated/tensorplay.functional.real.html#tensorplay.functional.real). Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – If the inputs are tensorplay.float32, must be tensorplay.complex64. If the inputs are tensorplay.float64, must be tensorplay.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 ``` [#](#api-tensorplay.functional.concat) ### concat function[Full reference ↗](/docs/generated/tensorplay.functional.concat.html) ```python tensorplay.functional.concat(tensors, dim=0, *, out=None) → Tensor ``` Alias of tensorplay.cat(). [#](#api-tensorplay.functional.concatenate) ### concatenate function[Full reference ↗](/docs/generated/tensorplay.functional.concatenate.html) ```python tensorplay.functional.concatenate(tensors, axis=0, out=None) → Tensor ``` Alias of tensorplay.cat(). [#](#api-tensorplay.functional.conj_physical_) ### conj_physical_ function[Full reference ↗](/docs/generated/tensorplay.functional.conj_physical_.html) ```python tensorplay.functional.conj_physical_(input) ``` [#](#api-tensorplay.functional.conj_physical) ### conj_physical function[Full reference ↗](/docs/generated/tensorplay.functional.conj_physical.html) ```python tensorplay.functional.conj_physical(input, *, out=None) → Tensor ``` Computes the element-wise conjugate of the given input tensor. If input has a non-complex dtype, this function just returns input. > **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 an input of non-complex dtype. It’s recommended that programs not modify the tensor returned by tensorplay.conj_physical() when input is of non-complex dtype to be compatible with this change. @@TPBLOCK_306@@ Parameters : input (Tensor) – the input tensor. Keyword Arguments : out (Tensor, optional) – the output tensor. Example: @@TPBLOCK_54@@ [#](#api-tensorplay.functional.conj) ### conj function[Full reference ↗](/docs/generated/tensorplay.functional.conj.html) ```python tensorplay.functional.conj(input) → Tensor ``` Returns a view of input with a flipped conjugate bit. If input has a non-complex dtype, this function just returns input. > **Note** > > tensorplay.conj() performs a lazy conjugation, but the actual conjugated tensor can be materialized at any time using tensorplay.resolve_conj(). > **Warning** > > In the future, tensorplay.conj() may return a non-writeable view for an input of non-complex dtype. It’s recommended that programs not modify the tensor returned by tensorplay.conj_physical() when input is of non-complex dtype to be compatible with this change. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.conv_tbc) ### conv_tbc function[Full reference ↗](/docs/generated/tensorplay.functional.conv_tbc.html) ```python tensorplay.functional.conv_tbc(input, weight, bias, pad=0) ``` [#](#api-tensorplay.functional.conv_transpose1d) ### conv_transpose1d function[Full reference ↗](/docs/generated/tensorplay.functional.conv_transpose1d.html) ```python tensorplay.functional.conv_transpose1d(input, weight, bias=None, stride=[], padding=[], output_padding=[], groups=1, dilation=[]) ``` [#](#api-tensorplay.functional.conv_transpose2d) ### conv_transpose2d function[Full reference ↗](/docs/generated/tensorplay.functional.conv_transpose2d.html) ```python tensorplay.functional.conv_transpose2d(input, weight, bias=None, stride=[1, 1], padding=[0, 0], output_padding=[0, 0], groups=1, dilation=[1, 1]) ``` [#](#api-tensorplay.functional.conv_transpose3d) ### conv_transpose3d function[Full reference ↗](/docs/generated/tensorplay.functional.conv_transpose3d.html) ```python 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]) ``` [#](#api-tensorplay.functional.conv1d) ### conv1d function[Full reference ↗](/docs/generated/tensorplay.functional.conv1d.html) ```python tensorplay.functional.conv1d(input, weight, bias=None, stride=[1], padding=[0], dilation=[1], groups=1) ``` [#](#api-tensorplay.functional.conv3d) ### conv3d function[Full reference ↗](/docs/generated/tensorplay.functional.conv3d.html) ```python tensorplay.functional.conv3d(input, weight, bias=None, stride=[1, 1, 1], padding=[0, 0, 0], dilation=[1, 1, 1], groups=1) ``` [#](#api-tensorplay.functional.convolution) ### convolution function[Full reference ↗](/docs/generated/tensorplay.functional.convolution.html) ```python tensorplay.functional.convolution(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups) ``` [#](#api-tensorplay.functional.copysign) ### copysign function[Full reference ↗](/docs/generated/tensorplay.functional.copysign.html) ```python tensorplay.functional.copysign(input, other, *, out=None) → Tensor ``` Create a new floating-point tensor with the magnitude of input and the sign of other, elementwise. $$\begin{split}\text{out}_{i} = \begin{cases} -|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\ |\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\ \end{cases}\end{split}$$ Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), and integer and float inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – magnitudes. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – contains value(s) whose signbit(s) are applied to the magnitudes in input. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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. [#](#api-tensorplay.functional.corrcoef) ### corrcoef function[Full reference ↗](/docs/generated/tensorplay.functional.corrcoef.html) ```python tensorplay.functional.corrcoef(input) → Tensor ``` Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the input matrix, 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 $R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }$ > **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](/docs/generated/tensorplay.Tensor.html#tensorplay.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.) ``` [#](#api-tensorplay.functional.cos_) ### cos_ function[Full reference ↗](/docs/generated/tensorplay.functional.cos_.html) ```python tensorplay.functional.cos_(input) ``` [#](#api-tensorplay.functional.cos) ### cos function[Full reference ↗](/docs/generated/tensorplay.functional.cos.html) ```python tensorplay.functional.cos(input, *, out=None) → Tensor ``` Returns a new tensor with the cosine of the elements of input. $$\text{out}_{i} = \cos(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.cosh_) ### cosh_ function[Full reference ↗](/docs/generated/tensorplay.functional.cosh_.html) ```python tensorplay.functional.cosh_(input) ``` [#](#api-tensorplay.functional.cosh) ### cosh function[Full reference ↗](/docs/generated/tensorplay.functional.cosh.html) ```python tensorplay.functional.cosh(input, *, out=None) → Tensor ``` Returns a new tensor with the hyperbolic cosine of the elements of input. $$\text{out}_{i} = \cosh(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 input is 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. [#](#api-tensorplay.functional.cosine_embedding_loss) ### cosine_embedding_loss function[Full reference ↗](/docs/generated/tensorplay.functional.cosine_embedding_loss.html) ```python tensorplay.functional.cosine_embedding_loss(x1, x2, target, margin=0) ``` [#](#api-tensorplay.functional.cosine_similarity) ### cosine_similarity function[Full reference ↗](/docs/generated/tensorplay.functional.cosine_similarity.html) ```python tensorplay.functional.cosine_similarity(x1, x2, dim=1, eps=1e-08) ``` [#](#api-tensorplay.functional.count_nonzero) ### count_nonzero function[Full reference ↗](/docs/generated/tensorplay.functional.count_nonzero.html) ```python tensorplay.functional.count_nonzero(input, dim=None) → Tensor ``` Counts the number of non-zero values in the tensor input along the given dim. If no dim is specified then all non-zeros in the tensor are counted. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – Dim or tuple of dims along which to count non-zeros. 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]) ``` [#](#api-tensorplay.functional.cov) ### cov function[Full reference ↗](/docs/generated/tensorplay.functional.cov.html) ```python tensorplay.functional.cov(input, *, correction=1, fweights=None, aweights=None) → Tensor ``` Estimates the covariance matrix of the variables given by the input matrix, 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 input represents a single variable (Scalar or 1D) then its variance is returned. The sample covariance of the variables $x$ and $y$ is given by: $$\text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}$$ where $\bar{x}$ and $\bar{y}$ are the simple means of the $x$ and $y$ respectively, and $\delta N$ is the correction. If fweights and/or aweights are provided, the weighted covariance is calculated, which is given by: $$\text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)} {\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}$$ where $w$ denotes fweights or aweights (f and a for brevity) based on whichever is provided, or $w = f \times a$ if both are provided, and $\mu_x^* = \frac{\sum^{N}_{i = 1}w_ix_{i} }{\sum^{N}_{i = 1}w_i}$ is the weighted mean of the variable. If not provided, f and/or a can be seen as a $\mathbb{1}$ vector of appropriate size. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – A 2D matrix containing multiple variables and observations, or a Scalar or 1D vector representing a single variable. Keyword Arguments: - correction ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction, correction = 1 which returns the unbiased estimate, even if both fweights and aweights are specified. correction = 0 will return the simple average. Defaults to 1. - 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 if None. Defaults to None. - 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 if None. Defaults to None. 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]]) ``` [#](#api-tensorplay.functional.cross) ### cross function[Full reference ↗](/docs/generated/tensorplay.functional.cross.html) ```python tensorplay.functional.cross(input, other, dim=None, *, out=None) → Tensor ``` Returns the cross product of vectors in dimension dim of input and other. 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 dim is 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor - dim ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the dimension to take the cross-product in. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.crow_indices_copy) ### crow_indices_copy function[Full reference ↗](/docs/generated/tensorplay.functional.crow_indices_copy.html) ```python tensorplay.functional.crow_indices_copy(input) ``` Performs the same operation as [tensorplay.crow_indices()](/docs/generated/tensorplay.crow_indices.html#tensorplay.crow_indices), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.ctc_loss) ### ctc_loss function[Full reference ↗](/docs/generated/tensorplay.functional.ctc_loss.html) ```python tensorplay.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reduction=1, zero_infinity=False) ``` [#](#api-tensorplay.functional.cudnn_affine_grid_generator) ### cudnn_affine_grid_generator function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_affine_grid_generator.html) ```python tensorplay.functional.cudnn_affine_grid_generator(theta, N, C, H, W) ``` [#](#api-tensorplay.functional.cudnn_batch_norm) ### cudnn_batch_norm function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_batch_norm.html) ```python tensorplay.functional.cudnn_batch_norm(input, weight, bias, running_mean, running_var, training, exponential_average_factor, epsilon, *, out=None) ``` [#](#api-tensorplay.functional.cudnn_convolution_add_relu) ### cudnn_convolution_add_relu function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_convolution_add_relu.html) ```python tensorplay.functional.cudnn_convolution_add_relu(input, weight, z, alpha, bias, stride, padding, dilation, groups) ``` [#](#api-tensorplay.functional.cudnn_convolution_relu) ### cudnn_convolution_relu function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_convolution_relu.html) ```python tensorplay.functional.cudnn_convolution_relu(input, weight, bias, stride, padding, dilation, groups) ``` [#](#api-tensorplay.functional.cudnn_convolution_transpose) ### cudnn_convolution_transpose function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_convolution_transpose.html) ```python tensorplay.functional.cudnn_convolution_transpose(input, weight, padding, output_padding, stride, dilation, groups, benchmark, deterministic, allow_tf32) ``` [#](#api-tensorplay.functional.cudnn_convolution) ### cudnn_convolution function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_convolution.html) ```python tensorplay.functional.cudnn_convolution(input, weight, padding, stride, dilation, groups, benchmark, deterministic, allow_tf32, *, out=None) ``` [#](#api-tensorplay.functional.cudnn_grid_sampler) ### cudnn_grid_sampler function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_grid_sampler.html) ```python tensorplay.functional.cudnn_grid_sampler(input, grid) ``` [#](#api-tensorplay.functional.cudnn_is_acceptable) ### cudnn_is_acceptable function[Full reference ↗](/docs/generated/tensorplay.functional.cudnn_is_acceptable.html) ```python tensorplay.functional.cudnn_is_acceptable(input) ``` [#](#api-tensorplay.functional.cummax) ### cummax function[Full reference ↗](/docs/generated/tensorplay.functional.cummax.html) ```python tensorplay.functional.cummax(input, dim, *, out=None) ``` [#](#api-tensorplay.functional.cummin) ### cummin function[Full reference ↗](/docs/generated/tensorplay.functional.cummin.html) ```python tensorplay.functional.cummin(input, dim, *, out=None) ``` [#](#api-tensorplay.functional.cumprod) ### cumprod function[Full reference ↗](/docs/generated/tensorplay.functional.cumprod.html) ```python tensorplay.functional.cumprod(input, dim, *, dtype=None, out=None) → Tensor ``` Returns the cumulative product of elements of input in the dimension dim. For example, if input is a vector of size N, the result will also be a vector of size N, with elements. $$y_i = x_1 \times x_2\times x_3\times \dots \times x_i$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to do the operation over Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.cumsum) ### cumsum function[Full reference ↗](/docs/generated/tensorplay.functional.cumsum.html) ```python tensorplay.functional.cumsum(input, dim, *, dtype=None, out=None) → Tensor ``` Returns the cumulative sum of elements of input in the dimension dim. For example, if input is a vector of size N, the result will also be a vector of size N, with elements. $$y_i = x_1 + x_2 + x_3 + \dots + x_i$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to do the operation over Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.cumulative_trapezoid) ### cumulative_trapezoid function[Full reference ↗](/docs/generated/tensorplay.functional.cumulative_trapezoid.html) ```python tensorplay.functional.cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) → Tensor ``` Cumulatively computes the [trapezoidal rule](https://en.wikipedia.org/wiki/Trapezoidal_rule) along dim. By default the spacing between elements is assumed to be 1, but dx can be used to specify a different constant spacing, and x can be used to specify arbitrary spacing along dim. For more details, please read tensorplay.trapezoid(). The difference between tensorplay.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: - y ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – Values to use when computing the trapezoidal rule. - x ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – If specified, defines spacing between values as specified above. Keyword Arguments: - dx ([float](https://docs.python.org/3/builtins/functions.html#float)) – constant spacing between values. If neither x or dx are specified then this defaults to 1. Effectively multiplies the result by its value. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – The dimension along which to compute the trapezoidal rule. The last (inner-most) dimension by default. 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.]]) ``` [#](#api-tensorplay.functional.deg2rad_) ### deg2rad_ function[Full reference ↗](/docs/generated/tensorplay.functional.deg2rad_.html) ```python tensorplay.functional.deg2rad_(input) ``` [#](#api-tensorplay.functional.deg2rad) ### deg2rad function[Full reference ↗](/docs/generated/tensorplay.functional.deg2rad.html) ```python tensorplay.functional.deg2rad(input, *, out=None) → Tensor ``` Returns a new tensor with each of the elements of input converted from angles in degrees to radians. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.dequantize) ### dequantize function[Full reference ↗](/docs/generated/tensorplay.functional.dequantize.html) ```python tensorplay.functional.dequantize(tensor) → Tensor ``` Returns an fp32 Tensor by dequantizing a quantized Tensor Parameters: tensor ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – A quantized Tensor ```python tensorplay.functional.dequantize(tensors) → sequence of Tensors ``` 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 [#](#api-tensorplay.functional.det) ### det function[Full reference ↗](/docs/generated/tensorplay.functional.det.html) ```python tensorplay.functional.det(input) → Tensor ``` Alias for [tensorplay.linalg.det()](/docs/generated/tensorplay.linalg.det.html#tensorplay.linalg.det) [#](#api-tensorplay.functional.detach_) ### detach_ function[Full reference ↗](/docs/generated/tensorplay.functional.detach_.html) ```python tensorplay.functional.detach_(input) ``` [#](#api-tensorplay.functional.detach_copy) ### detach_copy function[Full reference ↗](/docs/generated/tensorplay.functional.detach_copy.html) ```python tensorplay.functional.detach_copy(input) ``` Performs the same operation as tensorplay.detach(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.detach) ### detach function[Full reference ↗](/docs/generated/tensorplay.functional.detach.html) ```python tensorplay.functional.detach(input) ``` [#](#api-tensorplay.functional.diag_embed) ### diag_embed function[Full reference ↗](/docs/generated/tensorplay.functional.diag_embed.html) ```python tensorplay.functional.diag_embed(input, offset=0, dim1=-2, dim2=-1) → Tensor ``` Creates a tensor whose diagonals of certain 2D planes (specified by dim1 and dim2) are filled by input. 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 offset controls which diagonal to consider: - If offset = 0, it is the main diagonal. - If offset > 0, it is above the main diagonal. - If offset 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 offset other than $0$, the order of dim1 and dim2 matters. Exchanging them is equivalent to changing the sign of offset. 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Must be at least 1-dimensional. - offset ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – which diagonal to consider. Default: 0 (main diagonal). - dim1 ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – first dimension with respect to which to take diagonal. Default: -2. - dim2 ([int](https://docs.python.org/3/builtins/functions.html#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]]]) ``` [#](#api-tensorplay.functional.diag) ### diag function[Full reference ↗](/docs/generated/tensorplay.functional.diag.html) ```python tensorplay.functional.diag(input, diagonal=0, *, out=None) → Tensor ``` - If input is a vector (1-D tensor), then returns a 2-D square tensor with the elements of input as the diagonal. - If input is a matrix (2-D tensor), then returns a 1-D tensor with the diagonal elements of input. The argument [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) controls which diagonal to consider: - If [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) = 0, it is the main diagonal. - If [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) > 0, it is above the main diagonal. - If [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - diagonal ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the diagonal to consider Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.diagflat) ### diagflat function[Full reference ↗](/docs/generated/tensorplay.functional.diagflat.html) ```python tensorplay.functional.diagflat(input, offset=0) → Tensor ``` - If input is a vector (1-D tensor), then returns a 2-D square tensor with the elements of input as the diagonal. - If input is a tensor with more than one dimension, then returns a 2-D tensor with diagonal elements equal to a flattened input. The argument offset controls which diagonal to consider: - If offset = 0, it is the main diagonal. - If offset > 0, it is above the main diagonal. - If offset Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - offset ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the diagonal to consider. Default: 0 (main diagonal). 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]]) ``` [#](#api-tensorplay.functional.diagonal_copy) ### diagonal_copy function[Full reference ↗](/docs/generated/tensorplay.functional.diagonal_copy.html) ```python tensorplay.functional.diagonal_copy(input, offset=0, dim1=0, dim2=1) ``` Performs the same operation as tensorplay.diagonal(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.diagonal_scatter) ### diagonal_scatter function[Full reference ↗](/docs/generated/tensorplay.functional.diagonal_scatter.html) ```python tensorplay.functional.diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) → Tensor ``` Embeds the values of the src tensor into input along the diagonal elements of input, with respect to dim1 and dim2. This function returns a tensor with fresh storage; it does not return a view. The argument offset controls which diagonal to consider: - If offset = 0, it is the main diagonal. - If offset > 0, it is above the main diagonal. - If offset Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Must be at least 2-dimensional. - src ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to embed into input. - offset ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – which diagonal to consider. Default: 0 (main diagonal). - dim1 ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – first dimension with respect to which to take diagonal. Default: 0. - dim2 ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – second dimension with respect to which to take diagonal. Default: 1. > **Note** > > src must be of the proper size in order to be embedded into input. Specifically, it should have the same shape as tensorplay.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.]]) ``` [#](#api-tensorplay.functional.diagonal) ### diagonal function[Full reference ↗](/docs/generated/tensorplay.functional.diagonal.html) ```python tensorplay.functional.diagonal(input, offset=0, dim1=0, dim2=1) → Tensor ``` Returns a partial view of input with the its diagonal elements with respect to dim1 and dim2 appended as a dimension at the end of the shape. The argument offset controls which diagonal to consider: - If offset = 0, it is the main diagonal. - If offset > 0, it is above the main diagonal. - If offset 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Must be at least 2-dimensional. - offset ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – which diagonal to consider. Default: 0 (main diagonal). - dim1 ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – first dimension with respect to which to take diagonal. Default: 0. - dim2 ([int](https://docs.python.org/3/builtins/functions.html#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]]]) ``` [#](#api-tensorplay.functional.diff) ### diff function[Full reference ↗](/docs/generated/tensorplay.functional.diff.html) ```python tensorplay.functional.diff(input, n=1, dim=-1, prepend=None, append=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compute the differences on - n ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the number of times to recursively compute the difference - dim ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the dimension to compute the difference along. Default is the last dimension. - prepend ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – values to prepend or append to input along dim before computing the difference. Their dimensions must be equivalent to that of input, and their shapes must match input’s shape except on dim. - append ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – values to prepend or append to input along dim before computing the difference. Their dimensions must be equivalent to that of input, and their shapes must match input’s shape except on dim. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.digamma) ### digamma function[Full reference ↗](/docs/generated/tensorplay.functional.digamma.html) ```python tensorplay.functional.digamma(input, *, out=None) → Tensor ``` Alias for tensorplay.special.digamma(). [#](#api-tensorplay.functional.dist) ### dist function[Full reference ↗](/docs/generated/tensorplay.functional.dist.html) ```python tensorplay.functional.dist(input, other, p=2) → Tensor ``` Returns the p-norm of (input - other) The shapes of input and other must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the Right-hand-side input tensor - p ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the norm to be computed 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) ``` [#](#api-tensorplay.functional.div) ### div function[Full reference ↗](/docs/generated/tensorplay.functional.div.html) ```python tensorplay.functional.div(input, other, *, rounding_mode=None, out=None) → Tensor ``` Divides each element of the input input by the corresponding element of other. $$\text{out}_i = \frac{\text{input}_i}{\text{other}_i}$$ > **Note** > > By default, this performs a “true” division like Python 3. See the rounding_mode argument for floor division. Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer, float, and complex inputs. Always promotes integer types to the default scalar type. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the dividend - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the divisor Keyword Arguments: - rounding_mode ([str](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – Type of rounding applied to the result: None - default behavior. Performs no rounding and, if both input and other are integer types, promotes the inputs to the default scalar type. Equivalent to true division in Python (the / operator) and NumPy’s np.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’s np.floor_divide. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]]) ``` [#](#api-tensorplay.functional.divide) ### divide function[Full reference ↗](/docs/generated/tensorplay.functional.divide.html) ```python tensorplay.functional.divide(input, other, *, rounding_mode=None, out=None) → Tensor ``` Alias for tensorplay.div(). [#](#api-tensorplay.functional.dot) ### dot function[Full reference ↗](/docs/generated/tensorplay.functional.dot.html) ```python tensorplay.functional.dot(input, tensor, *, out=None) → Tensor ``` 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – first tensor in the dot product, must be 1D. - tensor ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – second tensor in the dot product, must be 1D. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.dropout_) ### dropout_ function[Full reference ↗](/docs/generated/tensorplay.functional.dropout_.html) ```python tensorplay.functional.dropout_(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.dsplit) ### dsplit function[Full reference ↗](/docs/generated/tensorplay.functional.dsplit.html) ```python tensorplay.functional.dsplit(input, indices_or_sections) → List of Tensors ``` Splits input, a tensor with three or more dimensions, into multiple tensors depthwise according to indices_or_sections. Each split is a view of input. This is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=2) (the split dimension is 2), except that if indices_or_sections is 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – tensor to split. - indices_or_sections ([int](https://docs.python.org/3/builtins/functions.html#int) or [list](https://docs.python.org/3/builtins/stdtypes.html#list) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – See argument in tensorplay.tensor_split(). 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))) ``` [#](#api-tensorplay.functional.dstack) ### dstack function[Full reference ↗](/docs/generated/tensorplay.functional.dstack.html) ```python tensorplay.functional.dstack(tensors, *, out=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]]) ``` [#](#api-tensorplay.functional.embedding_renorm_) ### embedding_renorm_ function[Full reference ↗](/docs/generated/tensorplay.functional.embedding_renorm_.html) ```python tensorplay.functional.embedding_renorm_(input, indices, max_norm, norm_type) ``` [#](#api-tensorplay.functional.embedding) ### embedding function[Full reference ↗](/docs/generated/tensorplay.functional.embedding.html) ```python tensorplay.functional.embedding(weight, indices, padding_idx=-1, scale_grad_by_freq=False, sparse=False) ``` [#](#api-tensorplay.functional.empty_like) ### empty_like function[Full reference ↗](/docs/generated/tensorplay.functional.empty_like.html) ```python 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 to tensorplay.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 with tensorplay.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_format is 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), 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) ``` [#](#api-tensorplay.functional.empty_permuted) ### empty_permuted function[Full reference ↗](/docs/generated/tensorplay.functional.empty_permuted.html) ```python tensorplay.functional.empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) → Tensor ``` Creates an uninitialized, non-overlapping and dense tensor with the specified size, with physical_layout specifying how the dimensions are physically laid out in memory (each logical dimension is listed from outermost to innermost). physical_layout is 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 tensor t are such that t.stride(physical_layout[i]) == contiguous_strides[i] (notably, this function is not equivalent to tensorplay.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 over tensorplay.empty_strided() or manual use of tensorplay.as_strided(). > **Note** > > The returned storage is uninitialized, and tensorplay.use_deterministic_algorithms() does not change that. If the contents matter, allocate with tensorplay.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: - size ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the shape of the output tensor - physical_layout ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the ordering of dimensions physically in memory Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.empty_quantized) ### empty_quantized function[Full reference ↗](/docs/generated/tensorplay.functional.empty_quantized.html) ```python tensorplay.functional.empty_quantized(size, qtensor, dtype=None, layout=None, device=None, pin_memory=None, memory_format=None) ``` [#](#api-tensorplay.functional.empty_strided) ### empty_strided function[Full reference ↗](/docs/generated/tensorplay.functional.empty_strided.html) ```python tensorplay.functional.empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) → Tensor ``` Creates a tensor with the specified size and stride and 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 with tensorplay.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: - size ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the shape of the output tensor - stride ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the strides of the output tensor Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#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]) ``` [#](#api-tensorplay.functional.entr) ### entr function[Full reference ↗](/docs/generated/tensorplay.functional.entr.html) ```python tensorplay.functional.entr(input) ``` [#](#api-tensorplay.functional.eq) ### eq function[Full reference ↗](/docs/generated/tensorplay.functional.eq.html) ```python tensorplay.functional.eq(input, other, *, out=None) → Tensor ``` Computes element-wise equality The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [float](https://docs.python.org/3/builtins/functions.html#float)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is equal to other and False elsewhere Example: ``` >>> tensorplay.eq(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[ True, False], [False, True]]) ``` [#](#api-tensorplay.functional.equal) ### equal function[Full reference ↗](/docs/generated/tensorplay.functional.equal.html) ```python tensorplay.functional.equal(input, other) → bool ``` True if two tensors have the same size and elements, False otherwise. > **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 ``` [#](#api-tensorplay.functional.erf_) ### erf_ function[Full reference ↗](/docs/generated/tensorplay.functional.erf_.html) ```python tensorplay.functional.erf_(input) ``` [#](#api-tensorplay.functional.erf) ### erf function[Full reference ↗](/docs/generated/tensorplay.functional.erf.html) ```python tensorplay.functional.erf(input, *, out=None) → Tensor ``` Alias for tensorplay.special.erf(). [#](#api-tensorplay.functional.erfc_) ### erfc_ function[Full reference ↗](/docs/generated/tensorplay.functional.erfc_.html) ```python tensorplay.functional.erfc_(input) ``` [#](#api-tensorplay.functional.erfc) ### erfc function[Full reference ↗](/docs/generated/tensorplay.functional.erfc.html) ```python tensorplay.functional.erfc(input, *, out=None) → Tensor ``` Alias for tensorplay.special.erfc(). [#](#api-tensorplay.functional.erfcx) ### erfcx function[Full reference ↗](/docs/generated/tensorplay.functional.erfcx.html) ```python tensorplay.functional.erfcx(input) ``` [#](#api-tensorplay.functional.erfinv) ### erfinv function[Full reference ↗](/docs/generated/tensorplay.functional.erfinv.html) ```python tensorplay.functional.erfinv(input, *, out=None) → Tensor ``` Alias for tensorplay.special.erfinv(). [#](#api-tensorplay.functional.exp_) ### exp_ function[Full reference ↗](/docs/generated/tensorplay.functional.exp_.html) ```python tensorplay.functional.exp_(input) ``` [#](#api-tensorplay.functional.exp) ### exp function[Full reference ↗](/docs/generated/tensorplay.functional.exp.html) ```python tensorplay.functional.exp(input, *, out=None) → Tensor ``` Returns a new tensor with the exponential of the elements of the input tensor input. $$y_{i} = e^{x_{i}}$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.exp(tensorplay.tensor([0, math.log(2.)])) tensor([ 1., 2.]) ``` [#](#api-tensorplay.functional.exp2_) ### exp2_ function[Full reference ↗](/docs/generated/tensorplay.functional.exp2_.html) ```python tensorplay.functional.exp2_(input) ``` [#](#api-tensorplay.functional.exp2) ### exp2 function[Full reference ↗](/docs/generated/tensorplay.functional.exp2.html) ```python tensorplay.functional.exp2(input, *, out=None) → Tensor ``` Alias for tensorplay.special.exp2(). [#](#api-tensorplay.functional.expand_copy) ### expand_copy function[Full reference ↗](/docs/generated/tensorplay.functional.expand_copy.html) ```python tensorplay.functional.expand_copy(input, size, implicit=False) ``` Performs the same operation as tensorplay.Tensor.expand(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.expm1_) ### expm1_ function[Full reference ↗](/docs/generated/tensorplay.functional.expm1_.html) ```python tensorplay.functional.expm1_(input) ``` [#](#api-tensorplay.functional.expm1) ### expm1 function[Full reference ↗](/docs/generated/tensorplay.functional.expm1.html) ```python tensorplay.functional.expm1(input, *, out=None) → Tensor ``` Alias for tensorplay.special.expm1(). [#](#api-tensorplay.functional.eye) ### eye function[Full reference ↗](/docs/generated/tensorplay.functional.eye.html) ```python 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: - n ([int](https://docs.python.org/3/builtins/functions.html#int)) – the number of rows - m ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the number of columns with default being n Keyword Arguments: - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> tensorplay.eye(3) tensor([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) ``` [#](#api-tensorplay.functional.fake_quantize_per_channel_affine) ### fake_quantize_per_channel_affine function[Full reference ↗](/docs/generated/tensorplay.functional.fake_quantize_per_channel_affine.html) ```python tensorplay.functional.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) → Tensor ``` Returns a new tensor with the data in input fake quantized per channel using scale, zero_point, quant_min and quant_max, across the channel specified by axis. $$\text{output} = ( min( \text{quant\_max}, max( \text{quant\_min}, \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point} ) ) - \text{zero\_point} ) \times \text{scale}$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input value(s), in tensorplay.float32 - scale ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – quantization scale, per channel in tensorplay.float32 - zero_point ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – quantization zero_point, per channel in tensorplay.int32 or tensorplay.half or tensorplay.float32 - axis (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.float32 tensor Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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]]]) ``` [#](#api-tensorplay.functional.fake_quantize_per_tensor_affine) ### fake_quantize_per_tensor_affine function[Full reference ↗](/docs/generated/tensorplay.functional.fake_quantize_per_tensor_affine.html) ```python tensorplay.functional.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) → Tensor ``` Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min and quant_max. $$\text{output} = ( min( \text{quant\_max}, max( \text{quant\_min}, \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point} ) ) - \text{zero\_point} ) \times \text{scale}$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input value(s), tensorplay.float32 tensor - scale (double scalar or float32 Tensor) – quantization scale - zero_point (int64 scalar or int32 Tensor) – quantization zero_point - quant_min (int64) – lower bound of the quantized domain - quant_max (int64) – upper bound of the quantized domain Returns: A newly fake_quantized tensorplay.float32 tensor Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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]) ``` [#](#api-tensorplay.functional.fbgemm_linear_fp16_weight_fp32_activation) ### fbgemm_linear_fp16_weight_fp32_activation function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_linear_fp16_weight_fp32_activation.html) ```python tensorplay.functional.fbgemm_linear_fp16_weight_fp32_activation(input, packed_weight, bias, *, out=None) ``` [#](#api-tensorplay.functional.fbgemm_linear_fp16_weight) ### fbgemm_linear_fp16_weight function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_linear_fp16_weight.html) ```python tensorplay.functional.fbgemm_linear_fp16_weight(input, packed_weight, bias, *, out=None) ``` [#](#api-tensorplay.functional.fbgemm_linear_int8_weight_fp32_activation) ### fbgemm_linear_int8_weight_fp32_activation function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_linear_int8_weight_fp32_activation.html) ```python tensorplay.functional.fbgemm_linear_int8_weight_fp32_activation(input, weight, packed, col_offsets, weight_scale, weight_zero_point, bias) ``` [#](#api-tensorplay.functional.fbgemm_linear_int8_weight) ### fbgemm_linear_int8_weight function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_linear_int8_weight.html) ```python tensorplay.functional.fbgemm_linear_int8_weight(input, weight, packed, col_offsets, weight_scale, weight_zero_point, bias) ``` [#](#api-tensorplay.functional.fbgemm_linear_quantize_weight) ### fbgemm_linear_quantize_weight function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_linear_quantize_weight.html) ```python tensorplay.functional.fbgemm_linear_quantize_weight(input) ``` [#](#api-tensorplay.functional.fbgemm_pack_gemm_matrix_fp16) ### fbgemm_pack_gemm_matrix_fp16 function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_pack_gemm_matrix_fp16.html) ```python tensorplay.functional.fbgemm_pack_gemm_matrix_fp16(input) ``` [#](#api-tensorplay.functional.fbgemm_pack_quantized_matrix) ### fbgemm_pack_quantized_matrix function[Full reference ↗](/docs/generated/tensorplay.functional.fbgemm_pack_quantized_matrix.html) ```python tensorplay.functional.fbgemm_pack_quantized_matrix(input, K=None, N=None) ``` [#](#api-tensorplay.functional.feature_alpha_dropout_) ### feature_alpha_dropout_ function[Full reference ↗](/docs/generated/tensorplay.functional.feature_alpha_dropout_.html) ```python tensorplay.functional.feature_alpha_dropout_(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.feature_alpha_dropout) ### feature_alpha_dropout function[Full reference ↗](/docs/generated/tensorplay.functional.feature_alpha_dropout.html) ```python tensorplay.functional.feature_alpha_dropout(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.feature_dropout_) ### feature_dropout_ function[Full reference ↗](/docs/generated/tensorplay.functional.feature_dropout_.html) ```python tensorplay.functional.feature_dropout_(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.feature_dropout) ### feature_dropout function[Full reference ↗](/docs/generated/tensorplay.functional.feature_dropout.html) ```python tensorplay.functional.feature_dropout(input, p=0.5, train=True) ``` [#](#api-tensorplay.functional.fill_) ### fill_ function[Full reference ↗](/docs/generated/tensorplay.functional.fill_.html) ```python tensorplay.functional.fill_(input, value) ``` [#](#api-tensorplay.functional.fill) ### fill function[Full reference ↗](/docs/generated/tensorplay.functional.fill.html) ```python tensorplay.functional.fill(input, value) ``` [#](#api-tensorplay.functional.fix_) ### fix_ function[Full reference ↗](/docs/generated/tensorplay.functional.fix_.html) ```python tensorplay.functional.fix_(input) ``` [#](#api-tensorplay.functional.fix) ### fix function[Full reference ↗](/docs/generated/tensorplay.functional.fix.html) ```python tensorplay.functional.fix(input, *, out=None) → Tensor ``` Alias for tensorplay.trunc() [#](#api-tensorplay.functional.flatten) ### flatten function[Full reference ↗](/docs/generated/tensorplay.functional.flatten.html) ```python tensorplay.functional.flatten(input, start_dim=0, end_dim=-1) → Tensor ``` Flattens input by reshaping it into a one-dimensional tensor. If start_dim or end_dim are passed, only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is 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 input is 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. See tensorplay.Tensor.view() for details on when a view will be returned. > **Note** > > Flattening a zero-dimensional tensor will return a one-dimensional view. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - start_dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the first dim to flatten - end_dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the last dim to flatten 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]]) ``` [#](#api-tensorplay.functional.flip) ### flip function[Full reference ↗](/docs/generated/tensorplay.functional.flip.html) ```python tensorplay.functional.flip(input, dims) → Tensor ``` 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. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dims (a list or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)) – axis to flip on 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]]]) ``` [#](#api-tensorplay.functional.fliplr) ### fliplr function[Full reference ↗](/docs/generated/tensorplay.functional.fliplr.html) ```python tensorplay.functional.fliplr(input) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.flipud) ### flipud function[Full reference ↗](/docs/generated/tensorplay.functional.flipud.html) ```python tensorplay.functional.flipud(input) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.float_power) ### float_power function[Full reference ↗](/docs/generated/tensorplay.functional.float_power.html) ```python tensorplay.functional.float_power(input, exponent, *, out=None) → Tensor ``` Raises input to the power of exponent, elementwise, in double precision. If neither input is complex returns a tensorplay.float64 tensor, and if one or more inputs is complex returns a tensorplay.complex128 tensor. > **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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the base value(s) - exponent ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the exponent value(s) Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.floor_) ### floor_ function[Full reference ↗](/docs/generated/tensorplay.functional.floor_.html) ```python tensorplay.functional.floor_(input) ``` [#](#api-tensorplay.functional.floor_divide) ### floor_divide function[Full reference ↗](/docs/generated/tensorplay.functional.floor_divide.html) ```python tensorplay.functional.floor_divide(input, other, *, out=None) → Tensor ``` > **Note** > > truncation division. To restore the previous behavior use tensorplay.div() with rounding_mode='trunc'. Computes input divided by other, elementwise, and floors the result. $$\text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)$$ Supports broadcasting to a common shape, type promotion, and integer and float inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the dividend - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the divisor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.floor) ### floor function[Full reference ↗](/docs/generated/tensorplay.functional.floor.html) ```python tensorplay.functional.floor(input, *, out=None) → Tensor ``` 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. $$\text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.fmax) ### fmax function[Full reference ↗](/docs/generated/tensorplay.functional.fmax.html) ```python tensorplay.functional.fmax(input, other, *, out=None) → Tensor ``` Computes the element-wise maximum of input and other. 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::fmax and is similar to NumPy’s fmax function. Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer and floating-point inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.fmin) ### fmin function[Full reference ↗](/docs/generated/tensorplay.functional.fmin.html) ```python tensorplay.functional.fmin(input, other, *, out=None) → Tensor ``` Computes the element-wise minimum of input and other. 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::fmin and is similar to NumPy’s fmin function. Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer and floating-point inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.fmod) ### fmod function[Full reference ↗](/docs/generated/tensorplay.functional.fmod.html) ```python tensorplay.functional.fmod(input, other, *, out=None) → Tensor ``` Applies C++’s [std::fmod](https://en.cppreference.com/w/cpp/numeric/math/fmod) entrywise. The result has the same sign as the dividend input and its absolute value is less than that of other. This function may be defined in terms of tensorplay.div() as ``` tensorplay.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b ``` Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer and float inputs. > **Note** > > When the divisor is zero, returns NaN for floating point dtypes on both CPU and GPU; raises RuntimeError for 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the dividend - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the divisor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.frac_) ### frac_ function[Full reference ↗](/docs/generated/tensorplay.functional.frac_.html) ```python tensorplay.functional.frac_(input) ``` [#](#api-tensorplay.functional.frac) ### frac function[Full reference ↗](/docs/generated/tensorplay.functional.frac.html) ```python tensorplay.functional.frac(input, *, out=None) → Tensor ``` Computes the fractional portion of each element in input. $$\text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})$$ Example: ``` >>> tensorplay.frac(tensorplay.tensor([1, 2.5, -3.2])) tensor([ 0.0000, 0.5000, -0.2000]) ``` [#](#api-tensorplay.functional.frexp) ### frexp function[Full reference ↗](/docs/generated/tensorplay.functional.frexp.html) ```python tensorplay.functional.frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent) ``` Decomposes input into mantissa and exponent tensors such that $\text{input} = \text{mantissa} \times 2^{\text{exponent}}$. The range of mantissa is the open interval (-1, 1). Supports float inputs. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor Keyword Arguments: out ([tuple](https://docs.python.org/3/builtins/stdtypes.html#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.]) ``` [#](#api-tensorplay.functional.from_file) ### from_file function[Full reference ↗](/docs/generated/tensorplay.functional.from_file.html) ```python tensorplay.functional.from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False) ``` Creates a CPU tensor with a storage backed by a memory-mapped file. If shared is True, then memory is shared between processes. All changes are written to the file. If shared is False, then changes to the tensor do not affect the file. size is the number of elements in the Tensor. If shared is False, then the file must contain at least size * sizeof(dtype) bytes. If shared is True the 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](https://docs.python.org/3/builtins/stdtypes.html#str)) – file name to map - shared ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – whether to share memory (whether MAP_SHARED or MAP_PRIVATE is passed to the underlying [mmap(2) call](https://man7.org/linux/man-pages/man2/mmap.2.html)) - size ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of elements in the tensor Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.full_like) ### full_like function[Full reference ↗](/docs/generated/tensorplay.functional.full_like.html) ```python 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 input filled with fill_value. tensorplay.full_like(input, fill_value) is equivalent to tensorplay.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. - fill_value – the number to fill the output tensor with. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), 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) ``` [#](#api-tensorplay.functional.fused_moving_avg_obs_fake_quant) ### fused_moving_avg_obs_fake_quant function[Full reference ↗](/docs/generated/tensorplay.functional.fused_moving_avg_obs_fake_quant.html) ```python 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) ``` [#](#api-tensorplay.functional.gammainc) ### gammainc function[Full reference ↗](/docs/generated/tensorplay.functional.gammainc.html) ```python tensorplay.functional.gammainc(a, x) ``` [#](#api-tensorplay.functional.gammaincc) ### gammaincc function[Full reference ↗](/docs/generated/tensorplay.functional.gammaincc.html) ```python tensorplay.functional.gammaincc(a, x) ``` [#](#api-tensorplay.functional.gather) ### gather function[Full reference ↗](/docs/generated/tensorplay.functional.gather.html) ```python tensorplay.functional.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor ``` 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 == 2 ``` input and index must have the same number of dimensions. It is also required that index.size(d) <= input.size(d) for all dimensions d != dim. out will have the same shape as index. Note that input and index do not broadcast against each other. When index is empty, we always return an empty output with the same shape without further error checking. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the source tensor - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the axis along which to index - index (LongTensor) – the indices of elements to gather Keyword Arguments: - sparse_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, gradient w.r.t. input will be a sparse tensor. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the destination tensor Example: ``` >>> t = tensorplay.tensor([[1, 2], [3, 4]]) >>> tensorplay.gather(t, 1, tensorplay.tensor([[0, 0], [1, 0]])) tensor([[ 1, 1], [ 4, 3]]) ``` [#](#api-tensorplay.functional.gcd_) ### gcd_ function[Full reference ↗](/docs/generated/tensorplay.functional.gcd_.html) ```python tensorplay.functional.gcd_(input, other) ``` [#](#api-tensorplay.functional.gcd) ### gcd function[Full reference ↗](/docs/generated/tensorplay.functional.gcd.html) ```python tensorplay.functional.gcd(input, other, *, out=None) → Tensor ``` Computes the element-wise greatest common divisor (GCD) of input and other. Both input and other must have integer types. > **Note** > > This defines $gcd(0, 0) = 0$. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.ge) ### ge function[Full reference ↗](/docs/generated/tensorplay.functional.ge.html) ```python tensorplay.functional.ge(input, other, *, out=None) → Tensor ``` Computes $\text{input} \geq \text{other}$ element-wise. The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [float](https://docs.python.org/3/builtins/functions.html#float)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is greater than or equal to other and False elsewhere Example: ``` >>> tensorplay.ge(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[True, True], [False, True]]) ``` [#](#api-tensorplay.functional.geqrf) ### geqrf function[Full reference ↗](/docs/generated/tensorplay.functional.geqrf.html) ```python tensorplay.functional.geqrf(input, *, out=None) ``` 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](http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html) . 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 with [tensorplay.linalg.householder_product()](/docs/generated/tensorplay.linalg.householder_product.html#tensorplay.linalg.householder_product) to obtain the Q matrix or with tensorplay.ormqr(), which uses an implicit representation of the Q matrix, for an efficient matrix-matrix multiplication. See [LAPACK documentation for geqrf](http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html) for further details. > **Note** > > See also tensorplay.linalg.qr(), which computes Q and R matrices, and tensorplay.linalg.lstsq() with the driver="gels" option for a function that can solve matrix equations using a QR decomposition. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input matrix Keyword Arguments: out ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple), optional) – the output tuple of (Tensor, Tensor). Ignored if None. Default: None. [#](#api-tensorplay.functional.ger) ### ger function[Full reference ↗](/docs/generated/tensorplay.functional.ger.html) ```python tensorplay.functional.ger(input, vec2, *, out=None) → Tensor ``` Alias of tensorplay.outer(). > **Warning** > > Use tensorplay.outer() instead. [#](#api-tensorplay.functional.get_device) ### get_device function[Full reference ↗](/docs/generated/tensorplay.functional.get_device.html) ```python tensorplay.functional.get_device(input) ``` [#](#api-tensorplay.functional.greater_equal) ### greater_equal function[Full reference ↗](/docs/generated/tensorplay.functional.greater_equal.html) ```python tensorplay.functional.greater_equal(input, other, *, out=None) → Tensor ``` Alias for tensorplay.ge(). [#](#api-tensorplay.functional.greater) ### greater function[Full reference ↗](/docs/generated/tensorplay.functional.greater.html) ```python tensorplay.functional.greater(input, other, *, out=None) → Tensor ``` Alias for tensorplay.gt(). [#](#api-tensorplay.functional.grid_sampler_2d) ### grid_sampler_2d function[Full reference ↗](/docs/generated/tensorplay.functional.grid_sampler_2d.html) ```python tensorplay.functional.grid_sampler_2d(input, grid, interpolation_mode, padding_mode, align_corners) ``` [#](#api-tensorplay.functional.grid_sampler_3d) ### grid_sampler_3d function[Full reference ↗](/docs/generated/tensorplay.functional.grid_sampler_3d.html) ```python tensorplay.functional.grid_sampler_3d(input, grid, interpolation_mode, padding_mode, align_corners) ``` [#](#api-tensorplay.functional.group_norm) ### group_norm function[Full reference ↗](/docs/generated/tensorplay.functional.group_norm.html) ```python tensorplay.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-05) ``` [#](#api-tensorplay.functional.gru_cell) ### gru_cell function[Full reference ↗](/docs/generated/tensorplay.functional.gru_cell.html) ```python tensorplay.functional.gru_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) ``` [#](#api-tensorplay.functional.gru) ### gru function[Full reference ↗](/docs/generated/tensorplay.functional.gru.html) ```python tensorplay.functional.gru(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False) ``` [#](#api-tensorplay.functional.gt) ### gt function[Full reference ↗](/docs/generated/tensorplay.functional.gt.html) ```python tensorplay.functional.gt(input, other, *, out=None) → Tensor ``` Computes $\text{input} > \text{other}$ element-wise. The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [float](https://docs.python.org/3/builtins/functions.html#float)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is greater than other and False elsewhere Example: ``` >>> tensorplay.gt(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, True], [False, False]]) ``` [#](#api-tensorplay.functional.hamming_window) ### hamming_window function[Full reference ↗](/docs/generated/tensorplay.functional.hamming_window.html) ```python tensorplay.functional.hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function. $$w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),$$ where $N$ is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag 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 like tensorplay.stft(). Therefore, if periodic is true, the $N$ in above formula is in fact $\text{window\_length} + 1$. Also, we always have tensorplay.hamming_window(L, periodic=True) equal to tensorplay.hamming_window(L + 1, periodic=False)[:-1]). > **Note** > > If window_length $=1$, the returned window contains a single value 1. > **Note** > > This is a generalized version of tensorplay.hann_window(). Parameters: window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic and alpha specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. - alpha ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\alpha$ in the equation above Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic, alpha and beta specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. - alpha ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\alpha$ in the equation above - beta ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\beta$ in the equation above Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) [#](#api-tensorplay.functional.hann_window) ### hann_window function[Full reference ↗](/docs/generated/tensorplay.functional.hann_window.html) ```python tensorplay.functional.hann_window(window_length, periodic=True, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Hann window function. $$w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] = \sin^2 \left( \frac{\pi n}{N - 1} \right),$$ where $N$ is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag 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 like tensorplay.stft(). Therefore, if periodic is true, the $N$ in above formula is in fact $\text{window\_length} + 1$. Also, we always have tensorplay.hann_window(L, periodic=True) equal to tensorplay.hann_window(L + 1, periodic=False)[:-1]). > **Note** > > If window_length $=1$, the returned window contains a single value 1. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) [#](#api-tensorplay.functional.hardshrink) ### hardshrink function[Full reference ↗](/docs/generated/tensorplay.functional.hardshrink.html) ```python tensorplay.functional.hardshrink(input, lambd=0.5, *, out=None) ``` [#](#api-tensorplay.functional.hash_tensor) ### hash_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.hash_tensor.html) ```python tensorplay.functional.hash_tensor(input, *, mode=0) → Tensor ``` Returns a hash of all elements in the input tensor. Currently only mode=0 (reduction via xor) is supported. The output will always be of type tensorplay.uint64. The elements of input are upcasted to their 64 bit float / integer equivalent and bitcasted to tensorplay.uint64 before reduction via xor. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: mode ([int](https://docs.python.org/3/builtins/functions.html#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) ``` ```python tensorplay.functional.hash_tensor(input, dim, *, keepdim=False, mode=0) → Tensor ``` Returns the hash of each row of the input tensor in the given dimension dim given by mode. If dim is a list of dimensions, reduce over all of them. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: mode ([int](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.heaviside) ### heaviside function[Full reference ↗](/docs/generated/tensorplay.functional.heaviside.html) ```python tensorplay.functional.heaviside(input, values, *, out=None) → Tensor ``` Computes the Heaviside step function for each element in input. The Heaviside step function is defined as: $$\begin{split}\text{{heaviside}}(input, values) = \begin{cases} 0, & \text{if input < 0}\\ values, & \text{if input == 0}\\ 1, & \text{if input > 0} \end{cases}\end{split}$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - values ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The values to use where input is zero. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.hermite_polynomial_h) ### hermite_polynomial_h function[Full reference ↗](/docs/generated/tensorplay.functional.hermite_polynomial_h.html) ```python tensorplay.functional.hermite_polynomial_h(x, n) ``` [#](#api-tensorplay.functional.hermite_polynomial_he) ### hermite_polynomial_he function[Full reference ↗](/docs/generated/tensorplay.functional.hermite_polynomial_he.html) ```python tensorplay.functional.hermite_polynomial_he(x, n) ``` [#](#api-tensorplay.functional.hinge_embedding_loss) ### hinge_embedding_loss function[Full reference ↗](/docs/generated/tensorplay.functional.hinge_embedding_loss.html) ```python tensorplay.functional.hinge_embedding_loss(input, target, margin=1.0) ``` [#](#api-tensorplay.functional.histc) ### histc function[Full reference ↗](/docs/generated/tensorplay.functional.histc.html) ```python tensorplay.functional.histc(input, bins=100, min=0, max=0, *, out=None) → Tensor ``` Computes the histogram of a tensor. The elements are sorted into equal width bins between min and max. If min and max are both zero, the minimum and maximum values of the data are used. Elements lower than min and higher than max and NaN elements are ignored. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - bins ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of histogram bins - min ([Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – lower end of the range (inclusive) - max ([Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – upper end of the range (inclusive) Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: Histogram represented as a tensor Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> tensorplay.histc(tensorplay.tensor([1., 2, 1]), bins=4, min=0, max=3) tensor([ 0., 2., 1., 0.]) ``` [#](#api-tensorplay.functional.histogramdd) ### histogramdd function[Full reference ↗](/docs/generated/tensorplay.functional.histogramdd.html) ```python 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. input must 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 edgescorresponding 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 bins can be a sequence of N 1D tensors, a sequence of N ints, or a single int. If bins is 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 bins is 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. The [range](/docs/generated/tensorplay.functional.range.html#tensorplay.functional.range) argument can be provided to manually specify the leftmost and rightmost bin edges in each dimension. If bins is an int, it specifies the number of equal-width bins for all dimensions. > **Note** > > See also tensorplay.histogram(), which specifically computes 1D histograms. While tensorplay.histogramdd() infers the dimensionality of its bins and binned values from the shape of input, tensorplay.histogram() accepts and flattens input of any shape. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](https://docs.python.org/3/builtins/functions.html#float)) – Defines the leftmost and rightmost bin edges in each dimension. - weight ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 input tensor excluding its innermost dimension N. - density ([bool](https://docs.python.org/3/builtins/functions.html#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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]))) ``` [#](#api-tensorplay.functional.hsplit) ### hsplit function[Full reference ↗](/docs/generated/tensorplay.functional.hsplit.html) ```python tensorplay.functional.hsplit(input, indices_or_sections) → List of Tensors ``` Splits input, a tensor with one or more dimensions, into multiple tensors horizontally according to indices_or_sections. Each split is a view of input. If input is one dimensional this is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=0) (the split dimension is zero), and if input has 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 if indices_or_sections is 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – tensor to split. - indices_or_sections ([int](https://docs.python.org/3/builtins/functions.html#int) or [list](https://docs.python.org/3/builtins/stdtypes.html#list) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – See argument in tensorplay.tensor_split(). 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))) ``` [#](#api-tensorplay.functional.hstack) ### hstack function[Full reference ↗](/docs/generated/tensorplay.functional.hstack.html) ```python tensorplay.functional.hstack(tensors, *, out=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.hypot) ### hypot function[Full reference ↗](/docs/generated/tensorplay.functional.hypot.html) ```python tensorplay.functional.hypot(input, other, *, out=None) → Tensor ``` Given the legs of a right triangle, return its hypotenuse. $$\text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}$$ The shapes of input and other must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.i0_) ### i0_ function[Full reference ↗](/docs/generated/tensorplay.functional.i0_.html) ```python tensorplay.functional.i0_(input) ``` [#](#api-tensorplay.functional.i0) ### i0 function[Full reference ↗](/docs/generated/tensorplay.functional.i0.html) ```python tensorplay.functional.i0(input, *, out=None) → Tensor ``` Alias for tensorplay.special.i0(). [#](#api-tensorplay.functional.i0e) ### i0e function[Full reference ↗](/docs/generated/tensorplay.functional.i0e.html) ```python tensorplay.functional.i0e(input) ``` [#](#api-tensorplay.functional.i1) ### i1 function[Full reference ↗](/docs/generated/tensorplay.functional.i1.html) ```python tensorplay.functional.i1(input) ``` [#](#api-tensorplay.functional.i1e) ### i1e function[Full reference ↗](/docs/generated/tensorplay.functional.i1e.html) ```python tensorplay.functional.i1e(input) ``` [#](#api-tensorplay.functional.igamma) ### igamma function[Full reference ↗](/docs/generated/tensorplay.functional.igamma.html) ```python tensorplay.functional.igamma(input, other, *, out=None) → Tensor ``` Alias for tensorplay.special.gammainc(). [#](#api-tensorplay.functional.igammac) ### igammac function[Full reference ↗](/docs/generated/tensorplay.functional.igammac.html) ```python tensorplay.functional.igammac(input, other, *, out=None) → Tensor ``` Alias for tensorplay.special.gammaincc(). [#](#api-tensorplay.functional.imag) ### imag function[Full reference ↗](/docs/generated/tensorplay.functional.imag.html) ```python tensorplay.functional.imag(input) → Tensor ``` Returns a new tensor containing imaginary values of the self tensor. The returned tensor and self share the same underlying storage. > **Warning** > > imag() is only supported for tensors with complex dtypes. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.index_add) ### index_add function[Full reference ↗](/docs/generated/tensorplay.functional.index_add.html) ```python tensorplay.functional.index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Number | _complex = 1, out: Tensor | None) → Tensor ``` See index_add_() for function description. [#](#api-tensorplay.functional.index_copy) ### index_copy function[Full reference ↗](/docs/generated/tensorplay.functional.index_copy.html) ```python tensorplay.functional.index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Tensor | None) → Tensor ``` See index_add_() for function description. [#](#api-tensorplay.functional.index_put_) ### index_put_ function[Full reference ↗](/docs/generated/tensorplay.functional.index_put_.html) ```python tensorplay.functional.index_put_(input, indices, values, accumulate=False) ``` [#](#api-tensorplay.functional.index_reduce) ### index_reduce function[Full reference ↗](/docs/generated/tensorplay.functional.index_reduce.html) ```python tensorplay.functional.index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Tensor | None) → Tensor ``` See index_reduce_() for function description. [#](#api-tensorplay.functional.index_select) ### index_select function[Full reference ↗](/docs/generated/tensorplay.functional.index_select.html) ```python tensorplay.functional.index_select(input, dim, index, *, out=None) → Tensor ``` Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor. The returned tensor has the same number of dimensions as the original tensor (input). The dimth dimension has the same size as the length of index; 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 out has a different shape than expected, we silently change it to the correct shape, reallocating the underlying storage if necessary. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension in which we index - index (IntTensor or LongTensor) – the 1-D tensor containing the indices to index Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.indices_copy) ### indices_copy function[Full reference ↗](/docs/generated/tensorplay.functional.indices_copy.html) ```python tensorplay.functional.indices_copy(input) ``` Performs the same operation as [tensorplay.indices()](/docs/generated/tensorplay.indices.html#tensorplay.indices), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.inner) ### inner function[Full reference ↗](/docs/generated/tensorplay.functional.inner.html) ```python tensorplay.functional.inner(input, other, *, out=None) → Tensor ``` Computes the dot product for 1D tensors. For higher dimensions, sums the product of elements from input and other along their last dimension. > **Note** > > If either input or other is a scalar, the result is equivalent to tensorplay.mul(input, other). If both input and other are non-scalars, the size of their last dimension must match and the result is equivalent to tensorplay.tensordot(input, other, dims=([-1], [-1])) Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – First input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – Second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.instance_norm) ### instance_norm function[Full reference ↗](/docs/generated/tensorplay.functional.instance_norm.html) ```python 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) ``` [#](#api-tensorplay.functional.int_repr) ### int_repr function[Full reference ↗](/docs/generated/tensorplay.functional.int_repr.html) ```python tensorplay.functional.int_repr(input) ``` [#](#api-tensorplay.functional.inverse) ### inverse function[Full reference ↗](/docs/generated/tensorplay.functional.inverse.html) ```python tensorplay.functional.inverse(input, *, out=None) → Tensor ``` Alias for [tensorplay.linalg.inv()](/docs/generated/tensorplay.linalg.inv.html#tensorplay.linalg.inv) [#](#api-tensorplay.functional.is_complex) ### is_complex function[Full reference ↗](/docs/generated/tensorplay.functional.is_complex.html) ```python tensorplay.functional.is_complex(input: Tensor) → bool ``` Returns True if the data type of input is a complex data type i.e., one of tensorplay.complex64, and tensorplay.complex128. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.is_conj) ### is_conj function[Full reference ↗](/docs/generated/tensorplay.functional.is_conj.html) ```python tensorplay.functional.is_conj(input) ``` Returns True if the input is a conjugated tensor, i.e. its conjugate bit is set to True. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. [#](#api-tensorplay.functional.is_distributed) ### is_distributed function[Full reference ↗](/docs/generated/tensorplay.functional.is_distributed.html) ```python tensorplay.functional.is_distributed(input) ``` [#](#api-tensorplay.functional.is_floating_point) ### is_floating_point function[Full reference ↗](/docs/generated/tensorplay.functional.is_floating_point.html) ```python tensorplay.functional.is_floating_point(input: Tensor) → bool ``` Returns True if the data type of input is a floating point data type i.e., one of tensorplay.float64, tensorplay.float32, tensorplay.float16, and tensorplay.bfloat16. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.is_inference) ### is_inference function[Full reference ↗](/docs/generated/tensorplay.functional.is_inference.html) ```python tensorplay.functional.is_inference(input) ``` Returns True if input is 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](https://pytensorplay.org/cppdocs/notes/inference_mode.html). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. [#](#api-tensorplay.functional.is_neg) ### is_neg function[Full reference ↗](/docs/generated/tensorplay.functional.is_neg.html) ```python tensorplay.functional.is_neg(input) ``` [#](#api-tensorplay.functional.is_nonzero) ### is_nonzero function[Full reference ↗](/docs/generated/tensorplay.functional.is_nonzero.html) ```python tensorplay.functional.is_nonzero(input) ``` Returns True if the input is a single element tensor which is not equal to zero after type conversions. i.e. not equal to tensorplay.tensor([0.]) or tensorplay.tensor([0]) or tensorplay.tensor([False]). Throws a RuntimeError if tensorplay.numel() != 1 (even in case of sparse tensors). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.is_same_size) ### is_same_size function[Full reference ↗](/docs/generated/tensorplay.functional.is_same_size.html) ```python tensorplay.functional.is_same_size(input, other) ``` [#](#api-tensorplay.functional.is_signed) ### is_signed function[Full reference ↗](/docs/generated/tensorplay.functional.is_signed.html) ```python tensorplay.functional.is_signed(input) ``` [#](#api-tensorplay.functional.is_vulkan_available) ### is_vulkan_available function[Full reference ↗](/docs/generated/tensorplay.functional.is_vulkan_available.html) ```python tensorplay.functional.is_vulkan_available() ``` [#](#api-tensorplay.functional.isclose) ### isclose function[Full reference ↗](/docs/generated/tensorplay.functional.isclose.html) ```python tensorplay.functional.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor ``` Returns a new tensor with boolean elements representing if each element of input is “close” to the corresponding element of other. Closeness is defined as: $$\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}$$ where input and other are finite. Where input and/or other are nonfinite they are close if and only if they are equal, with NaNs being considered equal to each other when equal_nan is True. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – first tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – second tensor to compare - rtol ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – relative tolerance. Default: 1e-05 - atol ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – absolute tolerance. Default: 1e-08 - equal_nan ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – if True, then two NaN s will be considered equal. Default: False 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]) ``` [#](#api-tensorplay.functional.isfinite) ### isfinite function[Full reference ↗](/docs/generated/tensorplay.functional.isfinite.html) ```python tensorplay.functional.isfinite(input) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Returns: A boolean tensor that is True where input is finite and False elsewhere Example: ``` >>> tensorplay.isfinite(tensorplay.tensor([1, float('inf'), 2, float('-inf'), float('nan')])) tensor([True, False, True, False, False]) ``` [#](#api-tensorplay.functional.isin) ### isin function[Full reference ↗](/docs/generated/tensorplay.functional.isin.html) ```python tensorplay.functional.isin(elements, test_elements, *, assume_unique=False, invert=False) → Tensor ``` Tests if each element of elements is in test_elements. Returns a boolean tensor of the same shape as elements that is True for elements in test_elements and False otherwise. > **Note** > > One of elements or test_elements can be a scalar, but not both. Parameters: - elements ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – Input elements - test_elements ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – Values against which to test for each input element - assume_unique ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, assumes both elements and test_elements contain unique elements, which can speed up the calculation. Default: False - invert ([bool](https://docs.python.org/3/builtins/functions.html#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 elements that is True for elements in test_elements and False otherwise Example ``` >>> tensorplay.isin(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([2, 3])) tensor([[False, True], [ True, False]]) ``` [#](#api-tensorplay.functional.isinf) ### isinf function[Full reference ↗](/docs/generated/tensorplay.functional.isinf.html) ```python tensorplay.functional.isinf(input) → Tensor ``` Tests if each element of input is infinite (positive or negative infinity) or not. > **Note** > > Complex values are infinite when their real or imaginary part is infinite. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Returns: A boolean tensor that is True where input is infinite and False elsewhere Example: ``` >>> tensorplay.isinf(tensorplay.tensor([1, float('inf'), 2, float('-inf'), float('nan')])) tensor([False, True, False, True, False]) ``` [#](#api-tensorplay.functional.isnan) ### isnan function[Full reference ↗](/docs/generated/tensorplay.functional.isnan.html) ```python tensorplay.functional.isnan(input) → Tensor ``` Returns a new tensor with boolean elements representing if each element of input is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Returns: A boolean tensor that is True where input is NaN and False elsewhere Example: ``` >>> tensorplay.isnan(tensorplay.tensor([1, float('nan'), 2])) tensor([False, True, False]) ``` [#](#api-tensorplay.functional.isneginf) ### isneginf function[Full reference ↗](/docs/generated/tensorplay.functional.isneginf.html) ```python tensorplay.functional.isneginf(input, *, out=None) → Tensor ``` Tests if each element of input is negative infinity or not. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> a = tensorplay.tensor([-float('inf'), float('inf'), 1.2]) >>> tensorplay.isneginf(a) tensor([ True, False, False]) ``` [#](#api-tensorplay.functional.isposinf) ### isposinf function[Full reference ↗](/docs/generated/tensorplay.functional.isposinf.html) ```python tensorplay.functional.isposinf(input, *, out=None) → Tensor ``` Tests if each element of input is positive infinity or not. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> a = tensorplay.tensor([-float('inf'), float('inf'), 1.2]) >>> tensorplay.isposinf(a) tensor([False, True, False]) ``` [#](#api-tensorplay.functional.isreal) ### isreal function[Full reference ↗](/docs/generated/tensorplay.functional.isreal.html) ```python tensorplay.functional.isreal(input) → Tensor ``` Returns a new tensor with boolean elements representing if each element of input is 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Returns: A boolean tensor that is True where input is real and False elsewhere Example: ``` >>> tensorplay.isreal(tensorplay.tensor([1, 1+1j, 2+0j])) tensor([True, False, True]) ``` [#](#api-tensorplay.functional.istft) ### istft function[Full reference ↗](/docs/generated/tensorplay.functional.istft.html) ```python 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) ``` [#](#api-tensorplay.functional.kaiser_window) ### kaiser_window function[Full reference ↗](/docs/generated/tensorplay.functional.kaiser_window.html) ```python tensorplay.functional.kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Computes the Kaiser window with window length window_length and shape parameter beta. Let I_0 be the zeroth order modified Bessel function of the first kind (see tensorplay.i0()) and N = L - 1 if periodic is False and L if periodic is True, where L is the window_length. This function computes: $$out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )$$ Calling tensorplay.kaiser_window(L, B, periodic=True) is equivalent to calling tensorplay.kaiser_window(L + 1, B, periodic=False)[:-1]). The periodic argument is intended as a helpful shorthand to produce a periodic window as input to functions like tensorplay.stft(). > **Note** > > If window_length is one, then the returned window is a single element tensor containing a one. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – length of the window. - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. - beta ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – shape parameter for the window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. [#](#api-tensorplay.functional.kl_div) ### kl_div function[Full reference ↗](/docs/generated/tensorplay.functional.kl_div.html) ```python tensorplay.functional.kl_div(input, target) ``` [#](#api-tensorplay.functional.kron) ### kron function[Full reference ↗](/docs/generated/tensorplay.functional.kron.html) ```python tensorplay.functional.kron(input, other, *, out=None) → Tensor ``` Computes the Kronecker product, denoted by $\otimes$, of input and other. If input is a $(a_0 \times a_1 \times \dots \times a_n)$ tensor and other is a $(b_0 \times b_1 \times \dots \times b_n)$ tensor, the result will be a $(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)$ tensor with the following entries: $$(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} = \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},$$ where $k_t = i_t * b_t + j_t$ for $0 \leq t \leq n$. 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 input is a $(m \times n)$ matrix and other is a $(p \times q)$ matrix, the result will be a $(p*m \times q*n)$ block matrix: @@TPBLOCK_328@@ where input is $\mathbf{A}$ and other is $\mathbf{B}$. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]]) ``` [#](#api-tensorplay.functional.kthvalue) ### kthvalue function[Full reference ↗](/docs/generated/tensorplay.functional.kthvalue.html) ```python tensorplay.functional.kthvalue(input, k, dim=-1, keepdim=False, *, out=None) ``` [#](#api-tensorplay.functional.laguerre_polynomial_l) ### laguerre_polynomial_l function[Full reference ↗](/docs/generated/tensorplay.functional.laguerre_polynomial_l.html) ```python tensorplay.functional.laguerre_polynomial_l(x, n) ``` [#](#api-tensorplay.functional.lcm_) ### lcm_ function[Full reference ↗](/docs/generated/tensorplay.functional.lcm_.html) ```python tensorplay.functional.lcm_(input, other) ``` [#](#api-tensorplay.functional.lcm) ### lcm function[Full reference ↗](/docs/generated/tensorplay.functional.lcm.html) ```python tensorplay.functional.lcm(input, other, *, out=None) → Tensor ``` Computes the element-wise least common multiple (LCM) of input and other. Both input and other must have integer types. > **Note** > > This defines $lcm(0, 0) = 0$ and $lcm(0, a) = 0$. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.ldexp_) ### ldexp_ function[Full reference ↗](/docs/generated/tensorplay.functional.ldexp_.html) ```python tensorplay.functional.ldexp_(input, other) ``` [#](#api-tensorplay.functional.ldexp) ### ldexp function[Full reference ↗](/docs/generated/tensorplay.functional.ldexp.html) ```python tensorplay.functional.ldexp(input, other, *, out=None) → Tensor ``` Multiplies input by 2 ** other. $$\text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i$$ Typically this function is used to construct floating point numbers by multiplying mantissas in input with integral powers of two created from the exponents in other. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – a tensor of exponents, typically integers. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.le) ### le function[Full reference ↗](/docs/generated/tensorplay.functional.le.html) ```python tensorplay.functional.le(input, other, *, out=None) → Tensor ``` Computes $\text{input} \leq \text{other}$ element-wise. The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is less than or equal to other and False elsewhere Example: ``` >>> tensorplay.le(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[True, False], [True, True]]) ``` [#](#api-tensorplay.functional.legendre_polynomial_p) ### legendre_polynomial_p function[Full reference ↗](/docs/generated/tensorplay.functional.legendre_polynomial_p.html) ```python tensorplay.functional.legendre_polynomial_p(x, n) ``` [#](#api-tensorplay.functional.lerp) ### lerp function[Full reference ↗](/docs/generated/tensorplay.functional.lerp.html) ```python tensorplay.functional.lerp(input, end, weight, *, out=None) ``` Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor. $$\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)$$ The shapes of start and end must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). If weight is a tensor, then the shapes of weight, start, and end must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor with the starting points - end ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor with the ending points - weight ([float](https://docs.python.org/3/builtins/functions.html#float) or tensor) – the weight for the interpolation formula Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.less_equal) ### less_equal function[Full reference ↗](/docs/generated/tensorplay.functional.less_equal.html) ```python tensorplay.functional.less_equal(input, other, *, out=None) → Tensor ``` Alias for tensorplay.le(). [#](#api-tensorplay.functional.less) ### less function[Full reference ↗](/docs/generated/tensorplay.functional.less.html) ```python tensorplay.functional.less(input, other, *, out=None) → Tensor ``` Alias for tensorplay.lt(). [#](#api-tensorplay.functional.lgamma) ### lgamma function[Full reference ↗](/docs/generated/tensorplay.functional.lgamma.html) ```python tensorplay.functional.lgamma(input, *, out=None) → Tensor ``` Computes the natural logarithm of the absolute value of the gamma function on input. $$\text{out}_{i} = \ln |\Gamma(\text{input}_{i})|$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> a = tensorplay.arange(0.5, 2, 0.5) >>> tensorplay.lgamma(a) tensor([ 0.5724, 0.0000, -0.1208]) ``` [#](#api-tensorplay.functional.linspace) ### linspace function[Full reference ↗](/docs/generated/tensorplay.functional.linspace.html) ```python tensorplay.functional.linspace(start, end, steps, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Creates a one-dimensional tensor of size steps whose values are evenly spaced from start to end, inclusive. That is, the value are: $$(\text{start}, \text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1}, \ldots, \text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1}, \text{end})$$ Parameters: - start ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the starting value for the set of points. If Tensor, it must be 0-dimensional - end ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the ending value for the set of points. If Tensor, it must be 0-dimensional - steps ([int](https://docs.python.org/3/builtins/functions.html#int)) – size of the constructed tensor Keyword Arguments: - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#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 start and end are 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](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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.]) ``` [#](#api-tensorplay.functional.log_) ### log_ function[Full reference ↗](/docs/generated/tensorplay.functional.log_.html) ```python tensorplay.functional.log_(input) ``` [#](#api-tensorplay.functional.log_ndtr) ### log_ndtr function[Full reference ↗](/docs/generated/tensorplay.functional.log_ndtr.html) ```python tensorplay.functional.log_ndtr(input) ``` [#](#api-tensorplay.functional.log) ### log function[Full reference ↗](/docs/generated/tensorplay.functional.log.html) ```python tensorplay.functional.log(input, *, out=None) → Tensor ``` Returns a new tensor with the natural logarithm of the elements of input. $$y_{i} = \log_{e} (x_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.log10_) ### log10_ function[Full reference ↗](/docs/generated/tensorplay.functional.log10_.html) ```python tensorplay.functional.log10_(input) ``` [#](#api-tensorplay.functional.log10) ### log10 function[Full reference ↗](/docs/generated/tensorplay.functional.log10.html) ```python tensorplay.functional.log10(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the logarithm to the base 10 of the elements of input. $$y_{i} = \log_{10} (x_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.log1p_) ### log1p_ function[Full reference ↗](/docs/generated/tensorplay.functional.log1p_.html) ```python tensorplay.functional.log1p_(input) ``` [#](#api-tensorplay.functional.log1p) ### log1p function[Full reference ↗](/docs/generated/tensorplay.functional.log1p.html) ```python tensorplay.functional.log1p(input, *, out=None) → Tensor ``` Returns a new tensor with the natural logarithm of (1 + input). $$y_i = \log_{e} (x_i + 1)$$ > **Note** > > This function is more accurate than tensorplay.log() for small values of input Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.log2_) ### log2_ function[Full reference ↗](/docs/generated/tensorplay.functional.log2_.html) ```python tensorplay.functional.log2_(input) ``` [#](#api-tensorplay.functional.log2) ### log2 function[Full reference ↗](/docs/generated/tensorplay.functional.log2.html) ```python tensorplay.functional.log2(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the logarithm to the base 2 of the elements of input. $$y_{i} = \log_{2} (x_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logaddexp) ### logaddexp function[Full reference ↗](/docs/generated/tensorplay.functional.logaddexp.html) ```python tensorplay.functional.logaddexp(input, other, *, out=None) → Tensor ``` Logarithm of the sum of exponentiations of the inputs. Calculates pointwise $\log\left(e^x + e^y\right)$. 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logaddexp2) ### logaddexp2 function[Full reference ↗](/docs/generated/tensorplay.functional.logaddexp2.html) ```python tensorplay.functional.logaddexp2(input, other, *, out=None) → Tensor ``` Logarithm of the sum of exponentiations of the inputs in base-2. Calculates pointwise $\log_2\left(2^x + 2^y\right)$. See tensorplay.logaddexp() for more details. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. [#](#api-tensorplay.functional.logcumsumexp) ### logcumsumexp function[Full reference ↗](/docs/generated/tensorplay.functional.logcumsumexp.html) ```python tensorplay.functional.logcumsumexp(input, dim, *, out=None) → Tensor ``` Returns the logarithm of the cumulative summation of the exponentiation of elements of input in the dimension dim. For summation index $j$ given by dim and other indices $i$, the result is $$\text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to do the operation over Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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])) ``` [#](#api-tensorplay.functional.logdet) ### logdet function[Full reference ↗](/docs/generated/tensorplay.functional.logdet.html) ```python tensorplay.functional.logdet(input) → Tensor ``` Calculates log determinant of a square matrix or batches of square matrices. It returns -inf if the input has a determinant of zero, and NaN if it has a negative determinant. > **Note** > > Backward through logdet() internally uses SVD results when input is not invertible. In this case, double backward through logdet() will be unstable in when input doesn’t have distinct singular values. See tensorplay.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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logical_and) ### logical_and function[Full reference ↗](/docs/generated/tensorplay.functional.logical_and.html) ```python tensorplay.functional.logical_and(input, other, *, out=None) → Tensor ``` Computes the element-wise logical AND of the given input tensors. Zeros are treated as False and nonzeros are treated as True. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compute AND with Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logical_not) ### logical_not function[Full reference ↗](/docs/generated/tensorplay.functional.logical_not.html) ```python tensorplay.functional.logical_not(input, *, out=None) → Tensor ``` 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 False and non-zeros are treated as True. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.logical_or) ### logical_or function[Full reference ↗](/docs/generated/tensorplay.functional.logical_or.html) ```python tensorplay.functional.logical_or(input, other, *, out=None) → Tensor ``` Computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compute OR with Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logical_xor) ### logical_xor function[Full reference ↗](/docs/generated/tensorplay.functional.logical_xor.html) ```python tensorplay.functional.logical_xor(input: Tensor, other: Tensor, *, out: Tensor | None) → Tensor ``` Computes the element-wise logical XOR of the given input tensors. Zeros are treated as False and nonzeros are treated as True. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compute XOR with Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.logit_) ### logit_ function[Full reference ↗](/docs/generated/tensorplay.functional.logit_.html) ```python tensorplay.functional.logit_(input, eps=None) ``` [#](#api-tensorplay.functional.logit) ### logit function[Full reference ↗](/docs/generated/tensorplay.functional.logit.html) ```python tensorplay.functional.logit(input, eps=None, *, out=None) → Tensor ``` Alias for tensorplay.special.logit(). [#](#api-tensorplay.functional.logspace) ### logspace function[Full reference ↗](/docs/generated/tensorplay.functional.logspace.html) ```python tensorplay.functional.logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Creates a one-dimensional tensor of size steps whose values are evenly spaced from ${{\text{{base}}}}^{{\text{{start}}}}$ to ${{\text{{base}}}}^{{\text{{end}}}}$, inclusive, on a logarithmic scale with base base. That is, the values are: $$(\text{base}^{\text{start}}, \text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})}, \ldots, \text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})}, \text{base}^{\text{end}})$$ Parameters: - start ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the starting value for the set of points. If Tensor, it must be 0-dimensional - end ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the ending value for the set of points. If Tensor, it must be 0-dimensional - steps ([int](https://docs.python.org/3/builtins/functions.html#int)) – size of the constructed tensor - base ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – base of the logarithm function. Default: 10.0. Keyword Arguments: - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#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 start and end are 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](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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]) ``` [#](#api-tensorplay.functional.logsumexp) ### logsumexp function[Full reference ↗](/docs/generated/tensorplay.functional.logsumexp.html) ```python tensorplay.functional.logsumexp(input, dim, keepdim=False, *, out=None) ``` Returns the log of summed exponentials of each row of the input tensor in the given dimension dim. The computation is numerically stabilized. For summation index $j$ given by dim and other indices $i$, the result is $$\text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})$$ If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – the dimension or dimensions to reduce. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.lstm_cell) ### lstm_cell function[Full reference ↗](/docs/generated/tensorplay.functional.lstm_cell.html) ```python tensorplay.functional.lstm_cell(input, hx, cx, w_ih, w_hh, b_ih=None, b_hh=None) ``` [#](#api-tensorplay.functional.lstm) ### lstm function[Full reference ↗](/docs/generated/tensorplay.functional.lstm.html) ```python tensorplay.functional.lstm(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False) ``` [#](#api-tensorplay.functional.lt) ### lt function[Full reference ↗](/docs/generated/tensorplay.functional.lt.html) ```python tensorplay.functional.lt(input, other, *, out=None) → Tensor ``` Computes $\text{input} The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [float](https://docs.python.org/3/builtins/functions.html#float)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is less than other and False elsewhere Example: ``` >>> tensorplay.lt(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, False], [True, False]]) ``` [#](#api-tensorplay.functional.lu_solve) ### lu_solve function[Full reference ↗](/docs/generated/tensorplay.functional.lu_solve.html) ```python tensorplay.functional.lu_solve(b, LU_data, LU_pivots, *, out=None) → Tensor ``` Returns the LU solve of the linear system $Ax = b$ using the partially pivoted LU factorization of A from lu_factor(). This function supports float, double, cfloat and cdouble dtypes for input. > **Warning** > > tensorplay.lu_solve() is deprecated in favor of tensorplay.linalg.lu_solve(). X = tensorplay.lu_solve(B, LU, pivots) should be replaced with @@TPBLOCK_151@@ Parameters: - b ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the RHS tensor of size $(*, m, k)$, where $*$ is zero or more batch dimensions. - LU_data ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the pivoted LU factorization of A from lu_factor() of size $(*, m, m)$, where $*$ is zero or more batch dimensions. - LU_pivots (IntTensor) – the pivots of the LU factorization from lu_factor() of size $(*, m)$, where $*$ is zero or more batch dimensions. The batch dimensions of LU_pivots must be equal to the batch dimensions of LU_data. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.lu_unpack) ### lu_unpack function[Full reference ↗](/docs/generated/tensorplay.functional.lu_unpack.html) ```python tensorplay.functional.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) ``` 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 doing lu_factor() followed by lu_unpack(). Parameters: - LU_data ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the packed LU factorization data - LU_pivots ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the packed LU factorization pivots - unpack_data ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – flag indicating if the data should be unpacked. If False, then the returned L and U are empty tensors. Default: True - unpack_pivots ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – flag indicating if the pivots should be unpacked into a permutation matrix P. If False, then the returned P is an empty tensor. Default: True Keyword Arguments: out ([tuple](https://docs.python.org/3/builtins/stdtypes.html#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 ``` [#](#api-tensorplay.functional.margin_ranking_loss) ### margin_ranking_loss function[Full reference ↗](/docs/generated/tensorplay.functional.margin_ranking_loss.html) ```python tensorplay.functional.margin_ranking_loss(input1, input2, target, margin=0) ``` [#](#api-tensorplay.functional.masked_fill) ### masked_fill function[Full reference ↗](/docs/generated/tensorplay.functional.masked_fill.html) ```python tensorplay.functional.masked_fill(input, mask, value) ``` [#](#api-tensorplay.functional.masked_select) ### masked_select function[Full reference ↗](/docs/generated/tensorplay.functional.masked_select.html) ```python tensorplay.functional.masked_select(input, mask, *, out=None) → Tensor ``` Returns a new 1-D tensor which indexes the input tensor according to the boolean mask mask which is a BoolTensor. The shapes of the mask tensor and the input tensor don’t need to match, but they must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). > **Note** > > The returned tensor does not use the same storage as the original tensor Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - mask (BoolTensor) – the tensor containing the binary mask to index with Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.matmul) ### matmul function[Full reference ↗](/docs/generated/tensorplay.functional.matmul.html) ```python tensorplay.functional.matmul(input, other, *, out=None) → Tensor ``` 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](/docs/notes/broadcasting.html#broadcasting-semantics) (and thus must be broadcastable). The last 2, the matrix dimensions, are handled as in the matrix-matrix product. For example, if input is a $(j \times 1 \times n \times m)$ tensor and other is a $(k \times m \times p)$ tensor, the batch dimensions are $(j \times 1)$ and $(k)$, and the matrix dimensions are $(n \times m)$ and $(m \times p)$. out will be a $(j \times k \times n \times p)$ 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](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. > **Note** > > The 1-dimensional dot product version of this function does not support an out parameter. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first tensor to be multiplied - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second tensor to be multiplied Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.matrix_exp) ### matrix_exp function[Full reference ↗](/docs/generated/tensorplay.functional.matrix_exp.html) ```python tensorplay.functional.matrix_exp(A) → Tensor ``` Alias for [tensorplay.linalg.matrix_exp()](/docs/generated/tensorplay.linalg.matrix_exp.html#tensorplay.linalg.matrix_exp). [#](#api-tensorplay.functional.matrix_power) ### matrix_power function[Full reference ↗](/docs/generated/tensorplay.functional.matrix_power.html) ```python tensorplay.functional.matrix_power(input, n, *, out=None) → Tensor ``` Alias for [tensorplay.linalg.matrix_power()](/docs/generated/tensorplay.linalg.matrix_power.html#tensorplay.linalg.matrix_power) [#](#api-tensorplay.functional.max_pool1d) ### max_pool1d function[Full reference ↗](/docs/generated/tensorplay.functional.max_pool1d.html) ```python tensorplay.functional.max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) ``` [#](#api-tensorplay.functional.max_pool3d) ### max_pool3d function[Full reference ↗](/docs/generated/tensorplay.functional.max_pool3d.html) ```python tensorplay.functional.max_pool3d(input, kernel_size, stride=[], padding=[0, 0, 0], dilation=[1, 1, 1], ceil_mode=False) ``` [#](#api-tensorplay.functional.maximum) ### maximum function[Full reference ↗](/docs/generated/tensorplay.functional.maximum.html) ```python tensorplay.functional.maximum(input, other, *, out=None) → Tensor ``` Computes the element-wise maximum of input and other. > **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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.mean) ### mean function[Full reference ↗](/docs/generated/tensorplay.functional.mean.html) ```python tensorplay.functional.mean(input, *, dtype=None) → Tensor ``` > **Note** > > If the input tensor is empty, tensorplay.mean() returns nan. 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 input tensor. Input must be floating point or complex. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor, either of floating point or complex dtype Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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) ``` ```python tensorplay.functional.mean(input, dim, keepdim=False, *, dtype=None, out=None) → Tensor ``` Returns the mean value of each row of the input tensor in the given dimension dim. If dim is a list of dimensions, reduce over all of them. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.median) ### median function[Full reference ↗](/docs/generated/tensorplay.functional.median.html) ```python tensorplay.functional.median(input, dim=None, keepdim=False) ``` [#](#api-tensorplay.functional.meshgrid) ### meshgrid function[Full reference ↗](/docs/generated/tensorplay.functional.meshgrid.html) ```python tensorplay.functional.meshgrid(tensors, indexing='ij') ``` [#](#api-tensorplay.functional.minimum) ### minimum function[Full reference ↗](/docs/generated/tensorplay.functional.minimum.html) ```python tensorplay.functional.minimum(input, other, *, out=None) → Tensor ``` Computes the element-wise minimum of input and other. > **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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.miopen_batch_norm) ### miopen_batch_norm function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_batch_norm.html) ```python tensorplay.functional.miopen_batch_norm(input, weight, bias, running_mean, running_var, training, exponential_average_factor, epsilon) ``` [#](#api-tensorplay.functional.miopen_convolution_add_relu) ### miopen_convolution_add_relu function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_convolution_add_relu.html) ```python tensorplay.functional.miopen_convolution_add_relu(input, weight, z, alpha, bias, stride, padding, dilation, groups) ``` [#](#api-tensorplay.functional.miopen_convolution_relu) ### miopen_convolution_relu function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_convolution_relu.html) ```python tensorplay.functional.miopen_convolution_relu(input, weight, bias, stride, padding, dilation, groups) ``` [#](#api-tensorplay.functional.miopen_convolution_transpose) ### miopen_convolution_transpose function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_convolution_transpose.html) ```python tensorplay.functional.miopen_convolution_transpose(input, weight, bias, padding, output_padding, stride, dilation, groups, benchmark, deterministic) ``` [#](#api-tensorplay.functional.miopen_convolution) ### miopen_convolution function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_convolution.html) ```python tensorplay.functional.miopen_convolution(input, weight, bias, padding, stride, dilation, groups, benchmark, deterministic) ``` [#](#api-tensorplay.functional.miopen_ctc_loss) ### miopen_ctc_loss function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_ctc_loss.html) ```python tensorplay.functional.miopen_ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, deterministic, zero_infinity) ``` [#](#api-tensorplay.functional.miopen_depthwise_convolution) ### miopen_depthwise_convolution function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_depthwise_convolution.html) ```python tensorplay.functional.miopen_depthwise_convolution(input, weight, bias, padding, stride, dilation, groups, benchmark, deterministic) ``` [#](#api-tensorplay.functional.miopen_rnn) ### miopen_rnn function[Full reference ↗](/docs/generated/tensorplay.functional.miopen_rnn.html) ```python tensorplay.functional.miopen_rnn(input, weight, weight_stride0, hx, cx, mode, hidden_size, num_layers, batch_first, dropout, train, bidirectional, batch_sizes, dropout_state) ``` [#](#api-tensorplay.functional.mkldnn_adaptive_avg_pool2d) ### mkldnn_adaptive_avg_pool2d function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_adaptive_avg_pool2d.html) ```python tensorplay.functional.mkldnn_adaptive_avg_pool2d(input, output_size, *, out=None) ``` [#](#api-tensorplay.functional.mkldnn_convolution) ### mkldnn_convolution function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_convolution.html) ```python tensorplay.functional.mkldnn_convolution(input, weight, bias, padding, stride, dilation, groups) ``` [#](#api-tensorplay.functional.mkldnn_linear_backward_weights) ### mkldnn_linear_backward_weights function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_linear_backward_weights.html) ```python tensorplay.functional.mkldnn_linear_backward_weights(grad_output, input, weight, bias_defined) ``` [#](#api-tensorplay.functional.mkldnn_max_pool2d) ### mkldnn_max_pool2d function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_max_pool2d.html) ```python tensorplay.functional.mkldnn_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) ``` [#](#api-tensorplay.functional.mkldnn_max_pool3d) ### mkldnn_max_pool3d function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_max_pool3d.html) ```python tensorplay.functional.mkldnn_max_pool3d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) ``` [#](#api-tensorplay.functional.mkldnn_rnn_layer) ### mkldnn_rnn_layer function[Full reference ↗](/docs/generated/tensorplay.functional.mkldnn_rnn_layer.html) ```python 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) ``` [#](#api-tensorplay.functional.mm) ### mm function[Full reference ↗](/docs/generated/tensorplay.functional.mm.html) ```python tensorplay.functional.mm(input, mat2, out_dtype=None, *, out=None) → Tensor ``` Performs a matrix multiplication of the matrices input and mat2. If input is a $(n \times m)$ tensor, mat2 is a $(m \times p)$ tensor, out will be a $(n \times p)$ 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 out is provided its layout will be used. Otherwise, the result layout will be deduced from that of input. > **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](/docs/notes/numerical_accuracy.html#id6). On certain ROCm devices, when using float16 inputs this module will use [different precision](/docs/notes/numerical_accuracy.html#fp16-on-mi200) for backward. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first matrix to be matrix multiplied - mat2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second matrix to be matrix multiplied - out_dtype ([dtype](/docs/generated/tensorplay.DType.html#tensorplay.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: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.mode) ### mode function[Full reference ↗](/docs/generated/tensorplay.functional.mode.html) ```python tensorplay.functional.mode(input, dim=-1, keepdim=False, *, out=None) ``` [#](#api-tensorplay.functional.modified_bessel_i0) ### modified_bessel_i0 function[Full reference ↗](/docs/generated/tensorplay.functional.modified_bessel_i0.html) ```python tensorplay.functional.modified_bessel_i0(input) ``` [#](#api-tensorplay.functional.modified_bessel_i1) ### modified_bessel_i1 function[Full reference ↗](/docs/generated/tensorplay.functional.modified_bessel_i1.html) ```python tensorplay.functional.modified_bessel_i1(input) ``` [#](#api-tensorplay.functional.modified_bessel_k0) ### modified_bessel_k0 function[Full reference ↗](/docs/generated/tensorplay.functional.modified_bessel_k0.html) ```python tensorplay.functional.modified_bessel_k0(input) ``` [#](#api-tensorplay.functional.modified_bessel_k1) ### modified_bessel_k1 function[Full reference ↗](/docs/generated/tensorplay.functional.modified_bessel_k1.html) ```python tensorplay.functional.modified_bessel_k1(input) ``` [#](#api-tensorplay.functional.moveaxis) ### moveaxis function[Full reference ↗](/docs/generated/tensorplay.functional.moveaxis.html) ```python tensorplay.functional.moveaxis(input, source, destination) → Tensor ``` 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]]]) ``` [#](#api-tensorplay.functional.movedim) ### movedim function[Full reference ↗](/docs/generated/tensorplay.functional.movedim.html) ```python tensorplay.functional.movedim(input, source, destination) → Tensor ``` Moves the dimension(s) of input at the position(s) in source to the position(s) in destination. Other dimensions of input that are not explicitly moved remain in their original order and appear at the positions not specified in destination. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - source ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – Original positions of the dims to move. These must be unique. - destination ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – Destination positions for each of the original dims. These must also be unique. 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]]]) ``` [#](#api-tensorplay.functional.msort) ### msort function[Full reference ↗](/docs/generated/tensorplay.functional.msort.html) ```python tensorplay.functional.msort(input: Tensor, *, out: Tensor | None) → Tensor ``` Sorts the elements of the input tensor 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.mul) ### mul function[Full reference ↗](/docs/generated/tensorplay.functional.mul.html) ```python tensorplay.functional.mul(input, other, *, out=None) → Tensor ``` Multiplies input by other. $$\text{out}_i = \text{input}_i \times \text{other}_i$$ Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer, float, and complex inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the tensor or number to multiply input by. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.multinomial) ### multinomial function[Full reference ↗](/docs/generated/tensorplay.functional.multinomial.html) ```python tensorplay.functional.multinomial(input, num_samples, replacement=False, *, generator=None, out=None) → LongTensor ``` Returns a tensor where each row contains num_samples indices sampled from the multinomial (a stricter definition would be multivariate, refer to [tensorplay.distributions.multinomial.Multinomial](/docs/generated/tensorplay.distributions.Multinomial.html#tensorplay.distributions.Multinomial) for more details) probability distribution located in the corresponding row of tensor input. > **Note** > > The rows of input do 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 input is a vector, out is a vector of size num_samples. If input is a matrix with m rows, out is an matrix of shape $(m \times \text{num\_samples})$. 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_samples must be lower than number of non-zero elements in input (or the min number of non-zero elements in each row of input if it is a matrix). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor containing probabilities - num_samples ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of samples to draw - replacement ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – whether to draw with replacement or not Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.multiply) ### multiply function[Full reference ↗](/docs/generated/tensorplay.functional.multiply.html) ```python tensorplay.functional.multiply(input, other, *, out=None) ``` Alias for tensorplay.mul(). [#](#api-tensorplay.functional.mv) ### mv function[Full reference ↗](/docs/generated/tensorplay.functional.mv.html) ```python tensorplay.functional.mv(input, vec, *, out=None) → Tensor ``` Performs a matrix-vector product of the matrix input and the vector vec. If input is a $(n \times m)$ tensor, vec is a 1-D tensor of size $m$, out will be 1-D of size $n$. > **Note** > > This function does not broadcast. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – matrix to be multiplied - vec ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – vector to be multiplied Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> mat = tensorplay.randn(2, 3) >>> vec = tensorplay.randn(3) >>> tensorplay.mv(mat, vec) tensor([ 1.0404, -0.6361]) ``` [#](#api-tensorplay.functional.mvlgamma) ### mvlgamma function[Full reference ↗](/docs/generated/tensorplay.functional.mvlgamma.html) ```python tensorplay.functional.mvlgamma(input, p, *, out=None) → Tensor ``` Alias for tensorplay.special.multigammaln(). [#](#api-tensorplay.functional.nan_to_num_) ### nan_to_num_ function[Full reference ↗](/docs/generated/tensorplay.functional.nan_to_num_.html) ```python tensorplay.functional.nan_to_num_(input, nan=0.0, posinf=None, neginf=None) ``` [#](#api-tensorplay.functional.nan_to_num) ### nan_to_num function[Full reference ↗](/docs/generated/tensorplay.functional.nan_to_num.html) ```python tensorplay.functional.nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) → Tensor ``` Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively. By default, NaNs are replaced with zero, positive infinity is replaced with the greatest finite value representable by input’s dtype, and negative infinity is replaced with the least finite value representable by input’s dtype. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.nanmean) ### nanmean function[Full reference ↗](/docs/generated/tensorplay.functional.nanmean.html) ```python tensorplay.functional.nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) → Tensor ``` 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 the input tensor. In the presence of NaN, tensorplay.mean() will propagate the NaN to the output whereas tensorplay.nanmean() will ignore the NaN values (tensorplay.nanmean(a) is equivalent to tensorplay.mean(a[~a.isnan()])). If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor, either of floating point or complex dtype - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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) ``` [#](#api-tensorplay.functional.nanmedian) ### nanmedian function[Full reference ↗](/docs/generated/tensorplay.functional.nanmedian.html) ```python tensorplay.functional.nanmedian(input, dim=None, keepdim=False) ``` [#](#api-tensorplay.functional.nansum) ### nansum function[Full reference ↗](/docs/generated/tensorplay.functional.nansum.html) ```python tensorplay.functional.nansum(input, *, dtype=None) → Tensor ``` Returns the sum of all elements, treating Not a Numbers (NaNs) as zero. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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.) ``` ```python tensorplay.functional.nansum(input, dim, keepdim=False, *, dtype=None) → Tensor ``` Returns the sum of each row of the input tensor in the given dimension dim, treating Not a Numbers (NaNs) as zero. If dim is a list of dimensions, reduce over all of them. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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.]) ``` [#](#api-tensorplay.functional.narrow_copy) ### narrow_copy function[Full reference ↗](/docs/generated/tensorplay.functional.narrow_copy.html) ```python tensorplay.functional.narrow_copy(input, dim, start, length, *, out=None) → Tensor ``` 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to narrow - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension along which to narrow - start ([int](https://docs.python.org/3/builtins/functions.html#int)) – index of the element to start the narrowed dimension from. Can be negative, which means indexing from the end of dim - length ([int](https://docs.python.org/3/builtins/functions.html#int)) – length of the narrowed dimension, must be weakly positive Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 [#](#api-tensorplay.functional.narrow) ### narrow function[Full reference ↗](/docs/generated/tensorplay.functional.narrow.html) ```python tensorplay.functional.narrow(input, dim, start, length) → Tensor ``` Returns a new tensor that is a narrowed version of input tensor. The dimension dim is input from start to start + length. The returned tensor and input tensor share the same underlying storage. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to narrow - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension along which to narrow - start ([int](https://docs.python.org/3/builtins/functions.html#int) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](https://docs.python.org/3/builtins/functions.html#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]]) ``` [#](#api-tensorplay.functional.native_batch_norm) ### native_batch_norm function[Full reference ↗](/docs/generated/tensorplay.functional.native_batch_norm.html) ```python tensorplay.functional.native_batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps, *, out=None) ``` [#](#api-tensorplay.functional.native_channel_shuffle) ### native_channel_shuffle function[Full reference ↗](/docs/generated/tensorplay.functional.native_channel_shuffle.html) ```python tensorplay.functional.native_channel_shuffle(input, groups) ``` [#](#api-tensorplay.functional.native_group_norm) ### native_group_norm function[Full reference ↗](/docs/generated/tensorplay.functional.native_group_norm.html) ```python tensorplay.functional.native_group_norm(input, weight, bias, N, C, HxW, group, eps) ``` [#](#api-tensorplay.functional.native_layer_norm) ### native_layer_norm function[Full reference ↗](/docs/generated/tensorplay.functional.native_layer_norm.html) ```python tensorplay.functional.native_layer_norm(input, normalized_shape, weight, bias, eps) ``` [#](#api-tensorplay.functional.native_norm) ### native_norm function[Full reference ↗](/docs/generated/tensorplay.functional.native_norm.html) ```python tensorplay.functional.native_norm(input, p=2) ``` [#](#api-tensorplay.functional.ndtr) ### ndtr function[Full reference ↗](/docs/generated/tensorplay.functional.ndtr.html) ```python tensorplay.functional.ndtr(input) ``` [#](#api-tensorplay.functional.ndtri) ### ndtri function[Full reference ↗](/docs/generated/tensorplay.functional.ndtri.html) ```python tensorplay.functional.ndtri(input) ``` [#](#api-tensorplay.functional.ne) ### ne function[Full reference ↗](/docs/generated/tensorplay.functional.ne.html) ```python tensorplay.functional.ne(input, other, *, out=None) → Tensor ``` Computes $\text{input} \neq \text{other}$ element-wise. The second argument can be a number or a tensor whose shape is [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics) with the first argument. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to compare - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [float](https://docs.python.org/3/builtins/functions.html#float)) – the tensor or value to compare Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A boolean tensor that is True where input is not equal to other and False elsewhere Example: ``` >>> tensorplay.ne(tensorplay.tensor([[1, 2], [3, 4]]), tensorplay.tensor([[1, 1], [4, 4]])) tensor([[False, True], [True, False]]) ``` [#](#api-tensorplay.functional.neg_) ### neg_ function[Full reference ↗](/docs/generated/tensorplay.functional.neg_.html) ```python tensorplay.functional.neg_(input) ``` [#](#api-tensorplay.functional.neg) ### neg function[Full reference ↗](/docs/generated/tensorplay.functional.neg.html) ```python tensorplay.functional.neg(input, *, out=None) → Tensor ``` Returns a new tensor with the negative of the elements of input. $$\text{out} = -1 \times \text{input}$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.negative_) ### negative_ function[Full reference ↗](/docs/generated/tensorplay.functional.negative_.html) ```python tensorplay.functional.negative_(input) ``` [#](#api-tensorplay.functional.negative) ### negative function[Full reference ↗](/docs/generated/tensorplay.functional.negative.html) ```python tensorplay.functional.negative(input, *, out=None) → Tensor ``` Alias for tensorplay.neg() [#](#api-tensorplay.functional.nextafter) ### nextafter function[Full reference ↗](/docs/generated/tensorplay.functional.nextafter.html) ```python tensorplay.functional.nextafter(input, other, *, out=None) → Tensor ``` Return the next floating-point value after input towards other, elementwise. The shapes of input and other must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the first input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.nonzero_static) ### nonzero_static function[Full reference ↗](/docs/generated/tensorplay.functional.nonzero_static.html) ```python tensorplay.functional.nonzero_static(input, *, size, fill_value=-1, out=None) ``` [#](#api-tensorplay.functional.nonzero) ### nonzero function[Full reference ↗](/docs/generated/tensorplay.functional.nonzero.html) ```python tensorplay.functional.nonzero(input, *, out=None, as_tuple=False) → LongTensor or tuple of LongTensors ``` > **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, so x[x.nonzero(as_tuple=True)] gives all nonzero values of tensor x. Of the returned tuple, each index tensor contains nonzero indices for a certain dimension. See below for more details on the two behaviors. When input is on CUDA, tensorplay.nonzero() causes host-device synchronization. When as_tuple is False (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 in input. The result is sorted lexicographically, with the last index changing the fastest (C-style). If input has $n$ dimensions, then the resulting indices tensor out is of size $(z \times n)$, where $z$ is the total number of non-zero elements in the input tensor. When as_tuple is True: 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 of input . If input has $n$ dimensions, then the resulting tuple contains $n$ tensors of size $z$, where $z$ is the total number of non-zero elements in the input tensor. As a special case, when input has zero dimensions and a nonzero scalar value, it is treated as a one-dimensional tensor with one element. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out (LongTensor, optional) – the output tensor containing indices Returns: If as_tuple is False, the output tensor containing indices. If as_tuple is True, one 1-D tensor for each dimension, containing the indices of each nonzero element along that dimension. Return type: LongTensor or [tuple](https://docs.python.org/3/builtins/stdtypes.html#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]),) ``` [#](#api-tensorplay.functional.norm_except_dim) ### norm_except_dim function[Full reference ↗](/docs/generated/tensorplay.functional.norm_except_dim.html) ```python tensorplay.functional.norm_except_dim(v, pow=2, dim=0) ``` [#](#api-tensorplay.functional.norm) ### norm function[Full reference ↗](/docs/generated/tensorplay.functional.norm.html) ```python tensorplay.functional.norm(input, p=2.0, dim=None, keepdim=False) ``` [#](#api-tensorplay.functional.normal) ### normal function[Full reference ↗](/docs/generated/tensorplay.functional.normal.html) ```python tensorplay.functional.normal(mean, std, *, generator=None, out=None) → Tensor ``` Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given. The [mean](/docs/generated/tensorplay.functional.mean.html#tensorplay.functional.mean) is a tensor with the mean of each output element’s normal distribution The [std](/docs/generated/tensorplay.functional.std.html#tensorplay.functional.std) is a tensor with the standard deviation of each output element’s normal distribution The shapes of [mean](/docs/generated/tensorplay.functional.mean.html#tensorplay.functional.mean) and [std](/docs/generated/tensorplay.functional.std.html#tensorplay.functional.std) don’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 mean is used as the shape for the returned output tensor > **Note** > > When std is a CUDA tensor, this function synchronizes its device with the CPU. Parameters: - mean ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element means - std ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element standard deviations Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` ```python tensorplay.functional.normal(mean=0.0, std, *, out=None) → Tensor ``` Similar to the function above, but the means are shared among all drawn elements. Parameters: - mean ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the mean for all distributions - std ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element standard deviations Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` ```python tensorplay.functional.normal(mean, std=1.0, *, out=None) → Tensor ``` Similar to the function above, but the standard deviations are shared among all drawn elements. Parameters: - mean ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element means - std ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the standard deviation for all distributions Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor Example: ``` >>> tensorplay.normal(mean=tensorplay.arange(1., 6.)) tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361]) ``` ```python tensorplay.functional.normal(mean, std, size, *, out=None) → Tensor ``` 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: - mean ([float](https://docs.python.org/3/builtins/functions.html#float)) – the mean for all distributions - std ([float](https://docs.python.org/3/builtins/functions.html#float)) – the standard deviation for all distributions - size ([int](https://docs.python.org/3/builtins/functions.html#int)...) – a sequence of integers defining the shape of the output tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.normal(2, 3, size=(1, 4)) tensor([[-1.3987, -1.9544, 3.6048, 0.7909]]) ``` [#](#api-tensorplay.functional.not_equal) ### not_equal function[Full reference ↗](/docs/generated/tensorplay.functional.not_equal.html) ```python tensorplay.functional.not_equal(input, other, *, out=None) → Tensor ``` Alias for tensorplay.ne(). [#](#api-tensorplay.functional.nuclear_norm) ### nuclear_norm function[Full reference ↗](/docs/generated/tensorplay.functional.nuclear_norm.html) ```python tensorplay.functional.nuclear_norm(input, keepdim=False, dim=None) ``` [#](#api-tensorplay.functional.numel) ### numel function[Full reference ↗](/docs/generated/tensorplay.functional.numel.html) ```python tensorplay.functional.numel(input: Tensor) → int ``` Returns the total number of elements in the input tensor. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Example: ``` >>> a = tensorplay.randn(1, 2, 3, 4, 5) >>> tensorplay.numel(a) 120 >>> a = tensorplay.zeros(4,4) >>> tensorplay.numel(a) 16 ``` [#](#api-tensorplay.functional.ones_like) ### ones_like function[Full reference ↗](/docs/generated/tensorplay.functional.ones_like.html) ```python 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 to tensorplay.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device). > **Warning** > > As of 0.4, this function does not support an out keyword. As an alternative, the old tensorplay.ones_like(input, out=output) is equivalent to tensorplay.ones(input.size(), out=output). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), 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.]]) ``` [#](#api-tensorplay.functional.orgqr) ### orgqr function[Full reference ↗](/docs/generated/tensorplay.functional.orgqr.html) ```python tensorplay.functional.orgqr(input, tau) → Tensor ``` Alias for [tensorplay.linalg.householder_product()](/docs/generated/tensorplay.linalg.householder_product.html#tensorplay.linalg.householder_product). [#](#api-tensorplay.functional.ormqr) ### ormqr function[Full reference ↗](/docs/generated/tensorplay.functional.ormqr.html) ```python tensorplay.functional.ormqr(input, tau, other, left=True, transpose=False, *, out=None) → Tensor ``` Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix. Multiplies a $m \times n$ 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](https://www.netlib.org/lapack/lug/node128.html) for further details. If left is True then op(Q) times C is computed, otherwise the result is C times op(Q). When left is True, the implicit matrix Q has size $m \times m$. It has size $n \times n$ otherwise. If [transpose](/docs/generated/tensorplay.functional.transpose.html#tensorplay.functional.transpose) is 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/or tau.size(-1) is very small. `` Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – tensor of shape (*, min(mn, k)) where * is zero or more batch dimensions. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – tensor of shape (*, m, n) where * is zero or more batch dimensions. - left ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – controls the order of multiplication. - transpose ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – controls whether the matrix Q is conjugate transposed or not. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output Tensor. Ignored if None. Default: None. [#](#api-tensorplay.functional.outer) ### outer function[Full reference ↗](/docs/generated/tensorplay.functional.outer.html) ```python tensorplay.functional.outer(input, vec2, *, out=None) → Tensor ``` Outer product of input and vec2. If input is a vector of size $n$ and vec2 is a vector of size $m$, then out must be a matrix of size $(n \times m)$. > **Note** > > This function does not broadcast. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1-D input vector - vec2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1-D input vector Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]]) ``` [#](#api-tensorplay.functional.pairwise_distance) ### pairwise_distance function[Full reference ↗](/docs/generated/tensorplay.functional.pairwise_distance.html) ```python tensorplay.functional.pairwise_distance(x1, x2, p=2.0, eps=1e-06, keepdim=False) ``` [#](#api-tensorplay.functional.pdist) ### pdist function[Full reference ↗](/docs/generated/tensorplay.functional.pdist.html) ```python tensorplay.functional.pdist(input, p=2.0) ``` [#](#api-tensorplay.functional.permute_copy) ### permute_copy function[Full reference ↗](/docs/generated/tensorplay.functional.permute_copy.html) ```python tensorplay.functional.permute_copy(input, dims) ``` Performs the same operation as tensorplay.permute(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.permute) ### permute function[Full reference ↗](/docs/generated/tensorplay.functional.permute.html) ```python tensorplay.functional.permute(input, dims) → Tensor ``` Returns a view of the original tensor input with its dimensions permuted. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dims ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – The desired ordering of dimensions Example ``` >>> x = tensorplay.randn(2, 3, 5) >>> x.size() tensorplay.Size([2, 3, 5]) >>> tensorplay.permute(x, (2, 0, 1)).size() tensorplay.Size([5, 2, 3]) ``` [#](#api-tensorplay.functional.pinverse) ### pinverse function[Full reference ↗](/docs/generated/tensorplay.functional.pinverse.html) ```python tensorplay.functional.pinverse(input, rcond=1e-15) → Tensor ``` Alias for [tensorplay.linalg.pinv()](/docs/generated/tensorplay.linalg.pinv.html#tensorplay.linalg.pinv) [#](#api-tensorplay.functional.pixel_unshuffle) ### pixel_unshuffle function[Full reference ↗](/docs/generated/tensorplay.functional.pixel_unshuffle.html) ```python tensorplay.functional.pixel_unshuffle(input, downscale_factor) ``` [#](#api-tensorplay.functional.poisson_nll_loss) ### poisson_nll_loss function[Full reference ↗](/docs/generated/tensorplay.functional.poisson_nll_loss.html) ```python tensorplay.functional.poisson_nll_loss(input, target, log_input=True, full=False, eps=1e-08) ``` [#](#api-tensorplay.functional.poisson) ### poisson function[Full reference ↗](/docs/generated/tensorplay.functional.poisson.html) ```python tensorplay.functional.poisson(input, generator=None) → Tensor ``` Returns a tensor of the same size as input with each element sampled from a Poisson distribution with rate parameter given by the corresponding element in input i.e., $$\text{out}_i \sim \text{Poisson}(\text{input}_i)$$ input must be non-negative. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor containing the rates of the Poisson distribution Keyword Arguments: generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#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.]]) ``` [#](#api-tensorplay.functional.polar) ### polar function[Full reference ↗](/docs/generated/tensorplay.functional.polar.html) ```python tensorplay.functional.polar(abs, angle, *, out=None) → Tensor ``` Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value [abs](/docs/generated/tensorplay.functional.abs.html#tensorplay.functional.abs) and angle [angle](/docs/generated/tensorplay.functional.angle.html#tensorplay.functional.angle). $$\text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j$$ > **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: - abs ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The absolute value the complex tensor. Must be float or double. - angle ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The angle of the complex tensor. Must be same dtype as [abs](/docs/generated/tensorplay.functional.abs.html#tensorplay.functional.abs). Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – If the inputs are tensorplay.float32, must be tensorplay.complex64. If the inputs are tensorplay.float64, must be tensorplay.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) ``` [#](#api-tensorplay.functional.polygamma) ### polygamma function[Full reference ↗](/docs/generated/tensorplay.functional.polygamma.html) ```python tensorplay.functional.polygamma(n, input, *, out=None) → Tensor ``` Alias for tensorplay.special.polygamma(). [#](#api-tensorplay.functional.positive) ### positive function[Full reference ↗](/docs/generated/tensorplay.functional.positive.html) ```python tensorplay.functional.positive(input) → Tensor ``` Returns input. Throws a runtime error if input is a bool tensor. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.pow) ### pow function[Full reference ↗](/docs/generated/tensorplay.functional.pow.html) ```python tensorplay.functional.pow(input, exponent, *, out=None) → Tensor ``` Takes the power of each element in input with exponent and returns a tensor with the result. exponent can be either a single float number or a Tensor with the same number of elements as input. When exponent is a scalar value, the operation applied is: $$\text{out}_i = x_i ^ \text{exponent}$$ When exponent is a tensor, the operation applied is: $$\text{out}_i = x_i ^ {\text{exponent}_i}$$ When exponent is a tensor, the shapes of input and exponent must be [broadcastable](/docs/notes/broadcasting.html#broadcasting-semantics). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - exponent ([float](https://docs.python.org/3/builtins/functions.html#float) or tensor) – the exponent value Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` ```python tensorplay.functional.pow(self, exponent, *, out=None) → Tensor ``` self is a scalar float value, and exponent is a tensor. The returned tensor out is of the same shape as exponent The operation applied is: $$\text{out}_i = \text{self} ^ {\text{exponent}_i}$$ Parameters: - self ([float](https://docs.python.org/3/builtins/functions.html#float)) – the scalar base value for the power operation - exponent ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the exponent tensor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> exp = tensorplay.arange(1., 5.) >>> base = 2 >>> tensorplay.pow(base, exp) tensor([ 2., 4., 8., 16.]) ``` [#](#api-tensorplay.functional.prelu) ### prelu function[Full reference ↗](/docs/generated/tensorplay.functional.prelu.html) ```python tensorplay.functional.prelu(input, weight) ``` [#](#api-tensorplay.functional.prod) ### prod function[Full reference ↗](/docs/generated/tensorplay.functional.prod.html) ```python tensorplay.functional.prod(input: Tensor, *, dtype: _dtype | None) → Tensor ``` Returns the product of all elements in the input tensor. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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) ``` ```python tensorplay.functional.prod(input, dim, keepdim=False, *, dtype=None) → Tensor ``` Returns the product of each row of the input tensor in the given dimension dim. If keepdim is True, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 fewer dimension than input. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the dimension to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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]) ``` [#](#api-tensorplay.functional.promote_types) ### promote_types function[Full reference ↗](/docs/generated/tensorplay.functional.promote_types.html) ```python tensorplay.functional.promote_types(type1, type2) → dtype ``` Returns the [tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType) with 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](/docs/generated/tensorplay.DType.html#tensorplay.DType)) - type2 ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType)) Example: ``` >>> tensorplay.promote_types(tensorplay.int32, tensorplay.float32) tensorplay.float32 >>> tensorplay.promote_types(tensorplay.uint8, tensorplay.long) tensorplay.long ``` [#](#api-tensorplay.functional.put) ### put function[Full reference ↗](/docs/generated/tensorplay.functional.put.html) ```python tensorplay.functional.put(input, index, source, accumulate=False) ``` [#](#api-tensorplay.functional.q_per_channel_axis) ### q_per_channel_axis function[Full reference ↗](/docs/generated/tensorplay.functional.q_per_channel_axis.html) ```python tensorplay.functional.q_per_channel_axis(input) ``` [#](#api-tensorplay.functional.q_per_channel_scales) ### q_per_channel_scales function[Full reference ↗](/docs/generated/tensorplay.functional.q_per_channel_scales.html) ```python tensorplay.functional.q_per_channel_scales(input) ``` [#](#api-tensorplay.functional.q_per_channel_zero_points) ### q_per_channel_zero_points function[Full reference ↗](/docs/generated/tensorplay.functional.q_per_channel_zero_points.html) ```python tensorplay.functional.q_per_channel_zero_points(input) ``` [#](#api-tensorplay.functional.q_scale) ### q_scale function[Full reference ↗](/docs/generated/tensorplay.functional.q_scale.html) ```python tensorplay.functional.q_scale(input) ``` [#](#api-tensorplay.functional.q_zero_point) ### q_zero_point function[Full reference ↗](/docs/generated/tensorplay.functional.q_zero_point.html) ```python tensorplay.functional.q_zero_point(input) ``` [#](#api-tensorplay.functional.quantize_per_channel) ### quantize_per_channel function[Full reference ↗](/docs/generated/tensorplay.functional.quantize_per_channel.html) ```python tensorplay.functional.quantize_per_channel(input, scales, zero_points, axis, dtype) → Tensor ``` Converts a float tensor to a per-channel quantized tensor with given scales and zero points. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor to quantize - scales ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float 1D tensor of scales to use, size should match input.size(axis) - zero_points ([int](https://docs.python.org/3/builtins/functions.html#int)) – integer 1D tensor of offset to use, size should match input.size(axis) - axis ([int](https://docs.python.org/3/builtins/functions.html#int)) – dimension on which apply per-channel quantization - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantize_per_tensor_dynamic) ### quantize_per_tensor_dynamic function[Full reference ↗](/docs/generated/tensorplay.functional.quantize_per_tensor_dynamic.html) ```python tensorplay.functional.quantize_per_tensor_dynamic(input, dtype, reduce_range) → Tensor ``` Converts a float tensor to a quantized tensor with scale and zero_point calculated dynamically based on the input. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor or list of tensors to quantize - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType)) – the desired data type of returned tensor. Has to be one of the quantized dtypes: tensorplay.quint8, tensorplay.qint8 - reduce_range ([bool](https://docs.python.org/3/builtins/functions.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantize_per_tensor) ### quantize_per_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.quantize_per_tensor.html) ```python tensorplay.functional.quantize_per_tensor(input, scale, zero_point, dtype) → Tensor ``` Converts a float tensor to a quantized tensor with given scale and zero point. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor or list of tensors to quantize - scale ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – scale to apply in quantization formula - zero_point ([int](https://docs.python.org/3/builtins/functions.html#int) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – offset in integer value that maps to float zero - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantized_batch_norm) ### quantized_batch_norm function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_batch_norm.html) ```python tensorplay.functional.quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) → Tensor ``` Applies batch normalization on a 4D (NCHW) quantized tensor. $$y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta$$ Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – quantized tensor - weight ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor that corresponds to the gamma, size C - bias ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor that corresponds to the beta, size C - mean ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float mean value in batch normalization, size C - var ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor for variance, size C - eps ([float](https://docs.python.org/3/builtins/functions.html#float)) – a value added to the denominator for numerical stability. - output_scale ([float](https://docs.python.org/3/builtins/functions.html#float)) – output quantized tensor scale - output_zero_point ([int](https://docs.python.org/3/builtins/functions.html#int)) – output quantized tensor zero_point Returns: A quantized tensor with batch normalization applied. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantized_gru_cell) ### quantized_gru_cell function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_gru_cell.html) ```python 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) ``` [#](#api-tensorplay.functional.quantized_lstm_cell) ### quantized_lstm_cell function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_lstm_cell.html) ```python 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) ``` [#](#api-tensorplay.functional.quantized_max_pool1d) ### quantized_max_pool1d function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_max_pool1d.html) ```python tensorplay.functional.quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) → Tensor ``` Applies a 1D max pooling over an input quantized tensor composed of several input planes. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – quantized tensor - kernel_size ([list](https://docs.python.org/3/builtins/stdtypes.html#list) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the size of the sliding window - stride (list of int, optional) – the stride of the sliding window - padding (list of int, optional) – padding to be added on both sides, must be >= 0 and 0. Default 1 - ceil_mode ([bool](https://docs.python.org/3/builtins/functions.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantized_max_pool2d) ### quantized_max_pool2d function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_max_pool2d.html) ```python tensorplay.functional.quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) → Tensor ``` Applies a 2D max pooling over an input quantized tensor composed of several input planes. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – quantized tensor - kernel_size (list of int) – the size of the sliding window - stride (list of int, optional) – the stride of the sliding window - padding (list of int, optional) – padding to be added on both sides, must be >= 0 and 0. Default 1 - ceil_mode ([bool](https://docs.python.org/3/builtins/functions.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` [#](#api-tensorplay.functional.quantized_max_pool3d) ### quantized_max_pool3d function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_max_pool3d.html) ```python tensorplay.functional.quantized_max_pool3d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) ``` [#](#api-tensorplay.functional.quantized_rnn_relu_cell) ### quantized_rnn_relu_cell function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_rnn_relu_cell.html) ```python 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) ``` [#](#api-tensorplay.functional.quantized_rnn_tanh_cell) ### quantized_rnn_tanh_cell function[Full reference ↗](/docs/generated/tensorplay.functional.quantized_rnn_tanh_cell.html) ```python 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) ``` [#](#api-tensorplay.functional.rad2deg_) ### rad2deg_ function[Full reference ↗](/docs/generated/tensorplay.functional.rad2deg_.html) ```python tensorplay.functional.rad2deg_(input) ``` [#](#api-tensorplay.functional.rad2deg) ### rad2deg function[Full reference ↗](/docs/generated/tensorplay.functional.rad2deg.html) ```python tensorplay.functional.rad2deg(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with each of the elements of input converted from angles in radians to degrees. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.rand_like) ### rand_like function[Full reference ↗](/docs/generated/tensorplay.functional.rand_like.html) ```python tensorplay.functional.rand_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) → Tensor ``` Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval $[0, 1)$. tensorplay.rand_like(input) is equivalent to tensorplay.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), optional) – the desired memory format of returned Tensor. Default: tensorplay.preserve_format. [#](#api-tensorplay.functional.randint_like) ### randint_like function[Full reference ↗](/docs/generated/tensorplay.functional.randint_like.html) ```python tensorplay.functional.randint_like(input, low=0, high, \*, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) → Tensor ``` Returns a tensor with the same shape as Tensor input filled with random integers generated uniformly between low (inclusive) and high (exclusive). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. - low ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – Lowest integer to be drawn from the distribution. Default: 0. - high ([int](https://docs.python.org/3/builtins/functions.html#int)) – One above the highest integer to be drawn from the distribution. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), optional) – the desired memory format of returned Tensor. Default: tensorplay.preserve_format. [#](#api-tensorplay.functional.randint) ### randint function[Full reference ↗](/docs/generated/tensorplay.functional.randint.html) ```python tensorplay.functional.randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (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 dtype tensorplay.int64. Parameters: - low ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – Lowest integer to be drawn from the distribution. Default: 0. - high ([int](https://docs.python.org/3/builtins/functions.html#int)) – One above the highest integer to be drawn from the distribution. - size ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)) – a tuple defining the shape of the output tensor. Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, this function returns a tensor with dtype tensorplay.int64. - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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]]) ``` [#](#api-tensorplay.functional.randn_like) ### randn_like function[Full reference ↗](/docs/generated/tensorplay.functional.randn_like.html) ```python tensorplay.functional.randn_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=tensorplay.preserve_format) → Tensor ``` Returns a tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1. Please refer to [tensorplay.randn()](/docs/generated/tensorplay.randn.html#tensorplay.randn) for the sampling process of complex dtypes. tensorplay.randn_like(input) is equivalent to tensorplay.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), optional) – the desired memory format of returned Tensor. Default: tensorplay.preserve_format. [#](#api-tensorplay.functional.randperm) ### randperm function[Full reference ↗](/docs/generated/tensorplay.functional.randperm.html) ```python tensorplay.functional.randperm(n, *, generator=None, out=None, dtype=tensorplay.int64, layout=tensorplay.strided, device=None, requires_grad=False, pin_memory=False) → Tensor ``` Returns a random permutation of integers from 0 to n - 1. Parameters: n ([int](https://docs.python.org/3/builtins/functions.html#int)) – the upper bound (exclusive) Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#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](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#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]) ``` [#](#api-tensorplay.functional.range) ### range function[Full reference ↗](/docs/generated/tensorplay.functional.range.html) ```python tensorplay.functional.range(start=0, end, step=1, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor ``` Returns a 1-D tensor of size $\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1$ with values from start to end with step step. Step is the gap between two values in the tensor. $$\text{out}_{i+1} = \text{out}_i + \text{step}.$$ > **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: - start ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the starting value for the set of points. Default: 0. - end ([float](https://docs.python.org/3/builtins/functions.html#float)) – the ending value for the set of points - step ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the gap between each pair of adjacent points. Default: 1. Keyword Arguments: - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.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, see [get_default_dtype()](/docs/generated/tensorplay.get_default_dtype.html#tensorplay.get_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](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#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]) ``` [#](#api-tensorplay.functional.ravel) ### ravel function[Full reference ↗](/docs/generated/tensorplay.functional.ravel.html) ```python tensorplay.functional.ravel(input) → Tensor ``` Return a contiguous flattened tensor. A copy is made only if needed. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.real) ### real function[Full reference ↗](/docs/generated/tensorplay.functional.real.html) ```python tensorplay.functional.real(input) → Tensor ``` Returns a new tensor containing real values of the self tensor. The returned tensor and self share the same underlying storage. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.reciprocal_) ### reciprocal_ function[Full reference ↗](/docs/generated/tensorplay.functional.reciprocal_.html) ```python tensorplay.functional.reciprocal_(input) ``` [#](#api-tensorplay.functional.reciprocal) ### reciprocal function[Full reference ↗](/docs/generated/tensorplay.functional.reciprocal.html) ```python tensorplay.functional.reciprocal(input, *, out=None) → Tensor ``` Returns a new tensor with the reciprocal of the elements of input $$\text{out}_{i} = \frac{1}{\text{input}_{i}}$$ > **Note** > > Unlike NumPy’s reciprocal, tensorplay.reciprocal supports integral inputs. Integral inputs to reciprocal are automatically promoted to the default scalar type. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.relu_) ### relu_ function[Full reference ↗](/docs/generated/tensorplay.functional.relu_.html) ```python tensorplay.functional.relu_(input) ``` [#](#api-tensorplay.functional.remainder) ### remainder function[Full reference ↗](/docs/generated/tensorplay.functional.remainder.html) ```python tensorplay.functional.remainder(input, other, *, out=None) → Tensor ``` Computes [Python’s modulus operation](https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations) entrywise. The result has the same sign as the divisor other and its absolute value is less than that of other. It may also be defined in terms of tensorplay.div() as ``` tensorplay.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b ``` Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the dividend - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – the divisor Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ]) ``` [#](#api-tensorplay.functional.renorm) ### renorm function[Full reference ↗](/docs/generated/tensorplay.functional.renorm.html) ```python tensorplay.functional.renorm(input, p, dim, maxnorm, *, out=None) → Tensor ``` Returns a tensor where each sub-tensor of input along dimension dim is normalized such that the p-norm of the sub-tensor is lower than the value maxnorm > **Note** > > If the norm of a row is lower than maxnorm, the row is unchanged Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - p ([float](https://docs.python.org/3/builtins/functions.html#float)) – the power for the norm computation - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to slice over to get the sub-tensors - maxnorm ([float](https://docs.python.org/3/builtins/functions.html#float)) – the maximum norm to keep each sub-tensor under Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.repeat_interleave) ### repeat_interleave function[Full reference ↗](/docs/generated/tensorplay.functional.repeat_interleave.html) ```python tensorplay.functional.repeat_interleave(input, repeats, dim=None, *, output_size=None) → Tensor ``` Repeat elements of a tensor. > **Warning** > > This is different from tensorplay.Tensor.repeat() but similar to numpy.repeat. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - repeats ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [int](https://docs.python.org/3/builtins/functions.html#int)) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis. - dim ([int](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#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: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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. ```python tensorplay.functional.repeat_interleave(repeats, *) → Tensor ``` Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc. Parameters: repeats ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The number of repetitions for each element. Returns: Repeated tensor of size sum(repeats). Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> tensorplay.repeat_interleave(tensorplay.tensor([1, 2, 3])) tensor([0, 1, 1, 2, 2, 2]) ``` [#](#api-tensorplay.functional.reshape) ### reshape function[Full reference ↗](/docs/generated/tensorplay.functional.reshape.html) ```python tensorplay.functional.reshape(input, shape) → Tensor ``` 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 of input. 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. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to be reshaped - shape ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [int](https://docs.python.org/3/builtins/functions.html#int)) – the new shape 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]) ``` [#](#api-tensorplay.functional.resize_as_) ### resize_as_ function[Full reference ↗](/docs/generated/tensorplay.functional.resize_as_.html) ```python tensorplay.functional.resize_as_(input, other, memory_format=None) ``` [#](#api-tensorplay.functional.resize_as_sparse_) ### resize_as_sparse_ function[Full reference ↗](/docs/generated/tensorplay.functional.resize_as_sparse_.html) ```python tensorplay.functional.resize_as_sparse_(input, the_template) ``` [#](#api-tensorplay.functional.resolve_conj) ### resolve_conj function[Full reference ↗](/docs/generated/tensorplay.functional.resolve_conj.html) ```python tensorplay.functional.resolve_conj(input) → Tensor ``` Returns a new tensor with materialized conjugation if input’s conjugate bit is set to True, else returns input. The output tensor will always have its conjugate bit set to False. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.resolve_neg) ### resolve_neg function[Full reference ↗](/docs/generated/tensorplay.functional.resolve_neg.html) ```python tensorplay.functional.resolve_neg(input) → Tensor ``` Returns a new tensor with materialized negation if input’s negative bit is set to True, else returns input. The output tensor will always have its negative bit set to False. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 ``` [#](#api-tensorplay.functional.result_type) ### result_type function[Full reference ↗](/docs/generated/tensorplay.functional.result_type.html) ```python tensorplay.functional.result_type(tensor1, tensor2) → dtype ``` Returns the [tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType) that 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: - tensor1 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – an input tensor or number - tensor2 ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – an input tensor or number 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 ``` [#](#api-tensorplay.functional.rms_norm) ### rms_norm function[Full reference ↗](/docs/generated/tensorplay.functional.rms_norm.html) ```python tensorplay.functional.rms_norm(input, normalized_shape, weight=None, eps=None) ``` [#](#api-tensorplay.functional.rnn_relu_cell) ### rnn_relu_cell function[Full reference ↗](/docs/generated/tensorplay.functional.rnn_relu_cell.html) ```python tensorplay.functional.rnn_relu_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) ``` [#](#api-tensorplay.functional.rnn_relu) ### rnn_relu function[Full reference ↗](/docs/generated/tensorplay.functional.rnn_relu.html) ```python tensorplay.functional.rnn_relu(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False) ``` [#](#api-tensorplay.functional.rnn_tanh_cell) ### rnn_tanh_cell function[Full reference ↗](/docs/generated/tensorplay.functional.rnn_tanh_cell.html) ```python tensorplay.functional.rnn_tanh_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) ``` [#](#api-tensorplay.functional.rnn_tanh) ### rnn_tanh function[Full reference ↗](/docs/generated/tensorplay.functional.rnn_tanh.html) ```python tensorplay.functional.rnn_tanh(input, hx, params, has_biases=True, num_layers=1, dropout_p=0.0, training=False, bidirectional=False, batch_first=False) ``` [#](#api-tensorplay.functional.roll) ### roll function[Full reference ↗](/docs/generated/tensorplay.functional.roll.html) ```python tensorplay.functional.roll(input, shifts, dims=None) → Tensor ``` Roll the tensor input along the given dimension(s). Elements that are shifted beyond the last position are re-introduced at the first position. If dims is None, the tensor will be flattened before rolling and then restored to the original shape. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - shifts ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – The number of places by which the elements of the tensor are shifted. If shifts is a tuple, dims must be a tuple of the same size, and each dimension will be rolled by the corresponding value - dims ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – Axis along which to roll 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]]) ``` [#](#api-tensorplay.functional.rot90) ### rot90 function[Full reference ↗](/docs/generated/tensorplay.functional.rot90.html) ```python tensorplay.functional.rot90(input, k=1, dims=(0, 1)) → Tensor ``` 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - k ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of times to rotate. Default value is 1 - dims (a list or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)) – axis to rotate. Default value is [0, 1] 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]]]) ``` [#](#api-tensorplay.functional.round_) ### round_ function[Full reference ↗](/docs/generated/tensorplay.functional.round_.html) ```python tensorplay.functional.round_(input) ``` [#](#api-tensorplay.functional.round) ### round function[Full reference ↗](/docs/generated/tensorplay.functional.round.html) ```python tensorplay.functional.round(input, *, decimals=0, out=None) → Tensor ``` Rounds elements of input to 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - decimals ([int](https://docs.python.org/3/builtins/functions.html#int)) – Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.row_indices_copy) ### row_indices_copy function[Full reference ↗](/docs/generated/tensorplay.functional.row_indices_copy.html) ```python tensorplay.functional.row_indices_copy(input) ``` [#](#api-tensorplay.functional.row_stack) ### row_stack function[Full reference ↗](/docs/generated/tensorplay.functional.row_stack.html) ```python tensorplay.functional.row_stack(tensors, *, out=None) → Tensor ``` Alias of tensorplay.vstack(). [#](#api-tensorplay.functional.rrelu_) ### rrelu_ function[Full reference ↗](/docs/generated/tensorplay.functional.rrelu_.html) ```python tensorplay.functional.rrelu_(input, lower=0.125, upper=0.3333333333333333, training=False, generator=None) ``` [#](#api-tensorplay.functional.rrelu) ### rrelu function[Full reference ↗](/docs/generated/tensorplay.functional.rrelu.html) ```python tensorplay.functional.rrelu(input, lower=0.125, upper=0.3333333333333333, training=False, generator=None) ``` [#](#api-tensorplay.functional.rsqrt_) ### rsqrt_ function[Full reference ↗](/docs/generated/tensorplay.functional.rsqrt_.html) ```python tensorplay.functional.rsqrt_(input) ``` [#](#api-tensorplay.functional.rsqrt) ### rsqrt function[Full reference ↗](/docs/generated/tensorplay.functional.rsqrt.html) ```python tensorplay.functional.rsqrt(input, *, out=None) → Tensor ``` Returns a new tensor with the reciprocal of the square-root of each of the elements of input. $$\text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.rsub) ### rsub function[Full reference ↗](/docs/generated/tensorplay.functional.rsub.html) ```python tensorplay.functional.rsub(input, other, alpha=1) ``` [#](#api-tensorplay.functional.scalar_tensor) ### scalar_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.scalar_tensor.html) ```python tensorplay.functional.scalar_tensor(s, dtype=None, device=None, pin_memory=False) ``` [#](#api-tensorplay.functional.scaled_modified_bessel_k0) ### scaled_modified_bessel_k0 function[Full reference ↗](/docs/generated/tensorplay.functional.scaled_modified_bessel_k0.html) ```python tensorplay.functional.scaled_modified_bessel_k0(input) ``` [#](#api-tensorplay.functional.scaled_modified_bessel_k1) ### scaled_modified_bessel_k1 function[Full reference ↗](/docs/generated/tensorplay.functional.scaled_modified_bessel_k1.html) ```python tensorplay.functional.scaled_modified_bessel_k1(input) ``` [#](#api-tensorplay.functional.scatter_add) ### scatter_add function[Full reference ↗](/docs/generated/tensorplay.functional.scatter_add.html) ```python tensorplay.functional.scatter_add(input, dim, index, src) → Tensor ``` Out-of-place version of tensorplay.Tensor.scatter_add_() [#](#api-tensorplay.functional.scatter_reduce) ### scatter_reduce function[Full reference ↗](/docs/generated/tensorplay.functional.scatter_reduce.html) ```python tensorplay.functional.scatter_reduce(input, dim, index, src, reduce, *, include_self=True) → Tensor ``` Out-of-place version of tensorplay.Tensor.scatter_reduce_() [#](#api-tensorplay.functional.scatter) ### scatter function[Full reference ↗](/docs/generated/tensorplay.functional.scatter.html) ```python tensorplay.functional.scatter(input, dim, index, src) → Tensor ``` Out-of-place version of tensorplay.Tensor.scatter_() [#](#api-tensorplay.functional.searchsorted) ### searchsorted function[Full reference ↗](/docs/generated/tensorplay.functional.searchsorted.html) ```python tensorplay.functional.searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) → Tensor ``` Find the indices from the innermost dimension of sorted_sequence such that, if the corresponding values in values were inserted before the indices, when sorted, the order of the corresponding innermost dimension within sorted_sequence would be preserved. Return a new tensor with the same size as values. More formally, the returned index satisfies the following rules: | sorted_sequence |right |returned 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: - sorted_sequence ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – N-D or 1-D tensor, containing monotonically increasing sequence on the innermost dimension unless sorter is provided, in which case the sequence does not need to be sorted - values ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – N-D tensor or a Scalar containing the search value(s). Keyword Arguments: - out_int32 ([bool](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#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 in values on the corresponding innermost dimension of the sorted_sequence. If True, gets the upper bound index instead. Default value is False. side does the same and is preferred. It will error if side is set to “left” while this is True. - side ([str](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – the same as right but preferred. “left” corresponds to False for right and “right” corresponds to True for right. It will error if this is set to “left” while right is True. Default value is None. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor, must be the same size as values if provided. - sorter (LongTensor, optional) – if provided, a tensor matching the shape of the unsorted sorted_sequence containing 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]]) ``` [#](#api-tensorplay.functional.segment_reduce) ### segment_reduce function[Full reference ↗](/docs/generated/tensorplay.functional.segment_reduce.html) ```python 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 ``` Perform a segment reduction operation on the input tensor along the specified axis. Parameters: - data ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The input tensor on which the segment reduction operation will be performed. - reduce ([str](https://docs.python.org/3/builtins/stdtypes.html#str)) – The type of reduction operation. Supported values are sum, mean, max, min, prod. Keyword Arguments: - lengths ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – Length of each segment. Default: None. - offsets ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – Offset of each segment. Default: None. - axis ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – The axis perform reduction. Default: 0. - unsafe ([bool](https://docs.python.org/3/builtins/functions.html#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') ``` [#](#api-tensorplay.functional.select_copy) ### select_copy function[Full reference ↗](/docs/generated/tensorplay.functional.select_copy.html) ```python tensorplay.functional.select_copy(input, dim, index) ``` Performs the same operation as tensorplay.select(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.select_scatter) ### select_scatter function[Full reference ↗](/docs/generated/tensorplay.functional.select_scatter.html) ```python tensorplay.functional.select_scatter(input, src, dim, index) → Tensor ``` Embeds the values of the src tensor into input at the given index. This function returns a tensor with fresh storage; it does not create a view. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - src ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The tensor to embed into input - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to insert the slice into. - index ([int](https://docs.python.org/3/builtins/functions.html#int)) – the index to select with > **Note** > > src must be of the proper size in order to be embedded into input. Specifically, it should have the same shape as tensorplay.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.]]) ``` [#](#api-tensorplay.functional.select) ### select function[Full reference ↗](/docs/generated/tensorplay.functional.select.html) ```python tensorplay.functional.select(input, dim, index) → Tensor ``` Slices the input tensor along the selected dimension at the given index. This function returns a view of the original tensor with the given dimension removed. > **Note** > > If input is a sparse tensor and returning a view of the tensor is not possible, a RuntimeError exception is raised. In this is the case, consider using tensorplay.select_copy() function. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to slice - index ([int](https://docs.python.org/3/builtins/functions.html#int)) – the index to select with > **Note** > > select() is equivalent to slicing. For example, tensor.select(0, index) is equivalent to tensor[index] and tensor.select(2, index) is equivalent to tensor[:,:,index]. [#](#api-tensorplay.functional.selu_) ### selu_ function[Full reference ↗](/docs/generated/tensorplay.functional.selu_.html) ```python tensorplay.functional.selu_(input) ``` [#](#api-tensorplay.functional.selu) ### selu function[Full reference ↗](/docs/generated/tensorplay.functional.selu.html) ```python tensorplay.functional.selu(input) ``` [#](#api-tensorplay.functional.sgn) ### sgn function[Full reference ↗](/docs/generated/tensorplay.functional.sgn.html) ```python tensorplay.functional.sgn(input, *, out=None) → Tensor ``` 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 input and absolute values (i.e. magnitudes) of one for complex tensors and is equivalent to tensorplay.sign() for non-complex tensors. $$\begin{split}\text{out}_{i} = \begin{cases} 0 & |\text{{input}}_i| == 0 \\ \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise} \end{cases}\end{split}$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.shifted_chebyshev_polynomial_t) ### shifted_chebyshev_polynomial_t function[Full reference ↗](/docs/generated/tensorplay.functional.shifted_chebyshev_polynomial_t.html) ```python tensorplay.functional.shifted_chebyshev_polynomial_t(x, n) ``` [#](#api-tensorplay.functional.shifted_chebyshev_polynomial_u) ### shifted_chebyshev_polynomial_u function[Full reference ↗](/docs/generated/tensorplay.functional.shifted_chebyshev_polynomial_u.html) ```python tensorplay.functional.shifted_chebyshev_polynomial_u(x, n) ``` [#](#api-tensorplay.functional.shifted_chebyshev_polynomial_v) ### shifted_chebyshev_polynomial_v function[Full reference ↗](/docs/generated/tensorplay.functional.shifted_chebyshev_polynomial_v.html) ```python tensorplay.functional.shifted_chebyshev_polynomial_v(x, n) ``` [#](#api-tensorplay.functional.shifted_chebyshev_polynomial_w) ### shifted_chebyshev_polynomial_w function[Full reference ↗](/docs/generated/tensorplay.functional.shifted_chebyshev_polynomial_w.html) ```python tensorplay.functional.shifted_chebyshev_polynomial_w(x, n) ``` [#](#api-tensorplay.functional.sigmoid_) ### sigmoid_ function[Full reference ↗](/docs/generated/tensorplay.functional.sigmoid_.html) ```python tensorplay.functional.sigmoid_(input) ``` [#](#api-tensorplay.functional.sigmoid) ### sigmoid function[Full reference ↗](/docs/generated/tensorplay.functional.sigmoid.html) ```python tensorplay.functional.sigmoid(input, *, out=None) → Tensor ``` Alias for tensorplay.special.expit(). [#](#api-tensorplay.functional.sign) ### sign function[Full reference ↗](/docs/generated/tensorplay.functional.sign.html) ```python tensorplay.functional.sign(input, *, out=None) → Tensor ``` Returns a new tensor with the signs of the elements of input. $$\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.signbit) ### signbit function[Full reference ↗](/docs/generated/tensorplay.functional.signbit.html) ```python tensorplay.functional.signbit(input, *, out=None) → Tensor ``` Tests if each element of input has its sign bit set or not. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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. [#](#api-tensorplay.functional.sin_) ### sin_ function[Full reference ↗](/docs/generated/tensorplay.functional.sin_.html) ```python tensorplay.functional.sin_(input) ``` [#](#api-tensorplay.functional.sin) ### sin function[Full reference ↗](/docs/generated/tensorplay.functional.sin.html) ```python tensorplay.functional.sin(input, *, out=None) → Tensor ``` Returns a new tensor with the sine of the elements of input. $$\text{out}_{i} = \sin(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.sinc_) ### sinc_ function[Full reference ↗](/docs/generated/tensorplay.functional.sinc_.html) ```python tensorplay.functional.sinc_(input) ``` [#](#api-tensorplay.functional.sinc) ### sinc function[Full reference ↗](/docs/generated/tensorplay.functional.sinc.html) ```python tensorplay.functional.sinc(input, *, out=None) → Tensor ``` Alias for tensorplay.special.sinc(). [#](#api-tensorplay.functional.sinh_) ### sinh_ function[Full reference ↗](/docs/generated/tensorplay.functional.sinh_.html) ```python tensorplay.functional.sinh_(input) ``` [#](#api-tensorplay.functional.sinh) ### sinh function[Full reference ↗](/docs/generated/tensorplay.functional.sinh.html) ```python tensorplay.functional.sinh(input, *, out=None) → Tensor ``` Returns a new tensor with the hyperbolic sine of the elements of input. $$\text{out}_{i} = \sinh(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 input is 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. [#](#api-tensorplay.functional.slice_copy) ### slice_copy function[Full reference ↗](/docs/generated/tensorplay.functional.slice_copy.html) ```python tensorplay.functional.slice_copy(input, dim=0, start=None, end=None, step=1) ``` Performs the same operation as [tensorplay.slice()](/docs/generated/tensorplay.slice.html#tensorplay.slice), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.slice_inverse) ### slice_inverse function[Full reference ↗](/docs/generated/tensorplay.functional.slice_inverse.html) ```python tensorplay.functional.slice_inverse(input, src, dim=0, start=None, end=None, step=1) ``` [#](#api-tensorplay.functional.slice_scatter) ### slice_scatter function[Full reference ↗](/docs/generated/tensorplay.functional.slice_scatter.html) ```python tensorplay.functional.slice_scatter(input, src, dim=0, start=None, end=None, step=1) → Tensor ``` Embeds the values of the src tensor into input at the given dimension. This function returns a tensor with fresh storage; it does not create a view. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - src ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The tensor to embed into input - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the dimension to insert the slice into - start (Optional[[int](https://docs.python.org/3/builtins/functions.html#int)]) – the start index of where to insert the slice - end (Optional[[int](https://docs.python.org/3/builtins/functions.html#int)]) – the end index of where to insert the slice - step ([int](https://docs.python.org/3/builtins/functions.html#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.]]) ``` [#](#api-tensorplay.functional.slogdet) ### slogdet function[Full reference ↗](/docs/generated/tensorplay.functional.slogdet.html) ```python tensorplay.functional.slogdet(input) ``` Alias for [tensorplay.linalg.slogdet()](/docs/generated/tensorplay.linalg.slogdet.html#tensorplay.linalg.slogdet) [#](#api-tensorplay.functional.softmax) ### softmax function[Full reference ↗](/docs/generated/tensorplay.functional.softmax.html) ```python tensorplay.functional.softmax(input, dim, *, dtype=None) → Tensor ``` Alias for [tensorplay.nn.functional.softmax()](/docs/generated/tensorplay.nn.functional.softmax.html#tensorplay.nn.functional.softmax). [#](#api-tensorplay.functional.sort) ### sort function[Full reference ↗](/docs/generated/tensorplay.functional.sort.html) ```python tensorplay.functional.sort(input, dim=-1, descending=False, *, stable=, out=None) ``` [#](#api-tensorplay.functional.sparse_bsc_tensor) ### sparse_bsc_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.sparse_bsc_tensor.html) ```python 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 ``` Constructs a [sparse tensor in BSC (Block Compressed Sparse Column))](/docs/sparse.html#sparse-bsc-docs) with specified 2-dimensional blocks at the given ccol_indices and row_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](/docs/sparse.html#sparse-bsc-docs). > **Note** > > If the device argument is not specified the device of the given values and 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 where K is the number of dense dimensions. - size (list, tuple, [tensorplay.Size](/docs/generated/tensorplay.Size.html#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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, infers data type from values. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - check_invariants ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.sparse_bsr_tensor) ### sparse_bsr_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.sparse_bsr_tensor.html) ```python 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 ``` Constructs a [sparse tensor in BSR (Block Compressed Sparse Row))](/docs/sparse.html#sparse-bsr-docs) with specified 2-dimensional blocks at the given crow_indices and col_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](/docs/sparse.html#sparse-bsr-docs). > **Note** > > If the device argument is not specified the device of the given values and 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 where K is the number of dense dimensions. - size (list, tuple, [tensorplay.Size](/docs/generated/tensorplay.Size.html#tensorplay.Size), optional) – Size of the sparse tensor: (*batchsize, nrows * blocksize[0], ncols * blocksize[1], *densesize) where blocksize == 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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, infers data type from values. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - check_invariants ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.sparse_coo_tensor) ### sparse_coo_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.sparse_coo_tensor.html) ```python 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 ``` Constructs a [sparse tensor in COO(rdinate) format](/docs/sparse.html#sparse-coo-docs) with specified values at the given indices. > **Note** > > This function returns an uncoalesced tensor when is_coalesced is unspecified or None. > **Note** > > If the device argument is not specified the device of the given values and 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 a tensorplay.LongTensor internally. 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](/docs/generated/tensorplay.Size.html#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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, infers data type from values. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - check_invariants ([bool](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#bool), optional) – When``True``, the caller is responsible for providing tensor indices that correspond to a coalesced tensor. If the check_invariants flag 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 use coalesce() on the resulting Tensor. Default: None: except for trivial cases (e.g. nnz 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) ``` [#](#api-tensorplay.functional.sparse_csc_tensor) ### sparse_csc_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.sparse_csc_tensor.html) ```python 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 ``` Constructs a [sparse tensor in CSC (Compressed Sparse Column)](/docs/sparse.html#sparse-csc-docs) with specified values at the given ccol_indices and row_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](/docs/sparse.html#sparse-csc-docs). > **Note** > > If the device argument is not specified the device of the given values and 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 where K is the number of dense dimensions. - size (list, tuple, [tensorplay.Size](/docs/generated/tensorplay.Size.html#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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, infers data type from values. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - check_invariants ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.sparse_csr_tensor) ### sparse_csr_tensor function[Full reference ↗](/docs/generated/tensorplay.functional.sparse_csr_tensor.html) ```python 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 ``` Constructs a [sparse tensor in CSR (Compressed Sparse Row)](/docs/sparse.html#sparse-csr-docs) with specified values at the given crow_indices and col_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](/docs/sparse.html#sparse-csr-docs). > **Note** > > If the device argument is not specified the device of the given values and 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 where K is the number of dense dimensions. - size (list, tuple, [tensorplay.Size](/docs/generated/tensorplay.Size.html#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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, infers data type from values. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - check_invariants ([bool](https://docs.python.org/3/builtins/functions.html#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) ``` [#](#api-tensorplay.functional.spherical_bessel_j0) ### spherical_bessel_j0 function[Full reference ↗](/docs/generated/tensorplay.functional.spherical_bessel_j0.html) ```python tensorplay.functional.spherical_bessel_j0(input) ``` [#](#api-tensorplay.functional.split_copy) ### split_copy function[Full reference ↗](/docs/generated/tensorplay.functional.split_copy.html) ```python tensorplay.functional.split_copy(input, split_size, dim=0, *, out=None) ``` Performs the same operation as tensorplay.split(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.split_with_sizes_copy) ### split_with_sizes_copy function[Full reference ↗](/docs/generated/tensorplay.functional.split_with_sizes_copy.html) ```python tensorplay.functional.split_with_sizes_copy(input, split_sizes, dim=0, *, out=None) ``` Performs the same operation as [tensorplay.split_with_sizes()](/docs/generated/tensorplay.split_with_sizes.html#tensorplay.split_with_sizes), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.split) ### split function[Full reference ↗](/docs/generated/tensorplay.functional.split.html) ```python tensorplay.functional.split(input, split_size, dim=0) ``` [#](#api-tensorplay.functional.sqrt_) ### sqrt_ function[Full reference ↗](/docs/generated/tensorplay.functional.sqrt_.html) ```python tensorplay.functional.sqrt_(input) ``` [#](#api-tensorplay.functional.sqrt) ### sqrt function[Full reference ↗](/docs/generated/tensorplay.functional.sqrt.html) ```python tensorplay.functional.sqrt(input, *, out=None) → Tensor ``` Returns a new tensor with the square-root of the elements of input. $$\text{out}_{i} = \sqrt{\text{input}_{i}}$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.square_) ### square_ function[Full reference ↗](/docs/generated/tensorplay.functional.square_.html) ```python tensorplay.functional.square_(input) ``` [#](#api-tensorplay.functional.square) ### square function[Full reference ↗](/docs/generated/tensorplay.functional.square.html) ```python tensorplay.functional.square(input: Tensor, *, out: Tensor | None) → Tensor ``` Returns a new tensor with the square of the elements of input. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.squeeze_copy) ### squeeze_copy function[Full reference ↗](/docs/generated/tensorplay.functional.squeeze_copy.html) ```python tensorplay.functional.squeeze_copy(input, dim=None) ``` Performs the same operation as tensorplay.squeeze(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.squeeze) ### squeeze function[Full reference ↗](/docs/generated/tensorplay.functional.squeeze.html) ```python tensorplay.functional.squeeze(input: Tensor, dim: int | List[int] | None) → Tensor ``` Returns a tensor with all specified dimensions of input of size 1 removed. For example, if input is of shape: $(A \times 1 \times B \times C \times 1 \times D)$ then the input.squeeze() will be of shape: $(A \times B \times C \times D)$. When dim is given, a squeeze operation is done only in the given dimension(s). If input is of shape: $(A \times 1 \times B)$, squeeze(input, 0) leaves the tensor unchanged, but squeeze(input, 1) will squeeze the tensor to the shape $(A \times B)$. > **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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – if given, the input will be squeezedonly in the specified dimensions. Changed in version 2.0: dim now accepts tuples of dimensions. 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]) ``` [#](#api-tensorplay.functional.stack) ### stack function[Full reference ↗](/docs/generated/tensorplay.functional.stack.html) ```python tensorplay.functional.stack(tensors, dim=0, *, out=None) → Tensor ``` 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](https://docs.python.org/3/builtins/functions.html#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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]]) ``` [#](#api-tensorplay.functional.std_mean) ### std_mean function[Full reference ↗](/docs/generated/tensorplay.functional.std_mean.html) ```python tensorplay.functional.std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) ``` Calculates the standard deviation and mean over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions. The standard deviation ($\sigma$) is calculated as $$\sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}$$ where $x$ is the sample set of elements, $\bar{x}$ is the sample mean, $N$ is the number of samples and $\delta N$ is the correction. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. Keyword Arguments: - correction ([int](https://docs.python.org/3/builtins/functions.html#int)) – difference between the sample size and sample degrees of freedom. Defaults to [Bessel’s correction](https://en.wikipedia.org/wiki/Bessel%27s_correction), correction=1. Changed in version 2.0: Previously this argument was called unbiased and was a boolean with True corresponding to correction=1 and False being correction=0. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]])) ``` [#](#api-tensorplay.functional.std) ### std function[Full reference ↗](/docs/generated/tensorplay.functional.std.html) ```python tensorplay.functional.std(input, dim=None, *, correction=1, keepdim=False, out=None) → Tensor ``` Calculates the standard deviation over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions. The standard deviation ($\sigma$) is calculated as $$\sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}$$ where $x$ is the sample set of elements, $\bar{x}$ is the sample mean, $N$ is the number of samples and $\delta N$ is the correction. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. Keyword Arguments: - correction ([int](https://docs.python.org/3/builtins/functions.html#int)) – difference between the sample size and sample degrees of freedom. Defaults to [Bessel’s correction](https://en.wikipedia.org/wiki/Bessel%27s_correction), correction=1. Changed in version 2.0: Previously this argument was called unbiased and was a boolean with True corresponding to correction=1 and False being correction=0. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.stft) ### stft function[Full reference ↗](/docs/generated/tensorplay.functional.stft.html) ```python 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) ``` [#](#api-tensorplay.functional.sub) ### sub function[Full reference ↗](/docs/generated/tensorplay.functional.sub.html) ```python tensorplay.functional.sub(input, other, *, alpha=1, out=None) → Tensor ``` Subtracts other, scaled by alpha, from input. $$\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i$$ Supports [broadcasting to a common shape](/docs/notes/broadcasting.html#broadcasting-semantics), type promotion, and integer, float, and complex inputs. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or Number) – the tensor or number to subtract from input. Keyword Arguments: - alpha (Number) – the multiplier for other. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.subtract) ### subtract function[Full reference ↗](/docs/generated/tensorplay.functional.subtract.html) ```python tensorplay.functional.subtract(input, other, *, alpha=1, out=None) → Tensor ``` Alias for tensorplay.sub(). [#](#api-tensorplay.functional.sum) ### sum function[Full reference ↗](/docs/generated/tensorplay.functional.sum.html) ```python tensorplay.functional.sum(input, *, dtype=None) → Tensor ``` Returns the sum of all elements in the input tensor. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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) ``` ```python tensorplay.functional.sum(input, dim, keepdim=False, *, dtype=None) → Tensor ``` Returns the sum of each row of the input tensor in the given dimension dim. If dim is a list of dimensions, reduce over all of them. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. Keyword Arguments: dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before 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.]) ``` [#](#api-tensorplay.functional.svd) ### svd function[Full reference ↗](/docs/generated/tensorplay.functional.svd.html) ```python tensorplay.functional.svd(input, some=True, compute_uv=True, *, out=None) ``` 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 that input $= U \text{diag}(S) V^{\text{H}}$. where $V^{\text{H}}$ is the transpose of V for real inputs, and the conjugate transpose of V for complex inputs. If input is a batch of matrices, then U, S, and V are also batched with the same batch dimensions as input. If some is True (default), the method returns the reduced singular value decomposition. In this case, if the last two dimensions of input are m and n, then the returned U and V matrices will contain only min(n, m) orthonormal columns. If compute_uv is False, the returned U and V will be zero-filled matrices of shape (m, m) and (n, n) respectively, and the same device as input. The argument some has no effect when compute_uv is False. Supports input of float, double, cfloat and cdouble data types. The dtypes of U and V are the same as input’s. S will always be real-valued, even if input is complex. > **Warning** > > tensorplay.svd() is deprecated in favor of tensorplay.linalg.svd() U, S, V = tensorplay.svd(A, some=some, compute_uv=True) (default) should be replaced with @@TPBLOCK_242@@ _, S, _ = tensorplay.svd(A, some=some, compute_uv=False) should be replaced with ``` S = tensorplay.linalg.svdvals(A) ``` > **Note** > > Differences with tensorplay.linalg.svd(): some is the opposite of tensorplay.linalg.svd()’s full_matrices. Note that default value for both is True, so the default behavior is effectively the opposite. tensorplay.svd() returns V, whereas tensorplay.linalg.svd() returns Vh, that is, $V^{\text{H}}$. If compute_uv is False, tensorplay.svd() returns zero-filled tensors for U and Vh, whereas tensorplay.linalg.svd() returns empty tensors. > **Note** > > The singular values are returned in descending order. If input is 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_uv is True. > **Note** > > When some is 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 $\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}$. The same happens when the matrix has small singular values, as these gradients also depend on S^{-1}. > **Warning** > > For complex-valued input the singular value decomposition is not unique, as U and V may be multiplied by an arbitrary phase factor $e^{i \phi}$ on every column. The same happens when input has 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor of size (*, m, n) where * is zero or more batch dimensions consisting of (m, n) matrices. - some ([bool](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#bool), optional) – controls whether to compute U and V. Default: True. Keyword Arguments: out ([tuple](https://docs.python.org/3/builtins/stdtypes.html#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) ``` [#](#api-tensorplay.functional.swapaxes) ### swapaxes function[Full reference ↗](/docs/generated/tensorplay.functional.swapaxes.html) ```python tensorplay.functional.swapaxes(input, axis0, axis1) → Tensor ``` 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]]]) ``` [#](#api-tensorplay.functional.swapdims) ### swapdims function[Full reference ↗](/docs/generated/tensorplay.functional.swapdims.html) ```python tensorplay.functional.swapdims(input, dim0, dim1) → Tensor ``` 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]]]) ``` [#](#api-tensorplay.functional.sym_constrain_range_for_size) ### sym_constrain_range_for_size function[Full reference ↗](/docs/generated/tensorplay.functional.sym_constrain_range_for_size.html) ```python tensorplay.functional.sym_constrain_range_for_size(size, min=None, max=None) ``` [#](#api-tensorplay.functional.sym_constrain_range) ### sym_constrain_range function[Full reference ↗](/docs/generated/tensorplay.functional.sym_constrain_range.html) ```python tensorplay.functional.sym_constrain_range(size, min=None, max=None) ``` [#](#api-tensorplay.functional.t_copy) ### t_copy function[Full reference ↗](/docs/generated/tensorplay.functional.t_copy.html) ```python tensorplay.functional.t_copy(input) ``` Performs the same operation as tensorplay.t(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.t) ### t function[Full reference ↗](/docs/generated/tensorplay.functional.t.html) ```python tensorplay.functional.t(input) → Tensor ``` Expects input to 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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(). [#](#api-tensorplay.functional.take_along_dim) ### take_along_dim function[Full reference ↗](/docs/generated/tensorplay.functional.take_along_dim.html) ```python tensorplay.functional.take_along_dim(input, indices, dim=None, *, out=None) → Tensor ``` Selects values from input at the 1-dimensional indices from indices along the given dim. If dim is None, the input array is treated as if it has been flattened to 1d. Functions that return indices along a dimension, like tensorplay.argmax() and tensorplay.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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - indices (LongTensor) – the indices into input. Must have long dtype. - dim ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – dimension to select along. Default: 0 Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.take) ### take function[Full reference ↗](/docs/generated/tensorplay.functional.take.html) ```python tensorplay.functional.take(input, index) → Tensor ``` Returns a new tensor with the elements of input at 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.tan_) ### tan_ function[Full reference ↗](/docs/generated/tensorplay.functional.tan_.html) ```python tensorplay.functional.tan_(input) ``` [#](#api-tensorplay.functional.tan) ### tan function[Full reference ↗](/docs/generated/tensorplay.functional.tan.html) ```python tensorplay.functional.tan(input, *, out=None) → Tensor ``` Returns a new tensor with the tangent of the elements of input. $$\text{out}_{i} = \tan(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.tanh_) ### tanh_ function[Full reference ↗](/docs/generated/tensorplay.functional.tanh_.html) ```python tensorplay.functional.tanh_(input) ``` [#](#api-tensorplay.functional.tanh) ### tanh function[Full reference ↗](/docs/generated/tensorplay.functional.tanh.html) ```python tensorplay.functional.tanh(input, *, out=None) → Tensor ``` Returns a new tensor with the hyperbolic tangent of the elements of input. $$\text{out}_{i} = \tanh(\text{input}_{i})$$ Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]) ``` [#](#api-tensorplay.functional.tensor_split) ### tensor_split function[Full reference ↗](/docs/generated/tensorplay.functional.tensor_split.html) ```python tensorplay.functional.tensor_split(input, indices_or_sections, dim=0) → List of Tensors ``` Splits a tensor into multiple sub-tensors, all of which are views of input, along dimension dim according to the indices or number of sections specified by indices_or_sections. This function is based on NumPy’s numpy.array_split(). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to split - indices_or_sections ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), [int](https://docs.python.org/3/builtins/functions.html#int) or [list](https://docs.python.org/3/builtins/stdtypes.html#list) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – If indices_or_sections is an integer n or a zero dimensional long tensor with value n, input is split into n sections along dimension dim. If input is divisible by n along dimension dim, each section will be of equal size, input.size(dim) / n. If input is not divisible by n, the sizes of the first int(input.size(dim) % n) sections will have size int(input.size(dim) / n) + 1, and the rest will have size int(input.size(dim) / n). If indices_or_sections is a list or tuple of ints, or a one-dimensional long tensor, then input is split along dimension dim at each of the indices in the list, tuple or tensor. For instance, indices_or_sections=[2, 3] and dim=0 would result in the tensors input[:2], input[2:3], and input[3:]. If indices_or_sections is a tensor, it must be a zero-dimensional or one-dimensional long tensor on the CPU. - dim ([int](https://docs.python.org/3/builtins/functions.html#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]])) ``` [#](#api-tensorplay.functional.threshold_) ### threshold_ function[Full reference ↗](/docs/generated/tensorplay.functional.threshold_.html) ```python tensorplay.functional.threshold_(input, threshold, value) ``` [#](#api-tensorplay.functional.threshold) ### threshold function[Full reference ↗](/docs/generated/tensorplay.functional.threshold.html) ```python tensorplay.functional.threshold(input, threshold, value, *, out=None) ``` [#](#api-tensorplay.functional.tile) ### tile function[Full reference ↗](/docs/generated/tensorplay.functional.tile.html) ```python tensorplay.functional.tile(input, dims) → Tensor ``` Constructs a tensor by repeating the elements of input. The dims argument specifies the number of repetitions in each dimension. If dims specifies fewer dimensions than input has, then ones are prepended to dims until all dimensions are specified. For example, if input has shape (8, 6, 4, 2) and dims is (2, 2), then dims is treated as (1, 1, 2, 2). Analogously, if input has fewer dimensions than dims specifies, then input is treated as if it were unsqueezed at dimension zero until it has as many dimensions as dims specifies. For example, if input has shape (4, 2) and dims is (3, 3, 2, 2), then input is treated as if it had the shape (1, 1, 4, 2). > **Note** > > This function is similar to NumPy’s tile function. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor whose elements to repeat. - dims ([tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)) – the number of repetitions per dimension. 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]]) ``` [#](#api-tensorplay.functional.topk) ### topk function[Full reference ↗](/docs/generated/tensorplay.functional.topk.html) ```python tensorplay.functional.topk(input, k, dim=-1, largest=True, sorted=True, impl=0, *, out=None) ``` [#](#api-tensorplay.functional.trace) ### trace function[Full reference ↗](/docs/generated/tensorplay.functional.trace.html) ```python tensorplay.functional.trace(input) → Tensor ``` Returns the sum of the elements of the diagonal of the input 2-D matrix. Example: ``` >>> x = tensorplay.arange(1., 10.).view(3, 3) >>> x tensor([[ 1., 2., 3.], [ 4., 5., 6.], [ 7., 8., 9.]]) >>> tensorplay.trace(x) tensor(15.) ``` [#](#api-tensorplay.functional.transpose_copy) ### transpose_copy function[Full reference ↗](/docs/generated/tensorplay.functional.transpose_copy.html) ```python tensorplay.functional.transpose_copy(input, dim0, dim1) ``` Performs the same operation as tensorplay.transpose(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.transpose) ### transpose function[Full reference ↗](/docs/generated/tensorplay.functional.transpose.html) ```python tensorplay.functional.transpose(input, dim0, dim1) → Tensor ``` Returns a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped. If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other. If input is a the relevant documentation then the resulting out tensor does not share the underlying storage with the input tensor. If input is a the relevant documentation with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions. > **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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim0 ([int](https://docs.python.org/3/builtins/functions.html#int)) – the first dimension to be transposed - dim1 ([int](https://docs.python.org/3/builtins/functions.html#int)) – the second dimension to be transposed 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(). [#](#api-tensorplay.functional.trapezoid) ### trapezoid function[Full reference ↗](/docs/generated/tensorplay.functional.trapezoid.html) ```python tensorplay.functional.trapezoid(y, x=None, *, dx=None, dim=-1) → Tensor ``` Computes the [trapezoidal rule](https://en.wikipedia.org/wiki/Trapezoidal_rule) along dim. By default the spacing between elements is assumed to be 1, but dx can be used to specify a different constant spacing, and x can be used to specify arbitrary spacing along dim. Only one of x or dx should be specified. Assuming y is a one-dimensional tensor with elements ${y_0, y_1, ..., y_n}$, the default computation is $$\begin{aligned} \sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1}) \end{aligned}$$ When dx is specified the computation becomes $$\begin{aligned} \sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1}) \end{aligned}$$ effectively multiplying the result by dx. When x is specified, assuming x is also a one-dimensional tensor with elements ${x_0, x_1, ..., x_n}$, the computation becomes $$\begin{aligned} \sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1}) \end{aligned}$$ When x and y have 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 both x and y, the function computes the difference between consecutive elements along dimension dim. This effectively creates two tensors, x_diff and y_diff, that have the same shape as the original tensors except their lengths along the dimension dim is 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: - y ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – Values to use when computing the trapezoidal rule. - x ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – If specified, defines spacing between values as specified above. Keyword Arguments: - dx ([float](https://docs.python.org/3/builtins/functions.html#float)) – constant spacing between values. If neither x or dx are specified then this defaults to 1. Effectively multiplies the result by its value. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – The dimension along which to compute the trapezoidal rule. The last (inner-most) dimension by default. 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.]) ``` [#](#api-tensorplay.functional.trapz) ### trapz function[Full reference ↗](/docs/generated/tensorplay.functional.trapz.html) ```python tensorplay.functional.trapz(y, x, *, dim=-1) → Tensor ``` Alias for tensorplay.trapezoid(). [#](#api-tensorplay.functional.triangular_solve) ### triangular_solve function[Full reference ↗](/docs/generated/tensorplay.functional.triangular_solve.html) ```python tensorplay.functional.triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) ``` Solves a system of equations with a square upper or lower triangular invertible matrix $A$ and multiple right-hand sides $b$. In symbols, it solves $AX = b$ and assumes $A$ 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 A contains zeros or elements that are very close to zero and unitriangular= 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 of tensorplay.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).solution should be replaced with @@TPBLOCK_257@@ Parameters: - b ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – multiple right-hand sides of size $(*, m, k)$ where $*$ is zero of more batch dimensions - A ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input triangular coefficient matrix of size $(*, m, m)$ where $*$ is zero or more batch dimensions - upper ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – whether $A$ is upper or lower triangular. Default: True. - transpose ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – solves op(A)X = b where op(A) = A^T if this flag is True, and op(A) = A if it is False. Default: False. - unitriangular ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – whether $A$ is unit triangular. If True, the diagonal elements of $A$ are assumed to be 1 and not referenced from $A$. Default: False. Keyword Arguments: out (([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 $A$ and solution is the solution $X$ to $AX = b$ (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]])) ``` [#](#api-tensorplay.functional.tril_indices) ### tril_indices function[Full reference ↗](/docs/generated/tensorplay.functional.tril_indices.html) ```python tensorplay.functional.tril_indices(row, col, offset=0, *, dtype=tensorplay.long, device='cpu', layout=tensorplay.strided) → Tensor ``` Returns the indices of the lower triangular part of a row-by- col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates. 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 offset controls which diagonal to consider. If offset = 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 $\lbrace (i, i) \rbrace$ for $i \in [0, \min\{d_{1}, d_{2}\} - 1]$ where $d_{1}, d_{2}$ are the dimensions of the matrix. > **Note** > > When running on CUDA, row * col must be less than $2^{59}$ 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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor, only support tensorplay.int, tensorplay.long. Default: if None, tensorplay.long. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - layout (tensorplay.layout, optional) – currently only support tensorplay.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]]) ``` [#](#api-tensorplay.functional.tril) ### tril function[Full reference ↗](/docs/generated/tensorplay.functional.tril.html) ```python tensorplay.functional.tril(input, diagonal=0, *, out=None) → Tensor ``` Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0. The lower triangular part of the matrix is defined as the elements on and below the diagonal. The argument [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) controls which diagonal to consider. If [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) = 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 $\lbrace (i, i) \rbrace$ for $i \in [0, \min\{d_{1}, d_{2}\} - 1]$ where $d_{1}, d_{2}$ are the dimensions of the matrix. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - diagonal ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the diagonal to consider Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.triplet_margin_loss) ### triplet_margin_loss function[Full reference ↗](/docs/generated/tensorplay.functional.triplet_margin_loss.html) ```python tensorplay.functional.triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2.0) ``` [#](#api-tensorplay.functional.triu_indices) ### triu_indices function[Full reference ↗](/docs/generated/tensorplay.functional.triu_indices.html) ```python tensorplay.functional.triu_indices(row, col, offset=0, *, dtype=tensorplay.long, device='cpu', layout=tensorplay.strided) → Tensor ``` Returns the indices of the upper triangular part of a row by col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates. 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 offset controls which diagonal to consider. If offset = 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 $\lbrace (i, i) \rbrace$ for $i \in [0, \min\{d_{1}, d_{2}\} - 1]$ where $d_{1}, d_{2}$ are the dimensions of the matrix. > **Note** > > When running on CUDA, row * col must be less than $2^{59}$ 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](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor, only support tensorplay.int, tensorplay.long. Default: if None, tensorplay.long. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - layout (tensorplay.layout, optional) – currently only support tensorplay.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]]) ``` [#](#api-tensorplay.functional.triu) ### triu function[Full reference ↗](/docs/generated/tensorplay.functional.triu.html) ```python tensorplay.functional.triu(input, diagonal=0, *, out=None) → Tensor ``` Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0. The upper triangular part of the matrix is defined as the elements on and above the diagonal. The argument [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) controls which diagonal to consider. If [diagonal](/docs/generated/tensorplay.functional.diagonal.html#tensorplay.functional.diagonal) = 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 $\lbrace (i, i) \rbrace$ for $i \in [0, \min\{d_{1}, d_{2}\} - 1]$ where $d_{1}, d_{2}$ are the dimensions of the matrix. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - diagonal ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – the diagonal to consider Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.true_divide) ### true_divide function[Full reference ↗](/docs/generated/tensorplay.functional.true_divide.html) ```python tensorplay.functional.true_divide(dividend, divisor, *, out) → Tensor ``` Alias for tensorplay.div() with rounding_mode=None. [#](#api-tensorplay.functional.trunc_) ### trunc_ function[Full reference ↗](/docs/generated/tensorplay.functional.trunc_.html) ```python tensorplay.functional.trunc_(input) ``` [#](#api-tensorplay.functional.trunc) ### trunc function[Full reference ↗](/docs/generated/tensorplay.functional.trunc.html) ```python tensorplay.functional.trunc(input, *, out=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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.]) ``` [#](#api-tensorplay.functional.unbind_copy) ### unbind_copy function[Full reference ↗](/docs/generated/tensorplay.functional.unbind_copy.html) ```python tensorplay.functional.unbind_copy(input, dim=0, *, out=None) ``` Performs the same operation as tensorplay.unbind(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.unbind) ### unbind function[Full reference ↗](/docs/generated/tensorplay.functional.unbind.html) ```python tensorplay.functional.unbind(input, dim=0) → seq ``` Removes a tensor dimension. Returns a tuple of all slices along a given dimension, already without it. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor to unbind - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – dimension to remove 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])) ``` [#](#api-tensorplay.functional.unflatten) ### unflatten function[Full reference ↗](/docs/generated/tensorplay.functional.unflatten.html) ```python tensorplay.functional.unflatten(input, dim, sizes) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – Dimension to be unflattened, specified as an index into input.shape. - sizes (Tuple[[int](https://docs.python.org/3/builtins/functions.html#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 sizes must equal input.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]) ``` [#](#api-tensorplay.functional.unfold_copy) ### unfold_copy function[Full reference ↗](/docs/generated/tensorplay.functional.unfold_copy.html) ```python tensorplay.functional.unfold_copy(input, dimension, size, step) ``` Performs the same operation as [tensorplay.unfold()](/docs/generated/tensorplay.unfold.html#tensorplay.unfold), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.unique_consecutive) ### unique_consecutive function[Full reference ↗](/docs/generated/tensorplay.functional.unique_consecutive.html) ```python tensorplay.functional.unique_consecutive(input, return_inverse=False, return_counts=False, dim=None) ``` [#](#api-tensorplay.functional.unique) ### unique function[Full reference ↗](/docs/generated/tensorplay.functional.unique.html) ```python tensorplay.functional.unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None) ``` [#](#api-tensorplay.functional.unsqueeze_copy) ### unsqueeze_copy function[Full reference ↗](/docs/generated/tensorplay.functional.unsqueeze_copy.html) ```python tensorplay.functional.unsqueeze_copy(input, dim) ``` Performs the same operation as tensorplay.unsqueeze(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.unsqueeze) ### unsqueeze function[Full reference ↗](/docs/generated/tensorplay.functional.unsqueeze.html) ```python tensorplay.functional.unsqueeze(input, dim) → Tensor ``` Returns a new tensor with a dimension of size one inserted at the specified position. The returned tensor shares the same underlying data with this tensor. A dim value within the range [-input.dim() - 1, input.dim() + 1) can be used. Negative dim will correspond to [unsqueeze()](#tensorplay.functional.unsqueeze) applied at dim = dim + input.dim() + 1. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int)) – the index at which to insert the singleton dimension 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]]) ``` [#](#api-tensorplay.functional.values_copy) ### values_copy function[Full reference ↗](/docs/generated/tensorplay.functional.values_copy.html) ```python tensorplay.functional.values_copy(input) ``` Performs the same operation as [tensorplay.values()](/docs/generated/tensorplay.values.html#tensorplay.values), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.vander) ### vander function[Full reference ↗](/docs/generated/tensorplay.functional.vander.html) ```python tensorplay.functional.vander(x, N=None, increasing=False) → Tensor ``` Generates a Vandermonde matrix. The columns of the output matrix are elementwise powers of the input vector $x^{(N-1)}, x^{(N-2)}, ..., x^0$. If increasing is True, the order of the columns is reversed $x^0, x^1, ..., x^{(N-1)}$. Such a matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde. Parameters: - x ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – 1-D input tensor. - N ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – Number of columns in the output. If N is not specified, a square array is returned $(N = len(x))$. - increasing ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed. Returns: Vandermonde matrix. If increasing is False, the first column is $x^{(N-1)}$, the second $x^{(N-2)}$ and so forth. If increasing is True, the columns are $x^0, x^1, ..., x^{(N-1)}$. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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]]) ``` [#](#api-tensorplay.functional.var_mean) ### var_mean function[Full reference ↗](/docs/generated/tensorplay.functional.var_mean.html) ```python tensorplay.functional.var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) ``` Calculates the variance and mean over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions. The variance ($\sigma^2$) is calculated as $$\sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2$$ where $x$ is the sample set of elements, $\bar{x}$ is the sample mean, $N$ is the number of samples and $\delta N$ is the correction. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. Keyword Arguments: - correction ([int](https://docs.python.org/3/builtins/functions.html#int)) – difference between the sample size and sample degrees of freedom. Defaults to [Bessel’s correction](https://en.wikipedia.org/wiki/Bessel%27s_correction), correction=1. Changed in version 2.0: Previously this argument was called unbiased and was a boolean with True corresponding to correction=1 and False being correction=0. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]])) ``` [#](#api-tensorplay.functional.var) ### var function[Full reference ↗](/docs/generated/tensorplay.functional.var.html) ```python tensorplay.functional.var(input, dim=None, *, correction=1, keepdim=False, out=None) → Tensor ``` Calculates the variance over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions. The variance ($\sigma^2$) is calculated as $$\sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2$$ where $x$ is the sample set of elements, $\bar{x}$ is the sample mean, $N$ is the number of samples and $\delta N$ is the correction. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – the dimension or dimensions to reduce. If None, all dimensions are reduced. Keyword Arguments: - correction ([int](https://docs.python.org/3/builtins/functions.html#int)) – difference between the sample size and sample degrees of freedom. Defaults to [Bessel’s correction](https://en.wikipedia.org/wiki/Bessel%27s_correction), correction=1. Changed in version 2.0: Previously this argument was called unbiased and was a boolean with True corresponding to correction=1 and False being correction=0. keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False. - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.vdot) ### vdot function[Full reference ↗](/docs/generated/tensorplay.functional.vdot.html) ```python tensorplay.functional.vdot(input, other, *, out=None) → Tensor ``` Computes the dot product of two 1D vectors along a dimension. In symbols, this function computes $$\sum_{i=1}^n \overline{x_i}y_i.$$ where $\overline{x_i}$ 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – first tensor in the dot product, must be 1D. Its conjugate is used if it’s complex. - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – second tensor in the dot product, must be 1D. 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]) ``` [#](#api-tensorplay.functional.view_as_complex_copy) ### view_as_complex_copy function[Full reference ↗](/docs/generated/tensorplay.functional.view_as_complex_copy.html) ```python tensorplay.functional.view_as_complex_copy(input) ``` Performs the same operation as tensorplay.view_as_complex(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.view_as_complex) ### view_as_complex function[Full reference ↗](/docs/generated/tensorplay.functional.view_as_complex.html) ```python tensorplay.functional.view_as_complex(input) → Tensor ``` Returns a view of input as a complex tensor. For an input complex tensor of size $m1, m2, \dots, mi, 2$, this function returns a new complex tensor of size $m1, m2, \dots, mi$ where 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 with tensorplay.dtype tensorplay.float64 and tensorplay.float32. The input is expected to have the last dimension of size 2. 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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)]) ``` [#](#api-tensorplay.functional.view_as_real_copy) ### view_as_real_copy function[Full reference ↗](/docs/generated/tensorplay.functional.view_as_real_copy.html) ```python tensorplay.functional.view_as_real_copy(input) ``` Performs the same operation as tensorplay.view_as_real(), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.view_as_real) ### view_as_real function[Full reference ↗](/docs/generated/tensorplay.functional.view_as_real.html) ```python tensorplay.functional.view_as_real(input) → Tensor ``` Returns a view of input as a real tensor. For an input complex tensor of size $m1, m2, \dots, mi$, this function returns a new real tensor of size $m1, m2, \dots, mi, 2$, 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 with complex dtypes. Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.view_copy) ### view_copy function[Full reference ↗](/docs/generated/tensorplay.functional.view_copy.html) ```python tensorplay.functional.view_copy(input, size) ``` Performs the same operation as [tensorplay.view()](/docs/generated/tensorplay.view.html#tensorplay.view), but all output tensors are freshly created instead of aliasing the input. [#](#api-tensorplay.functional.vsplit) ### vsplit function[Full reference ↗](/docs/generated/tensorplay.functional.vsplit.html) ```python tensorplay.functional.vsplit(input, indices_or_sections) → List of Tensors ``` Splits input, a tensor with two or more dimensions, into multiple tensors vertically according to indices_or_sections. Each split is a view of input. This is equivalent to calling tensorplay.tensor_split(input, indices_or_sections, dim=0) (the split dimension is 0), except that if indices_or_sections is 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: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – tensor to split. - indices_or_sections ([int](https://docs.python.org/3/builtins/functions.html#int) or [list](https://docs.python.org/3/builtins/stdtypes.html#list) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints) – See argument in tensorplay.tensor_split(). 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))) ``` [#](#api-tensorplay.functional.vstack) ### vstack function[Full reference ↗](/docs/generated/tensorplay.functional.vstack.html) ```python tensorplay.functional.vstack(tensors, *, out=None) → Tensor ``` 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](/docs/generated/tensorplay.Tensor.html#tensorplay.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]]) ``` [#](#api-tensorplay.functional.where) ### where function[Full reference ↗](/docs/generated/tensorplay.functional.where.html) ```python tensorplay.functional.where(condition, input, other, *, out=None) → Tensor ``` Return a tensor of elements selected from either input or other, depending on condition. The operation is defined as: $$\begin{split}\text{out}_i = \begin{cases} \text{input}_i & \text{if } \text{condition}_i \\ \text{other}_i & \text{otherwise} \\ \end{cases}\end{split}$$ > **Note** > > The tensors condition, input, other must be broadcastable. Parameters: - condition (BoolTensor) – When True (nonzero), yield input, otherwise yield other - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – value (if input is a scalar) or values selected at indices where condition is True - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – value (if other is a scalar) or values selected at indices where condition is False Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A tensor of shape equal to the broadcasted shape of condition, input, other Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) 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) ``` ```python tensorplay.functional.where(condition) → tuple of LongTensor ``` tensorplay.where(condition) is identical to tensorplay.nonzero(condition, as_tuple=True). > **Note** > > See also tensorplay.nonzero(). [#](#api-tensorplay.functional.xlog1py) ### xlog1py function[Full reference ↗](/docs/generated/tensorplay.functional.xlog1py.html) ```python tensorplay.functional.xlog1py(input, other) ``` [#](#api-tensorplay.functional.xlogy_) ### xlogy_ function[Full reference ↗](/docs/generated/tensorplay.functional.xlogy_.html) ```python tensorplay.functional.xlogy_(input, other) ``` [#](#api-tensorplay.functional.xlogy) ### xlogy function[Full reference ↗](/docs/generated/tensorplay.functional.xlogy.html) ```python tensorplay.functional.xlogy(input, other, *, out=None) → Tensor ``` Alias for tensorplay.special.xlogy(). [#](#api-tensorplay.functional.zero_) ### zero_ function[Full reference ↗](/docs/generated/tensorplay.functional.zero_.html) ```python tensorplay.functional.zero_(input) ``` [#](#api-tensorplay.functional.zeros_like) ### zeros_like function[Full reference ↗](/docs/generated/tensorplay.functional.zeros_like.html) ```python 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 to tensorplay.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device). > **Warning** > > As of 0.4, this function does not support an out keyword. As an alternative, the old tensorplay.zeros_like(input, out=output) is equivalent to tensorplay.zeros(input.size(), out=output). Parameters: input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the size of input will determine size of the output tensor. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input. - layout (tensorplay.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. - memory_format ([tensorplay.memory_format](/docs/generated/tensorplay.MemoryFormat.html#tensorplay.MemoryFormat), 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.]]) ``` [#](#api-tensorplay.functional.zeta) ### zeta function[Full reference ↗](/docs/generated/tensorplay.functional.zeta.html) ```python tensorplay.functional.zeta(input, other) ```