torch

package torch

The torch package contains data structures for multi-dimensional tensors and defines mathematical operations over these tensors. Additionally, it provides many utilities for efficient serialization of Tensors and arbitrary types, and other useful utilities.

It has a CUDA counterpart, that enables you to run your tensor computations on an NVIDIA GPU with compute capability >= 3.0.

Attributes

Members list

Packages

package torch.cuda

This package adds support for CUDA tensor types, that implement the same function as CPU tensors, but they utilize GPUs for computation.

This package adds support for CUDA tensor types, that implement the same function as CPU tensors, but they utilize GPUs for computation.

Attributes

package torch.data
package torch.nn

These are the basic building blocks for graphs.

These are the basic building blocks for graphs.

Attributes

package torch.optim
package torch.special

Grouped members

nn_activation

Exported from Activations

Applies a softmax function.

Applies a softmax function.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
Activations.scala

Reduction Ops

For each row of input in the given dimension dim, returns true if all elements in the row evaluate to true and false otherwise.

For each row of input in the given dimension dim, returns true if all elements in the row evaluate to true and false otherwise.

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def all[D <: DType](input: Tensor[D]): Tensor[Bool]

Tests if all elements of this tensor evaluate to true.

Tests if all elements of this tensor evaluate to true.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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

Returns the maximum value of each slice of the input tensor in the given dimension(s) 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 torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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

Returns the minimum value of each slice of the input tensor in the given dimension(s) 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 torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Computes the minimum and maximum values of the input tensor.

Computes the minimum and maximum values of the input tensor.

Value parameters

dim

The dimension along which to compute the values. If None, computes the values over the entire input tensor. Default is None.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

For each row of input in the given dimension dim, returns true if any element in the row evaluates to true and false otherwise.

For each row of input in the given dimension dim, returns true if any element in the row evaluates to true and false otherwise.

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def any[D <: DType](input: Tensor[D]): Tensor[Bool]

Tests if any elements of this tensor evaluate to true.

Tests if any elements of this tensor evaluate to true.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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

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

This is the second value returned by torch.max(). See its documentation for the exact semantics of this method.

Example:

val a = torch.rand(Seq(1, 3))
torch.argmax(a)
// tensor dtype=int64, shape=[], device=CPU
// 1

Value parameters

dim

the dimension to reduce. If None, the argmin of the flattened input is returned.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the indices of the minimum value of all elements in the tensor.

Returns the indices of the minimum value of all elements in the tensor.

This is the second value returned by torch.min(). See its documentation for the exact semantics of this method.

Example:

val a = torch.rand(Seq(1, 3))
torch.argmin(a)
// tensor dtype=int64, shape=[], device=CPU
// 1

Value parameters

dim

the dimension to reduce. If None, the argmin of the flattened input is returned.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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.

Value parameters

dim

Dim or seq of dims along which to count non-zeros.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the p-norm of (input - other)

Returns the p-norm of (input - other)

The shapes of input and other must be broadcastable.

Value parameters

p

the norm to be computed

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the log of summed exponentials of each row of the input tensor in the given dimension dim. The computation is numerically stabilized.

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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns a TensorTuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

Returns a TensorTuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Note

If there are multiple maximal values in a reduced row then the indices of the first maximal value are returned.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def max[D <: RealNN](input: Tensor[D]): Tensor[Int64]

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

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

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns a TensorTuple (values, indices) where values contains the median of each row of input in the dimension dim, and indices contains the index of the median values found in the dimension dim.

Returns a TensorTuple (values, indices) where values contains the median of each row of input in the dimension dim, and indices contains the index of the median values found in the dimension dim.

By default, dim is the last dimension of the input tensor.

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Note

The median is not unique for input tensors with an even number of elements in the dimension dim. In this case the lower of the two medians is returned. To compute the mean of both medians in input, use torch.quantile with q=0.5 instead. Warning indices does not necessarily contain the first occurrence of each median value found, unless it is unique. The exact implementation details are device-specific. Do not expect the same result when run on CPU and GPU in general. For the same reason do not expect the gradients to be deterministic.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the median of the values in input.

Returns the median of the values in input.

Attributes

Note

The median is not unique for input tensors with an even number of elements. In this case the lower of the two medians is returned. To compute the mean of both medians, use torch.quantile with q=0.5 instead. Warning This function produces deterministic (sub)gradients unlike median(dim=0)

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns a TensorTuple (values, indices) where values is the minimum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

Returns a TensorTuple (values, indices) where values is the minimum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Note

If there are multiple minimal values in a reduced row then the indices of the first minimal value are returned.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def min[D <: RealNN](input: Tensor[D]): Tensor[Int64]

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

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

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns a TensorTuple (values, indices) where values is the mode value of each row of the input tensor in the given dimension dim, i.e. a value which appears most often in that row, and indices is the index location of each mode value found.

Returns a TensorTuple (values, indices) where values is the mode value of each row of the input tensor in the given dimension dim, i.e. a value which appears most often in that row, and indices is the index location of each mode value found.

By default, dim is the last dimension of the input tensor.

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

keepdim

whether the output tensor has dim retained or not.

Attributes

Note

This function is not defined for torch.cuda.Tensor yet.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Computes the mean of all [non-NaN] elements along the specified dimensions.

Computes the mean of all [non-NaN] elements along the specified dimensions.

This function is identical to torch.mean when there are no [NaN] values in the input tensor. In the presence of [NaN], torch.mean will propagate the [NaN] to the output whereas torch.nanmean will ignore the [NaN] values ([torch.nanmean(a)] is equivalent to [torch.mean(a[~a.isnan()])]).

If keepdim is true, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns a TensorTuple (values, indices) where values contains the median of each row of input in the dimension dim, ignoring NaN values, and indices contains the index of the median values found in the dimension dim.

Returns a TensorTuple (values, indices) where values contains the median of each row of input in the dimension dim, ignoring NaN values, and indices contains the index of the median values found in the dimension dim.

This function is identical to :func:torch.median when there are no NaN values in a reduced row. When a reduced row has one or more NaN values, :func:torch.median will always reduce it to NaN, while this function will reduce it to the median of the non-NaN elements. If all the elements in a reduced row are NaN then it will be reduced to NaN, too.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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

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

This function is identical to torch.median when there are no NaN values in input. When input has one or more NaN values, torch.median will always return NaN, while this function will return the median of the non-NaN elements in input. If all the elements in input are NaN it will also return NaN.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the product of each row of the input tensor in the given dimension dim.

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 torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension to reduce.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def prod[D <: DType](input: Tensor[_], dtype: D): Tensor[D]

Returns the product of all elements in the input tensor.

Returns the product of all elements in the input tensor.

Value parameters

dtype

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.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def prod[D <: DType, D2 <: DType | Derive](input: Tensor[D]): Tensor[D]

Returns the product of all elements in the input tensor.

Returns the product of all elements in the input tensor.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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}{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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

correction

difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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}{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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

correction

difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

keepdim

whether the output tensor has dim retained or not.

Attributes

Returns

A tuple (std, mean) containing the standard deviation and mean.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Returns the sum of each row of the input tensor in the given dimension dim.

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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

dtype

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.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def sum[D <: DType](input: Tensor[_], dtype: D): Tensor[D]

Returns the sum of all elements in the input tensor.

Returns the sum of all elements in the input tensor.

Value parameters

dtype

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.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala
def sum[D <: DType, D2 <: DType | Derive](input: Tensor[D]): Tensor[D]

Returns the sum of all elements in the input tensor.

Returns the sum of all elements in the input tensor.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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}{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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

correction

difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

keepdim

whether the output tensor has dim retained or not.

Attributes

Returns

A tuple (var, mean) containing the variance and mean.

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

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.

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}{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 dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze), resulting in the output tensor having 1 fewer dimension than input.

Value parameters

correction

difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1.

dim

the dimension or dimensions to reduce. If empty, all dimensions are reduced.

keepdim

whether the output tensor has dim retained or not.

Attributes

Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

indexing_slicing_joining_mutating_ops

def adjoint[D <: DType](input: Tensor[D]): Tensor[D]

Returns a view of the tensor conjugated and with the last two dimensions transposed.

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.

Example:

import spire.math.Complex

val x = torch.arange(end = 4)
// tensor dtype=int32, shape=[4], device=CPU
// [0, 1, 2, 3]
val a = torch.Tensor(
 Seq(
   Seq(Complex(0.0, 0.0), Complex(1.0, 1.0)),
   Seq(Complex(2.0, 2.0), Complex(3.0, 3.0))
 )
)
// tensor dtype=complex128, shape=[2, 2], device=CPU
// [[(0.0 + 0.0i), (1.0 + 1.0i)],
//  [(2.0 + 2.0i), (3.0 + 3.0i)]]
a.adjoint()
// tensor dtype=complex128, shape=[2, 2], device=CPU
// [[(0.0 - 0.0i), (2.0 - 2.0i)],
//  [(1.0 - 1.0i), (3.0 - 3.0i)]]
(a.adjoint() == a.mH).all()
// tensor dtype=bool, shape=[], device=CPU
// true

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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).

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×n), where z is the total number of non-zero elements in the input tensor.

Note When input is on CUDA, this function causes host-device synchronization.

Example:

val t = torch.Tensor(Seq(1, 0, 1))
torch.argwhere(t)
// tensor dtype=int32, shape=[2, 1], device=CPU
// [[0],
//  [2]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def cat[D <: DType](tensors: Seq[Tensor[D]], dim: Int): Tensor[D]

Concatenates the given sequence of seq tensors in the given dimension. All tensors must either have the same shape (except in the concatenating dimension) or be empty.

Concatenates the given sequence of seq tensors in the given dimension. All tensors must either have the same shape (except in the concatenating dimension) or be empty.

torch.cat can be seen as an inverse operation for torch.split and torch.chunk.

torch.cat{class: interpreted-text, role: func} can be best understood via examples.

Non-empty tensors provided must have the same shape, except in the cat dimension.

Example:

val x = torch.randn(Seq(2, 3))
// tensor dtype=float32, shape=[2, 3], device=CPU
// [[ 0.6580, -1.0969, -0.4614],
//  [-0.1034, -0.5790,  0.1497]])
torch.cat(Seq(x, x, x), 0)
// tensor dtype=float32, shape=[6, 3], device=CPU
// [[ 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]])
torch.cat(Seq(x, x, x), 1)
// tensor dtype=float32, shape=[2, 9], device=CPU
// [[ 0.6580, -1.0969, -0.4614, ..., 0.6580, -1.0969, -0.4614],
//  [-0.1034, -0.5790,  0.1497, ..., -0.1034, -0.5790,  0.1497]])

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def chunk[D <: DType](input: Tensor[D], chunks: Int, dim: Int): Seq[Tensor[D]]

Attempts to split a tensor into the specified number of chunks. Each chunk is a view of the input tensor.

Attempts to split a tensor into the specified number of chunks. Each chunk is a view of the input tensor.

This function may return fewer than the specified number of chunks!

torch.tensorSplit 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.

Example:

torch.chunk(torch.arange(end = 11), 6)
// List(
//   tensor dtype=int32, shape=[2], device=CPU
//   [0, 1],
//   tensor dtype=int32, shape=[2], device=CPU
//   [2, 3],
//   tensor dtype=int32, shape=[2], device=CPU
//   [4, 5],
//   tensor dtype=int32, shape=[2], device=CPU
//   [6, 7],
//   tensor dtype=int32, shape=[2], device=CPU
//   [8, 9],
//   tensor dtype=int32, shape=[1], device=CPU
//   [10]
// )
torch.chunk(torch.arange(end = 12), 6)
// List(
//   tensor dtype=int32, shape=[2], device=CPU
//   [0, 1],
//   tensor dtype=int32, shape=[2], device=CPU
//   [2, 3],
//   tensor dtype=int32, shape=[2], device=CPU
//   [4, 5],
//   tensor dtype=int32, shape=[2], device=CPU
//   [6, 7],
//   tensor dtype=int32, shape=[2], device=CPU
//   [8, 9],
//   tensor dtype=int32, shape=[2], device=CPU
//   [10, 11]
// )
torch.chunk(torch.arange(end = 13), 6)
// List(
//   tensor dtype=int32, shape=[3], device=CPU
//   [0, 1, 2],
//   tensor dtype=int32, shape=[3], device=CPU
//   [3, 4, 5],
//   tensor dtype=int32, shape=[3], device=CPU
//   [6, 7, 8],
//   tensor dtype=int32, shape=[3], device=CPU
//   [9, 10, 11],
//   tensor dtype=int32, shape=[1], device=CPU
//   [12],
// )

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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

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

Equivalent to torch.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.

Example:

val a = torch.Tensor(Seq(1, 2, 3))
val b = torch.Tensor(Seq(4, 5, 6))
torch.columnStack(Seq(a, b))
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[1, 4],
//  [2, 5],
//  [3, 6]]
val c = torch.arange(end = 5)
val d = torch.arange(end = 10).reshape(5, 2)
torch.columnStack(Seq(c, d, d))
// tensor dtype=int32, shape=[5, 5], device=CPU
// [[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]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def conj[D <: DType](input: Tensor[D]): Tensor[D]

Returns a view of input with a flipped conjugate bit. If input has a non-complex dtype, this function just returns input.

Returns a view of input with a flipped conjugate bit. If input has a non-complex dtype, this function just returns input.

Note

torch.conj performs a lazy conjugation, but the actual conjugated tensor can be materialized at any time using torch.resolve_conj.

Warning

In the future, torch.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 torch.conj_physical when input is of non-complex dtype to be compatible with this change.

Example:

import spire.math.Complex
val x = torch.Tensor(
 Seq(Complex(-1.0, 1.0), Complex(-2.0, 2.0), Complex(3.0, 3.0))
)
// tensor dtype=complex128, shape=[3], device=CPU
// [(-1.0 + 1.0i), (-2.0 + 2.0i), (3.0 + 3.0i)]
x.isConj
// false
val y = torch.conj(x)
// tensor dtype=complex128, shape=[3], device=CPU
// [(-1.0 + 1.0i), (-2.0 + 2.0i), (3.0 + 3.0i)]
y.isConj
// true

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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.

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 torch.tensorSplit(input, indicesOrSections, dim=2) (the split dimension is 2), except that if indicesOrSections is an integer it must evenly divide the split dimension or a runtime error will be thrown.

Example:

// val t = torch.arange(end = 16.0).reshape(2, 2, 4)
// tensor dtype=float32, shape=[2, 2, 4], device=CPU
// [[[0.0, 1.0, 2.0, 3.0],
//   [4.0, 5.0, 6.0, 7.0]],
//  [[8.0, 9.0, 10.0, 11.0],
//   [12.0, 13.0, 14.0, 15.0]]]
// torch.dsplit(t, 2)
// List(
//   tensor dtype=float32, shape=[2, 2, 2], device=CPU
//   [[[0.0, 1.0],
//     [4.0, 5.0]],
//    [[8.0, 9.0],
//     [12.0, 13.0]]],
//   tensor dtype=float32, shape=[2, 2, 2], device=CPU
//   [[[2.0, 3.0],
//     [6.0, 7.0]],
//    [[10.0, 11.0],
//     [14.0, 15.0]]]
// )

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def dstack[D <: DType](tensors: Seq[Tensor[D]]): Tensor[D]

Stack tensors in sequence depthwise (along third axis).

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 torch.atleast3d

Example:

val a = torch.Tensor(Seq(1, 2, 3))
val b = torch.Tensor(Seq(4, 5, 6))
torch.dstack(Seq(a, b))
// tensor dtype=int32, shape=[1, 3, 2], device=CPU
// [[[1, 4],
//   [2, 5],
//   [3, 6]]]
val c = torch.Tensor(Seq(Seq(1), Seq(2), Seq(3)))
val d = torch.Tensor(Seq(Seq(4), Seq(5), Seq(6)))
torch.dstack(Seq(c, d))
// tensor dtype=int32, shape=[3, 1, 2], device=CPU
// [[[1, 4]],
//  [[2, 5]],
//  [[3, 6]]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Gathers values along an axis specified by dim.

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.

Example:

val t = torch.Tensor(Seq(Seq(1, 2), Seq(3, 4)))
val index = torch.Tensor(Seq(Seq(0L, 0L), Seq(1L, 0L)))
torch.gather(t, 1, index)
// tensor dtype=int32, shape=[2, 2], device=CPU
// [[1, 1],
//  [4, 3]]

Value parameters

dim

axis along which to index

index

indices of elements to gather

sparseGrad

if true, gradient w.r.t. input will be a sparse tensor

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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.

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 torch.tensorSplit(input, indicesOrSections, dim=0) (the split dimension is zero), and if input has two or more dimensions it's equivalent to calling torch.tensorSplit(input, indicesOrSections, dim=1) (the split dimension is 1), except that if indicesOrSections is an integer it must evenly divide the split dimension or a runtime error will be thrown.

Example:

val t = torch.arange(end = 16.0).reshape(4, 4)
torch.hsplit(t, 2)
// List(
//   tensor dtype=float32, shape=[4, 2], device=CPU
//   [[0.0, 1.0],
//    [4.0, 5.0],
//    [8.0, 9.0],
//    [12.0, 13.0]],
//   tensor dtype=float32, shape=[4, 2], device=CPU
//   [[2.0, 3.0],
//    [6.0, 7.0],
//    [10.0, 11.0],
//    [14.0, 15.0]]
// )

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def hstack[D <: DType](tensors: Seq[Tensor[D]]): Tensor[D]

Stack tensors in sequence horizontally (column wise).

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.

Example:

val a = torch.Tensor(Seq(1, 2, 3))
val b = torch.Tensor(Seq(4, 5, 6))
torch.hstack(Seq(a, b))
// tensor dtype=int32, shape=[6], device=CPU
// [1, 2, 3, 4, 5, 6]
val c = torch.Tensor(Seq(Seq(1), Seq(2), Seq(3)))
val d = torch.Tensor(Seq(Seq(4), Seq(5), Seq(6)))
torch.hstack(Seq(c, d))
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[1, 4],
//  [2, 5],
//  [3, 6]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Accumulate the elements of source into the input tensor by adding to the indices in the order given in index.

Accumulate the elements of source into the input tensor by adding to the indices in the order given in index.

The dimth dimension of source must have the same size as the length of index (which must be a vector), and all other dimensions must match self, or an error will be raised.

Note:

This operation may behave nondeterministically when given tensors on a CUDA device. See Reproducibility for more information.

Example:

val x = torch.ones(Seq(5, 3))
val index = torch.Tensor(Seq(0L, 4L, 2L))
val t = torch.Tensor(Seq(Seq(1, 2, 3), Seq(4, 5, 6), Seq(7, 8, 9))).to(dtype = torch.float32)
torch.indexAdd(x, 0, index, t)
// tensor dtype=float32, shape=[5, 3], device=CPU
// [[2.0, 3.0, 4.0],
//  [1.0, 1.0, 1.0],
//  [8.0, 9.0, 10.0],
//  [1.0, 1.0, 1.0],
//  [5.0, 6.0, 7.0]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Copies the elements of tensor into the self tensor by selecting the indices in the order given in index. For example, if dim == 0 and index[i] == j, then the ith row of tensor is copied to the jth row of self.

Copies the elements of tensor into the self tensor by selecting the indices in the order given in index. For example, if dim == 0 and index[i] == j, then the ith row of tensor is copied to the jth row of self.

The dimth dimension of tensor must have the same size as the length of index (which must be a vector), and all other dimensions must match self, or an error will be raised.

Note:

If index contains duplicate entries, multiple elements from tensor will be copied to the same index of self. The result is nondeterministic since it depends on which copy occurs last.

Example:

val x = torch.zeros(Seq(5, 3))
val t = torch.Tensor(Seq(Seq(1, 2, 3), Seq(4, 5, 6), Seq(7, 8, 9))).to(dtype = torch.float32)
// tensor dtype=float32, shape=[3, 3], device=CPU
// [[1.0, 2.0, 3.0],
//  [4.0, 5.0, 6.0],
//  [7.0, 8.0, 9.0]]
val index = torch.Tensor(Seq(0L, 4L, 2L))
torch.indexCopy(x, 0, index, t)
// tensor dtype=float32, shape=[5, 3], device=CPU
// [[1.0, 2.0, 3.0],
//  [0.0, 0.0, 0.0],
//  [7.0, 8.0, 9.0],
//  [0.0, 0.0, 0.0],
//  [4.0, 5.0, 6.0]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a Tensor[Int64].

Returns a new tensor which indexes the input tensor along dimension dim using the entries in index which is a Tensor[Int64].

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.

Example:

val x = torch.randn(Seq(3, 4))
// tensor dtype=float32, shape=[3, 4], device=CPU
// [[ 0.1427,  0.0231, -0.5414, -1.0009],
//  [-0.4664,  0.2647, -0.1228, -1.1068],
//  [-1.1734, -0.6571,  0.7230, -0.6004]]
val indices = torch.Tensor(Seq(0L, 2L))
torch.indexSelect(x, 0, indices)
// tensor dtype=float32, shape=[2, 4], device=CPU
// [[ 0.1427,  0.0231, -0.5414, -1.0009],
//  [-1.1734, -0.6571,  0.7230, -0.6004]]
torch.indexSelect(x, 1, indices)
// tensor dtype=float32, shape=[2, 4], device=CPU
// [[ 0.1427, -0.5414],
//  [-0.4664, -0.1228],
//  [-1.1734,  0.7230]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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

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 <broadcasting-semantics>.

Example:

val x = torch.randn(Seq(3, 4))
// tensor dtype=float32, shape=[3, 4], device=CPU
// [[ 0.3552, -2.3825, -0.8297,  0.3477],
//  [-1.2035,  1.2252,  0.5002,  0.6248],
//  [ 0.1307, -2.0608,  0.1244,  2.0139]]

val mask = x.ge(0.5)
// tensor dtype=bool, shape=[3, 4], device=CPU
// [[false, false, false, false],
//  [false, true, true, true],
//  [false, false, false, true]]

torch.maskedSelect(x, mask)
// tensor dtype=float32, shape=[4], device=CPU
// [1.2252, 0.5002, 0.6248, 2.0139]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Alias for torch.movedim.

Alias for torch.movedim.

Examples:

val t = torch.randn(Seq(3, 2, 1))
// tensor dtype=float32, shape=[3, 2, 1], device=CPU
// [[[-0.3362],
//   [-0.8437]],
//  [[-0.9627],
//   [ 0.1727]],
//  [[ 0.5173],
//   [-0.1398]]]

torch.moveaxis(t, 1, 0).shape
// Seq(2, 3, 1)

torch.moveaxis(t, 1, 0)
// tensor dtype=float32, shape=[2, 3, 1], device=CPU
// [[[-0.3362],
//   [-0.9627],
//   [ 0.5173]],
//  [[-0.8437],
//   [ 0.1727],
//   [-0.1398]]]

torch.moveaxis(t, Seq(1, 2), Seq(0, 1)).shape
// Seq(2, 1, 3)

torch.moveaxis(t, Seq(1, 2), Seq(0, 1))
// tensor dtype=float32, shape=[2, 1, 3], device=CPU
// [[[-0.3362, -0.9627,  0.5173]],
//  [[-0.8437,  0.1727, -0.1398]]]

Value parameters

destination

Destination positions for each of the original dims. These must also be unique.

source
  • Original positions of the dims to move. These must be unique destination

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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

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.

Examples:

val t = torch.randn(Seq(3, 2, 1))
// tensor dtype=float32, shape=[3, 2, 1], device=CPU
// [[[-0.3362],
//   [-0.8437]],
//  [[-0.9627],
//   [ 0.1727]],
//  [[ 0.5173],
//   [-0.1398]]]

torch.movedim(t, 1, 0).shape
// Seq(2, 3, 1)

torch.movedim(t, 1, 0)
// tensor dtype=float32, shape=[2, 3, 1], device=CPU
// [[[-0.3362],
//   [-0.9627],
//   [ 0.5173]],
//  [[-0.8437],
//   [ 0.1727],
//   [-0.1398]]]

torch.movedim(t, Seq(1, 2), Seq(0, 1)).shape
// Seq(2, 1, 3)

torch.movedim(t, Seq(1, 2), Seq(0, 1))
// tensor dtype=float32, shape=[2, 1, 3], device=CPU
// [[[-0.3362, -0.9627,  0.5173]],
//  [[-0.8437,  0.1727, -0.1398]]]

Value parameters

destination

Destination positions for each of the original dims. These must also be unique.

source

Original positions of the dims to move. These must be unique destination

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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.

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.

Args: input (Tensor): the tensor to narrow dim (int): the dimension along which to narrow start (int or Tensor): index of the element to start the narrowed dimension from. Can be negative, which means indexing from the end of dim. If Tensor, it must be an 0-dim integral Tensor (bools not allowed) length (int): length of the narrowed dimension, must be weakly positive

Example:

val x = torch.arange(start = 1, end = 10).reshape(3, 3)
// tensor dtype=int32, shape=[3, 3], device=CPU
// [[ 1,  2,  3],
//  [ 4,  5,  6],
//  [ 7,  8,  9]]

torch.narrow(x, 0, 0, 2)
// tensor dtype=int32, shape=[2, 3], device=CPU
// [[ 1,  2,  3],
//  [ 4,  5,  6]]

torch.narrow(x, 1, 1, 2)
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[ 2,  3],
//  [ 5,  6],
//  [ 8,  9]]

torch.narrow(x, -1, -1, 1)
// tensor dtype=int32, shape=[3, 1], device=CPU
// [[3],
//  [6],
//  [9]]

Value parameters

dim

the dimension along which to narrow

length

length of the narrowed dimension, must be weakly positive

start

index of the element to start the narrowed dimension from. Can be negative, which means indexing from the end of dim

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Same as torch.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.

Same as torch.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.

Keyword args: {out}

Example:

val x = torch.arange(start = 1, end = 10).reshape(3, 3)
// tensor dtype=int32, shape=[3, 3], device=CPU
// [[ 1,  2,  3],
//  [ 4,  5,  6],
//  [ 7,  8,  9]]

torch.narrowCopy(x, 0, 0, 2)
// tensor dtype=int32, shape=[2, 3], device=CPU
// [[ 1,  2,  3],
//  [ 4,  5,  6]]

torch.narrowCopy(x, 1, 1, 2)
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[ 2,  3],
//  [ 5,  6],
//  [ 8,  9]]

torch.narrowCopy(x, -1, -1, 1)
// tensor dtype=int32, shape=[3, 1], device=CPU
// [[3],
//  [6],
//  [9]]

Value parameters

dim

the dimension along which to narrow

length

length of the narrowed dimension, must be weakly positive

start

index of the element to start the narrowed dimension from. Can be negative, which means indexing from the end of dim

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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).

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×n), where z is the total number of non-zero elements in the input tensor.

Example:

val x = torch.Tensor(Seq(1, 1, 1, 0, 1))
torch.nonzero(x)
// tensor dtype=int32, shape=[4, 1], device=CPU
// [[ 0],
//  [ 1],
//  [ 2],
//  [ 4]]

val y = torch.Tensor(
 Seq(
   Seq(0.6, 0.0, 0.0, 0.0),
   Seq(0.0, 0.4, 0.0, 0.0),
   Seq(0.0, 0.0, 1.2, 0.0),
   Seq(0.0, 0.0, 0.0, -0.4)
 )
)
torch.nonzero(y)
// tensor dtype=int32, shape=[4, 2], device=CPU
// [[ 0,  0],
//  [ 1,  1],
//  [ 2,  2],
//  [ 3,  3]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def permute[D <: DType](input: Tensor[D], dims: Int*): Tensor[D]

Returns a view of the original tensor input with its dimensions permuted.

Returns a view of the original tensor input with its dimensions permuted.

Example:

val x = torch.randn(Seq(2, 3, 5))
// tensor dtype=float32, shape=[2, 3, 5], device=CPU
// ...

torch.permute(x, 2, 0, 1)
// tensor dtype=float32, shape=[5, 2, 3], device=CPU
// ...

Value parameters

dims

The desired ordering of dimensions, must be unique

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def reshape[D <: DType](input: Tensor[D], shape: Int*): Tensor[D]

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.

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 torch.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.

Args: input (Tensor): the tensor to be reshaped shape (tuple of int): the new shape

Example:

val a = torch.arange(end = 4.0)
torch.reshape(a, 2, 2)
// tensor dtype=float32, shape=[2, 2], device=CPU
// [[0.0, 1.0],
//  [2.0, 3.0]]

val b = torch.Tensor(Seq(Seq(0, 1), Seq(2, 3)))
torch.reshape(b, -1)
// tensor dtype=int32, shape=[4], device=CPU
// [0, 1, 2, 3]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def select[D <: DType](input: Tensor[D], dim: Int, index: Int): Tensor[D]

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.

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

select is equivalent to slicing. For example:

torch.select(tensor, 0, index) is equivalent to tensor(index)

torch.select(tensor, 2, index) is equivalent to tensor(---, ---,index).

Value parameters

dim

the dimension to slice

index

the index to select with

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def squeeze[D <: DType](input: Tensor[D], dim: Int*): Tensor[D]

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

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

For example, if input is of shape: (A×1×B×C×1×D) then the input.squeeze() will be of shape: (A×B×C×D).

When dim is given, a squeeze operation is done only in the given dimension(s). If input is of shape: (A×1×B), squeeze(input, 0) leaves the tensor unchanged, but squeeze(input, 1) will squeeze the tensor to the shape (A×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.

Example::

val x = torch.zeros(Seq(2, 1, 2, 1, 2))
x.size
// Seq(2, 1, 2, 1, 2)
val a = torch.squeeze(x)
a.size
// Seq(2, 2, 2)
val b = torch.squeeze(x, 0)
b.size
// Seq(2, 1, 2, 1, 2)
val c = torch.squeeze(x, 1)
c.size
// Seq(2, 2, 1, 2)
val d = torch.squeeze(x, 1, 2, 3)
d.size
// Seq(2, 2, 2)

Value parameters

dim

if given, the input will be squeezed only in the specified dimensions.

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def stack[D <: DType](tensors: Seq[Tensor[D]], dim: Int): Tensor[D]

Concatenates a sequence of tensors along a new dimension.

Concatenates a sequence of tensors along a new dimension.

All tensors need to be of the same size.

Value parameters

dim

dimension to insert. Has to be between 0 and the number of dimensions of concatenated tensors (inclusive)

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Alias for torch.transpose.

Alias for torch.transpose.

This function is equivalent to NumPy's swapaxes function.

Examples::

val x = torch.Tensor(Seq(Seq(Seq(0, 1), Seq(2, 3)), Seq(Seq(4, 5), Seq(6, 7))))
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 1],
//   [2, 3]],
//
//  [[4, 5],
//   [6, 7]]]

torch.swapaxes(x, 0, 1)
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 1],
//   [4, 5]],
//
//  [[2, 3],
//   [6, 7]]]

torch.swapaxes(x, 0, 2)
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 4],
//   [2, 6]],
//
//  [[1, 5],
//   [3, 7]]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Alias for torch.transpose.

Alias for torch.transpose.

This function is equivalent to NumPy's swapaxes function.

Examples:

val x = torch.Tensor(Seq(Seq(Seq(0, 1), Seq(2, 3)), Seq(Seq(4, 5), Seq(6, 7))))
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 1],
//   [2, 3]],
//
//  [[4, 5],
//   [6, 7]]]

torch.swapdims(x, 0, 1)
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 1],
//   [4, 5]],
//
//  [[2, 3],
//   [6, 7]]]

torch.swapdims(x, 0, 2)
// tensor dtype=int32, shape=[2, 2, 2], device=CPU
// [[[0, 4],
//   [2, 6]],
//
//  [[1, 5],
//   [3, 7]]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def t[D <: DType](input: Tensor[D]): Tensor[D]

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

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).

Example:

val x = torch.arange(end = 6).reshape(2, 3)
// tensor dtype=int32, shape=[2, 3], device=CPU
// [[0, 1, 2],
//  [3, 4, 5]]
torch.t(x)
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[0, 3],
//  [1, 4],
//  [2, 5]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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.

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.

Example:

val src = torch.Tensor(Seq(Seq(4, 3, 5), Seq(6, 7, 8)))
val index = torch.Tensor(Seq(0L, 2L, 5L))
torch.take(src, index)
// tensor dtype=int32, shape=[3], device=CPU
// [4, 5, 8]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Selects values from input at the 1-dimensional indices from indices along the given dim.

Selects values from input at the 1-dimensional indices from indices along the given dim.

Functions that return indices along a dimension, like torch.argmax and torch.argsort, are designed to work with this function. See the examples below.

Example:

val t = torch.Tensor(Seq(Seq(10, 30, 20), Seq(60, 40, 50)))
val maxIdx = torch.argmax(t)
torch.takeAlongDim(t, maxIdx)
// tensor dtype=int32, shape=[1], device=CPU
// [60]
val sortedIdx = torch.argsort(t, dim = 1)
torch.takeAlongDim(t, sortedIdx, dim = 1)
// tensor([[10, 20, 30],
//         [40, 50, 60]])

Value parameters

dim

dimension to select along.

index

the indices into input

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

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.

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.

Example:

val x = torch.arange(end = 8)
torch.tensorSplit(x, 3)
// List(
//   [0, 1, 2],
//   [3, 4, 5],
//   [6, 7]
// )

val y = torch.arange(end = 7)
torch.tensorSplit(y, 3)
// List(
//   [0, 1, 2],
//   [3, 4],
//   [5, 6]
// )

torch.tensorSplit(x, Seq(1, 6))
// List(
//   [0],
//   [1, 2, 3, 4, 5],
//   [6]
// )

val z = torch.arange(end = 14).reshape(2, 7)
torch.tensorSplit(z, 3, dim = 1)
// List(
//   [[0, 1, 2],
//    [7, 8, 9]],
//   [[ 3,  4],
//    [10, 11]],
//   [[ 5,  6],
//    [12, 13]]
// )

Value parameters

dim

dimension along which to split the tensor. Default: 0

input

the tensor to split indices_or_sections (Tensor, int or list or 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)

splitSizeOrSections

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.

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def tile[D <: DType](input: Tensor[D], reps: Int*): Tensor[D]

Constructs a tensor by repeating the elements of input. The dims argument specifies the number of repetitions in each dimension.

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).

Example:

val x = torch.Tensor(Seq(1, 2, 3))
torch.tile(x, 2)
// tensor dtype=int32, shape=[6], device=CPU
// [1, 2, 3, 1, 2, 3]
val y = torch.Tensor(Seq(Seq(1, 2), Seq(3, 4)))
torch.tile(y, 2, 2)
// tensor dtype=int32, shape=[4, 4], device=CPU
// [[1, 2, 1, 2],
//  [3, 4, 3, 4],
//  [1, 2, 1, 2],
//  [3, 4, 3, 4]]

Value parameters

reps

the number of repetitions per dimension.

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Returns a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.

Returns a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.

If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other.

If input is a sparse tensor then the resulting out tensor does not share the underlying storage with the input tensor.

If input is a sparse tensor with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.

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.

Args:

: {input} dim0 (int): the first dimension to be transposed dim1 (int): the second dimension to be transposed

Example:

val x = torch.arange(1, 7).reshape(2, 3)
torch.transpose(x, 0, 1)
// tensor dtype=int32, shape=[3, 2], device=CPU
// [[1, 4],
//  [2, 5],
//  [3, 6]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def unbind[D <: DType](input: Tensor[D], dim: Int): Seq[Tensor[D]]

Removes a tensor dimension.

Removes a tensor dimension.

Returns a sequence of all slices along a given dimension, already without it.

Example:

val t = torch.arange(1, 10).reshape(3, 3)
torch.unbind(t)
// List(
//   tensor dtype=int32, shape=[3], device=CPU
//   [1, 2, 3],
//   tensor dtype=int32, shape=[3], device=CPU
//   [4, 5, 6],
//   tensor dtype=int32, shape=[3], device=CPU
//   [7, 8, 9]
// )

Value parameters

dim

dimension to remove

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def unsqueeze[D <: DType](input: Tensor[D], dim: Int): Tensor[D]

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

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

The returned tensor shares the same underlying data with this tensor.

A dim value within the range [-input.dim() - 1, input.dim() + 1] can be used. Negative dim will correspond to unsqueeze applied at dim = dim + input.dim() + 1.

Example:

val x = torch.Tensor(Seq(1, 2, 3, 4))
torch.unsqueeze(x, 0)
// tensor dtype=int32, shape=[1, 4], device=CPU
// [[1, 2, 3, 4]]
torch.unsqueeze(x, 1)
// tensor dtype=int32, shape=[4, 1], device=CPU
// [[1],
//  [2],
//  [3],
//  [4]]

Value parameters

dim

the index at which to insert the singleton dimension

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Splits input, a tensor with two or more dimensions, into multiple tensors vertically according to indicesOrSections. Each split is a view of input.

Splits input, a tensor with two or more dimensions, into multiple tensors vertically according to indicesOrSections. Each split is a view of input.

This is equivalent to calling torch.tensorSplit(input, indicesOrSections, dim=0) (the split dimension is 0), except that if indicesOrSections is an integer it must evenly divide the split dimension or a runtime error will be thrown.

Example:

val t = torch.arange(end = 16.0).reshape(4, 4)
torch.vsplit(t, 2)
// List(
//   tensor dtype=float32, shape=[2, 4], device=CPU
//   [[0.0, 1.0, 2.0, 3.0],
//    [4.0, 5.0, 6.0, 7.0]],
//   tensor dtype=float32, shape=[2, 4], device=CPU
//   [[8.0, 9.0, 10.0, 11.0],
//    [12.0, 13.0, 14.0, 15.0]]
// )

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala
def vstack[D <: DType](tensors: Seq[Tensor[D]]): Tensor[D]

Stack tensors in sequence vertically (row wise).

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 torch.atleast2d

Example:

val a = torch.Tensor(Seq(1, 2, 3))
val b = torch.Tensor(Seq(4, 5, 6))
torch.vstack(Seq(a, b))
// tensor dtype=int32, shape=[2, 3], device=CPU
// [[1, 2, 3],
//  [4, 5, 6]]

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Return a tensor of elements selected from either input or other, depending on condition.

Return a tensor of elements selected from either input or other, depending on condition.

Note

The tensors condition, input, other must be broadcastable.

Example:

val x = torch.randn(Seq(3, 2))
// tensor dtype=torch.float32, size=[3, 2]
// [[-0.4620,  0.3139],
//  [ 0.3898, -0.7197],
//  [ 0.0478, -0.1657]]

torch.where(x > 0, 1.0, 0.0)
// tensor dtype=torch.float32, size=[3, 2]
// [[0.0, 1.0],
//  [1.0, 0.0],
//  [1.0, 0.0]]

val y = torch.ones(Seq(3, 2))
torch.where(x > 0, x, y)
// tensor dtype=torch.float32, size=[3, 2]
// [[ 1.0,  0.3139],
//  [ 0.3898,  1.0],
//  [ 0.0478,  1.0]]

val z = torch.randn(Seq(2, 2))
// tensor dtype=torch.float32, size=[2, 2]
// [[ 1.0779,  0.0383],
//  [-0.8785, -1.1089]]

torch.where(x > 0, x, 0.0)
// tensor dtype=torch.float32, size=[2, 2]
// [[1.0779, 0.0383],
//  [0.0, 0.0]]

Value parameters

condition

When True (nonzero), yield input, otherwise yield other

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

comparison_ops

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

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

This is the second value returned by torch.sort. See its documentation for the exact semantics of this method.

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.

Args: {input} dim (int, optional): the dimension to sort along descending (bool, optional): controls the sorting order (ascending or descending) stable (bool, optional): controls the relative order of equivalent elements

Example:

val a = torch.randn(Seq(4, 4))
// tensor dtype=float32, shape=[4, 4], device=CPU
// [[ 0.0785,  1.5267, -0.8521,  0.4065],
//  [ 0.1598,  0.0788, -0.0745, -1.2700],
//  [ 1.2208,  1.0722, -0.7064,  1.2564],
//  [ 0.0669, -0.2318, -0.8229, -0.9280]]

torch.argsort(a, dim = 1)
// tensor dtype=int64, shape=[4, 4], device=CPU
// [[2, 0, 3, 1],
//  [3, 2, 1, 0],
//  [2, 1, 0, 3],
//  [3, 2, 1, 0]]

Attributes

Inherited from:
ComparisonOps (hidden)
Source
ComparisonOps.scala

Pointwise Ops

def abs[D <: NumericNN](input: Tensor[D]): Tensor[D]

Computes the absolute value of each element in input.

Computes the absolute value of each element in input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def acos[D <: DType](input: Tensor[D]): Tensor[D]

Computes the inverse cosine of each element in input.

Computes the inverse cosine of each element in input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def acosh[D <: DType](input: Tensor[D]): Tensor[D]

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Adds other to input.

Adds other to input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def add[D <: DType, D2 <: DType](input: Tensor[D], other: Tensor[D2]): Tensor[Promoted[D, D2]]

Adds other to input.

Adds other to input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Performs the element-wise division of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

Performs the element-wise division of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Performs the element-wise multiplication of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

Performs the element-wise multiplication of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Element-wise arctangent of (input / other) with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector (other, input) and vector (1, 0). (Note that other, the second parameter, is the x-coordinate, while input, the first parameter, is the y-coordinate.)

Element-wise arctangent of (input / other) with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector (other, input) and vector (1, 0). (Note that other, the second parameter, is the x-coordinate, while input, the first parameter, is the y-coordinate.)

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the bitwise AND of input and other. For bool tensors, it computes the logical AND.

Computes the bitwise AND of input and other. For bool tensors, it computes the logical AND.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the left arithmetic shift of input by other bits.

Computes the left arithmetic shift of input by other bits.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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.

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.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the bitwise OR of input and other. For bool tensors, it computes the logical OR.

Computes the bitwise OR of input and other. For bool tensors, it computes the logical OR.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the right arithmetic s\hift of input by other bits.

Computes the right arithmetic s\hift of input by other bits.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the bitwise XOR of input and other. For bool tensors, it computes the logical XOR.

Computes the bitwise XOR of input and other. For bool tensors, it computes the logical XOR.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Clamps all elements in input into the range [ min, max ]. Letting min_value and max_value be min and max, respectively, this returns: min(max(input, min_value), max_value) If min is None, there is no lower bound. Or, if max is None there is no upper bound.

Clamps all elements in input into the range [ min, max ]. Letting min_value and max_value be min and max, respectively, this returns: min(max(input, min_value), max_value) If min is None, there is no lower bound. Or, if max is None there is no upper bound.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the element-wise conjugate of the given input tensor. If input has a non-complex dtype, this function just returns input.

Computes the element-wise conjugate of the given input tensor. If input has a non-complex dtype, this function just returns input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def exp[D <: DType](input: Tensor[D]): Tensor[D]

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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.

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.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Raises input to the power of exponent, elementwise, in double precision. If neither input is complex returns a torch.float64 tensor, and if one or more inputs is complex returns a torch.complex128 tensor.

Raises input to the power of exponent, elementwise, in double precision. If neither input is complex returns a torch.float64 tensor, and if one or more inputs is complex returns a torch.complex128 tensor.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def floorDivide[D <: RealNN, D2 <: RealNN](input: Tensor[D], other: Tensor[D2])(using OnlyOneBool[D, D2]): Tensor[Promoted[D, D2]]

Computes input divided by other, elementwise, and floors the result.

Computes input divided by other, elementwise, and floors the result.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def fmod[D <: RealNN, D2 <: RealNN](input: Tensor[D], other: Tensor[D2])(using OnlyOneBool[D, D2]): Tensor[Promoted[D, D2]]

Applies C++’s std::fmod entrywise. The result has the same sign as the dividend input and its absolute value is less than that of other.

Applies C++’s std::fmod entrywise. The result has the same sign as the dividend input and its absolute value is less than that of other.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def frac[D <: FloatNN](input: Tensor[D]): Tensor[D]

Computes the fractional portion of each element in input.

Computes the fractional portion of each element in input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Decomposes input into mantissa and exponent tensors such that input = mantissa * (2 ** exponent) The range of mantissa is the open interval (-1, 1).

Decomposes input into mantissa and exponent tensors such that input = mantissa * (2 ** exponent) The range of mantissa is the open interval (-1, 1).

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Estimates the gradient of a function g:Rn → R in one or more dimensions using the second-order accurate central differences method.

Estimates the gradient of a function g:Rn → R in one or more dimensions using the second-order accurate central differences method.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Returns a new tensor containing imaginary values of the input tensor. The returned tensor and input share the same underlying storage.

Returns a new tensor containing imaginary values of the input tensor. The returned tensor and input share the same underlying storage.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def ldexp[D <: DType](input: Tensor[D], other: Tensor[D]): Tensor[D]

Multiplies input by 2 ** other.

Multiplies input by 2 ** other.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def lerp[D <: DType](input: Tensor[D], other: Tensor[D], weight: Tensor[D] | Float | Double): Tensor[D]

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

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

  • weight × (end − start)

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def lgamma[D <: RealNN](input: Tensor[D]): Tensor[D]

Computes the natural logarithm of the absolute value of the gamma function on input.

Computes the natural logarithm of the absolute value of the gamma function on input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Logarithm of the sum of exponentiations of the inputs. Calculates pointwise log log(e**x + e**y). 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 torch.logsumexp() which performs a reduction on a single tensor.

Logarithm of the sum of exponentiations of the inputs. Calculates pointwise log log(e**x + e**y). 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 torch.logsumexp() which performs a reduction on a single tensor.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Logarithm of the sum of exponentiations of the inputs in base-2. Calculates pointwise log2(2**x + 2**y). See torch.logaddexp() for more details.

Logarithm of the sum of exponentiations of the inputs in base-2. Calculates pointwise log2(2**x + 2**y). See torch.logaddexp() for more details.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def logicalAnd[D <: DType, D2 <: DType](input: Tensor[D], other: Tensor[D2]): Tensor[Bool]

Computes the element-wise logical AND of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Computes the element-wise logical AND of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes the element-wise logical NOT of the given input tensor. If the input tensor is not a bool tensor, zeros are treated as False and non-zeros are treated as True.

Computes the element-wise logical NOT of the given input tensor. If the input tensor is not a bool tensor, zeros are treated as False and non-zeros are treated as True.

TODO If not specified, the output tensor will have the bool dtype.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def logicalOr[D <: DType, D2 <: DType](input: Tensor[D], other: Tensor[D2]): Tensor[Bool]

Computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def logicalXor[D <: DType, D2 <: DType](input: Tensor[D], other: Tensor[D2]): Tensor[Bool]

Computes the element-wise logical XOR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Computes the element-wise logical XOR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def mul[D <: DType, D2 <: DType](input: Tensor[D], other: Tensor[D2]): Tensor[Promoted[D, D2]]

Multiplies input by other.

Multiplies input by other.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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.

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.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def neg[D <: NumericNN](input: Tensor[D]): Tensor[D]

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Returns input. Normally throws a runtime error if input is a bool tensor in pytorch.

Returns input. Normally throws a runtime error if input is a bool tensor in pytorch.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def pow[D <: DType, D2 <: DType](input: Tensor[D], exponent: Tensor[D2])(using ev1: NotEqual[Promoted[D, D2], Bool], ev2: NotEqual[Promoted[D, D2], Complex32]): Tensor[Promoted[D, D2]]

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.

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.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Returns a new tensor containing real values of the self tensor. The returned tensor and self share the same underlying storage.

Returns a new tensor containing real values of the self tensor. The returned tensor and self share the same underlying storage.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Computes Python’s modulus operation entrywise. The result has the same sign as the divisor other and its absolute value is less than that of other.

Computes Python’s modulus operation entrywise. The result has the same sign as the divisor other and its absolute value is less than that of other.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Rounds elements of input to the nearest integer. If decimals is negative, it specifies the number of positions to the left of the decimal point.

Rounds elements of input to the nearest integer. If decimals is negative, it specifies the number of positions to the left of the decimal point.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def sgn[D <: DType](input: Tensor[D]): Tensor[D]

This function is an extension of torch.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 torch.sign() for non-complex tensors.

This function is an extension of torch.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 torch.sign() for non-complex tensors.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def sign[D <: RealNN](input: Tensor[D]): Tensor[D]

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Tests if each element of `input`` has its sign bit set or not.

Tests if each element of `input`` has its sign bit set or not.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Subtracts other, scaled by alpha, from input.

Subtracts other, scaled by alpha, from input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Alias for torch.div() with rounding_mode=None

Alias for torch.div() with rounding_mode=None

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

other_ops

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

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

Einsum allows computing many common multi-dimensional linear algebraic array operations by representing them in a short-hand format based on the Einstein summation convention, given by equation. The details of this format are described below, but the general idea is to label every dimension of the input operands with some subscript and define which subscripts are part of the output. The output is then computed by summing the product of the elements of the operands along the dimensions whose subscripts are not part of the output. For example, matrix multiplication can be computed using einsum as [torch.einsum("ij,jk->ik", A, B)]. Here, j is the summation subscript and i and k the output subscripts (see section below for more details on why).

Equation:

The equation string specifies the subscripts (letters in [[a-zA-Z]]) for each dimension of the input operands in the same order as the dimensions, separating subscripts for each operand by a comma (','), e.g. ['ij,jk'] specify subscripts for two 2D operands. The dimensions labeled with the same subscript must be broadcastable, that is, their size must either match or be [1]. The exception is if a subscript is repeated for the same input operand, in which case the dimensions labeled with this subscript for this operand must match in size and the operand will be replaced by its diagonal along these dimensions. The subscripts that appear exactly once in the equation will be part of the output, sorted in increasing alphabetical order. The output is computed by multiplying the input operands element-wise, with their dimensions aligned based on the subscripts, and then summing out the dimensions whose subscripts are not part of the output.

Optionally, the output subscripts can be explicitly defined by adding an arrow ('->') at the end of the equation followed by the subscripts for the output. For instance, the following equation computes the transpose of a matrix multiplication: 'ij,jk->ki'. The output subscripts must appear at least once for some input operand and at most once for the output.

Ellipsis ('...') can be used in place of subscripts to broadcast the dimensions covered by the ellipsis. Each input operand may contain at most one ellipsis which will cover the dimensions not covered by subscripts, e.g. for an input operand with 5 dimensions, the ellipsis in the equation ['ab...c'] cover the third and fourth dimensions. The ellipsis does not need to cover the same number of dimensions across the operands but the 'shape' of the ellipsis (the size of the dimensions covered by them) must broadcast together. If the output is not explicitly defined with the arrow ('->') notation, the ellipsis will come first in the output (left-most dimensions), before the subscript labels that appear exactly once for the input operands. e.g. the following equation implements batch matrix multiplication ['...ij,...jk'].

A few final notes: the equation may contain whitespaces between the different elements (subscripts, ellipsis, arrow and comma) but something like ['. . .'] is not valid. An empty string [''] is valid for scalar operands.

Note: Sublist format it not supported yet

Example:

import torch.*
// trace
torch.einsum("ii", torch.randn(Seq(4, 4)))

// diagonal
torch.einsum("ii->i", torch.randn(Seq(4, 4)))

// outer product
val x = torch.randn(Seq(5))
val y = torch.randn(Seq(4))
torch.einsum("i,j->ij", x, y)

// batch matrix multiplication
val As = torch.randn(Seq(3, 2, 5))
val Bs = torch.randn(Seq(3, 5, 4))
torch.einsum("bij,bjk->bik", As, Bs)

// with sublist format and ellipsis
// Not supported yet in Storch
// torch.einsum(As, Seq(---, 0, 1), Bs, Seq(---, 1, 2), Seq(---, 0, 2))

// batch permute
val A = torch.randn(Seq(2, 3, 4, 5))
torch.einsum("...ij->...ji", A).shape
// equivalent to torch.nn.functional.bilinear
val A = torch.randn(Seq(3, 5, 4))
val l = torch.randn(Seq(2, 5))
val r = torch.randn(Seq(2, 4))
torch.einsum("bn,anm,bm->ba", l, A, r)

Value parameters

equation

The subscripts for the Einstein summation.

operands

The tensors to compute the Einstein summation of.

Attributes

Inherited from:
OtherOps (hidden)
Source
OtherOps.scala

Creation Ops

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.

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 that non-integer step is subject to floating point rounding errors when comparing against end; to avoid inconsistency, we advise adding a small epsilon to end in such cases.

$$ \text{out}{{i+1}} = \text{out}{i} + \text{step} $$

Value parameters

end

The ending value for the set of points

start

The starting value for the set of points. Default: 0.

step

The gap between each pair of adjacent points. Default: 1.

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

Returns a tensor filled with uninitialized data.

Returns a tensor filled with uninitialized data.

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

Returns an uninitialized tensor with the same size as input.

Returns an uninitialized tensor with the same size as input.

torch.empty_like(input) is equivalent to torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

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

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

Value parameters

device

the desired device of the returned tensor.

dtype

the desired data type of the returned tensor.

layout

the desired layout of the returned tensor.

m

the number of columns with default being n

n

the number of rows

requiresGrad

If autograd should record operations on the returned tensor.

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

Creates a tensor of size size filled with fillValue. The tensor's dtype is inferred from fillValue.

Creates a tensor of size size filled with fillValue. The tensor's dtype is inferred from fillValue.

Type parameters

T

the data type of the returned tensor, or Default if the type should be derived from fillValue.

U

the data type of fillValue.

Value parameters

device

the desired device of the returned tensor.

dtype

the desired data type of the returned tensor.

fillValue

the value to fill the output tensor with.

layout

the desired layout of the returned Tensor.

requiresGrad

If autograd should record operations on the returned tensor.

size

a sequence of integers defining the shape of the output tensor.

Attributes

Returns

the newly created tensor.

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

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

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

Value parameters

size

a sequence of integers defining the shape of the output tensor.

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

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

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

Value parameters

size

a sequence of integers defining the shape of the output tensor.

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

Type members

Classlikes

sealed abstract class BFloat16 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bfloat16.type
sealed class BFloat16Tensor(native: Tensor) extends Tensor[BFloat16]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[BFloat16]
class Object
trait Matchable
class Any
sealed abstract class Bits16 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bits16.type
sealed class Bits16Tensor(native: Tensor) extends Tensor[Bits16]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bits16]
class Object
trait Matchable
class Any
sealed abstract class Bits1x8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bits1x8.type
sealed class Bits1x8Tensor(native: Tensor) extends Tensor[Bits1x8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bits1x8]
class Object
trait Matchable
class Any
sealed abstract class Bits2x4 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bits2x4.type
sealed class Bits2x4Tensor(native: Tensor) extends Tensor[Bits2x4]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bits2x4]
class Object
trait Matchable
class Any
sealed abstract class Bits4x2 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bits4x2.type
sealed class Bits4x2Tensor(native: Tensor) extends Tensor[Bits4x2]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bits4x2]
class Object
trait Matchable
class Any
sealed abstract class Bits8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bits8.type
sealed class Bits8Tensor(native: Tensor) extends Tensor[Bits8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bits8]
class Object
trait Matchable
class Any
sealed abstract class Bool extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object bool.type
sealed class BoolTensor(native: Tensor) extends Tensor[Bool]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Bool]
class Object
trait Matchable
class Any
sealed abstract class Complex128 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object complex128.type
sealed class Complex128Tensor(native: Tensor) extends Tensor[Complex128]

Attributes

Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
sealed abstract class Complex32 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object complex32.type
sealed class Complex32Tensor(native: Tensor) extends Tensor[Complex32]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Complex32]
class Object
trait Matchable
class Any
sealed abstract class Complex64 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object complex64.type
sealed class Complex64Tensor(native: Tensor) extends Tensor[Complex64]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Complex64]
class Object
trait Matchable
class Any
sealed abstract class DType

A torch.DType is an object that represents the data type of a torch.Tensor. PyTorch has twelve different data types:

A torch.DType is an object that represents the data type of a torch.Tensor. PyTorch has twelve different data types:

Data type dtype
32-bit floating point torch.float32 or torch.float
64-bit floating point torch.float64 or torch.double
64-bit complex torch.complex64 or torch.cfloat
128-bit complex torch.complex128 or torch.cdouble
16-bit floating point[1] torch.float16 or torch.half
16-bit floating point[2] torch.bfloat16
8-bit integer (unsigned) torch.uint8
8-bit integer (signed) torch.int8
16-bit integer (signed) torch.int16 or torch.short
32-bit integer (signed) torch.int32 or torch.int
64-bit integer (signed) torch.int64 or torch.long
Boolean torch.bool

To find out if a torch.dtype is a floating point data type, the property is_floating_point can be used, which returns True if the data type is a floating point data type.

To find out if a torch.dtype is a complex data type, the property is_complex can be used, which returns True if the data type is a complex data type.

When the dtypes of inputs to an arithmetic operation (add, sub, div, mul) differ, we promote by finding the minimum dtype that satisfies the following rules:

  • If the type of a scalar operand is of a higher category than tensor operands (where complex > floating > integral > boolean), we promote to a type with sufficient size to hold all scalar operands of that category.
  • If a zero-dimension tensor operand has a higher category than dimensioned operands, we promote to a type with sufficient size and category to hold all zero-dim tensor operands of that category.
  • If there are no higher-category zero-dim operands, we promote to a type with sufficient size and category to hold all dimensioned operands.

A floating point scalar operand has dtype torch.get_default_dtype() and an integral non-boolean scalar operand has dtype torch.int64. Unlike numpy, we do not inspect values when determining the minimum dtypes of an operand. Quantized and complex types are not yet supported.

[1] Sometimes referred to as binary16: uses 1 sign, 5 exponent, and 10 significand bits. Useful when precision is important.

[2] Sometimes referred to as Brain Floating Point: use 1 sign, 8 exponent and 7 significand bits. Useful when range is important, since it has the same number of exponent bits as float32

Attributes

Companion
object
Source
DType.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class BFloat16
object bfloat16.type
class Bits16
object bits16.type
class Bits1x8
object bits1x8.type
class Bits2x4
object bits2x4.type
class Bits4x2
object bits4x2.type
class Bits8
object bits8.type
class Bool
object bool.type
class Complex128
object complex128.type
class Complex32
object complex32.type
class Complex64
object complex64.type
class Float16
object float16.type
class Float32
object float32.type
class Float64
object float64.type
object float8_e4m3fn.type
class Float8_e5m2
object float8_e5m2.type
class Int16
object int16.type
class Int32
object int32.type
class Int64
object int64.type
class Int8
object int8.type
class NumOptions
object numoptions.type
class QInt32
object qint32.type
class QInt8
object qint8.type
class QUInt2x4
object quint2x4.type
class QUInt4x2
object quint4x2.type
class QUInt8
object quint8.type
class UInt8
object uint8.type
class Undefined
object undefined.type
Show all
object DType

Attributes

Companion
class
Source
DType.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
DType.type
trait Default[+D <: DType]

Default tensor type.

Default tensor type.

Defaults to float32 but can be overriden by providing providing the DType explicitly, or by overriding the default in the current scope through an import:

Example:

import torch.*

// Default:
nn.Linear(10, 10) // Linear[Float32]

// Override explicitly:
nn.Linear[BFloat16](10, 10) // Linear[BFloat16]

// Override default:
import Default.float64
nn.Linear(10, 10) // Linear[Float64]

Attributes

Companion
object
Source
DType.scala
Supertypes
class Object
trait Matchable
class Any
object Default extends LowPriorityDefaults

Attributes

Companion
trait
Source
DType.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Default.type
sealed class Derive

Attributes

Source
DType.scala
Supertypes
class Object
trait Matchable
class Any
case class Device(device: DeviceType, index: Byte)

Attributes

Companion
object
Source
Device.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Device

Attributes

Companion
class
Source
Device.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Device.type
enum DeviceType

Attributes

Companion
object
Source
Device.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object DeviceType

Attributes

Companion
enum
Source
Device.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
DeviceType.type
sealed abstract class Float16 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object float16.type
sealed class Float16Tensor(native: Tensor) extends Tensor[Float16]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Float16]
class Object
trait Matchable
class Any
sealed abstract class Float32 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object float32.type
sealed class Float32Tensor(native: Tensor) extends Tensor[Float32]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Float32]
class Object
trait Matchable
class Any
sealed abstract class Float64 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object float64.type
sealed class Float64Tensor(native: Tensor) extends Tensor[Float64]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Float64]
class Object
trait Matchable
class Any
sealed abstract class Float8_e4m3fn extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object float8_e4m3fn.type
sealed class Float8_e4m3fnTensor(native: Tensor) extends Tensor[Float8_e4m3fn]

Attributes

Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
sealed abstract class Float8_e5m2 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object float8_e5m2.type
sealed class Float8_e5m2Tensor(native: Tensor) extends Tensor[Float8_e5m2]

Attributes

Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
class Generator(val device: Device)

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

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

Attributes

Source
Generator.scala
Supertypes
class Object
trait Matchable
class Any
sealed abstract class Int16 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object int16.type
sealed class Int16Tensor(native: Tensor) extends Tensor[Int16]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Int16]
class Object
trait Matchable
class Any
sealed abstract class Int32 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object int32.type
sealed class Int32Tensor(native: Tensor) extends Tensor[Int32]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Int32]
class Object
trait Matchable
class Any
sealed abstract class Int64 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object int64.type
sealed class Int64Tensor(native: Tensor) extends Tensor[Int64]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Int64]
class Object
trait Matchable
class Any
sealed abstract class Int8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object int8.type
sealed class Int8Tensor(native: Tensor) extends Tensor[Int8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Int8]
class Object
trait Matchable
class Any
enum Layout

A torch.layout is an object that represents the memory layout of a torch.Tensor.

A torch.layout is an object that represents the memory layout of a torch.Tensor.

Currently, we support torch.strided (dense Tensors) and have beta support for torch.sparse_coo (sparse COO Tensors).

torch.strided represents dense Tensors and is the memory layout that is most commonly used. Each strided tensor has an associated torch.Storage, which holds its data. These tensors provide multi-dimensional, strided view of a storage. Strides are a list of integers: the k-th stride represents the jump in the memory necessary to go from one element to the next one in the k-th dimension of the Tensor. This concept makes it possible to perform many tensor operations efficiently.

Attributes

Companion
object
Source
Layout.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Layout

Attributes

Companion
enum
Source
Layout.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Layout.type

Attributes

Source
DType.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Default.type

A memoryFormat is an object representing the memory format on which a torch.Tensor is or will be allocated.

A memoryFormat is an object representing the memory format on which a torch.Tensor is or will be allocated.

Attributes

Source
MemoryFormat.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed abstract class NumOptions extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object numoptions.type
sealed class NumOptionsTensor(native: Tensor) extends Tensor[NumOptions]

Attributes

Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
sealed abstract class QInt32 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object qint32.type
sealed class QInt32Tensor(native: Tensor) extends Tensor[QInt32]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[QInt32]
class Object
trait Matchable
class Any
sealed abstract class QInt8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object qint8.type
sealed class QInt8Tensor(native: Tensor) extends Tensor[QInt8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[QInt8]
class Object
trait Matchable
class Any
sealed abstract class QUInt2x4 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object quint2x4.type
sealed class QUInt2x4Tensor(native: Tensor) extends Tensor[QUInt2x4]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[QUInt2x4]
class Object
trait Matchable
class Any
sealed abstract class QUInt4x2 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object quint4x2.type
sealed class QUInt4x2Tensor(native: Tensor) extends Tensor[QUInt4x2]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[QUInt4x2]
class Object
trait Matchable
class Any
sealed abstract class QUInt8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object quint8.type
sealed class QUInt8Tensor(native: Tensor) extends Tensor[QUInt8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[QUInt8]
class Object
trait Matchable
class Any
sealed abstract class Tensor[D <: DType](val native: Tensor)

A torch.Tensor is a multi-dimensional matrix containing elements of a single data type.

A torch.Tensor is a multi-dimensional matrix containing elements of a single data type.

Attributes

Companion
object
Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Tensor

Attributes

Companion
class
Source
Tensor.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Tensor.type

Attributes

Source
Tensor.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed abstract class UInt8 extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object uint8.type
sealed class UInt8Tensor(native: Tensor) extends Tensor[UInt8]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[UInt8]
class Object
trait Matchable
class Any
sealed abstract class Undefined extends DType

Attributes

Source
DType.scala
Supertypes
class DType
class Object
trait Matchable
class Any
Known subtypes
object undefined.type
sealed class UndefinedTensor(native: Tensor) extends Tensor[Undefined]

Attributes

Source
Tensor.scala
Supertypes
class Tensor[Undefined]
class Object
trait Matchable
class Any
object hub

Utilities to download and cache pre-trained model weights.

Utilities to download and cache pre-trained model weights.

Attributes

Source
hub.scala
Supertypes
class Object
trait Matchable
class Any
Self type
hub.type
object indexing

Attributes

Source
indexing.scala
Supertypes
class Object
trait Matchable
class Any
Self type
indexing.type

Types

Attributes

Source
Types.scala
type BitwiseNN = Bool | IntNN

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type ComplexPromoted[T <: DType, U <: DType] = (T, U) match { case (ComplexNN, U) => Complex128 case (T, ComplexNN) => Complex128 case Any => Float64 }

Promoted type for tensor operations that always output full sized complex or real (e.g. floatPower)

Promoted type for tensor operations that always output full sized complex or real (e.g. floatPower)

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type ComplexToReal[D <: DType] = D match { case Complex32 => Float16 case Complex64 => Float32 case Complex128 => Float64 case Any => D }

Demoted type for complex to real type extractions (e.g. imag, real)

Demoted type for complex to real type extractions (e.g. imag, real)

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type DTypeOrDeriveFromScalar[T <: DType | Derive, U <: ScalaType] = T match { case Derive => ScalaToDType[U] case T => TensorType[T] }

Attributes

Source
DType.scala
type DTypeOrDeriveFromTensor[D1 <: DType, U <: DType | Derive] = U match { case Derive => D1 case U => TensorType[U] }

Attributes

Source
DType.scala
type DTypeToScala[T <: DType] = T match { case UInt8 => UByte case Int8 => Byte case Int16 => Short case Int32 => Int case Int64 => Long case Float16 => Float case Float32 => Float case Float64 => Double case Complex32 => Complex[Float] case Complex64 => Complex[Float] case Complex128 => Complex[Double] case Bool => Boolean case Any => ScalaType }

Attributes

Source
DType.scala
type Div[T <: DType, U <: DType] = (T, U) match { case (BitwiseNN, BitwiseNN) => Float32 case Any => Promoted[T, U] }

Promoted type for tensor division

Promoted type for tensor division

Attributes

Source
DType.scala

DType combinations *

DType combinations *

Attributes

Source
DType.scala
type FloatPromoted[D <: DType] = D match { case Float16 => Float16 case BFloat16 => BFloat16 case Float64 => Float64 case Complex32 => Complex32 case Complex64 => Complex64 case Complex128 => Complex128 case Any => Float32 }

Promoted type for tensor operations that always output floats (e.g. sin)

Promoted type for tensor operations that always output floats (e.g. sin)

Attributes

Source
DType.scala
type IntNN = Int8 | UInt8 | Int16 | Int32 | Int64

Attributes

Source
DType.scala
type NotEqual[D <: DType, D2 <: DType] = NotGiven[D =:= D2]

Attributes

Source
Types.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type NumericPromoted[D <: DType] = D match { case Bool => Int64 case Any => D }

Promoted type for tensor operations that always output numbers (e.g. square)

Promoted type for tensor operations that always output numbers (e.g. square)

Attributes

Source
DType.scala

Scala type combinations *

Scala type combinations *

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type OnlyOneBool[A <: DType, B <: DType] = NotGiven[A =:= Bool & B =:= Bool]

Attributes

Source
Types.scala
type PromotedDType[A <: DType, B <: DType] = (A, B) match { case (Float64, B) => Float32 case (A, Float64) => Float32 case (Float32, B) => Float32 case (A, Float32) => Float32 case (Int64, B) => Int64 case (A, Int64) => Int64 case (Int32, B) => Int32 case (A, Int32) => Int32 case Any => Int64 }

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type ScalaToDType[S <: ScalaType] = S match { case UByte => UInt8 case Byte => Int8 case Short => Int16 case Int => Int32 case Long => Int64 case Float => Float32 case Double => Float64 case Boolean => Bool case Complex[Float] => Complex64 case Complex[Double] => Complex128 }

Attributes

Source
DType.scala

Attributes

Source
DType.scala
type Sum[D <: DType] = D match { case BitwiseNN => Int64 case D => D }

Promoted type for elementwise tensor sum

Promoted type for elementwise tensor sum

Attributes

Source
DType.scala
type TensorOrReal[D <: RealNN] = Tensor[D] | Real

Attributes

Source
Types.scala
type TensorType[T] = T match { case UInt8 => UInt8 case Int8 => Int8 case Int16 => Int16 case Int32 => Int32 case Int64 => Int64 case Float16 => Float16 case Float32 => Float32 case Float64 => Float64 case Complex32 => Complex32 case Complex64 => Complex64 case Complex128 => Complex128 case Bool => Bool case QInt8 => QInt8 case QUInt8 => QUInt8 case QInt32 => QInt32 case BFloat16 => BFloat16 case QUInt4x2 => QUInt4x2 case QUInt2x4 => QUInt2x4 case Bits1x8 => Bits1x8 case Bits2x4 => Bits2x4 case Bits4x2 => Bits4x2 case Bits8 => Bits8 case Bits16 => Bits16 case Float8_e5m2 => Float8_e5m2 case Float8_e4m3fn => Float8_e4m3fn case Undefined => Undefined case NumOptions => NumOptions case DType => DType }

Attributes

Source
DType.scala

Value members

Concrete methods

transparent inline def deriveDType[T <: DType]: DType

Attributes

Source
DType.scala
def noGrad[A](op: => A): A

Disable gradient calculation for op.

Disable gradient calculation for op.

Disabling gradient calculation is useful for inference, when you are sure that you will not call Tensor.backward(). It will reduce memory consumption for computations that would otherwise have requiresGrad=true.

In this mode, the result of every computation will have requiresGrad=false, even when the inputs have requiresGrad=true.

This context manager is thread local; it will not affect computation in other threads.

Attributes

Source
package.scala
def scalaToDType[S <: ScalaType](s: S): DType

Attributes

Source
DType.scala

Inherited methods

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Attributes

Inherited from:
RandomSamplingOps (hidden)
Source
RandomSamplingOps.scala
def matmul[D1 <: DType, D2 <: DType](t1: Tensor[D1], t2: Tensor[D2]): Tensor[Promoted[D1, D2]]

Attributes

Inherited from:
BLASOps (hidden)
Source
BLASOps.scala

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala
def pickleSave(tensors: SeqMap[String, Tensor[DType]]): SeqMap[IValue, IValue]

Attributes

Inherited from:
CreationOps (hidden)
Source
CreationOps.scala

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

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

The shape of the tensor is defined by the variable argument size.

Type parameters

T

the dtype of the created tensor.

Value parameters

device

the desired device of returned tensor.

dtype

the desired data type of returned tensor.

layout

the desired layout of returned Tensor.

requiresGrad

If autograd should record operations on the returned tensor.

size

a sequence of integers defining the shape of the output tensor.

Attributes

Inherited from:
RandomSamplingOps (hidden)
Source
RandomSamplingOps.scala

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

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

torch.randLike(input) is equivalent to torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Value parameters

device

the desired device of returned tensor. If derive , defaults to the device of input.

dtype

the desired data type of returned Tensor. If derive, defaults to the dtype of input.

input

the size of input will determine size of the output tensor.

layout

the desired layout of returned tensor. If derive, defaults to the layout of input.

memoryFormat

the desired memory format of returned Tensor.

requiresGrad

If autograd should record operations on the returned tensor.

Attributes

Inherited from:
RandomSamplingOps (hidden)
Source
RandomSamplingOps.scala

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

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.

Type parameters

T

the dtype of the created tensor.

Value parameters

device

the desired device of returned tensor.

dtype

the desired data type of returned tensor.

generator

a pseudorandom number generator for sampling

high

One above the highest integer to be drawn from the distribution.

layout

the desired layout of returned Tensor.

low

Lowest integer to be drawn from the distribution. Default: 0.

requiresGrad

If autograd should record operations on the returned tensor.

size

a tuple defining the shape of the output tensor.

Attributes

Inherited from:
RandomSamplingOps (hidden)
Source
RandomSamplingOps.scala

Returns a random permutation of integers from 0 to n - 1.

Returns a random permutation of integers from 0 to n - 1.

TODO support custom generator

Attributes

Inherited from:
RandomSamplingOps (hidden)
Source
RandomSamplingOps.scala

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala

Splits the tensor into chunks. Each chunk is a view of the original tensor.

Splits the tensor into chunks. Each chunk is a view of the original tensor.

If splitSizeOrSections is an integer type, then tensor will be split into equally sized chunks (if possible). Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by splitSize.

If splitSizeOrSections is a list, then tensor will be split into len(splitSizeOrSections) chunks with sizes in dim according to splitSizeOrSections.

Example:

val a = torch.arange(end = 10).reshape(5, 2)
// tensor dtype=int32, shape=[5, 2], device=CPU
// [[0, 1],
//  [2, 3],
//  [4, 5],
//  [6, 7],
//  [8, 9]]

torch.split(a, 2)
// List(
//   tensor dtype=int32, shape=[2, 2], device=CPU
//   [[0, 1],
//    [2, 3]],
//   tensor dtype=int32, shape=[2, 2], device=CPU
//   [[4, 5],
//    [6, 7]],
//   tensor dtype=int32, shape=[1, 2], device=CPU
//   [[8, 9]]
// )

torch.split(a, Seq(1, 4))
// List(
//   tensor dtype=int32, shape=[1, 2], device=CPU
//   [[0, 1]]
//   tensor dtype=int32, shape=[4, 2], device=CPU
//   [[2, 3],
//    [4, 5],
//    [6, 7],
//    [8, 9]]
// )

Attributes

Inherited from:
IndexingSlicingJoiningOps (hidden)
Source
IndexingSlicingJoiningOps.scala

Attributes

Inherited from:
PointwiseOps (hidden)
Source
PointwiseOps.scala
def trace[D <: DType](input: Tensor[D]): Tensor[D]

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

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

Attributes

Inherited from:
OtherOps (hidden)
Source
OtherOps.scala
def tril[D <: DType](input: Tensor[D], diagonal: Int): Tensor[D]

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.

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 controls which diagonal to consider. If 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 ${(i,i)}$ for $i \in [0,min⁡{d1,d2}−1]$ where $d_1​,d_2​$ are the dimensions of the matrix.

Value parameters

diagonal

the diagonal to consider

input

the input tensor.

Attributes

Returns

out the output tensor.

Example
val a = torch.randn(3, 3)
torch.tril(a)
val b = torch.randn(4, 6)
torch.tril(b, diagonal=1)
torch.tril(b, diagonal=-1)
Inherited from:
ReductionOps (hidden)
Source
ReductionOps.scala

Concrete fields

Attributes

Source
DType.scala
val bits16: Bits16

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala
val bits8: Bits8

Attributes

Source
DType.scala
val bool: Bool

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
Types.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala
val int16: Int16

Attributes

Source
DType.scala
val int32: Int32

Attributes

Source
DType.scala
val int64: Int64

Attributes

Source
DType.scala
val int8: Int8

Attributes

Source
DType.scala

Attributes

Source
DType.scala
val qint32: QInt32

Attributes

Source
DType.scala
val qint8: QInt8

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Attributes

Source
DType.scala
val quint8: QUInt8

Attributes

Source
DType.scala

Attributes

Source
Types.scala

Attributes

Source
Types.scala
val uint8: UInt8

Attributes

Source
DType.scala

Attributes

Source
DType.scala

Givens

Givens

Attributes

Source
Types.scala

Extensions

Extensions

extension [S <: ScalaType](s: S)
def *[D <: DType](t: Tensor[D]): Tensor[Promoted[D, ScalaToDType[S]]]

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala
def +[D <: DType](t: Tensor[D]): Tensor[Promoted[D, ScalaToDType[S]]]

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala
def -[D <: DType](t: Tensor[D]): Tensor[Promoted[D, ScalaToDType[S]]]

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala
def /[D <: DType](t: Tensor[D]): Tensor[Div[D, ScalaToDType[S]]]

Scalar/Tensor extensions to allow tensor operations directly on scalars

Scalar/Tensor extensions to allow tensor operations directly on scalars

Attributes

Source
Tensor.scala

Exports

Defined exports

val ---: Ellipsis.type
Exported from indexing

Ellipsis or ... in Python syntax.

Ellipsis or ... in Python syntax.

Attributes

Source
indexing.scala
val ::: Slice
Exported from indexing

Range (colon / :) in python syntax.

Range (colon / :) in python syntax.

Attributes

Source
indexing.scala
final val Ellipsis: Ellipsis.type
Exported from indexing
final type Ellipsis = Ellipsis
Exported from indexing$

Attributes

Source
indexing.scala
final val Slice: Slice.type
Exported from indexing
final type Slice = Slice
Exported from indexing$

Attributes

Source
indexing.scala
val derive: Derive
Exported from Derive

Attributes

Source
DType.scala

Inherited defined exports

Exported from `package`

Computes the logarithmic derivative of the gamma function on input.

Computes the logarithmic derivative of the gamma function on input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the error function of input.

Computes the error function of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the complementary error function of input.

Computes the complementary error function of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the inverse error function of input. The inverse error function is defined in the range (−1,1)

Computes the inverse error function of input. The inverse error function is defined in the range (−1,1)

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the base two exponential function of input.

Computes the base two exponential function of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the exponential of the elements minus 1 of input.

Computes the exponential of the elements minus 1 of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Returns a new tensor with the logit of the elements of input. input is clamped to [eps, 1 - eps] when eps is not None. When eps is None and input < 0 or input > 1, the function will yields NaN.

Returns a new tensor with the logit of the elements of input. input is clamped to [eps, 1 - eps] when eps is not None. When eps is None and input < 0 or input > 1, the function will yields NaN.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the multivariate log-gamma function with dimension p element-wise

Computes the multivariate log-gamma function with dimension p element-wise

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the nth derivative of the digamma function on input. n≥0 is called the order of the polygamma function.

Computes the nth derivative of the digamma function on input. n≥0 is called the order of the polygamma function.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Computes the expit (also known as the logistic sigmoid function) of the elements of input.

Computes the expit (also known as the logistic sigmoid function) of the elements of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

Returns a new tensor with the normalized sinc of the elements of input.

Returns a new tensor with the normalized sinc of the elements of input.

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala
Exported from `package`

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

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

Attributes

Inherited from:
PointwiseOps (hidden)
Source
package.scala